diff --git a/.gitea/workflows/deploy.yaml b/.gitea/workflows/deploy.yaml index a76ec11..55beb1d 100644 --- a/.gitea/workflows/deploy.yaml +++ b/.gitea/workflows/deploy.yaml @@ -39,7 +39,10 @@ on: description: quantus-node version (overrides the pin) required: false chainspec_url: - description: "chain spec JSON to run from (overrides CHAINSPEC_URL); empty = the built-in CHAIN name" + description: "chain spec JSON to run from (overrides CHAINSPEC_URL): an https URL, or a path in this repo such as asset/chainspec/mainnet.json; empty = the built-in CHAIN name" + required: false + chainspec_sha256: + description: "sha256 the chain spec file must have (overrides CHAINSPEC_SHA256); from the publisher's checksum file" required: false expected_genesis: description: "0x genesis hash the started node must report (overrides EXPECTED_GENESIS); required with a chain spec" @@ -74,6 +77,7 @@ env: # override each of these for the cutover; commit the values afterwards so # push-triggered deploys keep them. CHAINSPEC_URL: "" + CHAINSPEC_SHA256: "" EXPECTED_GENESIS: "" BOOTNODES: "" # The miner is deployed by quantus/miner's own workflow, following its main @@ -112,10 +116,12 @@ jobs: outputs: node_version: ${{ steps.v.outputs.node }} chainspec_url: ${{ steps.v.outputs.chainspec_url }} + chainspec_sha256: ${{ steps.v.outputs.chainspec_sha256 }} expected_genesis: ${{ steps.v.outputs.expected_genesis }} bootnodes: ${{ steps.v.outputs.bootnodes }} chain_id: ${{ steps.cs.outputs.chain_id }} steps: + - uses: actions/checkout@v4 - id: v run: | set -euo pipefail @@ -124,6 +130,7 @@ jobs: echo "quantus-node ${n}" cs="${{ github.event.inputs.chainspec_url || env.CHAINSPEC_URL }}" eg="${{ github.event.inputs.expected_genesis || env.EXPECTED_GENESIS }}" + sha="${{ github.event.inputs.chainspec_sha256 || env.CHAINSPEC_SHA256 }}" bn="${{ github.event.inputs.bootnodes || env.BOOTNODES }}" if [ -n "$cs" ] && [ -z "$eg" ]; then echo "a chain spec needs expected_genesis: without it a look-alike spec would pass validation" >&2 @@ -134,6 +141,7 @@ jobs: case "$b" in /*/p2p/*) ;; *) echo "bootnode '$b' is not a multiaddr ending in /p2p/" >&2; exit 1 ;; esac done echo "chainspec_url=${cs}" >> "$GITHUB_OUTPUT" + echo "chainspec_sha256=${sha}" >> "$GITHUB_OUTPUT" echo "expected_genesis=${eg}" >> "$GITHUB_OUTPUT" echo "bootnodes=${bn}" >> "$GITHUB_OUTPUT" echo "chain spec: ${cs:-built-in ${{ env.CHAIN }}}; expected genesis: ${eg:-not asserted}; bootnodes: ${bn:-none}" @@ -148,8 +156,22 @@ jobs: exit 0 fi mkdir -p _bin - curl -fSL --retry 5 --retry-delay 5 --retry-all-errors --connect-timeout 15 \ - -o _bin/chainspec.json "$cs" + case "$cs" in + http://*|https://*) + curl -fSL --retry 5 --retry-delay 5 --retry-all-errors --connect-timeout 15 \ + -o _bin/chainspec.json "$cs" ;; + *) + # A file committed to this repo (verified against the publisher's + # checksum before it was committed, and again below). + test -s "$cs" || { echo "chain spec '$cs' is neither a URL nor a file in this repo" >&2; exit 1; } + cp "$cs" _bin/chainspec.json ;; + esac + sha="${{ steps.v.outputs.chainspec_sha256 }}" + if [ -n "$sha" ]; then + got=$(sha256sum _bin/chainspec.json | cut -d' ' -f1) + [ "$got" = "$sha" ] || { echo "chain spec sha256 ${got} is not the expected ${sha}" >&2; exit 1; } + echo "chain spec sha256 matches" + fi # The spec must parse, and its id is the directory the node keeps # this chain's state and miner credentials under. id=$(python3 -c " diff --git a/asset/chainspec/README.md b/asset/chainspec/README.md new file mode 100644 index 0000000..84c3b1a --- /dev/null +++ b/asset/chainspec/README.md @@ -0,0 +1,5 @@ +Chain spec files the node deploy can run from (`CHAINSPEC_URL` / the +`chainspec_url` input as a repo path, e.g. `asset/chainspec/mainnet.json`). +Commit only a file verified against the publisher's checksum, and record that +checksum in `CHAINSPEC_SHA256` so the deploy re-verifies it; the started node's +genesis hash is asserted separately against `EXPECTED_GENESIS`.