diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index f7749721..3e220882 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -124,6 +124,7 @@ jobs: yq -Y --in-place '.deploy_zkevm_permissionless_node = false' params.yml yq -Y --in-place '.deploy_observability = false' params.yml yq -Y --in-place '.deploy_blutgang = false' params.yml + yq -Y --in-place '.apply_workload = false' params.yml - name: Deploy L1 run: | @@ -173,6 +174,12 @@ jobs: kurtosis run --enclave cdk-v1 --args-file params.yml . yq -Y --in-place '.deploy_blutgang = false' params.yml # reset + - name: Apply workload + run: | + yq -Y --in-place '.apply_workload = true' params.yml + kurtosis run --enclave cdk-v1 --args-file params.yml . + yq -Y --in-place '.apply_workload = false' params.yml # reset + - name: Check that batches are being verified run: | timeout_minutes="${CHECK_VERIFIED_BATCHES_TIMEOUT_MINUTES}" diff --git a/doc-drafts/workload.Dockerfile b/doc-drafts/workload.Dockerfile new file mode 100644 index 00000000..91be9514 --- /dev/null +++ b/doc-drafts/workload.Dockerfile @@ -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="devtools@polygon.technology" +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 diff --git a/main.star b/main.star index bdc77925..b4ff174d 100644 --- a/main.star +++ b/main.star @@ -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") blutgang_package = import_module("./cdk_blutgang.star") @@ -18,6 +19,7 @@ def run( deploy_zkevm_permissionless_node=True, deploy_observability=True, deploy_blutgang=True, + apply_workload=False, args={ "deployment_suffix": "-001", "zkevm_prover_image": "hermeznetwork/zkevm-prover:v6.0.0", @@ -94,6 +96,7 @@ def run( "l1_preallocated_mnemonic": "code code code code code code code code code code code quality", "l1_rpc_url": "http://el-1-geth-lighthouse:8545", "l1_ws_url": "ws://el-1-geth-lighthouse:8546", + "l1_additional_services": [], "zkevm_rollup_chain_id": 10101, "zkevm_rollup_fork_id": 9, "zkevm_rollup_consensus": "PolygonValidiumEtrog", @@ -104,7 +107,13 @@ def run( "zkevm_aggregator_host": "zkevm-node-aggregator-001", "genesis_file": "templates/permissionless-node/genesis.json", "polycli_version": "v0.1.42", - "l1_additional_services": [], + "workload_scripts": [ + "polycli_loadtest_on_l2.sh t", # eth transfers + "polycli_loadtest_on_l2.sh 2", # erc20 transfers + "polycli_loadtest_on_l2.sh 7", # erc721 mints + "polycli_loadtest_on_l2.sh v3", # uniswapv3 swaps + "polycli_rpcfuzz_on_l2.sh", # rpc calls + ], "blutgang_image": "makemake1337/blutgang:latest", "blutgang_rpc_port": "55555", "blutgang_admin_port": "55556", @@ -194,6 +203,13 @@ def run( 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") + # Deploy blutgang for caching if deploy_blutgang: plan.print("Deploying blutgang") diff --git a/params.yml b/params.yml index cc8c97fc..3de9cb01 100644 --- a/params.yml +++ b/params.yml @@ -23,9 +23,12 @@ deploy_zkevm_permissionless_node: true # Deploy observability stack. deploy_observability: true -# Deploy eth loadbalancer (blutgang). +# Deploy eth load balancer. deploy_blutgang: true +# Apply workload to the different components of the CDK stack. +apply_workload: false + args: # Suffix appended to service names. # Note: It should be a string. @@ -50,6 +53,7 @@ args: zkevm_bridge_ui_image: leovct/zkevm-bridge-ui:multi-network zkevm_bridge_proxy_image: haproxy:2.9.7 + workload_image: leovct/workload:0.0.1 # Port configuration. zkevm_hash_db_port: 50061 @@ -183,8 +187,16 @@ args: ## Tools versions polycli_version: v0.1.42 - ## blutgang configuration. - blutgang_image: makemake1337/blutgang:0.3.5 + ## Workload configuration. + workload_commands: [ + "polycli_loadtest_on_l2.sh t", # eth transfers + "polycli_loadtest_on_l2.sh 2", # erc20 transfers + "polycli_loadtest_on_l2.sh 7", # erc721 mints + "polycli_loadtest_on_l2.sh v3", # uniswapv3 swaps + "polycli_rpcfuzz_on_l2.sh", # rpc calls + ] + ## ETH Load balancer configuration. + blutgang_image: makemake1337/blutgang:0.3.5 blutgang_rpc_port: 55555 - blutgang_admin_port: 55556 \ No newline at end of file + blutgang_admin_port: 55556 diff --git a/templates/workload/apply_workload.sh b/templates/workload/apply_workload.sh new file mode 100644 index 00000000..9568bb19 --- /dev/null +++ b/templates/workload/apply_workload.sh @@ -0,0 +1,13 @@ +#!/bin/bash +set -e + +echo "Applying workload..." +while true; do + # shellcheck disable=SC1054,SC1083 + {{range .commands}} + # shellcheck disable=SC1054,SC1083 + {{.}} & + # shellcheck disable=SC1056,SC1072,SC1073,SC1009 + {{end}} + sleep 120 +done \ No newline at end of file diff --git a/templates/workload/polycli_loadtest.sh b/templates/workload/polycli_loadtest.sh new file mode 100755 index 00000000..3c0c98e1 --- /dev/null +++ b/templates/workload/polycli_loadtest.sh @@ -0,0 +1,26 @@ +#!/bin/bash +set -e + +# Check if the required arguments are provided +if [ "$#" -ne 1 ]; then + echo "Usage: $0 " + exit 1 +fi + +mode="$1" +requests=100 +concurrency=1 +rpc_url="{{.rpc_url}}" + +echo "Running polycli loadtest (rpc_url=$rpc_url mode=$mode requests=$requests concurrency=$concurrency)..." +# shellcheck disable=SC1083,SC2086 +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}' diff --git a/templates/workload/polycli_rpcfuzz.sh b/templates/workload/polycli_rpcfuzz.sh new file mode 100755 index 00000000..2858cc1e --- /dev/null +++ b/templates/workload/polycli_rpcfuzz.sh @@ -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}' diff --git a/workload.star b/workload.star new file mode 100644 index 00000000..669d2c93 --- /dev/null +++ b/workload.star @@ -0,0 +1,51 @@ +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_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_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. + ), + )