Skip to content

Segmented-trie tooling, and a whole-chain replay that found a Bridge consensus bug #9

Closed

Description

@SDL-A1

Migrated from SergioDemianLerner/rustock#9 (pull request by @SergioDemianLerner, 2026-09-15).
Merged: yes. The commits are already in this repository's history.
Original: SergioDemianLerner/rustock#9

Tooling and documentation from the segmented-trie work. No node code paths change: nothing outside the tools references WindowStore, and examples do not build into the node. The consensus fixes went in separately as #10.

What it produced

The point of this branch is an artifact and a result, not the code:

Blocks executed 9,217,860 of 9,230,008
State roots checked against headers (≥ #1,591,000) 7,626,860
Divergences 1 — block #9,217,796
Elapsed 36h 29m on 4 vCPU / 7.7 GB
Segments built 1,517 across 97 chunk databases, 137 GB

The divergence is a real bug and is not fixed here. Block #9,217,796 contains a Bridge addSignature(bytes,bytes[],bytes) call — a federator signing a peg-out release. rustock computes 0x34ef1353…, the chain says 0x0c47553b…. The header matches public-node.rsk.co exactly, the parent verified, and it reproduces from an independent seed with an empty store, so it is neither a bad header nor an artifact of the tooling. docs/trie-segments-design.md §10.4 has the detail.

One divergence in 7.6M verified state roots is the headline number for the Bridge implementation generally.

Findings worth a reviewer's time

  • The rskj snapshot is archival from Security/supply chain hardening #1,591,000 (RSKIP126), so every block's pre-state is already on disk and ranges replay in parallel today.
  • rustock's from-genesis Unitrie matches the chain at Security/supply chain hardening #1,591,000. 1,591,000 blocks replayed from genesis in 3h53m; the computed root equals the header's and the public network's. That validates the entire cumulative pre-RSKIP126 state — an era that had no ground truth at all — in one comparison.
  • Read amplification against the archive is 152×: 10.8 MB of useful nodes costs 1,651 MB of device reads. That, not density in the abstract, is the case for segmenting.
  • A resident working set is worth 10.6× (2.63 → 26.75 blocks/s) with the device untouched.
  • Core scaling with I/O removed: 1.00× / 1.95× / 2.84× / 3.23× on four cores.
  • More RAM alone does almost nothing. A forward pass never revisits a block, so the cache cannot cover it: the same repeat experiment gains 960% when the footprint fits and 6% when it does not.

What the pass does not verify

It compares only the state root. execute_block validates nothing; process_block is the one that also checks transactions root, ommers hash, gas used, receipts root and logs bloom — and the tool called the former. Receipts, gas and blooms are unchecked, as are all headers and every block below #1,591,000 except through the cumulative anchor. §10.3 says so plainly. A second pass with process_block against the segments should cost ~15–19 h here, ~7.5 h on eight cores.

Corrections recorded rather than quietly fixed

The document carries its own wrong turns, because they were expensive and the reasoning is reusable:

  • 137 GB against a projected 88. The projection modelled one continuous window; the build ran 97 independently-seeded chunks, each paying a cold start whose nodes land in its own database.
  • Re-rooting did not reclaim the ~800 MB per worker attributed to the materialized trie tree. That attribution was arithmetic, not measurement (§6.5a).
  • A scaling table that measured nothing — workers placed far enough apart that wall clock tracked the slowest rather than contention (§6.2).
  • Static work balancing failed twice, on trie-nodes-touched and then on sampled gas, before work stealing (§10.5).

Also here

docs/execution-model.md — structural differences from rskj, checked against the rskj source: when each client writes the trie (both accumulate a whole block and write once), why REVERT never reaches it, the per-transaction commit boundary rskj has and rustock must simulate for #3,173,807, and the raw-storage overlay.

Testing

cargo test --workspace: 1,091 passing, 0 failing.

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