Repository navigation
p2p: Relay stale tip announcements (BIP 332)(Stale Tip Relay) - #36920
pseudoramdom wants to merge 21 commits into
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. External sites
ReviewsSee the guideline and AI policy for information on the review process. ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. LLM Linter (✨ experimental)Possible places where comparison-specific test macros should replace generic comparisons:
2026-11-20 19:36:55 |
3d665bd to
3529b7d
Compare
|
🚧 At least one of the CI tasks failed. HintsTry to run the tests locally, according to the documentation. However, a CI failure may still
Leave a comment here, if you need help tracking down a confusing failure. |
3529b7d to
d682925
Compare
Notify validation interface listeners when a header or block is accepted that is not on the active chain and has no more work than the active tip. BIP 332 stale-tip tracking, added in later commits, uses this. Headers from one ProcessNewBlockHeaders() call are coalesced into one notification for the last new header. A block is notified again when its data is stored. Co-authored-by: woltx <[email protected]> Co-authored-by: Anthony Towns <[email protected]>
Add StaleTipTracker, which keeps up to MAX_ADVERTISED_STALETIPS recent stale tips that are eligible for relay under BIP 332. When full, it evicts the tip with the least work. Add BlockTree to test/util/blocktree.h so later tests can share it. Co-authored-by: woltx <[email protected]> Co-authored-by: Anthony Towns <[email protected]>
Test networks are less protected by proof of work, so BIP 332 recommends stricter stale-tip policies there. On signet, only track tips whose block has been validated, and one header variant per block. On testnet3 and testnet4, only track tips with a difficulty of at least about 1,000,000. Co-authored-by: woltx <[email protected]> Co-authored-by: Anthony Towns <[email protected]>
The tracker is not persisted, so add SeedFromBlockIndex() to rebuild it at startup from the eligible stale tips in the block index. Candidates go through AddStaleTip(), so the same policies apply as at runtime. Co-authored-by: woltx <[email protected]> Co-authored-by: Anthony Towns <[email protected]>
Add -staletips=<mode> to opt in to BIP 332 stale-tip relay. For now 'headers' only enables stale-tip tracking, which the next commits add; later PRs add relay behind the same mode. Make the PeerManager ApplyArgsManOptions() return util::Result, like the other ApplyArgsManOptions() helpers, so an invalid mode is reported at startup. Co-authored-by: woltx <[email protected]> Co-authored-by: Anthony Towns <[email protected]>
When -staletips is enabled, track the stale tips this node learns about. Co-authored-by: woltx <[email protected]> Co-authored-by: Anthony Towns <[email protected]>
Add an optional max_depth argument that limits getchaintips to tips at most that many blocks below the active tip, and report fork_point for each tip that is not on the active chain. This lets callers find recent forks without listing every old stale branch on mainnet or walking back each branch to its fork point.
Add a staletips_only argument to getchaintips that lists only the recent stale tips the node tracks with -staletips, taken from the stale-tip tracker. Co-authored-by: woltx <[email protected]> Co-authored-by: Anthony Towns <[email protected]>
Define the BIP 332 staletip message. Move MAX_STALETIP_HEADERS from the tracker to the message header, as the limit comes from the message format. Co-authored-by: woltx <[email protected]> Co-authored-by: Anthony Towns <[email protected]>
Add StaleTipRelayManager to hold the stale-tip relay state and policy, starting with the tracker that PeerManager has owned so far. It requires cs_main instead of a lock of its own, as it holds CBlockIndex pointers. Co-authored-by: woltx <[email protected]> Co-authored-by: Anthony Towns <[email protected]>
d682925 to
10ef89a
Compare
Add MakeStaleTipMessage() to build the staletip message announcing a tracked fork. Make HasAncestor() public so it can check the fork.
Advertise the BIP 434 stale-tip relay feature when -staletips is enabled, and record the feature data of peers that advertise it. Malformed feature data is ignored. On signet, set prefers_blocks, as stale tips there can only be validated with their blocks. Add NetFeatures to hold the recognized BIP 434 features, so that their data is parsed and serialized in one place. Co-authored-by: woltx <[email protected]> Co-authored-by: Anthony Towns <[email protected]>
Add "localfeatures" to getnetworkinfo and "features" to getpeerinfo, listing the BIP 434 features the node and each peer advertise, with their decoded data. Co-authored-by: woltx <[email protected]> Co-authored-by: Anthony Towns <[email protected]>
Name the 144-block anti-DoS buffer ANTI_DOS_WORK_WINDOW and let callers pass a different window. A later commit checks inbound staletip messages against a wider window.
Accept staletip messages from peers that negotiated the feature, and add their headers and track the tip if they pass validation and policy checks. Use STALETIP_RECENT_WINDOW for the work threshold rather than the default 144 blocks, so stale tips that peers may advertise are not discarded. Co-authored-by: woltx <[email protected]> Co-authored-by: Anthony Towns <[email protected]>
If a staletip branch has more work than our active tip, for example because we are behind, handle it as for a headers message: update the peer's header state and request the blocks through the direct-fetch path. Only do so when the peer set have_block, as otherwise it has not said it can serve the blocks. Co-authored-by: woltx <[email protected]> Co-authored-by: Anthony Towns <[email protected]>
Queue an inv for our new active tip to peers that negotiated staletip, even when the normal announcement is skipped because the peer already has the header. A peer only sends us a staletip message whose fork point it knows we have, which it infers from the blocks we announce, so BIP 332 asks nodes to always announce their active tip. Co-authored-by: woltx <[email protected]> Co-authored-by: Anthony Towns <[email protected]>
Announce each eligible stale tip once to negotiated peers that have its fork point but not the tip. On signet, wait until we can serve the block, which peers need to validate the tip. Remember per peer the tips it announced to us, so we don't echo them back. Remember the tips we announced to a peer for as long as they stay tracked, so a reorg doesn't make us announce them again. Co-authored-by: woltx <[email protected]> Co-authored-by: Anthony Towns <[email protected]>
BIP 332 lets a peer serve blocks on a stale branch it never connected, so their scripts may be unchecked. Remember which tips a peer announced with have_block set, and, as for BIP 152 compact blocks, don't punish it for a block on such a branch that only fails once connected, or that already turned out invalid, through an ancestor, when it arrives. Still punish it for a block failing the checks done before storing it, as the peer must have passed them to store the block.
10ef89a to
de7a810
Compare
|
🐙 This pull request conflicts with the target branch and needs rebase. |

Part of #36833.
Based on #36919; review from
p2p: add staletip message type and payload.This adds the BIP 332
staletipmessage, negotiated through the BIP 434BIP332feature. With-staletips=headers, the node announces the stale tips it tracks and tracks the ones its peers announce. Only headers are relayed.Key changes
New
staletipmessage type and payload.Add a
StaleTipRelayManager, which holds the relay policy.With
-staletips=headers, the node advertisesBIP332(withprefers_blocks=false) and relays only with peers that advertise it too.Stale tips learned from peers are tracked, and listed by
getchaintipswithstaletips_only:Sample output
A node that learned of a stale tip only from a peer's
staletipmessage:getnetworkinfogets alocalfeaturesfield, listing the BIP 434 features the node advertises.Sample output
getpeerinfogets afeaturesfield, listing the BIP 434 features each peer advertises.Sample output