diff --git a/.github/workflows/firewood-state-access-test.yml b/.github/workflows/firewood-state-access-test.yml new file mode 100644 index 000000000000..5c99f19cd298 --- /dev/null +++ b/.github/workflows/firewood-state-access-test.yml @@ -0,0 +1,88 @@ +name: Firewood State Access Test + +on: + workflow_dispatch: + inputs: + test: + description: 'Test name to run (e.g., firewood-archive-250k). Leave empty to use custom inputs below.' + default: '' + # Custom inputs (used when test is not provided) + start-block: + description: 'The start block for the test.' + default: '' + end-block: + description: 'The end block for the test.' + default: '' + current-state-dir-src: + description: 'The current state directory. Supports S3 directory/zip and local directories.' + default: '' + runner: + description: 'Runner to execute the state access test. Input to the runs-on field of the job.' + required: true + timeout-minutes: + description: 'Timeout in minutes for the job.' + default: '60' + schedule: + - cron: '0 9 * * *' # Runs every day at 09:00 UTC (04:00 EST) + # XXX: REMOVE BEFORE MERGING + pull_request: + +jobs: + define-matrix: + runs-on: ubuntu-latest + outputs: + matrix: ${{ steps.define-matrix.outputs.matrix }} + steps: + - uses: actions/checkout@v4 + - name: Define Matrix + id: define-matrix + shell: bash -x {0} + run: | + if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then + { + echo "matrix<> "$GITHUB_OUTPUT" + else + { + echo "matrix<> "$GITHUB_OUTPUT" + fi + + firewood-state-access-test: + needs: define-matrix + strategy: + fail-fast: false + matrix: ${{ fromJSON(needs.define-matrix.outputs.matrix) }} + timeout-minutes: ${{ matrix.timeout-minutes || 60 }} + runs-on: ${{ matrix.runner || 'ubuntu-latest' }} + permissions: + id-token: write + contents: read + steps: + - uses: cachix/install-nix-action@02a151ada4993995686f9ed4f1be7cfbb229e56f #v31 + with: + github_access_token: ${{ secrets.GITHUB_TOKEN }} + - name: Configure AWS Credentials + uses: aws-actions/configure-aws-credentials@v4 + with: + role-to-assume: ${{ secrets.AWS_S3_READ_ONLY_ROLE }} + aws-region: 'us-east-2' + role-duration-seconds: '43200' + - uses: actions/checkout@v4 + - name: Run state access test with Firewood archive + shell: nix develop --impure --command bash -x {0} + run: ./scripts/run_task.sh test-firewood-state-access -- "${{ matrix.test || '' }}" + env: + START_BLOCK: ${{ matrix.start-block }} + END_BLOCK: ${{ matrix.end-block }} + CURRENT_STATE_DIR_SRC: ${{ matrix.current-state-dir-src }} diff --git a/Taskfile.yml b/Taskfile.yml index a7967241f62b..07a06a32ccf4 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -239,6 +239,10 @@ tasks: cmds: - cmd: bash -x ./scripts/tests.e2e.kube.sh --ginkgo.focus-file=xsvm.go {{.CLI_ARGS}} + test-firewood-state-access: + desc: Runs Firewood state access test + cmd: ./scripts/tests.firewood_state_access.sh {{.CLI_ARGS}} + # To use a different fuzz time, run `task test-fuzz FUZZTIME=[value in seconds]`. # A value of `-1` will run until it encounters a failing output. diff --git a/scripts/benchmark_cchain_range.sh b/scripts/benchmark_cchain_range.sh index 1ac92cee635a..eef7bcbbf512 100755 --- a/scripts/benchmark_cchain_range.sh +++ b/scripts/benchmark_cchain_range.sh @@ -227,8 +227,8 @@ else ${METRICS_SERVER_PORT:+--metrics-server-port="${METRICS_SERVER_PORT}"} \ ${METRICS_COLLECTOR_ENABLED:+--metrics-collector-enabled="${METRICS_COLLECTOR_ENABLED}"} - if [[ -n "${PUSH_POST_STATE:-}" ]]; then - echo "=== Pushing post-state to S3 ===" - "${SCRIPT_DIR}/copy_dir.sh" "${CURRENT_STATE_DIR}/" "${PUSH_POST_STATE}" - fi -fi + if [[ -n "${PUSH_POST_STATE:-}" ]]; then + echo "=== Pushing post-state to S3 ===" + "${SCRIPT_DIR}/copy_dir.sh" "${CURRENT_STATE_DIR}/" "${PUSH_POST_STATE}" + fi +fi \ No newline at end of file diff --git a/scripts/import_cchain_data.sh b/scripts/import_cchain_data.sh index 31af15974d70..ea0e1baf1c86 100755 --- a/scripts/import_cchain_data.sh +++ b/scripts/import_cchain_data.sh @@ -5,22 +5,26 @@ set -euo pipefail # Import C-Chain blocks and state from S3 # # Required env vars: -# BLOCK_DIR_SRC - S3 object key for blocks (e.g., cchain-mainnet-blocks-200-ldb) # CURRENT_STATE_DIR_SRC - S3 object key for state (e.g., cchain-current-state-hashdb-full-100) # EXECUTION_DATA_DIR - Local directory to store imported data # +# Optional env vars: +# BLOCK_DIR_SRC - S3 object key for blocks (e.g., cchain-mainnet-blocks-200-ldb) +# # Result: -# Creates $EXECUTION_DATA_DIR/blocks and $EXECUTION_DATA_DIR/current-state +# Creates $EXECUTION_DATA_DIR/current-state (always) +# Creates $EXECUTION_DATA_DIR/blocks (if BLOCK_DIR_SRC is set) SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" S3_BOOTSTRAP_BUCKET="${S3_BOOTSTRAP_BUCKET:-s3://avalanchego-bootstrap-testing}" -: "${BLOCK_DIR_SRC:?BLOCK_DIR_SRC must be set}" : "${CURRENT_STATE_DIR_SRC:?CURRENT_STATE_DIR_SRC must be set}" : "${EXECUTION_DATA_DIR:?EXECUTION_DATA_DIR must be set}" -echo "=== Importing blocks from S3 ===" -"${SCRIPT_DIR}/copy_dir.sh" "${S3_BOOTSTRAP_BUCKET}/${BLOCK_DIR_SRC}/**" "${EXECUTION_DATA_DIR}/blocks" +if [[ -n "${BLOCK_DIR_SRC:-}" ]]; then + echo "=== Importing blocks from S3 ===" + "${SCRIPT_DIR}/copy_dir.sh" "${S3_BOOTSTRAP_BUCKET}/${BLOCK_DIR_SRC}/**" "${EXECUTION_DATA_DIR}/blocks" +fi echo "=== Importing state from S3 ===" "${SCRIPT_DIR}/copy_dir.sh" "${S3_BOOTSTRAP_BUCKET}/${CURRENT_STATE_DIR_SRC}/**" "${EXECUTION_DATA_DIR}/current-state" diff --git a/scripts/tests.firewood_state_access.sh b/scripts/tests.firewood_state_access.sh new file mode 100755 index 000000000000..2193e785e3dd --- /dev/null +++ b/scripts/tests.firewood_state_access.sh @@ -0,0 +1,104 @@ +#!/usr/bin/env bash + +set -euo pipefail + +# Firewood state access script +# +# Usage: +# ./tests.firewood_state_access.sh +# +# To see available tests, use `help` as the test name or invoke without a test +# name and without required env vars. +# +# Note: state access tests can only be run with Firewood archival states. +# +# Environment variables: +# Data sources (provide S3 sources OR local paths): +# CURRENT_STATE_DIR_SRC: S3 object key for state (triggers S3 import). +# CURRENT_STATE_DIR: Path to local current state directory. +# +# Required: +# START_BLOCK: The starting block height to query (inclusive). +# END_BLOCK: The ending block height to query (inclusive). + +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 <