Skip to content

net: introduce block tracker to retry to download blocks after failure - #35113

Closed
optout21 wants to merge 6 commits into
bitcoin:masterfrom
optout21:block-dl
Closed

optout21 wants to merge 6 commits into
bitcoin:masterfrom
optout21:block-dl

Conversation

@optout21

@optout21 optout21 commented Apr 19, 2026 •

Copy link
Copy Markdown
Contributor

Revival of closed/stale #27837 . The change is taken (as of b18c72c) and rebased to current master. Original description follows.

Coming from #27652, part of #29183.

The general idea is to keep track of the user requested blocks so, in
case of a bad behaving peer or a network disconnection, they can be
fetched from another one automatically without any further user interaction.

This was requested by users because the getblockfrompeer RPC command
lacks the functionality to notify them about block request failures or peer
disconnections (which is expected due to the asynchronous nature of the block
requests).

Currently, this new functionality is limited to blocks requested by the
user via the 'getblockfrompeer' RPC command.

In the future, this class could expand its scope and be utilized in the
regular chain synchronization process. Or, even could be employed in
special procedures like a prune node rescan that uses BIP158 block filters,
or even into BIP157 itself.

@DrahtBot DrahtBot added the P2P label Apr 19, 2026
@DrahtBot

DrahtBot commented Apr 19, 2026 •

Copy link
Copy Markdown
Contributor

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.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #35498 (net: move cs_main up in FetchBlock to fix rpc assert crash by Crypt-iQ)
  • #34565 (refactor: extract BlockDownloadManager from PeerManagerImpl by w0xlt)
  • #28690 (build: Introduce internal kernel library by sedited)

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.

furszy and others added 6 commits April 21, 2026 11:11
This is in preparation for block tracker.

Co-authored-by: optout <[email protected]>
If the initial block fetching process fails, the p2p layer will be in
charge of fetching the block from 'any' connected peer.
Re-trying to download the block from different peers until it is
received.

Co-authored-by: optout <[email protected]>
If no 'peer_id' is provided, 'getblockfrompeer' will delegate
the peer selection to the internal block downloading logic.

Co-authored-by: optout <[email protected]>
Allowing what we had before, a single block request with no automatic
retry nor tracking mechanism.

Co-authored-by: optout <[email protected]>
Comment thread src/rpc/blockchain.cpp
{"peer_id", RPCArg::Type::NUM, RPCArg::Optional::OMITTED, "The peer to fetch it from (see getpeerinfo for peer IDs). "
"If omitted, the node will fetch the block from any available peer."},
{"retry", RPCArg::Type::BOOL, RPCArg::Optional::OMITTED, "Whether to automatically retry to download the block from different peers if the initial request fails or not. "
"If omitted, the node will continuously attempt to download the block from various peers until it succeeds."},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like that's a default of true (not RPCArg::Optional::OMITTED with a description noting it)?

Comment thread src/rpc/blockchain.cpp
{"blockhash", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The block hash to try to fetch"},
{"peer_id", RPCArg::Type::NUM, RPCArg::Optional::NO, "The peer to fetch it from (see getpeerinfo for peer IDs)"},
{"peer_id", RPCArg::Type::NUM, RPCArg::Optional::OMITTED, "The peer to fetch it from (see getpeerinfo for peer IDs). "
"If omitted, the node will fetch the block from any available peer."},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"If omitted, the node will fetch the block from any available peer."},
"If omitted, the node will fetch the block from any available peer. (requires retry=true)"},

...or fix it to work without retry

Comment thread src/rpc/blockchain.cpp
{"peer_id", RPCArg::Type::NUM, RPCArg::Optional::NO, "The peer to fetch it from (see getpeerinfo for peer IDs)"},
{"peer_id", RPCArg::Type::NUM, RPCArg::Optional::OMITTED, "The peer to fetch it from (see getpeerinfo for peer IDs). "
"If omitted, the node will fetch the block from any available peer."},
{"retry", RPCArg::Type::BOOL, RPCArg::Optional::OMITTED, "Whether to automatically retry to download the block from different peers if the initial request fails or not. "

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Booleans should ideally not be positional parameters, named only (eg, with an options Object)

@optout21 optout21 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The last commit re-introduces behavior "what we had before". I will see how changes could be reordered to avoid removing some behavior and then re-introducing again.

@optout21

Copy link
Copy Markdown
Contributor Author

@luke-jr , thanks for the comments on the RPC parameters, I will consider them with upcoming changes.

@DrahtBot

Copy link
Copy Markdown
Contributor

🐙 This pull request conflicts with the target branch and needs rebase.

@DrahtBot

Copy link
Copy Markdown
Contributor

⌛ There hasn't been much activity lately and the patch still needs rebase. What is the status here?

  • Is it still relevant? ➡️ Please solve the conflicts to make it ready for review and to ensure the CI passes.
  • Is it no longer relevant? ➡️ Please close.
  • Did the author lose interest or time to work on this? ➡️ Please close it and mark it with one of the labels 'Up for grabs' or 'Insufficient Review', so that it can be picked up in the future.

@optout21

Copy link
Copy Markdown
Contributor Author

Closing for now, due to lack of focus, limited personal resources. Could be marked "Up for grabs"!

@optout21 optout21 closed this Oct 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants