Skip to content

feat(fastsync): verifiable anchor bundles, captured at scan time (#113)#120

Merged
LiranCohen merged 1 commit into
mainfrom
feat/fastsync-anchor-bundles
Jun 9, 2026
Merged

feat(fastsync): verifiable anchor bundles, captured at scan time (#113)#120
LiranCohen merged 1 commit into
mainfrom
feat/fastsync-anchor-bundles

Conversation

@LiranCohen

Copy link
Copy Markdown
Contributor

Summary

Second piece of the ION fast-sync overlay (epic #111), on top of the #112 merkle proofs. A node can now retain, per kept anchor, a self-contained PoW-verifiable bundle so it can later serve fast-sync inclusion proofs without retaining or re-fetching full blocks (which the Bitcoin network serves poorly due to pruning).

What's here

  • internal/fastsync/bundle.goBundle{Height, TxIndex, RawTx, Branch}. Verify(root) recomputes the txid from the non-witness RawTx (rejecting trailing garbage), checks the merkle branch against a caller-supplied, PoW-verified header merkle root, and returns the proven txid. Compact binary encode/decode.
  • internal/fastsync/store.go — a bbolt Store keyed by txnum (height<<32|txIndex): Put/Get/Range/Close. Auxiliary serving data in its own file (like the txid index), so a non-serving node pays nothing.
  • internal/indexBundleWriter interface + WithBundleWriter + BundlesEnabled(); scanBlock computes the merkle branch (it still holds the full block) and records a bundle for each kept anchor. Best-effort — a capture failure is logged, never fatal.

A fast-sync peer is untrusted, but a Bundle verified against the receiving node's own header merkle root makes "this anchor exists at block H, index I" impossible to forge. Omission is handled later by trust-then-verify (#116).

The cmd flag to enable capture ships with the serving protocol (#115) — there's no consumer until then.

Tests

  • Bundle.Verify against a real CalcMerkleRoot root; rejects tampered branch / wrong root / trailing-garbage tx.
  • Encode round-trip + truncation / over-long-branch decode errors.
  • Store Put/Get/Range.
  • End-to-end: a captured bundle verifies against the block's header merkle root — mutation-verified (an off-by-one capture index fails).

go test -race ./... green (28 packages).

Post-Deploy Monitoring & Validation

No additional operational monitoring required: not wired into the runtime yet (no --serve-fast-sync flag until #115); capture is opt-in and best-effort.

Part of #111. Closes #113

🤖 Generated with Claude Code

Second piece of the ION fast-sync overlay (epic #111), on top of the #112 merkle
proofs. A node now can retain, per kept anchor, a self-contained PoW-verifiable
bundle so it can later serve fast-sync inclusion proofs without retaining or
re-fetching full blocks.

- internal/fastsync/bundle.go: Bundle{Height, TxIndex, RawTx, Branch}. Verify(root)
  recomputes the txid from the non-witness RawTx (rejecting trailing garbage) and
  checks the merkle branch against a caller-supplied, PoW-verified header merkle root,
  returning the proven txid. Compact binary encode/decode.
- internal/fastsync/store.go: a bbolt Store keyed by txnum (height<<32|txIndex) —
  Put/Get/Range/Close. Auxiliary serving data in its own file (like the txid index),
  so a non-serving node pays nothing.
- internal/index: BundleWriter interface + WithBundleWriter + BundlesEnabled(); at
  scan time scanBlock computes the merkle branch (it still holds the full block) and
  records a bundle for each kept anchor. Best-effort (a capture failure is logged,
  never fatal — bundles are auxiliary, not part of the index).

A fast-sync peer is untrusted, but a Bundle verified against the receiving node's OWN
header merkle root makes "this anchor exists at block H, index I" impossible to forge
(omission is handled later by trust-then-verify, #116). The cmd flag to enable capture
ships with the serving protocol (#115); there is no consumer until then.

Tests: bundle Verify against a real CalcMerkleRoot root (+ tampered branch / wrong
root / trailing-garbage rejection); encode round-trip + truncation/over-long-branch
errors; store Put/Get/Range; and an end-to-end indexer test that a captured bundle
verifies against the block's header merkle root (mutation-verified: an off-by-one
capture index fails). go test -race ./... green.

Co-authored-by: Liran Cohen <liranlasvegas@gmail.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@LiranCohen LiranCohen merged commit 6effd45 into main Jun 9, 2026
1 check passed
@LiranCohen LiranCohen deleted the feat/fastsync-anchor-bundles branch June 9, 2026 01:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fast-sync 2/7: verifiable anchor bundles — retain proof data at scan time

1 participant