Skip to content

Commit

Permalink
feat: l1 and l2 tx spammer
Browse files Browse the repository at this point in the history
  • Loading branch information
leovct committed Apr 25, 2024
1 parent ba2fecd commit f8db025
Show file tree
Hide file tree
Showing 7 changed files with 168 additions and 0 deletions.
24 changes: 24 additions & 0 deletions doc-drafts/workload.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
FROM golang:1.21 AS polycli-builder
ARG POLYCLI_VERSION
WORKDIR /opt/polygon-cli
RUN git clone --branch ${POLYCLI_VERSION} https://github.com/maticnetwork/polygon-cli.git . \
&& CGO_ENABLED=0 go build -o polycli main.go


FROM ubuntu:22.04
LABEL author="[email protected]"
LABEL description="Helper image capable of executing diverse workloads"

COPY --from=polycli-builder /opt/polygon-cli/polycli /usr/bin/polycli
# WARNING (DL3008): Pin versions in apt get install.
# WARNING (DL4006): Set the SHELL option -o pipefail before RUN with a pipe in it
# WARNING (SC1091): (Sourced) file not included in mock.
# hadolint ignore=DL3008,DL4006,SC1091
RUN apt-get update \
&& apt-get install --yes --no-install-recommends curl jq git python3-pip \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* \
&& pip3 install yq \
&& curl --silent --location --proto "=https" https://foundry.paradigm.xyz | bash \
&& /root/.foundry/bin/foundryup \
&& cp /root/.foundry/bin/* /usr/local/bin
15 changes: 15 additions & 0 deletions main.star
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ cdk_central_environment_package = import_module("./cdk_central_environment.star"
cdk_bridge_infra_package = import_module("./cdk_bridge_infra.star")
zkevm_permissionless_node_package = import_module("./zkevm_permissionless_node.star")
observability_package = import_module("./observability.star")
workload_package = import_module("./workload.star")


def run(
Expand All @@ -16,6 +17,7 @@ def run(
deploy_cdk_central_environment=True,
deploy_zkevm_permissionless_node=True,
deploy_observability=True,
apply_workload=True,
args={
"deployment_suffix": "-001",
"zkevm_prover_image": "hermeznetwork/zkevm-prover:v6.0.0",
Expand Down Expand Up @@ -102,6 +104,12 @@ def run(
"zkevm_aggregator_host": "zkevm-node-aggregator-001",
"genesis_file": "templates/permissionless-node/genesis.json",
"polycli_version": "v0.1.42",
"workload_scripts": [
"polycli_loadtest_on_l1 t 100 10", # eth tranfers
"polycli_rpcfuzz_on_l1", # rpc calls
"polycli_loadtest_on_l2 t 100 10",
"polycli_rpcfuzz_on_l2",
],
},
):
"""Deploy a Polygon CDK Devnet with various configurable options.
Expand Down Expand Up @@ -187,3 +195,10 @@ def run(
observability_package.run(plan, observability_args)
else:
plan.print("Skipping the deployment of the observability stack")

# Apply workload
if apply_workload:
plan.print("Apply workload")
workload_package.run(plan, args)
else:
plan.print("Skipping workload application")
20 changes: 20 additions & 0 deletions params.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ deploy_zkevm_permissionless_node: true
# Deploy observability stack.
deploy_observability: true

# Apply workload to the different components of the CDK stack.
apply_workload: true

args:
# Suffix appended to service names.
# Note: It should be a string.
Expand All @@ -48,6 +51,7 @@ args:
zkevm_bridge_ui_image: nulyjkdhthz/zkevm-bridge-ui:kurtosis
zkevm_bridge_proxy_image: haproxy:2.9.7

workload_image: leovct/workload:0.0.1

# Port configuration.
zkevm_hash_db_port: 50061
Expand Down Expand Up @@ -179,3 +183,19 @@ args:

## Tools versions
polycli_version: v0.1.42

## Workload configuration.
workload_commands: [
# Generate load on L1.
"polycli_loadtest_on_l1.sh t 100 10", # eth transfers
"polycli_loadtest_on_l1.sh 2 100 10", # erc20 transfers
"polycli_loadtest_on_l1.sh 7 100 10", # erc721 mints
"polycli_loadtest_on_l1.sh v3 50 5", # uniswapv3 swaps
"polycli_rpcfuzz_on_l1.sh", # rpc calls
# Generate load on L2.
"polycli_loadtest_on_l2.sh t 100 10", # eth transfers
"polycli_loadtest_on_l2.sh 2 100 10", # erc20 transfers
"polycli_loadtest_on_l2.sh 7 100 10", # erc721 mints
"polycli_loadtest_on_l2.sh v3 50 5", # uniswapv3 swaps
"polycli_rpcfuzz_on_l2.sh", # rpc calls
]
10 changes: 10 additions & 0 deletions templates/workload/apply_workload.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash
set -e

echo "Applying workload..."
while true; do
{{range .commands}}
{{.}} &
{{end}}
sleep 120
done
25 changes: 25 additions & 0 deletions templates/workload/polycli_loadtest.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash
set -e

# Check if the required arguments are provided
if [ "$#" -ne 3 ]; then
echo "Usage: $0 <mode> <requests> <concurrency>"
exit 1
fi

mode="$1"
requests="$2"
concurrency="$3"
rpc_url="{{.rpc_url}}"

echo "Running polycli loadtest (rpc_url=$rpc_url mode=$mode requests=$requests concurrency=$concurrency)..."
polycli loadtest \
--rpc-url "$rpc_url" \
--chain-id {{.chain_id}} \
--private-key "{{.private_key}}" \
--verbosity 700 \
--mode "$mode" \
--requests "$requests" \
--concurrency "$concurrency" \
{{if .send_legacy_tx}}--legacy{{end}} \
2>$1 | awk -v mode="$mode" -v url="$rpc_url" '{print "loadtest-" mode "-" url " " $0}'
8 changes: 8 additions & 0 deletions templates/workload/polycli_rpcfuzz.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
set -e

echo "Running polycli rpcfuzz (rpc_url={{.rpc_url}})..."
polycli rpcfuzz \
--rpc-url "{{.rpc_url}}" \
--private-key "{{.private_key}}" \
2>&1 | awk '{print "[rpcfuzz] " $0}'
66 changes: 66 additions & 0 deletions workload.star
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
def run(plan, args):
# Create scripts artifacts.
apply_workload_template = read_file(src="./templates/workload/apply_workload.sh")
polycli_loadtest_template = read_file(
src="./templates/workload/polycli_loadtest.sh"
)
polycli_rpcfuzz_template = read_file(src="./templates/workload/polycli_rpcfuzz.sh")
zkevm_rpc_service = plan.get_service("zkevm-node-rpc" + args["deployment_suffix"])
zkevm_rpc_url = "http://{}:{}".format(
zkevm_rpc_service.ip_address, zkevm_rpc_service.ports["http-rpc"].number
)
workload_script_artifact = plan.render_templates(
name="workload-script-artifact",
config={
"apply_workload.sh": struct(
template=apply_workload_template,
data={
"commands": args["workload_commands"],
},
),
"polycli_loadtest_on_l1.sh": struct(
template=polycli_loadtest_template,
data={
"rpc_url": args["l1_rpc_url"],
"chain_id": args["l1_chain_id"],
"private_key": args["zkevm_l2_admin_private_key"],
},
),
"polycli_loadtest_on_l2.sh": struct(
template=polycli_loadtest_template,
data={
"rpc_url": zkevm_rpc_url,
"chain_id": args["zkevm_rollup_chain_id"],
"private_key": args["zkevm_l2_admin_private_key"],
"send_legacy_tx": True,
},
),
"polycli_rpcfuzz_on_l1.sh": struct(
template=polycli_rpcfuzz_template,
data={
"rpc_url": args["l1_rpc_url"],
"private_key": args["zkevm_l2_admin_private_key"],
},
),
"polycli_rpcfuzz_on_l2.sh": struct(
template=polycli_rpcfuzz_template,
data={
"rpc_url": zkevm_rpc_url,
"private_key": args["zkevm_l2_admin_private_key"],
},
),
},
)

plan.add_service(
name="workload" + args["deployment_suffix"],
config=ServiceConfig(
image=args["workload_image"],
files={
"/usr/local/bin": Directory(artifact_names=[workload_script_artifact]),
},
entrypoint=["bash", "-c"],
cmd=["chmod +x /usr/local/bin/*.sh && apply_workload.sh"],
user=User(uid=0, gid=0), # Run the container as root user.
),
)

0 comments on commit f8db025

Please sign in to comment.