Skip to content

Commit 053dc90

Browse files
Add test to re-execute specified range of mainnet C-Chain blocks (#4019)
Signed-off-by: aaronbuchwald <[email protected]>
1 parent b169a9d commit 053dc90

File tree

9 files changed

+916
-6
lines changed

9 files changed

+916
-6
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: C-Chain Re-Execution Benchmark
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
start-block:
7+
description: 'The start block for the benchmark.'
8+
required: false
9+
default: 101
10+
end-block:
11+
description: 'The end block for the benchmark.'
12+
required: false
13+
default: 250000
14+
source-block-dir:
15+
description: 'The source block directory. Supports S3 directory/zip and local directories.'
16+
required: false
17+
default: s3://avalanchego-bootstrap-testing/cchain-mainnet-blocks-1m-ldb.zip
18+
current-state-dir:
19+
description: 'The current state directory. Supports S3 directory/zip and local directories.'
20+
required: false
21+
default: s3://avalanchego-bootstrap-testing/cchain-current-state-hashdb-full-100.zip
22+
schedule:
23+
- cron: '0 6 * * 0' # Runs every Sunday at 06:00 UTC
24+
25+
jobs:
26+
c-chain-reexecution:
27+
permissions:
28+
id-token: write
29+
contents: write
30+
runs-on: ubuntu-latest
31+
steps:
32+
- name: Configure AWS Credentials
33+
uses: aws-actions/configure-aws-credentials@v4
34+
with:
35+
role-to-assume: ${{ secrets.AWS_S3_READ_ONLY_ROLE }}
36+
aws-region: us-east-2
37+
- name: Set task env via GITHUB_ENV
38+
id: set-params
39+
run: |
40+
{
41+
echo "START_BLOCK=${{ github.event.inputs.start-block || 101 }}"
42+
echo "END_BLOCK=${{ github.event.inputs.end-block || 250000 }}"
43+
echo "SOURCE_BLOCK_DIR=${{ github.event.inputs.source-block-dir || 's3://avalanchego-bootstrap-testing/cchain-mainnet-blocks-1m-ldb.zip' }}"
44+
echo "CURRENT_STATE_DIR=${{ github.event.inputs.current-state-dir || 's3://avalanchego-bootstrap-testing/cchain-current-state-hashdb-full-100.zip' }}"
45+
} >> "$GITHUB_ENV"
46+
- uses: actions/checkout@v4
47+
- uses: ./.github/actions/setup-go-for-project
48+
- name: Run C-Chain Re-Execution
49+
uses: ./.github/actions/run-monitored-tmpnet-cmd
50+
with:
51+
run: ./scripts/run_task.sh reexecute-cchain-range-with-copied-data EXECUTION_DATA_DIR=${{ github.workspace }}/reexecution-data BENCHMARK_OUTPUT_FILE=${{ github.workspace }}/reexecute-cchain-range-benchmark-res.txt
52+
prometheus_username: ${{ secrets.PROMETHEUS_ID || '' }}
53+
prometheus_password: ${{ secrets.PROMETHEUS_PASSWORD || '' }}
54+
grafana_dashboard_id: 'Gl1I20mnk/c-chain'
55+
loki_username: ${{ secrets.LOKI_ID || '' }}
56+
loki_password: ${{ secrets.LOKI_PASSWORD || '' }}
57+
runtime: "" # Set runtime input to empty string to disable log collection
58+
- name: Download Previous Benchmark Result
59+
uses: actions/cache@v4
60+
with:
61+
path: ./cache
62+
key: ${{ runner.os }}-reexecute-cchain-range-benchmark.json
63+
- name: Compare Benchmark Results
64+
uses: benchmark-action/github-action-benchmark@v1
65+
with:
66+
tool: 'go'
67+
output-file-path: ${{ github.workspace }}/reexecute-cchain-range-benchmark-res.txt
68+
external-data-json-path: ./cache/${{ runner.os }}-reexecute-cchain-range-benchmark.json
69+
fail-on-alert: true
70+
github-token: ${{ secrets.GITHUB_TOKEN }}
71+
summary-always: true
72+
comment-on-alert: true

Taskfile.yml

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,24 @@ tasks:
8585
- cmd: go mod tidy
8686
- task: check-clean-branch
8787

88+
export-cchain-block-range:
89+
desc: Export range of C-Chain blocks from source to target directory.
90+
vars:
91+
SOURCE_BLOCK_DIR: '{{.SOURCE_BLOCK_DIR}}'
92+
TARGET_BLOCK_DIR: '{{.TARGET_BLOCK_DIR}}'
93+
START_BLOCK: '{{.START_BLOCK}}'
94+
END_BLOCK: '{{.END_BLOCK}}'
95+
cmds:
96+
- cmd: go test -timeout=0 -run=TestExportBlockRange github.com/ava-labs/avalanchego/tests/reexecute/c --source-block-dir={{.SOURCE_BLOCK_DIR}} --target-block-dir={{.TARGET_BLOCK_DIR}} --start-block={{.START_BLOCK}} --end-block={{.END_BLOCK}}
97+
98+
export-dir-to-s3:
99+
desc: Copies a directory to s3
100+
vars:
101+
LOCAL_SRC: '{{.LOCAL_SRC}}'
102+
S3_DST: '{{.S3_DST}}'
103+
cmds:
104+
- cmd: s5cmd cp {{.LOCAL_SRC}} {{.S3_DST}}
105+
88106
generate-mocks:
89107
desc: Generates testing mocks
90108
cmds:
@@ -109,6 +127,30 @@ tasks:
109127
desc: Runs ginkgo against the current working directory
110128
cmd: ./bin/ginkgo build {{.USER_WORKING_DIR}}
111129

130+
import-cchain-reexecute-range:
131+
desc: Imports the C-Chain block and state data to re-execute. Defaults to import the first 200 and the current state created with the default config of the C-Chain (hashdb).
132+
vars:
133+
EXECUTION_DATA_DIR: '{{.EXECUTION_DATA_DIR}}'
134+
SOURCE_BLOCK_DIR: '{{.SOURCE_BLOCK_DIR | default "s3://avalanchego-bootstrap-testing/cchain-mainnet-blocks-200.zip"}}'
135+
CURRENT_STATE_DIR: '{{.CURRENT_STATE_DIR | default "s3://avalanchego-bootstrap-testing/cchain-current-state-hashdb-full-100.zip"}}'
136+
cmds:
137+
- task: import-s3-to-dir
138+
vars:
139+
SRC: '{{.SOURCE_BLOCK_DIR}}'
140+
DST: '{{.EXECUTION_DATA_DIR}}/blocks'
141+
- task: import-s3-to-dir
142+
vars:
143+
SRC: '{{.CURRENT_STATE_DIR}}'
144+
DST: '{{.EXECUTION_DATA_DIR}}/current-state'
145+
146+
import-s3-to-dir:
147+
desc: Imports an S3 path to a local directory. Unzipping if needed.
148+
vars:
149+
SRC: '{{.SRC}}'
150+
DST: '{{.DST}}'
151+
cmds:
152+
- cmd: bash -x ./scripts/copy_dir.sh {{.SRC}} {{.DST}}
153+
112154
install-nix:
113155
desc: Installs nix with the determinate systems installer
114156
cmd: curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- install
@@ -139,6 +181,49 @@ tasks:
139181
desc: Runs shellcheck to check sanity of shell scripts
140182
cmd: ./scripts/shellcheck.sh
141183

184+
reexecute-cchain-range:
185+
desc: Re-execute a range of C-Chain blocks.
186+
vars:
187+
CURRENT_STATE_DIR: '{{.CURRENT_STATE_DIR}}'
188+
SOURCE_BLOCK_DIR: '{{.SOURCE_BLOCK_DIR}}'
189+
START_BLOCK: '{{.START_BLOCK}}'
190+
END_BLOCK: '{{.END_BLOCK}}'
191+
LABELS: '{{.LABELS | default ""}}'
192+
BENCHMARK_OUTPUT_FILE: '{{.BENCHMARK_OUTPUT_FILE | default ""}}'
193+
cmd: |
194+
CURRENT_STATE_DIR={{.CURRENT_STATE_DIR}} \
195+
SOURCE_BLOCK_DIR={{.SOURCE_BLOCK_DIR}} \
196+
START_BLOCK={{.START_BLOCK}} \
197+
END_BLOCK={{.END_BLOCK}} \
198+
LABELS={{.LABELS}} \
199+
BENCHMARK_OUTPUT_FILE={{.BENCHMARK_OUTPUT_FILE}} \
200+
bash -x ./scripts/benchmark_cchain_range.sh
201+
202+
reexecute-cchain-range-with-copied-data:
203+
desc: Combines import-cchain-reexecute-range and reexecute-cchain-range
204+
vars:
205+
EXECUTION_DATA_DIR: '{{.EXECUTION_DATA_DIR}}'
206+
SOURCE_BLOCK_DIR: '{{.SOURCE_BLOCK_DIR | default "s3://avalanchego-bootstrap-testing/cchain-mainnet-blocks-1m-ldb.zip"}}'
207+
CURRENT_STATE_DIR: '{{.CURRENT_STATE_DIR | default "s3://avalanchego-bootstrap-testing/cchain-current-state-hashdb-full-100.zip"}}'
208+
START_BLOCK: '{{.START_BLOCK | default "101"}}'
209+
END_BLOCK: '{{.END_BLOCK | default "250000"}}'
210+
LABELS: '{{.LABELS | default ""}}'
211+
BENCHMARK_OUTPUT_FILE: '{{.BENCHMARK_OUTPUT_FILE | default ""}}'
212+
cmds:
213+
- task: import-cchain-reexecute-range
214+
vars:
215+
SOURCE_BLOCK_DIR: '{{.SOURCE_BLOCK_DIR}}'
216+
CURRENT_STATE_DIR: '{{.CURRENT_STATE_DIR}}'
217+
EXECUTION_DATA_DIR: '{{.EXECUTION_DATA_DIR}}'
218+
- task: reexecute-cchain-range
219+
vars:
220+
SOURCE_BLOCK_DIR: '{{.EXECUTION_DATA_DIR}}/blocks'
221+
CURRENT_STATE_DIR: '{{.EXECUTION_DATA_DIR}}/current-state'
222+
START_BLOCK: '{{.START_BLOCK}}'
223+
END_BLOCK: '{{.END_BLOCK}}'
224+
LABELS: '{{.LABELS}}'
225+
BENCHMARK_OUTPUT_FILE: '{{.BENCHMARK_OUTPUT_FILE}}'
226+
142227
test-bootstrap-monitor-e2e:
143228
desc: Runs bootstrap monitor e2e tests
144229
cmd: bash -x ./scripts/tests.e2e.bootstrap_monitor.sh

flake.lock

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@
6060

6161
# Solidity compiler
6262
solc
63+
64+
# s5cmd for rapid s3 interactions
65+
s5cmd
6366
] ++ lib.optionals stdenv.isDarwin [
6467
# macOS-specific frameworks
6568
darwin.apple_sdk.frameworks.Security

scripts/benchmark_cchain_range.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
# This script runs the C-Chain re-execution benchmark with a single iteration.
6+
# It expects the following environment variables to be set:
7+
# SOURCE_BLOCK_DIR: Path or S3 URL to the source block directory or zip.
8+
# CURRENT_STATE_DIR: Path or S3 URL to the current state directory or zip.
9+
# START_BLOCK: The starting block height (exclusive).
10+
# END_BLOCK: The ending block height (inclusive).
11+
# LABELS (optional): Comma-separated key=value pairs for metric labels.
12+
# BENCHMARK_OUTPUT_FILE (optional): If set, benchmark output is also written to this file.
13+
14+
: "${SOURCE_BLOCK_DIR:?SOURCE_BLOCK_DIR must be set}"
15+
: "${CURRENT_STATE_DIR:?CURRENT_STATE_DIR must be set}"
16+
: "${START_BLOCK:?START_BLOCK must be set}"
17+
: "${END_BLOCK:?END_BLOCK must be set}"
18+
19+
cmd="go test -timeout=0 -v -benchtime=1x -bench=BenchmarkReexecuteRange -run=^$ github.com/ava-labs/avalanchego/tests/reexecute/c --source-block-dir=\"${SOURCE_BLOCK_DIR}\" --target-dir=\"${CURRENT_STATE_DIR}\" --start-block=\"${START_BLOCK}\" --end-block=\"${END_BLOCK}\" ${LABELS:+--labels=\"${LABELS}\"}"
20+
21+
if [ -n "${BENCHMARK_OUTPUT_FILE:-}" ]; then
22+
eval "$cmd" | tee "${BENCHMARK_OUTPUT_FILE}"
23+
else
24+
eval "$cmd"
25+
fi

scripts/build_test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ AVALANCHE_PATH=$( cd "$( dirname "${BASH_SOURCE[0]}" )"; cd .. && pwd )
77
# Load the constants
88
source "$AVALANCHE_PATH"/scripts/constants.sh
99

10-
EXCLUDED_TARGETS="| grep -v /mocks | grep -v proto | grep -v tests/e2e | grep -v tests/load/c | grep -v tests/upgrade | grep -v tests/fixture/bootstrapmonitor/e2e"
10+
EXCLUDED_TARGETS="| grep -v /mocks | grep -v proto | grep -v tests/e2e | grep -v tests/load/c | grep -v tests/upgrade | grep -v tests/fixture/bootstrapmonitor/e2e | grep -v tests/reexecute"
1111

1212
if [[ "$(go env GOOS)" == "windows" ]]; then
1313
# Test discovery for the antithesis test setups is broken due to

scripts/copy_dir.sh

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
# Usage: ./scripts/copy_dir.sh source_directory destination_directory
6+
# Sources can be S3 URLs (s3://bucket/path) or a local file path
7+
# Assumes s5cmd has been installed and is available in the PATH.
8+
# s5cmd is included in the nix dev shell.
9+
10+
if [ $# -ne 2 ]; then
11+
echo "Usage: $0 <source_directory> <destination_directory>"
12+
echo "S3 Example: $0 's3://bucket1/path1' /dest/dir"
13+
echo "Local Example: $0 '/local/path1' /dest/dir"
14+
exit 1
15+
fi
16+
17+
SRC="$1"
18+
DST="$2"
19+
20+
# Ensure destination directory exists
21+
mkdir -p "$DST"
22+
23+
# Function to copy from a single source to destination
24+
copy_source() {
25+
local source="$1"
26+
local dest="$2"
27+
28+
# Check if source starts with s3://
29+
if [[ "$source" == s3://* ]]; then
30+
echo "Copying from S3: $source -> $dest"
31+
# Use s5cmd to copy from S3
32+
time s5cmd cp "$source" "$dest"
33+
34+
# If we copied a zip, extract it in place
35+
if [[ "$source" == *.zip ]]; then
36+
echo "Extracting zip file in place"
37+
time unzip "$dest"/*.zip -d "$dest"
38+
rm "$dest"/*.zip
39+
fi
40+
else
41+
echo "Copying from local filesystem: $source -> $dest"
42+
# Use cp for local filesystem with recursive support
43+
if [ -d "$source" ]; then
44+
time cp -r "$source"/* "$dest/"
45+
elif [ -f "$source" ]; then
46+
time cp "$source" "$dest/"
47+
else
48+
echo "Warning: Source not found: $source"
49+
return 1
50+
fi
51+
fi
52+
}
53+
54+
copy_source "$SRC" "$DST"

0 commit comments

Comments
 (0)