Merge bitcoin/bitcoin#36687: test: wait for the node to finish the last block in p2p_ping_ibd
What changed, and why it matters
This is a fix for a flaky automated test, not a security fix for the Bitcoin Core software itself. The test sometimes failed because it moved the simulated clock forward before the test node had fully finished recording the time of the last downloaded block. The patch adds a small synchronization step so the test waits for the node to finish processing before advancing the clock. It does not change production code or fix any vulnerability that could affect real users.
No security action required. Treat as a routine test reliability improvement.
Security signals we found
No production code changed
Test-only race condition fix
No input validation, memory handling, or network protocol changes
No privilege boundary crossed
Evidence from the diff
The commit modifies only test/functional/p2p_ping_ibd.py. It adds a peer.sync_with_ping() call after the test waits for getblockcount to reach the expected height and confirms no blocks are inflight. The race occurs because ProcessBlock() updates m_last_block_time only after ProcessNewBlock() returns; getblockcount can already reflect the new height while the timestamp has not yet been recorded. If bumpmocktime is called in that window, the block timestamp uses the bumped time, and the final clock bump places the ping timeout exactly at its boundary, preventing the timeout from firing. The fix ensures the node has handled a post-block ping before the clock is advanced, eliminating the nondeterministic test failure.
Changed components
test/functional/p2p_ping_ibd.pyInspect captured patch +3 / −0
### test/functional/p2p_ping_ibd.py
@@ -196,6 +196,9 @@ def test_ping_timeout_ibd(self):
peer.serve_next_block()
self.wait_until(lambda: node.getblockcount() == start_height + NUM_DOWNLOAD_BLOCKS)
assert_equal(node.getpeerinfo()[0]["inflight"], [])
+ # The node stamps the last block time only after the block is connected, so wait until it
+ # handled a message sent after the block before moving the clock.
+ peer.sync_with_ping()
self.log.info("Check that the peer still gets a grace period to answer the ping")
node.bumpmocktime(POST_BLOCK_PONG_GRACE // 2)Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.