p2p: Track recent stale tips (BIP 332)

bitcoin/bitcoin: PR #36919

Provider refusals

tests_followup: Provider declined the request because of a cybersecurity restriction. These inspection checks remain incomplete.

3 minor findings · 2 suggestions

Earlier concerns neither republished nor resolved: 1 suggestion. See the Run archive for their assessments.

Findings

Link

[minor] · Signet solution mutations bypass variant deduplication

On default Signet with -staletips=headers, solution mutations plus fresh proof of work can fill the local staletips_only list with copies of one signed block, bypassing deduplication and displacing lower-work stale tips.

Location: src/node/staletiptracker.cpp:40 (head).

Details and suggested fix

IsVariantOnBranch compares pprev and the ordinary header hashMerkleRoot, but SignetTxs::Create removes the solution before computing the BIP 325 signed merkle root. On the default bare-multisig challenge, prepending an unused push to the solution's scriptSig preserves signature validity because SCRIPT_VERIFY_CLEANSTACK is absent, while changing the coinbase txid and ordinary root. Each copy still needs Signet-difficulty proof of work. A synchronized node above MinimumChainWork() accepts an unsolicited equal-work sibling, validates its solution, and notifies the tracker after raising BLOCK_VALID_TRANSACTIONS. Its different header root bypasses both active-chain and tracked-branch deduplication. Ten copies of the active tip can displace lower-work entries; once full, the tracker refuses honest equal-work replacements. Key variants on the BIP 325 modified merkle root, retaining that identity through pruning and startup seeding, and add a test using valid blocks with different solutions.


Link

[minor] · Ahead-of-tip headers miss later stale-tip tracking

With -staletips=headers, a header submitted ahead of the active tip can remain absent from staletips_only after a sibling activates; submitheader supports this sequence, but persistent omission under normal P2P relay is unconfirmed.

Location: src/validation.cpp:3851 (head).

Details and suggested fix

On mainnet or regtest, submit header B extending active tip P without its block data, then activate sibling block A. MaybeNotifyAcceptedStaleTip skips B when first accepted because its work exceeds P's. Once A activates, B is eligible, but active-tip callbacks never reconsider it and duplicate headers produce no new notification. Startup seeding can add it on a later plain restart, and receiving its block data can also repair the omission. The callback follows its documented point-in-time contract, but the tracked RPC view misses an eligible fork based on arrival order. Keep a bounded pending set of higher-work headers and recheck it when the active tip changes. Add a regression test covering header B, sibling block A, and a duplicate announcement of B.


Link

[minor] · Reindex startup seeds stale tips before the active chain exists

-staletips=headers can report no tracked forks after -reindex-chainstate or an unpruned -reindex, despite eligible stored stale blocks; constructor-only seeding precedes chain activation, and an ordinary restart restores the list.

Location: src/net_processing.cpp:2171 (head).

Details and suggested fix

Both recovery options wipe the coins database and skip LoadChainTip(). PeerManagerImpl then calls SeedFromBlockIndex() before the initload thread runs ImportBlocks(), so GetEligibleForkPoint() rejects every candidate for lack of an active tip. A chainstate-only rebuild later connects the winning chain without notifying existing stale entries. In a fresh unpruned full reindex without concurrent activation, block-file import activates only genesis while accepting the remaining blocks, so the work gate also suppresses notifications for stored stale blocks. No later reseed reconstructs the list. New stale notifications can add entries, but need not recover the omitted stored forks. Run the one-time seed after import and best-chain activation, and extend the startup functional test with -reindex-chainstate.


Optional improvements

Link

[suggestion] · The Signet variant comment misidentifies nBits as mutable

The IsVariantOnBranch comment describes varying nBits as producing valid Signet variants, but contextual validation fixes that field; nNonce is the intended example.

Location: src/node/staletiptracker.cpp:33 (head).

Details and suggested fix

ContextualCheckBlockHeader requires nBits == GetNextWorkRequired(...), and Signet disables minimum-difficulty exceptions. For a fixed predecessor history, changing nBits therefore produces an invalid header rather than another valid variant. The BIP 325 signed data omits nNonce, so replace nBits with nNonce in this rationale.


Link

[suggestion] · max_depth still builds full-history orphan sets

The new max_depth option filters only after getchaintips builds its pre-existing full-history sets under cs_main; an earlier cutoff would save set allocations on fork-heavy nodes without changing results.

Location: src/rpc/blockchain.cpp:1701 (head).

Details and suggested fix

In the non-staletips_only path, every non-active index entry enters setOrphans and setPrevs before the cutoff is applied. Skip entries below active_chain.Height() - *max_depth during collection. This preserves leaf detection: any child that would exclude a retained parent has greater height and also survives the cutoff. Keep the separately inserted active tip and the final filter for tracked-tip queries. The full O(N) scan remains, but nodes with large stale histories avoid unnecessary set construction and allocation while holding cs_main.


Coverage details

Earlier concerns

Earlier reports raised these, with the titles and severities shown there. This review neither republished nor resolved them.

Background

Ralph's summary of historical context for the behaviour affected by this change. The historical record reviewed here is incomplete.

Unresolved disagreements

Reorg readiness and network-wide stale-history diversity motivate different selection preferences, and the inspected discussion does not establish one universally preferred policy.

Towns contrasted greatest-work selection for likely reorg candidates with randomized, potentially per-connection selection to maximize the number of distinct tips available across the network. The author left exact policy implementation-local. Thus the head's bounded greatest-work set has an articulated objective, but the historical record does not establish that it maximizes observability or mandates its equal-work behavior.

Source 1 · Source 2