p2p: Suspend ping timeout while downloading blocks from a peer #36080

Manually merged
mzumsande merged 3 commits from 202608_ping_ibd into master 2026-10-05 08:41:36 +00:00 AGit
mzumsande commented 2026-08-25 15:59:29 +00:00 (Migrated from github.com)

While serving blocks, there is a system in place that prioritizes a peer's block requests before answering other p2p messages:
See
github.com/bitcoin/bitcoin@11090c8bb3/src/net_processing.cpp (L5436)

As a result it can happen that if we do IBD with a low download bandwidth (that is distributed over 10 peers) a peer will not get around to answering our ping before the timeout of 20 minutes, in which case we would disconnect them, although they have done nothing wrong and are not even slow themselves (we are).
This situation has been described in #35761.

This PR fixes the issue by not enforcing the ping timeout from a peer while downloading blocks from them.
In order to do that, the ping timeout check is moved out of MaybeSendPing() (which was a slightly awkward place anyway, given the name of the function) and suspended until there are no longer blocks in flight with that peer (with a grace period, so that we don't disconnect immediately after the last block was received before the peer got a chance to send us the pong).

Note that during block download, there are still other timeouts:

  • A dynamic timeout (BLOCK_DOWNLOAD_TIMEOUT_BASE / BLOCK_DOWNLOAD_TIMEOUT_PER_PEER) which will result in a timeout of 600s × (1 + 0.5×9) = 55 minutes per block when downloading from 10 peers in parallel
  • the stalling logic which hits if the peer is much slower in comparison to other peers
  • the socket inactivity check disconnects a peer that hasn't sent us anything at all in the last 20 minutes.

So the ping timeout didn't add much value anyway in that situation.

Fixes #35761

While serving blocks, there is a system in place that prioritizes a peer's block requests before answering other p2p messages: See https://github.com/bitcoin/bitcoin/blob/11090c8bb359f894ef7d97b65aff52fe8191aec1/src/net_processing.cpp#L5436 As a result it can happen that if we do IBD with a low download bandwidth (that is distributed over 10 peers) a peer will not get around to answering our ping before the timeout of 20 minutes, in which case we would disconnect them, although they have done nothing wrong and are not even slow themselves (we are). This situation has been described in #35761. This PR fixes the issue by not enforcing the ping timeout from a peer while downloading blocks from them. In order to do that, the ping timeout check is moved out of `MaybeSendPing()` (which was a slightly awkward place anyway, given the name of the function) and suspended until there are no longer blocks in flight with that peer (with a grace period, so that we don't disconnect immediately after the last block was received before the peer got a chance to send us the `pong`). Note that during block download, there are still other timeouts: - A dynamic timeout (`BLOCK_DOWNLOAD_TIMEOUT_BASE` / `BLOCK_DOWNLOAD_TIMEOUT_PER_PEER`) which will result in a timeout of `600s × (1 + 0.5×9) = 55 minutes` per block when downloading from 10 peers in parallel - the stalling logic which hits if the peer is much slower in comparison to other peers - the socket inactivity check disconnects a peer that hasn't sent us anything at all in the last 20 minutes. So the ping timeout didn't add much value anyway in that situation. Fixes #35761
DrahtBot commented 2026-08-25 15:59:38 +00:00 (Migrated from github.com)

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.

Type Reviewers
ACK maflcko, fjahr, danielabrozzoni, sedited
Concept ACK l0rinc
Stale ACK AndreaDiazCorreia

If your review is incorrectly listed, please copy-paste <!--meta-tag:bot-skip--> into the comment that the bot should ignore.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #35502 (refactor: extract per-message helpers from ProcessMessage (move-only) by w0xlt)

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.

<!--e57a25ab6845829454e8d69fc972939a--> The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. <!--006a51241073e994b41acfe9ec718e94--> ### External sites * Code coverage & benchmarks: https://corecheck.dev/bitcoin/bitcoin/pulls/36080 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/36080.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/36080#author-ralph <!--021abf342d371248e50ceaed478a90ca--> ### Reviews See [the guideline](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#code-review) and [AI policy](https://github.com/bitcoin/bitcoin/blob/master/doc/AI_POLICY.md) for information on the review process. | Type | Reviewers | | ---- | --------- | | ACK | [maflcko](https://github.com/bitcoin/bitcoin/pull/36080#issuecomment-5954672733), [fjahr](https://github.com/bitcoin/bitcoin/pull/36080#issuecomment-5954854170), [danielabrozzoni](https://github.com/bitcoin/bitcoin/pull/36080#pullrequestreview-5404863414), [sedited](https://github.com/bitcoin/bitcoin/pull/36080#pullrequestreview-5411893106) | | Concept ACK | [l0rinc](https://github.com/bitcoin/bitcoin/pull/36080#pullrequestreview-5032343334) | | Stale ACK | [AndreaDiazCorreia](https://github.com/bitcoin/bitcoin/pull/36080#pullrequestreview-5263175519) | If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore. <!--174a7506f384e20aa4161008e828411d--> ### Conflicts Reviewers, this pull request conflicts with the following ones: * [#35502](https://github.com/bitcoin/bitcoin/pull/35502) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35502.svg"></sub> (refactor: extract per-message helpers from ProcessMessage (move-only) by w0xlt) 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. <!--5faf32d7da4f0f540f40219e4f7537a3-->
l0rinc (Migrated from github.com) reviewed 2026-08-26 15:37:30 +00:00
l0rinc (Migrated from github.com) left a comment

Concept ACK

Concept ACK
l0rinc (Migrated from github.com) commented 2026-08-26 15:36:40 +00:00

abeb912 test: check that the ping timeout is not enforced in IBD:

nit: whenever there's a test after the fix, I have a hard time understanding what the behavior was before the fix, it's why I usually add a characterization test before the fix to document the previous behavior, showing that intermediary refactors don't update the test (i.e. aren't changing behavior) while the fix commit only does surgical changes to the assertions, documenting exactly how the fix changes the assumptions, see https://github.com/bitcoin/bitcoin/pull/35260

It would help with the review if most of the tests would be moved before the fix to help us understand both the before and after states.

> [abeb912](https://github.com/bitcoin/bitcoin/pull/36080/changes/abeb912d45f333e7343f3d335621b9643438edec) _test: check that the ping timeout is not enforced in IBD_: nit: whenever there's a test after the fix, I have a hard time understanding what the behavior was before the fix, it's why I usually add a characterization test before the fix to document the previous behavior, showing that intermediary refactors don't update the test (i.e. aren't changing behavior) while the fix commit only does surgical changes to the assertions, documenting exactly how the fix changes the assumptions, see https://github.com/bitcoin/bitcoin/pull/35260 It would help with the review if most of the tests would be moved before the fix to help us understand both the before and after states.
danielabrozzoni (Migrated from github.com) reviewed 2026-09-02 18:46:20 +00:00
danielabrozzoni (Migrated from github.com) left a comment

Concept ACK! I am slowly going through it and learning more about block relay :)

Concept ACK! I am slowly going through it and learning more about block relay :)
danielabrozzoni (Migrated from github.com) commented 2026-08-31 15:19:04 +00:00

(Comment placed in random location)
nit: In commit message be32083ddb17d5bc1667a56fe7f3b7a82f7e0e68, there's a typo: timout -> timeout

(Comment placed in random location) nit: In commit message be32083ddb17d5bc1667a56fe7f3b7a82f7e0e68, there's a typo: `timout -> timeout`
danielabrozzoni (Migrated from github.com) commented 2026-09-02 18:31:27 +00:00

Surfaced using Opus 5, I checked manually and I think it's correct:

You were previously checking whether to disconnect for inactivity first, and only then deciding whether to send a new ping, based on peer.m_ping_queued and whether enough time passed from the last ping. Now you're doing the opposite, and what might happen is:

  • peer hasn't been responding to our ping, it's time to disconnect it
  • the user calls the ping RPC
  • in MaybeSendPing, peer.m_ping_queued is true, so pingSend gets set to true, and peer.m_ping_start = now and peer.m_ping_nonce_sent get reset.
  • When we reach the disconnection check here, m_ping_start will be fresh, and we won't disconnect.

The chances are of course slim, and I'm not sure what's the best way to fix...

  • You can save a snapshot of m_ping_queued and m_ping_start before MaybeSendPing is called, and here evaluate against those - not super clean, but will work
  • In MaybeSendPing you could honor the user's ping request only if there's not an outstanding ping, but I don't think that's correct
  • Maybe you can move MaybeSendPing down here, but I'm sure it has other implications...
  • You can document that this might happen and move on, the chances are slim, and if it happens it's not too big of a deal imho :)
Surfaced using Opus 5, I checked manually and I think it's correct: You were previously checking whether to disconnect for inactivity first, and only then deciding whether to send a new ping, based on `peer.m_ping_queued` and whether enough time passed from the last ping. Now you're doing the opposite, and what might happen is: - peer hasn't been responding to our ping, it's time to disconnect it - the user calls the ping RPC - in `MaybeSendPing`, `peer.m_ping_queued` is true, so `pingSend` gets set to true, and `peer.m_ping_start = now` and `peer.m_ping_nonce_sent` get reset. - When we reach the disconnection check here, `m_ping_start` will be fresh, and we won't disconnect. The chances are of course slim, and I'm not sure what's the best way to fix... - You can save a snapshot of `m_ping_queued` and `m_ping_start` before `MaybeSendPing` is called, and here evaluate against those - not super clean, but will work - In `MaybeSendPing` you could honor the user's ping request only if there's not an outstanding ping, but I don't think that's correct - Maybe you can move MaybeSendPing down here, but I'm sure it has other implications... - You can document that this might happen and move on, the chances are slim, and if it happens it's not too big of a deal imho :)
danielabrozzoni (Migrated from github.com) commented 2026-09-02 13:44:58 +00:00

Opus 5 flagged this - I think it's true in theory, but I'm not sure in practice if it can ever happen, there's a lot of details around block relay that I don't really know and I'm trying to understand :)

You're using m_last_block_time, but it gets updated only upon receiving a block we didn't already have, which means that a peer that sends us block that we already had would get a shorter post block pong grace, or none at all.

github.com/bitcoin/bitcoin@dc0395c585/src/net_processing.cpp (L3676-L3681)

Suppose peerA has been sending us blocks, and not responding to our pings in the meantime. We only miss one block, the tip. Then, either of this happens:

  • peerB pushes one or more unsolicited BLOCK message with the tip
  • peerB is one of our high bandwidth compact block peers, and sends us the tip, unsolicited, via CMPCTBLOCK. (I think this particular condition can't happen if we were doing IBD with peerA, but it can happen that we have compact block peers if we were synced and then feel behind by a few blocks)

In any case, peerB sends us the last block in peerA's queue. Then peerA will be given a shorter post block pong grace, or none at all, if the last new block they sent was more than 1min ago. This is because peerA sending us the last block didn't update m_last_block_time, since the block wasn't new to us.

Opus 5 flagged this - I think it's true in theory, but I'm not sure in practice if it can ever happen, there's a lot of details around block relay that I don't really know and I'm trying to understand :) You're using `m_last_block_time`, but it gets updated only upon receiving a block we didn't already have, which means that a peer that sends us block that we already had would get a shorter post block pong grace, or none at all. https://github.com/bitcoin/bitcoin/blob/dc0395c5858a1d55239b82a834e5075cf2069219/src/net_processing.cpp#L3676-L3681 Suppose peerA has been sending us blocks, and not responding to our pings in the meantime. We only miss one block, the tip. Then, either of this happens: - peerB pushes one or more unsolicited BLOCK message with the tip - peerB is one of our high bandwidth compact block peers, and sends us the tip, unsolicited, via CMPCTBLOCK. (I think this particular condition can't happen if we were doing IBD with peerA, but it can happen that we have compact block peers if we were synced and then feel behind by a few blocks) In any case, peerB sends us the last block in peerA's queue. Then peerA will be given a shorter post block pong grace, or none at all, if the last new block they sent was more than 1min ago. This is because peerA sending us the last block didn't update `m_last_block_time`, since the block wasn't new to us.
danielabrozzoni (Migrated from github.com) commented 2026-08-31 16:45:44 +00:00

In e13760ad536f15a3280ae555c65ff922cf820478: I don't understand what's the purpose of this check; if the peer was a Bitcoin Core node, we wouldn't be connected anymore (this is the first commit, so there's still ping timeout). The peer is still connected only because P2PInterface has no ping timeout.

In e13760ad536f15a3280ae555c65ff922cf820478: I don't understand what's the purpose of this check; if the peer was a Bitcoin Core node, we wouldn't be connected anymore (this is the first commit, so there's still ping timeout). The peer is still connected only because `P2PInterface` has no ping timeout.
mzumsande (Migrated from github.com) reviewed 2026-09-04 16:35:23 +00:00
mzumsande (Migrated from github.com) commented 2026-09-04 16:35:23 +00:00

moved some of the test into the first commit. The grace period test coverage makes no sense there though.

moved some of the test into the first commit. The grace period test coverage makes no sense there though.
mzumsande (Migrated from github.com) reviewed 2026-09-04 16:35:32 +00:00
mzumsande (Migrated from github.com) commented 2026-09-04 16:35:32 +00:00

fixed

fixed
mzumsande (Migrated from github.com) reviewed 2026-09-04 16:35:50 +00:00
mzumsande (Migrated from github.com) commented 2026-09-04 16:35:50 +00:00

makes sense, I removed the check.

makes sense, I removed the check.
mzumsande (Migrated from github.com) reviewed 2026-09-04 16:38:25 +00:00
mzumsande (Migrated from github.com) commented 2026-09-04 16:38:25 +00:00

I also don't think that this is a real issue in practice, because the original problem exists mostly during IBD, where bandwidth is spread over 10 peers and 16 blocks are queued at the same time. In IBD, we don't request a single block from multiple peers at the same time, so this wouldn't happen. Even if this could happen in theory as a one-off after catching up with the tip as in your scenario, it's a one-off and not a systematic problem as the status quo.

I also don't think that this is a real issue in practice, because the original problem exists mostly during IBD, where bandwidth is spread over 10 peers and 16 blocks are queued at the same time. In IBD, we don't request a single block from multiple peers at the same time, so this wouldn't happen. Even if this could happen in theory as a one-off after catching up with the tip as in your scenario, it's a one-off and not a systematic problem as the status quo.
mzumsande (Migrated from github.com) reviewed 2026-09-04 16:42:52 +00:00
mzumsande (Migrated from github.com) commented 2026-09-04 16:42:52 +00:00

this feels like one of those fringe KI findings that I think don't really need to be addressed:
As far as I can see, a user can meddle with pings already today on master - if they send a ping rpc every 19 minutes, an unresponsive peer will never be disconnected due to missing pings. For the particular issue here, they would need to time their ping exactly, which seems very unlikely. But I don't even think we need to fix the behavior on master.

this feels like one of those fringe KI findings that I think don't really need to be addressed: As far as I can see, a user can meddle with pings already today on master - if they send a `ping` rpc every 19 minutes, an unresponsive peer will never be disconnected due to missing pings. For the particular issue here, they would need to time their ping exactly, which seems very unlikely. But I don't even think we need to fix the behavior on master.
mzumsande commented 2026-09-04 16:43:17 +00:00 (Migrated from github.com)

abeb912 to c551ff4: addressed feedback

[abeb912](https://github.com/bitcoin/bitcoin/commit/abeb912d45f333e7343f3d335621b9643438edec) to [c551ff4](https://github.com/bitcoin/bitcoin/commit/c551ff40a4f924eb42680e3eeef39d47d889e55c): addressed feedback
danielabrozzoni (Migrated from github.com) reviewed 2026-09-11 16:08:45 +00:00
danielabrozzoni (Migrated from github.com) left a comment

Thanks for dealing with my AI-assisted review :) I only left an additional comment, I think the test can be made slightly more robust, by checking that the timeout and post block pong grace are only enforced if there are no blocks in flight, which kills one mutant.

Thanks for dealing with my AI-assisted review :) I only left an additional comment, I think the test can be made slightly more robust, by checking that the timeout and post block pong grace are only enforced if there are no blocks in flight, which kills one mutant.
danielabrozzoni (Migrated from github.com) commented 2026-09-11 16:01:37 +00:00

I think here you should also wait for POST_BLOCK_PONG_GRACE + 1 seconds, and check that you don't get disconnected:

diff --git a/test/functional/p2p_ping_ibd.py b/test/functional/p2p_ping_ibd.py
index 0774bf8dc8..7f1ec2d4b5 100755
--- a/test/functional/p2p_ping_ibd.py
+++ b/test/functional/p2p_ping_ibd.py
@@ -186,6 +186,9 @@ class PingIBDTest(BitcoinTestFramework):
                 self.wait_until(lambda: node.getblockcount() == start_height + peer.blocks_served)
                 assert peer.is_connected
         assert_greater_than(node.getpeerinfo()[0]["pingwait"], TIMEOUT_INTERVAL)
+        node.bumpmocktime(POST_BLOCK_PONG_GRACE + 1)
+        peer.sync_with_ping()
+        assert peer.is_connected
 
         self.log.info("Serve the remaining blocks, so that nothing is in flight anymore")
         while peer.blocks_served < NUM_DOWNLOAD_BLOCKS:

This way you're checking that we're not disconnecting once the timeout elapsed and the POST_BLOCK_PONG_GRACE period passed if there are still blocks in flight.

If you don't add this check, you can mutate the original code like this, and the test will still pass:

diff --git a/src/net_processing.cpp b/src/net_processing.cpp
index c339b471c5..734a41796d 100644
--- a/src/net_processing.cpp
+++ b/src/net_processing.cpp
@@ -6441,7 +6441,7 @@ bool PeerManagerImpl::SendMessages(CNode& node)
         // If the peer failed to answer our ping in time, disconnect due to timeout.
         // Skip the check while it is serving us blocks and let the block download timeout above govern
         // instead. Once the last new block was received, give the peer a grace period to answer the ping.
-        if (state.vBlocksInFlight.empty() &&
+        if (/*state.vBlocksInFlight.empty() &&*/
             now > NodeSeconds{node.m_last_block_time.load()} + POST_BLOCK_PONG_GRACE &&
             m_connman.ShouldRunInactivityChecks(node, now) &&
             peer.m_ping_nonce_sent &&
I think here you should also wait for `POST_BLOCK_PONG_GRACE + 1` seconds, and check that you don't get disconnected: ```diff diff --git a/test/functional/p2p_ping_ibd.py b/test/functional/p2p_ping_ibd.py index 0774bf8dc8..7f1ec2d4b5 100755 --- a/test/functional/p2p_ping_ibd.py +++ b/test/functional/p2p_ping_ibd.py @@ -186,6 +186,9 @@ class PingIBDTest(BitcoinTestFramework): self.wait_until(lambda: node.getblockcount() == start_height + peer.blocks_served) assert peer.is_connected assert_greater_than(node.getpeerinfo()[0]["pingwait"], TIMEOUT_INTERVAL) + node.bumpmocktime(POST_BLOCK_PONG_GRACE + 1) + peer.sync_with_ping() + assert peer.is_connected self.log.info("Serve the remaining blocks, so that nothing is in flight anymore") while peer.blocks_served < NUM_DOWNLOAD_BLOCKS: ``` This way you're checking that we're not disconnecting once the timeout elapsed and the `POST_BLOCK_PONG_GRACE` period passed if there are still blocks in flight. If you don't add this check, you can mutate the original code like this, and the test will still pass: ```diff diff --git a/src/net_processing.cpp b/src/net_processing.cpp index c339b471c5..734a41796d 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -6441,7 +6441,7 @@ bool PeerManagerImpl::SendMessages(CNode& node) // If the peer failed to answer our ping in time, disconnect due to timeout. // Skip the check while it is serving us blocks and let the block download timeout above govern // instead. Once the last new block was received, give the peer a grace period to answer the ping. - if (state.vBlocksInFlight.empty() && + if (/*state.vBlocksInFlight.empty() &&*/ now > NodeSeconds{node.m_last_block_time.load()} + POST_BLOCK_PONG_GRACE && m_connman.ShouldRunInactivityChecks(node, now) && peer.m_ping_nonce_sent && ```
mzumsande (Migrated from github.com) reviewed 2026-09-16 14:00:09 +00:00
mzumsande (Migrated from github.com) commented 2026-09-16 14:00:09 +00:00

good suggestion - done!

good suggestion - done!
AndreaDiazCorreia (Migrated from github.com) reviewed 2026-09-21 05:00:15 +00:00
AndreaDiazCorreia (Migrated from github.com) left a comment

tested ACK 31280333dd

Built each commit. Between MaybeSendPing and the new location there are only two returns, and both already set fDisconnect, so no peer class gains or loses the timeout from the move alone. p2p_ping_ibd.py, --v2transport and p2p_ping.py pass at the tip, and the test from 56c194e655 passes against the 95dcf8f10d binary while only failing against the tip, so the relocation is behaviour-preserving.

I also tested it between two regtest nodes, no mocktime, with a local proxy limiting the serving side to 8 KiB/s while the receiver downloaded 25 blocks of ~946 kB. Before the fix the receiver disconnected after ~22 minutes at height 211, with 14 blocks still in flight:

2026-09-21T04:38:36.772959Z [net] ping timeout: 1200.019086s, disconnecting peer=0

With the fix it stayed connected, answered a ping 30m47s late and finished the 25 blocks in ~48 minutes.

One question (non-blocking): with a block in flight, is the block download timeout now the only bound, and does its window reset on every front-of-queue arrival? That would let a peer that never pongs but keeps delivering stay connected for hours. Seems right to me but I just want to confirm it is intended.

Part of the testing was AI-assisted (build and test orchestration, log collection). I checked the results myself.

tested ACK 31280333dd4f9ef2ec818b1a9d25daaeb502659e Built each commit. Between `MaybeSendPing` and the new location there are only two returns, and both already set `fDisconnect`, so no peer class gains or loses the timeout from the move alone. `p2p_ping_ibd.py`, `--v2transport` and `p2p_ping.py` pass at the tip, and the test from 56c194e655 passes against the 95dcf8f10d binary while only failing against the tip, so the relocation is behaviour-preserving. I also tested it between two regtest nodes, no mocktime, with a local proxy limiting the serving side to 8 KiB/s while the receiver downloaded 25 blocks of ~946 kB. Before the fix the receiver disconnected after ~22 minutes at height 211, with 14 blocks still in flight: 2026-09-21T04:38:36.772959Z [net] ping timeout: 1200.019086s, disconnecting peer=0 With the fix it stayed connected, answered a ping 30m47s late and finished the 25 blocks in ~48 minutes. One question (non-blocking): with a block in flight, is the block download timeout now the only bound, and does its window reset on every front-of-queue arrival? That would let a peer that never pongs but keeps delivering stay connected for hours. Seems right to me but I just want to confirm it is intended. Part of the testing was AI-assisted (build and test orchestration, log collection). I checked the results myself.
fjahr (Migrated from github.com) reviewed 2026-09-28 16:03:21 +00:00
fjahr (Migrated from github.com) left a comment

Code review ACK 31280333dd

Modulo my comment in the functional test, but it's also pretty harmless afaict, just would be good to address if you retouch.

Code review ACK 31280333dd4f9ef2ec818b1a9d25daaeb502659e Modulo my comment in the functional test, but it's also pretty harmless afaict, just would be good to address if you retouch.
fjahr (Migrated from github.com) commented 2026-09-28 15:38:40 +00:00

I am not sure I am getting this incorrectly but the peer is the one that would need their time bumped because that's the receiving side. But also running the check immediately feels racy. It seems to pong is being stalled by the stalling of blocks, so this can't actually fail as it is done now. I think the whole check can be removed since the assert just duplicates the one above if the timebump has no effect.

I am not sure I am getting this incorrectly but the peer is the one that would need their time bumped because that's the receiving side. But also running the check immediately feels racy. It seems to `pong` is being stalled by the stalling of blocks, so this can't actually fail as it is done now. I think the whole check can be removed since the assert just duplicates the one above if the timebump has no effect.
maflcko (Migrated from github.com) approved these changes 2026-09-29 13:14:23 +00:00
maflcko (Migrated from github.com) left a comment

review ACK 31280333dd 🛐

Show signature

Signature:

untrusted comment: signature from minisign secret key on empty file; verify via: minisign -Vm "${path_to_any_empty_file}" -P RWTRmVTMeKV5noAMqVlsMugDDCyyTSbA3Re5AkUrhvLVln0tSaFWglOw -x "${path_to_this_whole_four_line_signature_blob}"
RUTRmVTMeKV5npGrKx1nqXCw5zeVHdtdYURB/KlyA/LMFgpNCs+SkW9a8N95d+U4AP1RJMi+krxU1A3Yux4bpwZNLvVBKy0wLgM=
trusted comment: review ACK 31280333dd4f9ef2ec818b1a9d25daaeb502659e 🛐
5aW7uyMCJTscjwRcjliby8TfMCn7FltFsZy0R1a53FnKeNXBPpQfm6tERiTlLwGrxuTBCaF1JLVShaTlr4GbCQ==
review ACK 31280333dd4f9ef2ec818b1a9d25daaeb502659e 🛐 <details><summary>Show signature</summary> Signature: ``` untrusted comment: signature from minisign secret key on empty file; verify via: minisign -Vm "${path_to_any_empty_file}" -P RWTRmVTMeKV5noAMqVlsMugDDCyyTSbA3Re5AkUrhvLVln0tSaFWglOw -x "${path_to_this_whole_four_line_signature_blob}" RUTRmVTMeKV5npGrKx1nqXCw5zeVHdtdYURB/KlyA/LMFgpNCs+SkW9a8N95d+U4AP1RJMi+krxU1A3Yux4bpwZNLvVBKy0wLgM= trusted comment: review ACK 31280333dd4f9ef2ec818b1a9d25daaeb502659e 🛐 5aW7uyMCJTscjwRcjliby8TfMCn7FltFsZy0R1a53FnKeNXBPpQfm6tERiTlLwGrxuTBCaF1JLVShaTlr4GbCQ== ``` </details>
maflcko (Migrated from github.com) commented 2026-09-29 13:00:07 +00:00

nit in the second commit 95dcf8f10d: Obviously this is fine, but personally I am not a fan of expanding massive scopes (and locks) that span several unrelated topics over hundreds of lines.

For me, this makes it hard to review, because:

  • The git --function-context will pull in all tx getdata logic.
  • The large scope can hide shadowing issues.
  • The large lock scope can imply there are atomicity requirements that don't exist.

So I am thinking if it could make sense to move this to its own small lock scope. I don't think placement matters: It could be in the end after MaybeSendFeefilter, or early (before MaybeSendPing). I don't mind moving it out of MaybeSendPing, I just wonder if there is a better placement with a smaller (lock) scope, so that future code changes in this area are easier to review.

nit in the second commit 95dcf8f10dc83fd1d5048fc82027f53b3f83dba3: Obviously this is fine, but personally I am not a fan of expanding massive scopes (and locks) that span several unrelated topics over hundreds of lines. For me, this makes it hard to review, because: * The git `--function-context` will pull in all tx getdata logic. * The large scope can hide shadowing issues. * The large lock scope can imply there are atomicity requirements that don't exist. So I am thinking if it could make sense to move this to its own small lock scope. I don't think placement matters: It could be in the end after `MaybeSendFeefilter`, or early (before `MaybeSendPing`). I don't mind moving it out of `MaybeSendPing`, I just wonder if there is a better placement with a smaller (lock) scope, so that future code changes in this area are easier to review.
maflcko (Migrated from github.com) commented 2026-09-29 13:09:47 +00:00

nit in the last commit 31280333dd: Not sure why this line is removed? It seems it should come right after the

        self.log.info("Check that the grace period doesn't apply while blocks are still in flight")
...> assert that blocks are still in flight here <...
nit in the last commit 31280333dd4f9ef2ec818b1a9d25daaeb502659e: Not sure why this line is removed? It seems it should come right after the ```py self.log.info("Check that the grace period doesn't apply while blocks are still in flight") ...> assert that blocks are still in flight here <...
maflcko (Migrated from github.com) commented 2026-09-29 10:45:22 +00:00

I had the same thought: This sub-test is mostly about the order of messages and that stalling can occur, not about exact timing. Seems fine to remove, but no strong opinion.

I had the same thought: This sub-test is mostly about the order of messages and that stalling can occur, not about exact timing. Seems fine to remove, but no strong opinion.
maflcko (Migrated from github.com) commented 2026-09-29 10:46:38 +00:00

nit in the first commit: The timeout can probably be dropped? Sending 16MB should be faster than that even with sanitizers (and sanitizer come with an increased --timout-factor anyway).

nit in the first commit: The timeout can probably be dropped? Sending 16MB should be faster than that even with sanitizers (and sanitizer come with an increased --timout-factor anyway).
First-time contributor

Base: 69142eacd1374925cc9e4ea736c21fcec16307d0
Head: d83647e7c48a11dc54ad697342a4b7e3bce9061b

🟡 Minor

Grant grace for late duplicate block responses (src/net_processing.cpp:6445, head)

When multiple peers are asked for the same block, one peer can deliver it first, causing ProcessBlock to remove all in-flight requests. If another peer's already-issued response then arrives as a duplicate, ProcessBlock does not refresh m_last_block_time; an expired ping can therefore trigger this check immediately when the peer's in-flight list is empty. Track relevant block responses separately or otherwise grant grace for a late response to a canceled request. Parallel compact-block requests are permitted, but how often a late duplicate coincides with an expired ping in production is unconfirmed.

Review coverage was incomplete. The alternatives experiment had incomplete evidence. The adversarial review had incomplete evidence. The adversarial_glm review had incomplete evidence.

Full review report

<!-- forgejo-review-bot:bitcoin/bitcoin --> Base: `69142eacd1374925cc9e4ea736c21fcec16307d0` Head: `d83647e7c48a11dc54ad697342a4b7e3bce9061b` ##### 🟡 Minor **Grant grace for late duplicate block responses** (src/net_processing.cpp:6445, head) When multiple peers are asked for the same block, one peer can deliver it first, causing `ProcessBlock` to remove all in-flight requests. If another peer's already-issued response then arrives as a duplicate, `ProcessBlock` does not refresh `m_last_block_time`; an expired ping can therefore trigger this check immediately when the peer's in-flight list is empty. Track relevant block responses separately or otherwise grant grace for a late response to a canceled request. Parallel compact-block requests are permitted, but how often a late duplicate coincides with an expired ping in production is unconfirmed. Review coverage was incomplete. The alternatives experiment had incomplete evidence. The adversarial review had incomplete evidence. The adversarial_glm review had incomplete evidence. [Full review report](<https://review.fish.foo/traces/36080-d83647e7c48a11dc54ad697342a4b7e3bce9061b-287-2.html>)
mzumsande (Migrated from github.com) reviewed 2026-10-02 14:20:25 +00:00
mzumsande (Migrated from github.com) commented 2026-10-02 14:20:25 +00:00

good point, I removed it. I just left the comment about what would happen at the peer, the other added test covers the other side anyway.

good point, I removed it. I just left the comment about what would happen at the peer, the other added test covers the other side anyway.
mzumsande (Migrated from github.com) reviewed 2026-10-02 14:20:42 +00:00
mzumsande (Migrated from github.com) commented 2026-10-02 14:20:42 +00:00

done

done
mzumsande (Migrated from github.com) reviewed 2026-10-02 14:22:26 +00:00
mzumsande (Migrated from github.com) commented 2026-10-02 14:22:26 +00:00

The reason I did that was to avoid locking cs_main multiple times in SendMessages, which seemed to be the preexisting philosophy of that function. I checked that the refactor #35522 also doesn't change this. I feel that if taking/releasing the lock multiple times is not something we want to avoid, we could also just leave the check where it is in MaybeSendPing and add a lock there (even if it is a bit unexpected given the function name). So no strong opinion, but I didn't change it with the last push.

The reason I did that was to avoid locking `cs_main` multiple times in `SendMessages`, which seemed to be the preexisting philosophy of that function. I checked that the refactor #35522 also doesn't change this. I feel that if taking/releasing the lock multiple times is not something we want to avoid, we could also just leave the check where it is in `MaybeSendPing` and add a lock there (even if it is a bit unexpected given the function name). So no strong opinion, but I didn't change it with the last push.
mzumsande (Migrated from github.com) reviewed 2026-10-02 14:22:48 +00:00
mzumsande (Migrated from github.com) commented 2026-10-02 14:22:48 +00:00

readded the line, it wasn't meant to be removed.

readded the line, it wasn't meant to be removed.
mzumsande commented 2026-10-02 14:26:37 +00:00 (Migrated from github.com)

3128033 to d83647e: addressed feedback

One question (non-blocking): with a block in flight, is the block download timeout now the only bound, and does its window reset on every front-of-queue arrival? That would let a peer that never pongs but keeps delivering stay connected for hours. Seems right to me but I just want to confirm it is intended.

yes, I think that is correct. There is still the socket inactivity check, but this will not fire if the peer keeps on sending blocks. But I don't think that this is a problem, blocks are more helpful for us than ping messages, which are not really important by themselves but a way to check responsibility in times when we don't exchanges more important messages.

[3128033](https://github.com/bitcoin/bitcoin/commit/31280333dd4f9ef2ec818b1a9d25daaeb502659e) to [d83647e](https://github.com/bitcoin/bitcoin/commit/d83647e7c48a11dc54ad697342a4b7e3bce9061b): addressed feedback > One question (non-blocking): with a block in flight, is the block download timeout now the only bound, and does its window reset on every front-of-queue arrival? That would let a peer that never pongs but keeps delivering stay connected for hours. Seems right to me but I just want to confirm it is intended. yes, I think that is correct. There is still the socket inactivity check, but this will not fire if the peer keeps on sending blocks. But I don't think that this is a problem, blocks are more helpful for us than ping messages, which are not really important by themselves but a way to check responsibility in times when we don't exchanges more important messages.
maflcko commented 2026-10-02 14:30:13 +00:00 (Migrated from github.com)

Only change is test nits

review ACK d83647e7c4 🌎

Show signature

Signature:

untrusted comment: signature from minisign secret key on empty file; verify via: minisign -Vm "${path_to_any_empty_file}" -P RWTRmVTMeKV5noAMqVlsMugDDCyyTSbA3Re5AkUrhvLVln0tSaFWglOw -x "${path_to_this_whole_four_line_signature_blob}"
RUTRmVTMeKV5npGrKx1nqXCw5zeVHdtdYURB/KlyA/LMFgpNCs+SkW9a8N95d+U4AP1RJMi+krxU1A3Yux4bpwZNLvVBKy0wLgM=
trusted comment: review ACK d83647e7c48a11dc54ad697342a4b7e3bce9061b 🌎
u8lrcdX5UP+MpTjsW0cLYHfcBM6Zj86Yu6pQBzXC7Zo2Cr+ebB4mswhEZtgofjNmW8AdY+KUtTXegtqfU3oMBw==
Only change is test nits review ACK d83647e7c48a11dc54ad697342a4b7e3bce9061b 🌎 <details><summary>Show signature</summary> Signature: ``` untrusted comment: signature from minisign secret key on empty file; verify via: minisign -Vm "${path_to_any_empty_file}" -P RWTRmVTMeKV5noAMqVlsMugDDCyyTSbA3Re5AkUrhvLVln0tSaFWglOw -x "${path_to_this_whole_four_line_signature_blob}" RUTRmVTMeKV5npGrKx1nqXCw5zeVHdtdYURB/KlyA/LMFgpNCs+SkW9a8N95d+U4AP1RJMi+krxU1A3Yux4bpwZNLvVBKy0wLgM= trusted comment: review ACK d83647e7c48a11dc54ad697342a4b7e3bce9061b 🌎 u8lrcdX5UP+MpTjsW0cLYHfcBM6Zj86Yu6pQBzXC7Zo2Cr+ebB4mswhEZtgofjNmW8AdY+KUtTXegtqfU3oMBw== ``` </details>
fjahr commented 2026-10-02 14:41:21 +00:00 (Migrated from github.com)

reACK d83647e7c4

reACK d83647e7c48a11dc54ad697342a4b7e3bce9061b
danielabrozzoni (Migrated from github.com) approved these changes 2026-10-04 07:33:39 +00:00
danielabrozzoni (Migrated from github.com) left a comment
ACK d83647e7c48a11dc54ad697342a4b7e3bce9061b
sedited (Migrated from github.com) approved these changes 2026-10-05 08:32:16 +00:00
sedited (Migrated from github.com) left a comment
ACK d83647e7c48a11dc54ad697342a4b7e3bce9061b
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
bitcoin/bitcoin!36080
No description provided.