From d9d8f956fc2f09a17e83957d9902ac19563a60ae Mon Sep 17 00:00:00 2001 From: maru Date: Wed, 17 Dec 2025 17:13:49 +0000 Subject: [PATCH 1/9] [ci] Migrate reexec tasks to a script to simplify maintenance Doing anything non-trivial in tasks is not recommended. This change moves the reexec logic to a new script for ease of maintenance and to simplify usage. --- .../c-chain-reexecution-benchmark/action.yml | 69 ++----- ...chain-reexecution-benchmark-container.json | 6 +- ...-chain-reexecution-benchmark-container.yml | 10 +- ...chain-reexecution-benchmark-gh-native.json | 6 +- ...-chain-reexecution-benchmark-gh-native.yml | 10 +- Taskfile.yml | 175 +----------------- scripts/reexecute_cchain.sh | 137 ++++++++++++++ 7 files changed, 175 insertions(+), 238 deletions(-) create mode 100755 scripts/reexecute_cchain.sh diff --git a/.github/actions/c-chain-reexecution-benchmark/action.yml b/.github/actions/c-chain-reexecution-benchmark/action.yml index 85546ceba8a6..32de697db172 100644 --- a/.github/actions/c-chain-reexecution-benchmark/action.yml +++ b/.github/actions/c-chain-reexecution-benchmark/action.yml @@ -2,10 +2,10 @@ name: 'C-Chain Re-Execution Benchmark' description: 'Run C-Chain re-execution benchmark' inputs: - task: - description: 'Task name to execute from Taskfile.yml. Leave empty to use custom inputs below.' + test: + description: 'Test name to run (e.g., hashdb-101-250k). Leave empty to use custom inputs below.' default: '' - # Custom inputs (alternative to task-based approach) + # Custom inputs (used when test is not provided) config: description: 'The config to pass to the VM for the benchmark. See BenchmarkReexecuteRange for details.' default: '' @@ -50,10 +50,6 @@ inputs: description: 'The password for the Prometheus instance.' required: true default: '' - workspace: - description: 'Working directory to use for the benchmark.' - required: true - default: ${{ github.workspace }} github-token: description: 'GitHub token provided to GitHub Action Benchmark.' required: true @@ -126,54 +122,30 @@ runs: role-to-assume: ${{ inputs.aws-role }} aws-region: ${{ inputs.aws-region }} role-duration-seconds: ${{ inputs.aws-role-duration-seconds }} - - name: Validate inputs - shell: bash - run: | - if [[ -z "${{ inputs.task }}" ]]; then - # Granular mode - validate required inputs - missing=() - [[ -z "${{ inputs.block-dir-src }}" ]] && missing+=("block-dir-src") - [[ -z "${{ inputs.current-state-dir-src }}" ]] && missing+=("current-state-dir-src") - [[ -z "${{ inputs.start-block }}" ]] && missing+=("start-block") - [[ -z "${{ inputs.end-block }}" ]] && missing+=("end-block") - - if [[ ${#missing[@]} -gt 0 ]]; then - echo "::error::When 'task' is empty, the following inputs are required: ${missing[*]}" - exit 1 - fi - fi - - name: Set task env + - name: Set benchmark output file shell: bash - run: | - TIMESTAMP=$(date '+%Y%m%d-%H%M%S') - echo "EXECUTION_DATA_DIR=/tmp/reexecution-data-${TIMESTAMP}" >> "$GITHUB_ENV" - echo "BENCHMARK_OUTPUT_FILE=${GITHUB_WORKSPACE}/benchmark-output.json" >> "$GITHUB_ENV" + run: echo "BENCHMARK_OUTPUT_FILE=${GITHUB_WORKSPACE}/benchmark-output.json" >> "$GITHUB_ENV" - name: Run C-Chain Re-execution Benchmark shell: nix develop --impure --command bash -x {0} - run: | - if [[ -n "${{ inputs.task }}" ]]; then - # Task-based approach - ./scripts/run_task.sh ${{ inputs.task }} \ - BENCHMARK_OUTPUT_FILE="${{ env.BENCHMARK_OUTPUT_FILE }}" \ - EXECUTION_DATA_DIR="${{ env.EXECUTION_DATA_DIR }}" - else - # Granular approach - ./scripts/run_task.sh reexecute-cchain-range-with-copied-data \ - CONFIG=${{ inputs.config }} \ - EXECUTION_DATA_DIR=${{ env.EXECUTION_DATA_DIR }} \ - BLOCK_DIR_SRC=${{ inputs.block-dir-src }} \ - CURRENT_STATE_DIR_SRC=${{ inputs.current-state-dir-src }} \ - START_BLOCK=${{ inputs.start-block }} \ - END_BLOCK=${{ inputs.end-block }} \ - BENCHMARK_OUTPUT_FILE="${{ env.BENCHMARK_OUTPUT_FILE }}" - fi + run: ./scripts/reexecute_cchain.sh "${{ inputs.test || 'custom' }}" env: + # Test configuration overrides + S3_BLOCK_DIR: ${{ inputs.block-dir-src }} + S3_STATE_DIR: ${{ inputs.current-state-dir-src }} + START_BLOCK: ${{ inputs.start-block }} + END_BLOCK: ${{ inputs.end-block }} + CONFIG: ${{ inputs.config }} + # Execution environment + BENCHMARK_OUTPUT_FILE: ${{ env.BENCHMARK_OUTPUT_FILE }} + PUSH_POST_STATE: ${{ inputs.push-post-state }} + # Runner and metrics RUNNER_TYPE: ${{ inputs.runner_type }} METRICS_COLLECTOR_ENABLED: ${{ inputs.prometheus-username != '' }} PROMETHEUS_URL: ${{ inputs.prometheus-url }} PROMETHEUS_PUSH_URL: ${{ inputs.prometheus-push-url }} PROMETHEUS_USERNAME: ${{ inputs.prometheus-username }} PROMETHEUS_PASSWORD: ${{ inputs.prometheus-password }} + # Github metadata GH_REPO: ${{ inputs.repository-owner }}/${{ inputs.repository-name }} GH_WORKFLOW: ${{ inputs.workflow }} GH_RUN_ID: ${{ inputs.run-id }} @@ -188,10 +160,3 @@ runs: summary-always: true github-token: ${{ inputs.github-token }} auto-push: ${{ inputs.push-github-action-benchmark }} - - name: Push Post-State to S3 - if: inputs.push-post-state != '' - shell: nix develop --impure --command bash -x {0} - run: | - ./scripts/run_task.sh export-dir-to-s3 \ - SRC=${{ env.EXECUTION_DATA_DIR }}/current-state/ \ - DST=${{ inputs.push-post-state }} diff --git a/.github/workflows/c-chain-reexecution-benchmark-container.json b/.github/workflows/c-chain-reexecution-benchmark-container.json index dfb8ce6df230..79e3be9a82dd 100644 --- a/.github/workflows/c-chain-reexecution-benchmark-container.json +++ b/.github/workflows/c-chain-reexecution-benchmark-container.json @@ -3,7 +3,7 @@ "include": [ { "runner": "ubuntu-latest", - "task": "c-chain-reexecution-hashdb-101-250k", + "test": "hashdb-101-250k", "timeout-minutes": 30 }, { @@ -21,12 +21,12 @@ "include": [ { "runner": "avago-runner-m6i-4xlarge-ebs-fast", - "task": "c-chain-reexecution-hashdb-33m-33m500k", + "test": "hashdb-33m-33m500k", "timeout-minutes": 1440 }, { "runner": "avago-runner-i4i-4xlarge-local-ssd", - "task": "c-chain-reexecution-hashdb-33m-33m500k", + "test": "hashdb-33m-33m500k", "timeout-minutes": 1440 } ] diff --git a/.github/workflows/c-chain-reexecution-benchmark-container.yml b/.github/workflows/c-chain-reexecution-benchmark-container.yml index 8c14edfecf30..483029c1f21f 100644 --- a/.github/workflows/c-chain-reexecution-benchmark-container.yml +++ b/.github/workflows/c-chain-reexecution-benchmark-container.yml @@ -4,8 +4,8 @@ on: pull_request: workflow_dispatch: inputs: - task: - description: 'Taskfile task to execute (e.g., c-chain-reexecution-hashdb-101-250k)' + test: + description: 'Test name (e.g., hashdb-101-250k, firewood-33m-33m500k). Leave empty for custom.' default: '' config: description: 'The config to pass to the VM for the benchmark. See BenchmarkReexecuteRange for details.' @@ -51,8 +51,8 @@ jobs: if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then { echo "matrix< +# +# Preset tests handle S3 import and execution automatically. +# Environment variables (BENCHMARK_OUTPUT_FILE, METRICS_*, etc.) are passed through. +# +# Optional env vars: +# PUSH_POST_STATE - S3 destination to push current-state after execution (requires AWS credentials) + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +S3_BOOTSTRAP_BUCKET="${S3_BOOTSTRAP_BUCKET:-s3://avalanchego-bootstrap-testing}" + +# CI-aware error function +error() { + if [[ "${GITHUB_ACTIONS:-}" == "true" ]]; then + echo "::error::$1" + else + echo "Error: $1" >&2 + fi + exit 1 +} + +if [[ $# -lt 1 ]]; then + echo "Usage: $0 " + echo "" + echo "Available tests:" + echo " test - Quick test run (blocks 101-200, hashdb)" + echo " hashdb-101-250k - Blocks 101-250k with hashdb" + echo " hashdb-archive-101-250k - Blocks 101-250k with hashdb archive" + echo " hashdb-33m-33m500k - Blocks 33m-33.5m with hashdb" + echo " firewood-101-250k - Blocks 101-250k with firewood" + echo " firewood-33m-33m500k - Blocks 33m-33.5m with firewood" + echo " firewood-33m-40m - Blocks 33m-40m with firewood" + echo " custom - Custom run using env vars:" + echo " S3_BLOCK_DIR, S3_STATE_DIR, START_BLOCK, END_BLOCK, CONFIG" + exit 1 +fi + +TEST_NAME="$1" + +# Set defaults based on test name. Env vars can override any value. +case "$TEST_NAME" in + test) + S3_BLOCK_DIR="${S3_BLOCK_DIR:-cchain-mainnet-blocks-200-ldb}" + S3_STATE_DIR="${S3_STATE_DIR:-cchain-current-state-hashdb-full-100}" + START_BLOCK="${START_BLOCK:-101}" + END_BLOCK="${END_BLOCK:-200}" + ;; + hashdb-101-250k) + S3_BLOCK_DIR="${S3_BLOCK_DIR:-cchain-mainnet-blocks-1m-ldb}" + S3_STATE_DIR="${S3_STATE_DIR:-cchain-current-state-hashdb-full-100}" + START_BLOCK="${START_BLOCK:-101}" + END_BLOCK="${END_BLOCK:-250000}" + ;; + hashdb-archive-101-250k) + S3_BLOCK_DIR="${S3_BLOCK_DIR:-cchain-mainnet-blocks-1m-ldb}" + S3_STATE_DIR="${S3_STATE_DIR:-cchain-current-state-hashdb-archive-100}" + START_BLOCK="${START_BLOCK:-101}" + END_BLOCK="${END_BLOCK:-250000}" + CONFIG="${CONFIG:-archive}" + ;; + hashdb-33m-33m500k) + S3_BLOCK_DIR="${S3_BLOCK_DIR:-cchain-mainnet-blocks-30m-40m-ldb}" + S3_STATE_DIR="${S3_STATE_DIR:-cchain-current-state-hashdb-full-33m}" + START_BLOCK="${START_BLOCK:-33000001}" + END_BLOCK="${END_BLOCK:-33500000}" + ;; + firewood-101-250k) + S3_BLOCK_DIR="${S3_BLOCK_DIR:-cchain-mainnet-blocks-1m-ldb}" + S3_STATE_DIR="${S3_STATE_DIR:-cchain-current-state-firewood-100}" + START_BLOCK="${START_BLOCK:-101}" + END_BLOCK="${END_BLOCK:-250000}" + CONFIG="${CONFIG:-firewood}" + ;; + firewood-33m-33m500k) + S3_BLOCK_DIR="${S3_BLOCK_DIR:-cchain-mainnet-blocks-30m-40m-ldb}" + S3_STATE_DIR="${S3_STATE_DIR:-cchain-current-state-firewood-33m}" + START_BLOCK="${START_BLOCK:-33000001}" + END_BLOCK="${END_BLOCK:-33500000}" + CONFIG="${CONFIG:-firewood}" + ;; + firewood-33m-40m) + S3_BLOCK_DIR="${S3_BLOCK_DIR:-cchain-mainnet-blocks-30m-40m-ldb}" + S3_STATE_DIR="${S3_STATE_DIR:-cchain-current-state-firewood-33m}" + START_BLOCK="${START_BLOCK:-33000001}" + END_BLOCK="${END_BLOCK:-40000000}" + CONFIG="${CONFIG:-firewood}" + ;; + custom) + # All configuration from env vars + ;; + *) + error "Unknown test '$TEST_NAME'" + ;; +esac + +# Validate required variables +missing=() +[[ -z "${S3_BLOCK_DIR:-}" ]] && missing+=("S3_BLOCK_DIR") +[[ -z "${S3_STATE_DIR:-}" ]] && missing+=("S3_STATE_DIR") +[[ -z "${START_BLOCK:-}" ]] && missing+=("START_BLOCK") +[[ -z "${END_BLOCK:-}" ]] && missing+=("END_BLOCK") + +if [[ ${#missing[@]} -gt 0 ]]; then + error "Missing required env vars: ${missing[*]}" +fi + +TIMESTAMP=$(date '+%Y%m%d-%H%M%S') +EXECUTION_DATA_DIR="${EXECUTION_DATA_DIR:-/tmp/reexec-${TEST_NAME}-${TIMESTAMP}}" + +echo "=== C-Chain Re-execution: ${TEST_NAME} ===" +echo "Blocks: ${START_BLOCK} - ${END_BLOCK}" +echo "Config: ${CONFIG:-default}" +echo "Data dir: ${EXECUTION_DATA_DIR}" + +echo "=== Importing blocks from S3 ===" +"${SCRIPT_DIR}/copy_dir.sh" "${S3_BOOTSTRAP_BUCKET}/${S3_BLOCK_DIR}/**" "${EXECUTION_DATA_DIR}/blocks" + +echo "=== Importing state from S3 ===" +"${SCRIPT_DIR}/copy_dir.sh" "${S3_BOOTSTRAP_BUCKET}/${S3_STATE_DIR}/**" "${EXECUTION_DATA_DIR}/current-state" + +echo "=== Running re-execution ===" +BLOCK_DIR="${EXECUTION_DATA_DIR}/blocks" \ +CURRENT_STATE_DIR="${EXECUTION_DATA_DIR}/current-state" \ +START_BLOCK="${START_BLOCK}" \ +END_BLOCK="${END_BLOCK}" \ +CONFIG="${CONFIG}" \ +"${SCRIPT_DIR}/benchmark_cchain_range.sh" + +if [[ -n "${PUSH_POST_STATE:-}" ]]; then + echo "=== Pushing post-state to S3 ===" + "${SCRIPT_DIR}/copy_dir.sh" "${EXECUTION_DATA_DIR}/current-state/" "${PUSH_POST_STATE}" +fi From dcd27d437f2d1c97e742f0f98a0c80d8c8b6d99a Mon Sep 17 00:00:00 2001 From: maru Date: Wed, 17 Dec 2025 21:16:15 +0000 Subject: [PATCH 2/9] fixup: Rename default test to 'default' --- scripts/reexecute_cchain.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/reexecute_cchain.sh b/scripts/reexecute_cchain.sh index 2c24258e0539..623a3f37c052 100755 --- a/scripts/reexecute_cchain.sh +++ b/scripts/reexecute_cchain.sh @@ -28,7 +28,7 @@ if [[ $# -lt 1 ]]; then echo "Usage: $0 " echo "" echo "Available tests:" - echo " test - Quick test run (blocks 101-200, hashdb)" + echo " default - Quick test run (blocks 101-200, hashdb)" echo " hashdb-101-250k - Blocks 101-250k with hashdb" echo " hashdb-archive-101-250k - Blocks 101-250k with hashdb archive" echo " hashdb-33m-33m500k - Blocks 33m-33.5m with hashdb" @@ -44,7 +44,7 @@ TEST_NAME="$1" # Set defaults based on test name. Env vars can override any value. case "$TEST_NAME" in - test) + default) S3_BLOCK_DIR="${S3_BLOCK_DIR:-cchain-mainnet-blocks-200-ldb}" S3_STATE_DIR="${S3_STATE_DIR:-cchain-current-state-hashdb-full-100}" START_BLOCK="${START_BLOCK:-101}" From beac43f8293763d5cc74978a2d06213b47816107 Mon Sep 17 00:00:00 2001 From: maru Date: Wed, 17 Dec 2025 21:16:36 +0000 Subject: [PATCH 3/9] fixup: Update README --- tests/reexecute/c/README.md | 62 ++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/tests/reexecute/c/README.md b/tests/reexecute/c/README.md index d8d124edc351..ff07aca0d986 100644 --- a/tests/reexecute/c/README.md +++ b/tests/reexecute/c/README.md @@ -2,8 +2,6 @@ The C-Chain benchmarks support re-executing a range of mainnet C-Chain blocks against a provided snapshot of the current state as of some initial state. -AvalancheGo provides a [Taskfile](https://taskfile.dev/) with commands to manage the import/export of data required for re-execution (block range and current state) and triggering a benchmark run. - ## Prerequisites Configuring your AvalancheGo dev environment requires: @@ -56,26 +54,29 @@ Running the re-execution test in CI will implicitly set `METRICS_COLLECTOR_ENABL Let's run the default benchmark to get started. Make sure that you have completed the [Prerequisites](#prerequisites) section because it is required to copy the data from S3. -### Using Predefined Tasks +### Using Predefined Tests -You can run `./scripts/run_task.sh --list | grep "c-chain-reexecution"` to list predefined tasks for common re-execution scenarios. +Run the script without arguments to see available tests: -To run a predefined task: ```bash -./scripts/run_task.sh c-chain-reexecution-hashdb-101-250k +./scripts/reexecute_cchain.sh ``` -These tasks automatically download the required data from S3 and run the benchmark with the appropriate configuration. +To run a predefined test: +```bash +./scripts/reexecute_cchain.sh hashdb-101-250k +``` -### Using Custom Parameters +These tests automatically download the required data from S3 and run the benchmark with the appropriate configuration. -For custom benchmark runs: +### Using Custom Parameters -[Taskfile](https://taskfile.dev/) supports reading arguments via both environment variables and named arguments on the command line, so we'll set `EXECUTION_DATA_DIR` and use the defaults for the remainder of the parameters: +For custom benchmark runs, use the `custom` test with environment variables: ```bash +# Export env vars that you want to be available to all future script invocations export EXECUTION_DATA_DIR=$HOME/.reexecute-cchain/default -task reexecute-cchain-range-with-copied-data +S3_BLOCK_DIR=cchain-mainnet-blocks-1m-ldb S3_STATE_DIR=cchain-current-state-hashdb-full-100 START_BLOCK=101 END_BLOCK=250000 ./scripts/reexecute_cchain.sh custom ``` This performs the following steps: @@ -132,11 +133,11 @@ First, we will import the first 10k blocks. To see what block databases are avai s5cmd ls s3://avalanchego-bootstrap-testing | grep blocks ``` -In this case, we will use the directory: `s3://avalanchego-bootstrap-testing/cchain-mainnet-blocks-10k-ldb/`. To import it, run the import task: +In this case, we will use the directory: `s3://avalanchego-bootstrap-testing/cchain-mainnet-blocks-10k-ldb/`. To import it: ```bash export EXECUTION_DATA_DIR=$HOME/.reexecute-cchain/walkthrough -task import-s3-to-dir SRC=s3://avalanchego-bootstrap-testing/cchain-mainnet-blocks-10k-ldb/** DST=$EXECUTION_DATA_DIR/blocks +./scripts/copy_dir.sh "s3://avalanchego-bootstrap-testing/cchain-mainnet-blocks-10k-ldb/**" "$EXECUTION_DATA_DIR/blocks" ``` Next, we need to want to execute the range of blocks [1, N]. We use 1 as the initial start block, since VM initialization vacuously executes the genesis block. @@ -153,7 +154,7 @@ To generate this from scratch, we can use a directory path for `CURRENT_STATE_DI ```bash export CURRENT_STATE_DIR=$EXECUTION_DATA_DIR/current-state export BLOCK_DIR=$EXECUTION_DATA_DIR/blocks -task reexecute-cchain-range START_BLOCK=1 END_BLOCK=100 +START_BLOCK=1 END_BLOCK=100 ./scripts/benchmark_cchain_range.sh ``` This initializes the contents of `$EXECUTION_DATA_DIR/current-state` to include two subdirectories: @@ -192,27 +193,27 @@ $HOME/exec-data After generating the `$EXECUTION_DATA_DIR/current-state` directory from executing the first segment of blocks, we can take a snapshot of the current state and push to S3 (or copy to another location including a local directory if preferred) for re-use. -Since we are already using the S3 bucket `s3://avalanchego-bootstrap-testing`, we'll re-use it here. We'll use the `export-dir-to-s3` task, which takes in two parameters: +Since we are already using the S3 bucket `s3://avalanchego-bootstrap-testing`, we'll re-use it here. We'll use the `copy-dir.sh` script, which takes in two parameters: -- `SRC` - local path to recursive copy contents from -- `DST` - S3 bucket destination path +-- local path to recursive copy contents from +-- S3 bucket destination path To avoid clobbering useful data, `export-dir-to-s3` will first attempt to check that the destination does not yet exist and that the path does not have any nesting. For example, `s3://avalanchego-bootstrap-testing/target-dir/` is valid, but `s3://avalanchego-bootstrap-testing/nested/target-dir/` is invalid because it contains two levels of nesting. As a result, if you run into a warning using this command, check the current contents using either the AWS Console or `s5cmd ls` and pick a valid, unused prefix. ```bash -task export-dir-to-s3 SRC=$EXECUTION_DATA_DIR/current-state/ DST=s3://avalanchego-bootstrap-testing/cchain-current-state-test/ +./scripts/copy_dir.sh "$EXECUTION_DATA_DIR/current-state/" "s3://avalanchego-bootstrap-testing/cchain-current-state-test/" ``` ### Re-Execute C-Chain Range -Now that we've pushed the current-state back to S3, we can run the target range of blocks [101, 200] either re-using the data we already have locally or copying the data in fresh using the `reexecute-cchain-range-with-copied-data` task. +Now that we've pushed the current-state back to S3, we can run the target range of blocks [101, 200] either re-using the data we already have locally or copying the data in fresh using the `benchmark_cchain_range.sh` script. -First, let's continue executing using the already available `CURRENT_STATE_DIR` and `BLOCK_DIR`. Since we have already exported these values, the task will pick them up and we can set only the `START_BLOCK` and `END_BLOCK` parameters: +First, let's continue executing using the already available `CURRENT_STATE_DIR` and `BLOCK_DIR`. Since we have already exported these values, the script will pick them up and we can set only the `START_BLOCK` and `END_BLOCK` parameters: ```bash -task reexecute-cchain-range START_BLOCK=101 END_BLOCK=200 +START_BLOCK=101 END_BLOCK=200 ./scripts/benchmark_cchain_range.sh ``` Note: if you attempt to re-execute a second time on the same data set, it will fail because the current state has been updated to block 200. @@ -234,12 +235,12 @@ Specify the following parameters: We'll use a new `EXECUTION_DATA_DIR` for this run to avoid conflicts with previous runs from this walkthrough: ```bash -task reexecute-cchain-range-with-copied-data EXECUTION_DATA_DIR=$HOME/.reexecute-cchain/reexecute-with-copied-data BLOCK_DIR_SRC=s3://avalanchego-bootstrap-testing/cchain-mainnet-blocks-10k-ldb/** CURRENT_STATE_DIR_SRC=s3://avalanchego-bootstrap-testing/cchain-current-state-test/** START_BLOCK=101 END_BLOCK=10000 +S3_BLOCK_DIR=cchain-mainnet-blocks-10k-ldb S3_STATE_DIR=cchain-current-state-test START_BLOCK=101 END_BLOCK=10000 EXECUTION_DATA_DIR=$HOME/.reexecute-cchain/reexecute-with-copied-data ./scripts/reexecute_cchain.sh custom ``` ## Predefined Configs -To support testing the VM in multiple configurations, the benchmark supports a set of pre-defined configs passed via the Task variable ex. `CONFIG=archive`. +To support testing the VM in multiple configurations, the benchmark supports a set of pre-defined configs passed via the `CONFIG` environment variable. The currently supported options are: "default", "archive", and "firewood". @@ -255,7 +256,7 @@ To export metrics for a local run, set the environment variables `METRICS_COLLEC ```bash export METRICS_COLLECTOR_ENABLED=true -./scripts/run_task.sh c-chain-reexecution-hashdb-101-250k +./scripts/reexecute_cchain.sh hashdb-101-250k ``` You can view granular C-Chain processing metrics with the label attached to this job (job="c-chain-reexecution") [here](https://grafana-poc.avax-dev.network/d/Gl1I20mnk/c-chain?orgId=1&from=now-5m&to=now&timezone=browser&var-datasource=P1809F7CD0C75ACF3&var-filter=job%7C%3D%7Cc-chain-reexecution&var-chain=C&refresh=10s). @@ -294,15 +295,15 @@ Both workflows provide three triggers: The manual workflow takes in all parameters specified by the user. To more easily specify a CI matrix and avoid GitHub's pain inducing matrix syntax, we define simple JSON files with the exact set of configs to run for each `pull_request` and `schedule` trigger. To add a new job for either of these triggers, simply define the entry in JSON and add it to run on the desired workflow. The workflows support two approaches: -1. **Task-based**: Specify a predefined `task` name (e.g., `"task": "c-chain-reexecution-firewood-101-250k"`) -2. **Custom parameters**: Specify individual parameters with `"task": ""` and provide `config`, `start-block`, `end-block`, `block-dir-src`, `current-state-dir-src` +1. **Test-based**: Specify a predefined `test` name (e.g., `"test": "firewood-101-250k"`) +2. **Custom parameters**: Leave `test` empty and provide `config`, `start-block`, `end-block`, `block-dir-src`, `current-state-dir-src` -For example, to add a new task-based Firewood benchmark to execute the block range [101, 250K] on a daily basis, add the following entry under the `schedule` include array in the [GH Native JSON file](../../../.github/workflows/c-chain-reexecution-benchmark-gh-native.json). +For example, to add a Firewood benchmark to execute the block range [101, 250K] on a daily basis, add the following entry under the `schedule` include array in the [GH Native JSON file](../../../.github/workflows/c-chain-reexecution-benchmark-gh-native.json). ```json { "runner": "blacksmith-4vcpu-ubuntu-2404", - "task": "c-chain-reexecution-firewood-101-250k", + "test": "firewood-101-250k", "timeout-minutes": 30 } ``` @@ -311,11 +312,11 @@ For example, to add a new task-based Firewood benchmark to execute the block ran To trigger runs conveniently, you can use the [GitHub CLI](https://cli.github.com/manual/gh_workflow_run) to trigger workflows. -### Using a Predefined Task +### Using a Predefined Test ```bash gh workflow run "C-Chain Re-Execution Benchmark GH Native" \ - -f task=c-chain-reexecution-firewood-101-250k \ + -f test=firewood-101-250k \ -f runner=blacksmith-4vcpu-ubuntu-2404 \ -f timeout-minutes=60 ``` @@ -324,7 +325,6 @@ gh workflow run "C-Chain Re-Execution Benchmark GH Native" \ ```bash gh workflow run "C-Chain Re-Execution Benchmark GH Native" \ - -f task="" \ -f block-dir-src=cchain-mainnet-blocks-1m-ldb \ -f current-state-dir-src=cchain-current-state-hashdb-full-100 \ -f start-block=101 \ From 25546409146c8fee203cef4966e29c9bcef3a21b Mon Sep 17 00:00:00 2001 From: maru Date: Thu, 18 Dec 2025 15:35:40 +0000 Subject: [PATCH 4/9] fixup: Consolidate the reexec scripts and add import script --- .../c-chain-reexecution-benchmark/action.yml | 6 +- Taskfile.yml | 12 +- scripts/benchmark_cchain_range.sh | 180 ++++++++++++++++-- scripts/import_cchain_data.sh | 26 +++ scripts/reexecute_cchain.sh | 137 ------------- tests/reexecute/c/README.md | 16 +- 6 files changed, 207 insertions(+), 170 deletions(-) create mode 100755 scripts/import_cchain_data.sh delete mode 100755 scripts/reexecute_cchain.sh diff --git a/.github/actions/c-chain-reexecution-benchmark/action.yml b/.github/actions/c-chain-reexecution-benchmark/action.yml index 32de697db172..c6e1eab2c2fc 100644 --- a/.github/actions/c-chain-reexecution-benchmark/action.yml +++ b/.github/actions/c-chain-reexecution-benchmark/action.yml @@ -127,11 +127,11 @@ runs: run: echo "BENCHMARK_OUTPUT_FILE=${GITHUB_WORKSPACE}/benchmark-output.json" >> "$GITHUB_ENV" - name: Run C-Chain Re-execution Benchmark shell: nix develop --impure --command bash -x {0} - run: ./scripts/reexecute_cchain.sh "${{ inputs.test || 'custom' }}" + run: ./scripts/run_task.sh test-c-chain-reexecution -- "${{ inputs.test || 'custom' }}" env: # Test configuration overrides - S3_BLOCK_DIR: ${{ inputs.block-dir-src }} - S3_STATE_DIR: ${{ inputs.current-state-dir-src }} + BLOCK_DIR_SRC: ${{ inputs.block-dir-src }} + CURRENT_STATE_DIR_SRC: ${{ inputs.current-state-dir-src }} START_BLOCK: ${{ inputs.start-block }} END_BLOCK: ${{ inputs.end-block }} CONFIG: ${{ inputs.config }} diff --git a/Taskfile.yml b/Taskfile.yml index 082fcd487341..a7967241f62b 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -3,6 +3,10 @@ # If in the nix dev shell, `task` is available. # To install nix, `./scripts/run_task.sh install-nix` +# - Tasks should be simple entrypoints to functionality exposed by scripts or code. +# - Avoid the temptation to use task vars to define an API surface. Prefer configuring the +# underlying script or code via CLI args and/or env vars. + version: '3' tasks: @@ -126,6 +130,10 @@ tasks: desc: Runs ginkgo against the current working directory cmd: ./bin/ginkgo build {{.USER_WORKING_DIR}} + import-chain-data: + desc: Imports the C-Chain block and state data to re-execute. + cmd: ./scripts/import_cchain_data.sh + install-nix: desc: Installs nix with an OS-appropriate installer cmd: ./scripts/install_nix.sh @@ -189,9 +197,9 @@ tasks: desc: Runs test of cross-platform docker image build cmd: bash -x scripts/tests.build_image.sh - test-c-chain-reexecution: + test-cchain-reexecution: desc: Runs C-Chain re-execution test. Run without args to see available tests. - cmd: ./scripts/reexecute_cchain.sh {{.CLI_ARGS}} + cmd: ./scripts/benchmark_cchain_range.sh {{.CLI_ARGS}} test-e2e: desc: Runs e2e tests diff --git a/scripts/benchmark_cchain_range.sh b/scripts/benchmark_cchain_range.sh index 379aca3172c6..41558b078baf 100755 --- a/scripts/benchmark_cchain_range.sh +++ b/scripts/benchmark_cchain_range.sh @@ -2,24 +2,165 @@ set -euo pipefail -# This script runs the C-Chain re-execution benchmark with a single iteration. -# It expects the following environment variables to be set: -# BLOCK_DIR: Path or S3 URL to the block directory or zip. -# CURRENT_STATE_DIR: Path or S3 URL to the current state directory or zip. -# START_BLOCK: The starting block height (exclusive). -# END_BLOCK: The ending block height (inclusive). -# RUNNER_TYPE (optional): Runner type/label to include in benchmark naming. -# LABELS (optional): Comma-separated key=value pairs for metric labels. -# BENCHMARK_OUTPUT_FILE (optional): If set, benchmark output is also written to this file. -# METRICS_SERVER_ENABLED (optional): If set, enables the metrics server. -# METRICS_SERVER_PORT (optional): If set, determines the port the metrics server will listen to. -# METRICS_COLLECTOR_ENABLED (optional): If set, enables the metrics collector. - -: "${BLOCK_DIR:?BLOCK_DIR must be set}" -: "${CURRENT_STATE_DIR:?CURRENT_STATE_DIR must be set}" -: "${START_BLOCK:?START_BLOCK must be set}" -: "${END_BLOCK:?END_BLOCK must be set}" +# C-Chain Re-execution Benchmark Script +# +# Usage: +# ./benchmark_cchain_range.sh [test-name] +# +# Running without arguments will output available tests. +# +# When test-name is provided, runs a predefined test that automatically imports data from S3. +# +# When no test-name (backward compatible): +# Expects these environment variables to be set: +# BLOCK_DIR: Path to the block directory. +# CURRENT_STATE_DIR: Path to the current state directory. +# START_BLOCK: The starting block height (exclusive). +# END_BLOCK: The ending block height (inclusive). +# +# Optional env vars (all modes): +# CONFIG: VM config preset (default, archive, firewood). +# LABELS: Comma-separated key=value pairs for metric labels. +# BENCHMARK_OUTPUT_FILE: If set, benchmark output is also written to this file. +# METRICS_SERVER_ENABLED: If set, enables the metrics server. +# METRICS_SERVER_PORT: If set, determines the port the metrics server will listen to. +# METRICS_COLLECTOR_ENABLED: If set, enables the metrics collector. +# PUSH_POST_STATE: S3 destination to push current-state after execution. +# +# For 'custom' test or S3 import with other tests: +# BLOCK_DIR_SRC: S3 object key for blocks. +# CURRENT_STATE_DIR_SRC: S3 object key for state. +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + +# CI-aware error function +error() { + if [[ "${GITHUB_ACTIONS:-}" == "true" ]]; then + echo "::error::$1" + else + echo "Error: $1" >&2 + fi + exit 1 +} + +show_usage() { + cat < -# -# Preset tests handle S3 import and execution automatically. -# Environment variables (BENCHMARK_OUTPUT_FILE, METRICS_*, etc.) are passed through. -# -# Optional env vars: -# PUSH_POST_STATE - S3 destination to push current-state after execution (requires AWS credentials) - -SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -S3_BOOTSTRAP_BUCKET="${S3_BOOTSTRAP_BUCKET:-s3://avalanchego-bootstrap-testing}" - -# CI-aware error function -error() { - if [[ "${GITHUB_ACTIONS:-}" == "true" ]]; then - echo "::error::$1" - else - echo "Error: $1" >&2 - fi - exit 1 -} - -if [[ $# -lt 1 ]]; then - echo "Usage: $0 " - echo "" - echo "Available tests:" - echo " default - Quick test run (blocks 101-200, hashdb)" - echo " hashdb-101-250k - Blocks 101-250k with hashdb" - echo " hashdb-archive-101-250k - Blocks 101-250k with hashdb archive" - echo " hashdb-33m-33m500k - Blocks 33m-33.5m with hashdb" - echo " firewood-101-250k - Blocks 101-250k with firewood" - echo " firewood-33m-33m500k - Blocks 33m-33.5m with firewood" - echo " firewood-33m-40m - Blocks 33m-40m with firewood" - echo " custom - Custom run using env vars:" - echo " S3_BLOCK_DIR, S3_STATE_DIR, START_BLOCK, END_BLOCK, CONFIG" - exit 1 -fi - -TEST_NAME="$1" - -# Set defaults based on test name. Env vars can override any value. -case "$TEST_NAME" in - default) - S3_BLOCK_DIR="${S3_BLOCK_DIR:-cchain-mainnet-blocks-200-ldb}" - S3_STATE_DIR="${S3_STATE_DIR:-cchain-current-state-hashdb-full-100}" - START_BLOCK="${START_BLOCK:-101}" - END_BLOCK="${END_BLOCK:-200}" - ;; - hashdb-101-250k) - S3_BLOCK_DIR="${S3_BLOCK_DIR:-cchain-mainnet-blocks-1m-ldb}" - S3_STATE_DIR="${S3_STATE_DIR:-cchain-current-state-hashdb-full-100}" - START_BLOCK="${START_BLOCK:-101}" - END_BLOCK="${END_BLOCK:-250000}" - ;; - hashdb-archive-101-250k) - S3_BLOCK_DIR="${S3_BLOCK_DIR:-cchain-mainnet-blocks-1m-ldb}" - S3_STATE_DIR="${S3_STATE_DIR:-cchain-current-state-hashdb-archive-100}" - START_BLOCK="${START_BLOCK:-101}" - END_BLOCK="${END_BLOCK:-250000}" - CONFIG="${CONFIG:-archive}" - ;; - hashdb-33m-33m500k) - S3_BLOCK_DIR="${S3_BLOCK_DIR:-cchain-mainnet-blocks-30m-40m-ldb}" - S3_STATE_DIR="${S3_STATE_DIR:-cchain-current-state-hashdb-full-33m}" - START_BLOCK="${START_BLOCK:-33000001}" - END_BLOCK="${END_BLOCK:-33500000}" - ;; - firewood-101-250k) - S3_BLOCK_DIR="${S3_BLOCK_DIR:-cchain-mainnet-blocks-1m-ldb}" - S3_STATE_DIR="${S3_STATE_DIR:-cchain-current-state-firewood-100}" - START_BLOCK="${START_BLOCK:-101}" - END_BLOCK="${END_BLOCK:-250000}" - CONFIG="${CONFIG:-firewood}" - ;; - firewood-33m-33m500k) - S3_BLOCK_DIR="${S3_BLOCK_DIR:-cchain-mainnet-blocks-30m-40m-ldb}" - S3_STATE_DIR="${S3_STATE_DIR:-cchain-current-state-firewood-33m}" - START_BLOCK="${START_BLOCK:-33000001}" - END_BLOCK="${END_BLOCK:-33500000}" - CONFIG="${CONFIG:-firewood}" - ;; - firewood-33m-40m) - S3_BLOCK_DIR="${S3_BLOCK_DIR:-cchain-mainnet-blocks-30m-40m-ldb}" - S3_STATE_DIR="${S3_STATE_DIR:-cchain-current-state-firewood-33m}" - START_BLOCK="${START_BLOCK:-33000001}" - END_BLOCK="${END_BLOCK:-40000000}" - CONFIG="${CONFIG:-firewood}" - ;; - custom) - # All configuration from env vars - ;; - *) - error "Unknown test '$TEST_NAME'" - ;; -esac - -# Validate required variables -missing=() -[[ -z "${S3_BLOCK_DIR:-}" ]] && missing+=("S3_BLOCK_DIR") -[[ -z "${S3_STATE_DIR:-}" ]] && missing+=("S3_STATE_DIR") -[[ -z "${START_BLOCK:-}" ]] && missing+=("START_BLOCK") -[[ -z "${END_BLOCK:-}" ]] && missing+=("END_BLOCK") - -if [[ ${#missing[@]} -gt 0 ]]; then - error "Missing required env vars: ${missing[*]}" -fi - -TIMESTAMP=$(date '+%Y%m%d-%H%M%S') -EXECUTION_DATA_DIR="${EXECUTION_DATA_DIR:-/tmp/reexec-${TEST_NAME}-${TIMESTAMP}}" - -echo "=== C-Chain Re-execution: ${TEST_NAME} ===" -echo "Blocks: ${START_BLOCK} - ${END_BLOCK}" -echo "Config: ${CONFIG:-default}" -echo "Data dir: ${EXECUTION_DATA_DIR}" - -echo "=== Importing blocks from S3 ===" -"${SCRIPT_DIR}/copy_dir.sh" "${S3_BOOTSTRAP_BUCKET}/${S3_BLOCK_DIR}/**" "${EXECUTION_DATA_DIR}/blocks" - -echo "=== Importing state from S3 ===" -"${SCRIPT_DIR}/copy_dir.sh" "${S3_BOOTSTRAP_BUCKET}/${S3_STATE_DIR}/**" "${EXECUTION_DATA_DIR}/current-state" - -echo "=== Running re-execution ===" -BLOCK_DIR="${EXECUTION_DATA_DIR}/blocks" \ -CURRENT_STATE_DIR="${EXECUTION_DATA_DIR}/current-state" \ -START_BLOCK="${START_BLOCK}" \ -END_BLOCK="${END_BLOCK}" \ -CONFIG="${CONFIG}" \ -"${SCRIPT_DIR}/benchmark_cchain_range.sh" - -if [[ -n "${PUSH_POST_STATE:-}" ]]; then - echo "=== Pushing post-state to S3 ===" - "${SCRIPT_DIR}/copy_dir.sh" "${EXECUTION_DATA_DIR}/current-state/" "${PUSH_POST_STATE}" -fi diff --git a/tests/reexecute/c/README.md b/tests/reexecute/c/README.md index ff07aca0d986..9bd660a334bb 100644 --- a/tests/reexecute/c/README.md +++ b/tests/reexecute/c/README.md @@ -56,15 +56,9 @@ Let's run the default benchmark to get started. Make sure that you have complete ### Using Predefined Tests -Run the script without arguments to see available tests: - -```bash -./scripts/reexecute_cchain.sh -``` - To run a predefined test: ```bash -./scripts/reexecute_cchain.sh hashdb-101-250k +./scripts/benchmark_cchain_range.sh hashdb-101-250k ``` These tests automatically download the required data from S3 and run the benchmark with the appropriate configuration. @@ -76,7 +70,7 @@ For custom benchmark runs, use the `custom` test with environment variables: ```bash # Export env vars that you want to be available to all future script invocations export EXECUTION_DATA_DIR=$HOME/.reexecute-cchain/default -S3_BLOCK_DIR=cchain-mainnet-blocks-1m-ldb S3_STATE_DIR=cchain-current-state-hashdb-full-100 START_BLOCK=101 END_BLOCK=250000 ./scripts/reexecute_cchain.sh custom +BLOCK_DIR_SRC=cchain-mainnet-blocks-1m-ldb CURRENT_STATE_DIR_SRC=cchain-current-state-hashdb-full-100 START_BLOCK=101 END_BLOCK=250000 ./scripts/benchmark_cchain_range.sh custom ``` This performs the following steps: @@ -220,7 +214,7 @@ Note: if you attempt to re-execute a second time on the same data set, it will f ### Re-Execute C-Chain Range with Copied Data -Next, we can re-execute the same range using the `CURRENT_STATE_DIR` that we exported to S3 using `reexecute-cchain-with-copied-data`. +Next, we can re-execute the same range using the `CURRENT_STATE_DIR` that we exported to S3. This time we will copy the same block directory from S3 and copy the state snapshot that we just exported into S3 to pick up re-execution from where we left off. @@ -235,7 +229,7 @@ Specify the following parameters: We'll use a new `EXECUTION_DATA_DIR` for this run to avoid conflicts with previous runs from this walkthrough: ```bash -S3_BLOCK_DIR=cchain-mainnet-blocks-10k-ldb S3_STATE_DIR=cchain-current-state-test START_BLOCK=101 END_BLOCK=10000 EXECUTION_DATA_DIR=$HOME/.reexecute-cchain/reexecute-with-copied-data ./scripts/reexecute_cchain.sh custom +BLOCK_DIR_SRC=cchain-mainnet-blocks-10k-ldb CURRENT_STATE_DIR_SRC=cchain-current-state-test START_BLOCK=101 END_BLOCK=10000 EXECUTION_DATA_DIR=$HOME/.reexecute-cchain/reexecute-with-copied-data ./scripts/benchmark_cchain_range.sh custom ``` ## Predefined Configs @@ -256,7 +250,7 @@ To export metrics for a local run, set the environment variables `METRICS_COLLEC ```bash export METRICS_COLLECTOR_ENABLED=true -./scripts/reexecute_cchain.sh hashdb-101-250k +./scripts/benchmark_cchain_range.sh hashdb-101-250k ``` You can view granular C-Chain processing metrics with the label attached to this job (job="c-chain-reexecution") [here](https://grafana-poc.avax-dev.network/d/Gl1I20mnk/c-chain?orgId=1&from=now-5m&to=now&timezone=browser&var-datasource=P1809F7CD0C75ACF3&var-filter=job%7C%3D%7Cc-chain-reexecution&var-chain=C&refresh=10s). From 2623a770b96cbce3a33f8f01fcba10d2bfc800cb Mon Sep 17 00:00:00 2001 From: maru Date: Thu, 18 Dec 2025 15:40:56 +0000 Subject: [PATCH 5/9] fixup: Add a `help` argument to output available tests --- scripts/benchmark_cchain_range.sh | 5 +++++ tests/reexecute/c/README.md | 10 ++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/scripts/benchmark_cchain_range.sh b/scripts/benchmark_cchain_range.sh index 41558b078baf..de5cacbb6a2a 100755 --- a/scripts/benchmark_cchain_range.sh +++ b/scripts/benchmark_cchain_range.sh @@ -48,6 +48,7 @@ show_usage() { Usage: $0 [test-name] Available tests: + help - Show this help message default - Quick test run (blocks 101-200, hashdb) hashdb-101-250k - Blocks 101-250k with hashdb hashdb-archive-101-250k - Blocks 101-250k with hashdb archive @@ -69,6 +70,10 @@ if [[ $# -ge 1 ]]; then # Set defaults based on test name. Env vars can override any value. case "$TEST_NAME" in + help) + show_usage + exit 0 + ;; default) BLOCK_DIR_SRC="${BLOCK_DIR_SRC:-cchain-mainnet-blocks-200-ldb}" CURRENT_STATE_DIR_SRC="${CURRENT_STATE_DIR_SRC:-cchain-current-state-hashdb-full-100}" diff --git a/tests/reexecute/c/README.md b/tests/reexecute/c/README.md index 9bd660a334bb..966248372a7d 100644 --- a/tests/reexecute/c/README.md +++ b/tests/reexecute/c/README.md @@ -56,6 +56,12 @@ Let's run the default benchmark to get started. Make sure that you have complete ### Using Predefined Tests +Run the script with `help` as the test name to see available tests: + +```bash +./scripts/benchmark_cchain_range.sh help +``` + To run a predefined test: ```bash ./scripts/benchmark_cchain_range.sh hashdb-101-250k @@ -253,9 +259,9 @@ export METRICS_COLLECTOR_ENABLED=true ./scripts/benchmark_cchain_range.sh hashdb-101-250k ``` -You can view granular C-Chain processing metrics with the label attached to this job (job="c-chain-reexecution") [here](https://grafana-poc.avax-dev.network/d/Gl1I20mnk/c-chain?orgId=1&from=now-5m&to=now&timezone=browser&var-datasource=P1809F7CD0C75ACF3&var-filter=job%7C%3D%7Cc-chain-reexecution&var-chain=C&refresh=10s). +You can view granular C-Chain processing metrics with the label attached to this job (job="c-chain-reexecution") [here](https://grafana-poc.avax-dev.network/d/Gl1I20mnk/c-chain?orgId=1&from=now-5m&to=now&timezone=browser&var-datasource=P1809F7CD0C75ACF3&var-filter=job%7C%3D%7Cc-chain-reexecution&var-chain=C&refresh=10s). -**NOTE: Prometheus credentials are required for collection** +**NOTE: Prometheus credentials are required for collection** --- From c06b86155cf0077a35076147b99b2d4950cca030 Mon Sep 17 00:00:00 2001 From: maru Date: Thu, 18 Dec 2025 15:46:44 +0000 Subject: [PATCH 6/9] fixup: Fix task name --- .github/actions/c-chain-reexecution-benchmark/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/c-chain-reexecution-benchmark/action.yml b/.github/actions/c-chain-reexecution-benchmark/action.yml index c6e1eab2c2fc..6a090a3c6526 100644 --- a/.github/actions/c-chain-reexecution-benchmark/action.yml +++ b/.github/actions/c-chain-reexecution-benchmark/action.yml @@ -127,7 +127,7 @@ runs: run: echo "BENCHMARK_OUTPUT_FILE=${GITHUB_WORKSPACE}/benchmark-output.json" >> "$GITHUB_ENV" - name: Run C-Chain Re-execution Benchmark shell: nix develop --impure --command bash -x {0} - run: ./scripts/run_task.sh test-c-chain-reexecution -- "${{ inputs.test || 'custom' }}" + run: ./scripts/run_task.sh test-cchain-reexecution -- "${{ inputs.test || 'custom' }}" env: # Test configuration overrides BLOCK_DIR_SRC: ${{ inputs.block-dir-src }} From b4666d2d36d3b3ee81e07bdfababa180dd5caafb Mon Sep 17 00:00:00 2001 From: maru Date: Fri, 19 Dec 2025 20:13:01 +0000 Subject: [PATCH 7/9] fixup: Respond to review comments --- scripts/benchmark_cchain_range.sh | 106 ++++++++++++++---------------- tests/reexecute/c/README.md | 6 +- 2 files changed, 54 insertions(+), 58 deletions(-) diff --git a/scripts/benchmark_cchain_range.sh b/scripts/benchmark_cchain_range.sh index de5cacbb6a2a..91c2c49f3a89 100755 --- a/scripts/benchmark_cchain_range.sh +++ b/scripts/benchmark_cchain_range.sh @@ -9,27 +9,28 @@ set -euo pipefail # # Running without arguments will output available tests. # -# When test-name is provided, runs a predefined test that automatically imports data from S3. +# Test names configure defaults for S3 sources and block ranges. +# All defaults can be overridden via environment variables. # -# When no test-name (backward compatible): -# Expects these environment variables to be set: -# BLOCK_DIR: Path to the block directory. -# CURRENT_STATE_DIR: Path to the current state directory. +# Environment variables: +# Data sources (provide S3 sources OR local paths): +# BLOCK_DIR_SRC: S3 object key for blocks (triggers S3 import). +# CURRENT_STATE_DIR_SRC: S3 object key for state (triggers S3 import). +# BLOCK_DIR: Path to local block directory. +# CURRENT_STATE_DIR: Path to local current state directory. +# +# Required: # START_BLOCK: The starting block height (exclusive). # END_BLOCK: The ending block height (inclusive). # -# Optional env vars (all modes): -# CONFIG: VM config preset (default, archive, firewood). -# LABELS: Comma-separated key=value pairs for metric labels. -# BENCHMARK_OUTPUT_FILE: If set, benchmark output is also written to this file. -# METRICS_SERVER_ENABLED: If set, enables the metrics server. -# METRICS_SERVER_PORT: If set, determines the port the metrics server will listen to. -# METRICS_COLLECTOR_ENABLED: If set, enables the metrics collector. -# PUSH_POST_STATE: S3 destination to push current-state after execution. -# -# For 'custom' test or S3 import with other tests: -# BLOCK_DIR_SRC: S3 object key for blocks. -# CURRENT_STATE_DIR_SRC: S3 object key for state. +# Optional: +# CONFIG: VM config preset (default, archive, firewood). +# LABELS: Comma-separated key=value pairs for metric labels. +# BENCHMARK_OUTPUT_FILE: If set, benchmark output is also written to this file. +# METRICS_SERVER_ENABLED: If set, enables the metrics server. +# METRICS_SERVER_PORT: If set, determines the port the metrics server will listen to. +# METRICS_COLLECTOR_ENABLED: If set, enables the metrics collector. +# PUSH_POST_STATE: S3 destination to push current-state after execution. SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" @@ -56,19 +57,13 @@ Available tests: firewood-101-250k - Blocks 101-250k with firewood firewood-33m-33m500k - Blocks 33m-33.5m with firewood firewood-33m-40m - Blocks 33m-40m with firewood - custom - Custom run using env vars: - BLOCK_DIR_SRC, CURRENT_STATE_DIR_SRC, START_BLOCK, END_BLOCK, CONFIG - -Without test-name, expects env vars: BLOCK_DIR, CURRENT_STATE_DIR, START_BLOCK, END_BLOCK EOF } -# Check if a test name was provided -if [[ $# -ge 1 ]]; then - TEST_NAME="$1" +# Set defaults based on test name (if provided) +TEST_NAME="${1:-}" +if [[ -n "$TEST_NAME" ]]; then shift - - # Set defaults based on test name. Env vars can override any value. case "$TEST_NAME" in help) show_usage @@ -120,51 +115,52 @@ if [[ $# -ge 1 ]]; then END_BLOCK="${END_BLOCK:-40000000}" CONFIG="${CONFIG:-firewood}" ;; - custom) - # All configuration from env vars - ;; *) error "Unknown test '$TEST_NAME'" ;; esac +fi - # Validate required variables for test mode - missing=() - [[ -z "${BLOCK_DIR_SRC:-}" ]] && missing+=("BLOCK_DIR_SRC") - [[ -z "${CURRENT_STATE_DIR_SRC:-}" ]] && missing+=("CURRENT_STATE_DIR_SRC") - [[ -z "${START_BLOCK:-}" ]] && missing+=("START_BLOCK") - [[ -z "${END_BLOCK:-}" ]] && missing+=("END_BLOCK") - - if [[ ${#missing[@]} -gt 0 ]]; then - error "Missing required env vars: ${missing[*]}" - fi - +# Determine data source: S3 import or local paths +if [[ -n "${BLOCK_DIR_SRC:-}" && -n "${CURRENT_STATE_DIR_SRC:-}" ]]; then + # S3 mode - import data TIMESTAMP=$(date '+%Y%m%d-%H%M%S') - EXECUTION_DATA_DIR="${EXECUTION_DATA_DIR:-/tmp/reexec-${TEST_NAME}-${TIMESTAMP}}" - - echo "=== C-Chain Re-execution: ${TEST_NAME} ===" - echo "Blocks: ${START_BLOCK} - ${END_BLOCK}" - echo "Config: ${CONFIG:-default}" - echo "Data dir: ${EXECUTION_DATA_DIR}" + EXECUTION_DATA_DIR="${EXECUTION_DATA_DIR:-/tmp/reexec-${TEST_NAME:-custom}-${TIMESTAMP}}" - # Import data from S3 BLOCK_DIR_SRC="${BLOCK_DIR_SRC}" \ CURRENT_STATE_DIR_SRC="${CURRENT_STATE_DIR_SRC}" \ EXECUTION_DATA_DIR="${EXECUTION_DATA_DIR}" \ "${SCRIPT_DIR}/import_cchain_data.sh" - # Set local paths for benchmark BLOCK_DIR="${EXECUTION_DATA_DIR}/blocks" CURRENT_STATE_DIR="${EXECUTION_DATA_DIR}/current-state" -else - # No test name - backward compatible mode with local paths - # Show usage if required env vars are missing - if [[ -z "${BLOCK_DIR:-}" || -z "${CURRENT_STATE_DIR:-}" || -z "${START_BLOCK:-}" || -z "${END_BLOCK:-}" ]]; then - show_usage - exit 1 - fi +elif [[ -n "${BLOCK_DIR_SRC:-}" || -n "${CURRENT_STATE_DIR_SRC:-}" ]]; then + error "Both BLOCK_DIR_SRC and CURRENT_STATE_DIR_SRC must be provided together" +elif [[ -z "${BLOCK_DIR:-}" || -z "${CURRENT_STATE_DIR:-}" ]]; then + show_usage + echo "" + echo "Env vars status:" + echo " S3 sources:" + [[ -n "${BLOCK_DIR_SRC:-}" ]] && echo " BLOCK_DIR_SRC: ${BLOCK_DIR_SRC}" || echo " BLOCK_DIR_SRC: (not set)" + [[ -n "${CURRENT_STATE_DIR_SRC:-}" ]] && echo " CURRENT_STATE_DIR_SRC: ${CURRENT_STATE_DIR_SRC}" || echo " CURRENT_STATE_DIR_SRC: (not set)" + echo " Local paths:" + [[ -n "${BLOCK_DIR:-}" ]] && echo " BLOCK_DIR: ${BLOCK_DIR}" || echo " BLOCK_DIR: (not set)" + [[ -n "${CURRENT_STATE_DIR:-}" ]] && echo " CURRENT_STATE_DIR: ${CURRENT_STATE_DIR}" || echo " CURRENT_STATE_DIR: (not set)" + echo " Block range:" + [[ -n "${START_BLOCK:-}" ]] && echo " START_BLOCK: ${START_BLOCK}" || echo " START_BLOCK: (not set)" + [[ -n "${END_BLOCK:-}" ]] && echo " END_BLOCK: ${END_BLOCK}" || echo " END_BLOCK: (not set)" + exit 1 fi +# Validate block range +if [[ -z "${START_BLOCK:-}" || -z "${END_BLOCK:-}" ]]; then + error "START_BLOCK and END_BLOCK are required" +fi + +echo "=== C-Chain Re-execution: ${TEST_NAME:-custom} ===" +echo "Blocks: ${START_BLOCK} - ${END_BLOCK}" +echo "Config: ${CONFIG:-default}" + echo "=== Running re-execution ===" go run github.com/ava-labs/avalanchego/tests/reexecute/c \ --block-dir="${BLOCK_DIR}" \ diff --git a/tests/reexecute/c/README.md b/tests/reexecute/c/README.md index 966248372a7d..8734286c2fec 100644 --- a/tests/reexecute/c/README.md +++ b/tests/reexecute/c/README.md @@ -71,12 +71,12 @@ These tests automatically download the required data from S3 and run the benchma ### Using Custom Parameters -For custom benchmark runs, use the `custom` test with environment variables: +For custom benchmark runs, provide S3 sources or local paths via environment variables: ```bash # Export env vars that you want to be available to all future script invocations export EXECUTION_DATA_DIR=$HOME/.reexecute-cchain/default -BLOCK_DIR_SRC=cchain-mainnet-blocks-1m-ldb CURRENT_STATE_DIR_SRC=cchain-current-state-hashdb-full-100 START_BLOCK=101 END_BLOCK=250000 ./scripts/benchmark_cchain_range.sh custom +BLOCK_DIR_SRC=cchain-mainnet-blocks-1m-ldb CURRENT_STATE_DIR_SRC=cchain-current-state-hashdb-full-100 START_BLOCK=101 END_BLOCK=250000 ./scripts/benchmark_cchain_range.sh ``` This performs the following steps: @@ -235,7 +235,7 @@ Specify the following parameters: We'll use a new `EXECUTION_DATA_DIR` for this run to avoid conflicts with previous runs from this walkthrough: ```bash -BLOCK_DIR_SRC=cchain-mainnet-blocks-10k-ldb CURRENT_STATE_DIR_SRC=cchain-current-state-test START_BLOCK=101 END_BLOCK=10000 EXECUTION_DATA_DIR=$HOME/.reexecute-cchain/reexecute-with-copied-data ./scripts/benchmark_cchain_range.sh custom +BLOCK_DIR_SRC=cchain-mainnet-blocks-10k-ldb CURRENT_STATE_DIR_SRC=cchain-current-state-test START_BLOCK=101 END_BLOCK=10000 EXECUTION_DATA_DIR=$HOME/.reexecute-cchain/reexecute-with-copied-data ./scripts/benchmark_cchain_range.sh ``` ## Predefined Configs From bb1e04b830784fcb96cf35c314a654633e3f3242 Mon Sep 17 00:00:00 2001 From: maru Date: Fri, 19 Dec 2025 20:37:48 +0000 Subject: [PATCH 8/9] fixup: Stop defaulting to 'custom' in github action --- .github/actions/c-chain-reexecution-benchmark/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/c-chain-reexecution-benchmark/action.yml b/.github/actions/c-chain-reexecution-benchmark/action.yml index 6a090a3c6526..a42e163921ad 100644 --- a/.github/actions/c-chain-reexecution-benchmark/action.yml +++ b/.github/actions/c-chain-reexecution-benchmark/action.yml @@ -127,7 +127,7 @@ runs: run: echo "BENCHMARK_OUTPUT_FILE=${GITHUB_WORKSPACE}/benchmark-output.json" >> "$GITHUB_ENV" - name: Run C-Chain Re-execution Benchmark shell: nix develop --impure --command bash -x {0} - run: ./scripts/run_task.sh test-cchain-reexecution -- "${{ inputs.test || 'custom' }}" + run: ./scripts/run_task.sh test-cchain-reexecution -- "${{ inputs.test || '' }}" env: # Test configuration overrides BLOCK_DIR_SRC: ${{ inputs.block-dir-src }} From 0d573ef6cf8e360af60e3c0d19f88a68cdcdd592 Mon Sep 17 00:00:00 2001 From: maru Date: Mon, 5 Jan 2026 14:50:46 +0000 Subject: [PATCH 9/9] fixup: Respond to review feedback --- scripts/benchmark_cchain_range.sh | 5 +++-- tests/reexecute/c/README.md | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/scripts/benchmark_cchain_range.sh b/scripts/benchmark_cchain_range.sh index 91c2c49f3a89..df37f8a01fb5 100755 --- a/scripts/benchmark_cchain_range.sh +++ b/scripts/benchmark_cchain_range.sh @@ -7,7 +7,8 @@ set -euo pipefail # Usage: # ./benchmark_cchain_range.sh [test-name] # -# Running without arguments will output available tests. +# To see available tests: use `help` as the test name or invoke +# without a test name and without required env vars. # # Test names configure defaults for S3 sources and block ranges. # All defaults can be overridden via environment variables. @@ -20,7 +21,7 @@ set -euo pipefail # CURRENT_STATE_DIR: Path to local current state directory. # # Required: -# START_BLOCK: The starting block height (exclusive). +# START_BLOCK: The starting block height (inclusive). # END_BLOCK: The ending block height (inclusive). # # Optional: diff --git a/tests/reexecute/c/README.md b/tests/reexecute/c/README.md index 8734286c2fec..281eff22a346 100644 --- a/tests/reexecute/c/README.md +++ b/tests/reexecute/c/README.md @@ -2,6 +2,8 @@ The C-Chain benchmarks support re-executing a range of mainnet C-Chain blocks against a provided snapshot of the current state as of some initial state. +Benchmarks can be invoked by running `./scripts/run_task.sh test-cchain-reexecution` or `./scripts/benchmark_cchain_range.sh`. + ## Prerequisites Configuring your AvalancheGo dev environment requires: