Skip to content

Optional: pass assume-valid ancestry to consensus (companion to blvm-consensus#24) - #39

Draft
MeABzZz wants to merge 1 commit into
BTCDecoded:mainfrom
MeABzZz:followups/assume-valid-ancestor-hook
Draft

MeABzZz wants to merge 1 commit into
BTCDecoded:mainfrom
MeABzZz:followups/assume-valid-ancestor-hook

Conversation

@MeABzZz

@MeABzZz MeABzZz commented Oct 21, 2026

Copy link
Copy Markdown

Optional: decision for reviewer. Draft. Companion to BTCDecoded/blvm-consensus#24 (assume-valid with Core semantics). This PR doesn't compile against published blvm-consensus until #24 is released, because it sets the new assume_valid_ancestor field. Locally it builds and passes through the sibling [patch.crates-io] paths.

What it does

BlockStore::assume_valid_ancestor_lookup() returns the hook consensus needs: the assume-valid block's ancestor at height h on the stored header tree (Core: assumevalid->GetAncestor(h)).

  • The ancestry is built once per process: walk prev_block_hash back from the assume-valid header, which gives one 32-byte hash per height. That's about 30 MB on mainnet. It's cached in a static, keyed by (hash, height).
  • It doesn't trust the height index. That index is first-seen per height, so a competing header chain seen first would otherwise make its blocks look like ancestors and skip scripts.
  • Until the assume-valid header is stored, the lookup returns None (nothing skips) and retries cheaply: one header read, no allocation.

Wired next to difficulty_ancestor on these paths:

  • parallel IBD (parallel_ibd/mod.rs)
  • the sequential connect in block_processor.rs
  • reorg_executor.rs
  • pruning.rs

The blvm-protocol validate_and_connect_block_with_difficulty paths (block_processor's first pass, RPC) build their own context and still verify every script. That's fail-closed, and those paths already verify fully today in block_processor.

Test: tests/assume_valid_ancestor_lookup.rs

Store a competing header chain for heights 0..=3 first, so it occupies the height index, then the real 10-header chain with assume-valid at height 6. Checks:

  • before the real chain arrives: None
  • after: heights 0..=6 return the real chain's hashes, even where the height index still holds the competing hash
  • height 7: None

Also green: fork_reorg_regtest, fork_reorg_events, blockchain_rpc_tests, cargo test --lib parallel_ibd (727 passed), and cargo clippy --lib with no new warnings.

Not done: an IBD-throughput measurement with the hook on mainnet headers. The one-time walk is about 938k header reads at the first block below the assume-valid height.

Merge order

  1. Optional: assume-valid with Core semantics (skip only ancestors, never reject) blvm-consensus#24, then a consensus release.
  2. This PR, with node's blvm-consensus pin bumped to that release.

Relative to the 7 criticals PRs: works with or without #31 (Core v31.1 hash and height per network). With #31, the default hash is anchored, so this lookup finds it once headers sync. No file overlap with #31, #32 or #38. #38 also touches reorg_executor.rs, but in a different hunk.

…lock

Companion to blvm-consensus's Core-semantics assume-valid: build the
assume-valid block's ancestry once by walking prev hashes on the stored
header tree, and pass it as BlockValidationContext::assume_valid_ancestor
on the IBD, connect, reorg and pruning paths.
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.

1 participant