feat(fastsync): verifiable anchor bundles, captured at scan time (#113)#120
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.go—Bundle{Height, TxIndex, RawTx, Branch}.Verify(root)recomputes the txid from the non-witnessRawTx(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 bboltStorekeyed 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—BundleWriterinterface +WithBundleWriter+BundlesEnabled();scanBlockcomputes 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.Verifyagainst a realCalcMerkleRootroot; rejects tampered branch / wrong root / trailing-garbage tx.Put/Get/Range.go test -race ./...green (28 packages).Post-Deploy Monitoring & Validation
No additional operational monitoring required: not wired into the runtime yet (no--serve-fast-syncflag until #115); capture is opt-in and best-effort.Part of #111. Closes #113
🤖 Generated with Claude Code