mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 13:50:38 +00:00
WIP: p2p: serve and fetch stale-branch blocks (BIP 332)(Stale Tip Relay) #36933
No reviewers
Labels
No labels
Android
Backport
Block storage
Brainstorming
Bug
Build system
CI failed
Consensus
Data corruption
Descriptors
Docs
DrahtBot Guix build requested
Feature
Fuzzing
GUI
Good First Review
IPC
Insufficient Review
Kernel
Linux/Unix
Mempool
Mining
Needs Backport (31.x)
Needs Backport (32.x)
Needs Benchmark
Needs Conceptual Review
Needs backport (30.x)
Needs rebase
Needs release note
Net
P2P
PSBT
Privacy
Private Broadcast
Questions and Help
RPC/REST/ZMQ
Refactoring
Resource usage
Review club
Scripts and tools
Settings
TX fees and policy
Tests
Tracking Issue
UTXO Db and Indexes
Up for grabs
Upstream
Utils/log/libs
Validation
Waiting for author
Wallet
Windows
good first issue
interfaces
macOS
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
bitcoin/bitcoin!36933
Loading…
Reference in a new issue
No description provided.
Delete branch "bip332-staletips-pt3-blocksrelay"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Part of #36833.
Based on #36920; review from
refactor: extract block serving limit checks.This PR lets peers fetch the blocks behind the stale tips announced in #36920. We now serve blocks on the stale branches we track, and the new -staletips=blocks mode downloads the branches peers offer.
Key changes
-staletips=blocksadvertisesprefers_blocks=trueand fetches offered branches. For peers that prefer blocks, we wait to announce a tip until we've fetched it, unless the fetch stalls.have_blockpromises.staletip. It used to go through normal block download, which expected every ancestor from that peer and could disconnect it. Now it's fetched best-effort, in both modes.The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
External sites
Reviews
See the guideline and AI policy for information on the review process.
A summary of reviews will appear here.
LLM Linter (✨ experimental)
Possible places where named args for integral literals may be used (e.g.
func(x, /*named_arg=*/0)in C++, andfunc(x, named_arg=0)in Python):src/test/staletiprelayman_tests.cpp:GetBlockRequestsToSend(peer.id, tree.active_chain, 0s, 1, AnyBlock)src/test/staletiprelayman_tests.cpp:GetBlockRequestsToSend(0, chain, 0s, 2, AnyBlock)src/test/staletiprelayman_tests.cpp:GetBlockRequestsToSend(0, chain, 0s, 0, AnyBlock)src/test/staletiprelayman_tests.cpp:GetBlockRequestsToSend(0, chain, 0s, 1, AnyBlock)(block request lifecycle; four occurrences)src/test/staletiprelayman_tests.cpp:GetBlockRequestsToSend(1, chain, 9s, 1, AnyBlock)src/test/staletiprelayman_tests.cpp:GetBlockRequestsToSend(0, chain, 10s, 1, AnyBlock)src/test/staletiprelayman_tests.cpp:GetBlockRequestsToSend(1, chain, 10s, 1, AnyBlock)src/test/staletiprelayman_tests.cpp:GetBlockRequestsToSend(0, chain, 0s, 1, AnyBlock)(higher-work block requests)src/test/staletiprelayman_tests.cpp:GetBlockRequestsToSend(0, chain, 0s, 1, [](const CBlockIndex&) { return false; })src/test/staletiprelayman_tests.cpp:GetBlockRequestsToSend(0, chain, 0s, 2, AnyBlock)src/test/staletiprelayman_tests.cpp:GetBlockRequestsToSend(0, chain, 0s, 1, AnyBlock)(defers while requesting)Possible places where comparison-specific test macros should replace generic comparisons:
src/test/staletipmessage_tests.cpp:BOOST_CHECK_THROW(DecodeExact(trailing), std::ios_base::failure)→ PreferBOOST_CHECK_EXCEPTIONwith a predicate checking the expected failure message.src/test/staletipmessage_tests.cpp:BOOST_CHECK_THROW(DecodeExact(invalid_bool), std::ios_base::failure)→ PreferBOOST_CHECK_EXCEPTIONwith a predicate checking the expected failure message.src/test/staletipmessage_tests.cpp:BOOST_CHECK_THROW(DecodeExact(truncated), std::ios_base::failure)→ PreferBOOST_CHECK_EXCEPTIONwith a predicate checking the expected failure message.src/test/staletipmessage_tests.cpp:BOOST_CHECK_THROW(DecodeExact(noncanonical), std::ios_base::failure)→ PreferBOOST_CHECK_EXCEPTIONwith a predicate checking the expected failure message.src/test/staletipmessage_tests.cpp:BOOST_CHECK_THROW(DecodeExact(empty_headers), std::ios_base::failure)→ PreferBOOST_CHECK_EXCEPTIONwith a predicate checking the expected failure message.test/functional/p2p_staletip.py:assert len(stale_features) == 1→ Preferassert_equal(len(stale_features), 1).test/functional/p2p_staletip.py:assert len(tracked) > 0→ Preferassert_greater_than(len(tracked), 0).test/functional/p2p_staletip.py:assert len([msg for msg in peer.staletips if msg.tip_hash() == block.hash_int]) == 1→ Preferassert_equal(len([msg for msg in peer.staletips if msg.tip_hash() == block.hash_int]), 1).2026-11-20 19:47:30
🟠 Minor · Re-offering a tip bypasses the stalled-fetch announcement fallback
With
-staletips=blocks, a negotiated peer can repeatedly reset its offer and suppress a tracked tip's announcements toprefers_blockspeers for its tracked lifetime when it is the only peer with an announcement history.Location:
src/node/staletiprelayman.cpp:236(head).🔵 Suggestion · Signet
headersmode cannot track header-only stale-tip offersOn signet,
-staletips=headersadvertisesprefers_blocks=truebut cannot track an unfamiliar equal- or lower-work offer without separately received block data, a limitation absent from the help and release note.Location:
src/node/staletiprelayman.cpp:262(head).🔵 Suggestion · Best-effort active-chain deliveries receive no block-delivery credit
A
STALETIPreply that activates a higher-work branch never updatesm_last_block_time, so it receives less block-delivery credit for eviction than the same newly stored block sent unsolicited.Location:
src/net_processing.cpp:3849(head).🔵 Suggestion · The best-effort fetch switch mixes plumbing and behavior changes
The best-effort switch in
bf6e9f6mixes receive-side plumbing with replacement of the fetch path introduced by2418e2a, making the behavioral transition harder to validate separately.Location: src/net_processing.cpp:6151 (commit).
🔵 Suggestion · No functional test covers lower-work storage followed by
have_blockrelayThe functional suite does not verify that a best-effort reply containing a strictly lower-work block is stored and releases a deferred
have_block=trueannouncement.Location:
test/functional/p2p_staletip.py:763(head).🔵 Suggestion · The stale-branch release note overstates the punishment exemption
The release note promises no disconnect for an invalid announced-branch block, but the implementation intentionally still punishes failures detectable before storage.
Location:
doc/release-notes-36920.md:9(head).Review coverage was incomplete.
Reviewed:
028ea5f8455b· Review report · Previous reportspermalink
🐙 This pull request conflicts with the target branch and needs rebase.