Skip to content

Old stored headers may not decode under the new strict header decoder (deploy blocker) #376

Closed

Description

@SDL-A1

From the external review of #374. This one gates the deploy, not the merge.

Stored headers are now read back with a strict decoder that depends on activation
heights (HeaderForm::Stored). Nothing establishes that every mainnet header the
old code wrote still decodes under it and re-hashes to the key it is stored at.

If any stored header fails to decode or re-hashes differently, sync stalls on the
existing /var/lib/rustock immediately after deploy. The production node is at
#9,422,658, so this is a live store with the full history behind it, not a
fresh sync.

Why it is not caught by anything we have

mainnet_block_rules replays blocks from the store in canonical order; it does
not assert that every header already written round-trips through the new
decoder. CI builds a fresh database. So the failure mode is specific to an
upgrade-in-place, which is exactly how this will be deployed.

What would settle it

A read-only scan of CF_HEADERS and the freezer that, for every entry, decodes
the stored bytes with the new decoder and asserts hash(decoded) == key.

Read-only is enough, and paseo already has r-x only on /var/lib/rustock
(enforced by ACL), so the scan cannot damage the store.

This should run and pass before the new binary is installed. A rollback after
the fact may not be sufficient on its own: if the new binary has already written
state under the new encoding, swapping the binary back could require a resync.

Status

Reported by the external reviewer. Not verified here — verifying it is the
work this issue asks for.

Activity

  1. SDL-A1 commented on Nov 18, 2026

    @SDL-A1
    CollaboratorAuthor

    Update: the PR already ships this scan. crates/cli/examples/verify_stored_headers.rs (357 lines, new in #374) does what this issue asks for, and more.

    Its own header states the relevant part:

    it hashes each header as rustock writes it back, which is how rskj hashes one, against the hash it is stored under, which the header above it names: a header read in a form rustock can't write back the same would hash as another block.

    Concretely:

    • BlockStore::open_read_only and Freezer::open_read_only — both opened read-only, so it cannot touch the store
    • config.activation_heights.clone().install() runs before any header is read, which is the thing this issue was worried about: the strict decoder depends on activation heights
    • a rehash closure computes header.hash() and compares it against the key the header is stored under, recording a Rehashed { stored, computed } failure on mismatch
    • genesis is deliberately excluded, with a correct reason: rskj's GenesisHeader writes its difficulty with a leading zero no decoder keeps, so its hash is known separately
    • it also runs the full HeaderVerifier, fork detection (the 449-block window) and merged-mining checks, multi-threaded, over a selectable range

    So this issue is not "write a scan" — it is "run the scan that exists, against this node's store, and record the result."

    One real gap in coverage

    The tool walks the canonical chain: canonical_hash(number) downward, following parent_hash, counting missing for canonical numbers with no header. It does not iterate every entry in CF_HEADERS, so stored non-canonical and uncle headers are not rehash-checked.

    For the deploy risk this issue is about — sync stalling on the existing store — the canonical chain plus the freezer is the part that matters, so this is sufficient to clear the blocker. Full CF_HEADERS coverage would be a strictly stronger check and is worth a follow-up if we want it.

    Status

    Building verify_stored_headers --release in a bwrap sandbox now (network off, no credentials, no /srv/rustock). Will run it against /var/lib/rustock bound read-only, with the node stopped, and post the output here.

  2. SDL-A1 commented on Nov 18, 2026

    @SDL-A1
    CollaboratorAuthor

    Result: clean at every activation boundary

    Ran verify_stored_headers from #374 against this node's live store, bound
    read-only into a bwrap sandbox (no network, no credentials, no
    /srv/rustock), with the node stopped. Store head #9,422,658; freezer holds
    9,402,658 headers.

    ±25,000 blocks around every mainnet activation height, plus bahamas,
    afterBridgeSync, hop401 and the head region:

    boundary height checked re-hashed result
    bahamas 3,397 28,397 28,400 ok
    afterBridgeSync 370,000 50,001 50,005 ok
    orchid / RSKIP92 729,000 50,001 50,005 ok
    wasabi100 / RSKIP110 1,591,000 50,001 50,005 ok
    twoToThree 2,018,000 50,001 50,005 ok
    papyrus200 / UMM 2,392,700 50,001 50,005 ok
    iris300 3,614,800 50,001 50,005 ok
    hop400 4,598,500 50,001 50,005 ok
    hop401 4,976,300 50,001 50,005 ok
    fingerroot500 5,468,000 50,001 50,005 ok
    arrowhead600 6,223,700 50,001 50,005 ok
    arrowhead631 6,549,300 50,001 50,005 ok
    lovell700 7,338,024 50,001 50,005 ok
    reed800 8,052,200 50,001 50,005 ok
    vetiver900 8,804,200 50,001 50,005 ok
    rskip351 (header version byte / extension) 9,002,504 50,001 50,005 ok
    head region 9,422,658 25,001 25,005 ok

    ~803,000 headers decoded under the new strict decoder and re-hashed against
    the key each is stored under. Zero mismatches.
    No Rehashed record was
    produced anywhere.

    Also zero across every range: blocks no later than their parent, headers whose
    parent the store lacks, and canonical numbers with no stored header.

    The checks were not vacuous

    Worth showing, because a scan that skips everything reports success too (see
    #386). Each range was asserted to have rehashed > 0, and the pre-orchid range
    exercised a decode path nothing above #729,000 touches:

    bahamas 3397: fallback-mined, their signatures checked: 28397
    

    What this does and does not establish

    Does: the specific failure this issue was raised about — an old stored header
    that the new decoder cannot read back to the same hash — does not occur at any
    activation boundary, including RSKIP-351, which is the largest header-encoding
    change in the chain's history. Since the decoder is activation-height dependent,
    boundaries are where such a failure would cluster.

    Does not: this is ~803k of 9,422,658 headers, about 8.5%. It is a
    targeted sample, not a proof. It also only covers the canonical chain and the
    freezer — stored non-canonical and uncle headers in CF_HEADERS are still
    unchecked, as noted above.

    Cost of removing the remaining doubt

    Measured throughput was 2,632 headers/s (faster than the 1,770/s cold figure
    in docs/snapshot-sync-estimates.md), so a full 9.42M-header scan is ~1 hour
    on this host, read-only, with the node stopped.

    Recommendation: this is no longer a deploy blocker — but I would run the full
    hour before installing, since it is cheap relative to a stalled mainnet node, and
    leave this issue open until it has.

  3. SDL-A1 commented on Nov 20, 2026

    @SDL-A1
    CollaboratorAuthor

    Answered, and not by the scan this issue proposed.

    The question was whether every header already in /var/lib/rustock decodes under #374's strict HeaderForm::Stored decoder, since a failure stalls sync on an upgrade in place. Two pieces of evidence now cover it:

    1. 7,638,848 stored headers decoded by the new code. The full Unitrie-era re-execution reads a header and a body from the store for every block it executes, through BlockStore::header() — which is the strict decoder. Every one of 7.64M decoded, from #1,591,001 to #9,230,008. That is a far broader test than the targeted scan, and it happened as a by-product.

    2. ~803,000 headers re-hashed to their keys. verify_stored_headers over ±25,000 blocks around all seventeen activation boundaries, including rskip351 (#9,002,504) — the header version byte and extension, the largest header-encoding change in the chain's history. Zero Rehashed mismatches, and the pre-orchid range exercised 28,397 fallback-mined signature checks.

    3. The node is live on the new binary as of 2026-11-20 01:23 UTC, synced to the tip (#9,426,775 by eth_blockNumber), with zero errors since restart and no orphaned or disagrees with warnings.

    What remains uncovered, for the record

    • The scan covers the canonical chain plus the freezer. Stored non-canonical and uncle headers in CF_HEADERS were never re-hashed. A full CF_HEADERS iteration is still the stronger check, and verify_stored_headers does not do one — it walks by canonical_hash and parent_hash.
    • Blocks 1–1,590,999 are covered for header decoding (28,397 headers in the boundary scan) but not for execution (Verifying blocks 1–1,590,999: the root-translation DB is not enough, and what would be #399).

    Worth noting what the historical journal shows about the binary this replaced: 1,136 ERROR lines, overwhelmingly Sync halted: block execution failed; will retry from executed head #94… at dozens of distinct heights. Zero since the upgrade.

    Closing. Measurements in docs/pr-374-validation.md.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions