Repository navigation
consensus: decide header and block rules without opening the store - #1055
Conversation
ed5c9a3 to
f3d7206
Compare
There was a problem hiding this comment.
Summary
The split holds. rbitcoin-consensus no longer depends on query, store, or log (store is dev-only); header, block, and spend rejects are decided from bytes plus caller facts; confirm has one accept_and_connect_block body; merkle including the CVE-2012-2459 flag lives once in rbitcoin-primitives; the two MTP/load-incomplete strings stay ConfirmError::Store; and rbitcoin-sv2's new query dependency only loads expected_next_bits and median_time_past (no cycle and no second rule pipeline). Store faults, including ConsensusError::Internal from the script/index pool, are not cached as failed blocks on the tip path, and the "parent create_fk unresolved" → MissingPrevout remap is the same outcome the old ConsensusError::From<StoreError> already produced, with IBD still reclassifying a one-block miss.
Issue counts by severity
- bugs: 0
- suggestions: 1
- nits: 0
| @@ -130,97 +147,6 @@ pub(crate) fn check_header_version_and_future_time( | |||
| /// chain, then load-stage header plans (same hybrid as [`crate::confirm_run`] | |||
There was a problem hiding this comment.
[suggestion] Deleting median_time_past left its rustdoc attached to next_work_bits. The comment describes an 11-block median and a confirm-load header-plan walk, and it links [crate::confirm_run], which is no longer a module of this crate. next_work_bits computes nBits from the parent, the period start, and the testnet min-difficulty callback. The difficulty-walk docs that used to sit on this function were removed in the same hunk.
Suggestion: Delete the median-time comment and put the nBits contract back on next_work_bits (period_first_time, bits_at, and None for a missing ancestor). Point MTP readers at median_time_past_times or the query loaders.
There was a problem hiding this comment.
Restored the nBits contract on next_work_bits (period_first_time, bits_at, and None for a missing ancestor). Median time is median_time_past_times. The confirm_run link is gone.
a6df196 to
fb432c9
Compare
Store tip revalidation and consensus block checks both call the primitives helpers, including the CVE-2012-2459 mutation flag.
check_header decides linkage, MTP, bits, and proof-of-work from caller facts. The read façade still returns the two confirm retry strings when a parent plan or confirmed header is missing.
BIP30 overwrite and coinbase maturity decide from heights the caller already loaded. Assemble no longer reads the milestone gate or flushes confirm stats; the confirm pipeline does both.
Rule accepts and rejects stay in rbitcoin-consensus, decided from bytes and caller facts. Query loads rows and writes Class A, Class C, and spend annotations, then calls those functions. Consensus no longer depends on query, store, or log.
expected_bits_extending is only called from confirm tests. ConsensusError imports that tests match on stay inside those test modules so a non-test build of query stays warning-clean.
Query callers match ConfirmError::Rules around a rule reject. A live index invariant stays StoreError::Corrupt, so it is not a cached block failure. Clippy: eight caller facts on check_header, an elided prevout lifetime, and JobPrevouts::is_empty.
The rebase onto the witness, sigop, and BIP68 coinbase pins left store-backed tests calling consensus paths that now live on query. The exception-hash pin stays in consensus because the job verifier is crate-private. Connect results match ConfirmError::Rules.
StoreError::Cancelled stays ConfirmError::Store. header_reject maps that abort to NetError::Cancelled and does not call block_reject_reason. A side block whose parent header read is cancelled is not BLOCK_FAILED.
The median-time note stayed behind when median_time_past left this crate, and it linked confirm_run. Median time is median_time_past_times.
The IBD stop flag stays set after teardown. A header read must not turn that into a cancel. Tests arm one cancelled read instead.
Scripthash materialize returns before a block mined in that window is connected. The wallet listener waits for that getheaders round and, when the scripthash index is on, for the head to cover the new tip.
Assemble used that median again for BIP113. The second sort of the same eleven timestamps is the value check_header already computed.
fb432c9 to
54e4930
Compare
Summary
rbitcoin-consensusdecides header, block, and transaction accepts and rejects from block bytes plus caller facts (parent header context, prevout amount and script bytes, spent flags, create heights, median-time-past). It does not open the store or the log.rbitcoin-queryloads rows, writes Class A, Class C, and spend annotations, and calls those functions.ConfirmError:Rules(ConsensusError)orStore(StoreError).ConsensusError::Storeis gone. Disk, io_uring session faults, and cancellation stay pipeline errors and are not cached as an invalid block. A corrupt row whose message is an unresolved parentcreate_fkis still a missing prevout at that edge.rbitcoin-primitives. Store’s public merkle names call it. The script fuzz target still calls this tree’s verifier.rbitcoin-sv2depends onrbitcoin-queryso the template provider can callexpected_next_bitsandmedian_time_past.getheadersround is connected and, with--sh-index, until that tip is in the scripthash head. A block mined during materialize is in history before the wallet port opens.Test plan
cargo tree -p rbitcoin-consensus -e normallists neither query, store, nor log; query lists consensuscore_script_tests_all_rowsPrevoutSpent, bad merkle, bad script, and a store fault that is not cached invalidcargo fmt --all -- --check,cargo clippy --workspace --all-targets -- -D warnings,cargo deny check,./scripts/ast-grep.shon the pre-rebase tip; touched files rustfmt-clean andclippy -p rbitcoin-net -p rbitcoin-node --all-targets -D warningsclean onfb432c99./scripts/ci-os-smoke.shon the pre-rebase tipend_of_ibd(4 tests) passed locally onfb432c99, includingend_of_ibd_sh_interrupt. The same test passed onorigin/master6c933cdband failed ona6df196fbecause Electrum answered before the follow block was indexed.qc,test,windows,macos, andcoverageonfb432c99