test: remove magic number when checking for blocks that have arrived
What changed, and why it matters
This commit only changes a test file. It replaces a hard-coded byte-count workaround with a cleaner check using existing peer information. There is no change to the actual Bitcoin Core software that users run, and no security issue is present.
No action needed. This is a non-security test refactor.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff modifies test/functional/p2p_ibd_stalling.py. It removes a helper method that summed per-message byte counts and a magic-number comparison, replacing them with a check that only one block remains in flight across all peers. This is a test-code readability and maintainability improvement; no production code is touched.
Changed components
test/functional/p2p_ibd_stalling.pyInspect captured patch +2 / −10
diff --git a/test/functional/p2p_ibd_stalling.py b/test/functional/p2p_ibd_stalling.py
index 542d767c..e7066ea7 100755
--- a/test/functional/p2p_ibd_stalling.py
+++ b/test/functional/p2p_ibd_stalling.py
@@ -80,10 +80,8 @@ class P2PIBDStallingTest(BitcoinTestFramework):
peers[-1].block_store = block_dict
peers[-1].send_and_ping(headers_message)
- # Need to wait until 1023 blocks are received - the magic total bytes number is a workaround in lack of an rpc
- # returning the number of downloaded (but not connected) blocks.
- bytes_recv = 172761 if not self.options.v2transport else 169692
- self.wait_until(lambda: self.total_bytes_recv_for_blocks() == bytes_recv)
+ # Wait until all blocks are received (except for stall_block), so that no other blocks are in flight.
+ self.wait_until(lambda: sum(len(peer['inflight']) for peer in node.getpeerinfo()) == 1)
self.all_sync_send_with_ping(peers)
# If there was a peer marked for stalling, it would get disconnected
@@ -144,12 +142,6 @@ class P2PIBDStallingTest(BitcoinTestFramework):
self.log.info("Check that all outstanding blocks get connected")
self.wait_until(lambda: node.getblockcount() == NUM_BLOCKS)
- def total_bytes_recv_for_blocks(self):
- total = 0
- for info in self.nodes[0].getpeerinfo():
- if ("block" in info["bytesrecv_per_msg"].keys()):
- total += info["bytesrecv_per_msg"]["block"]
- return total
def all_sync_send_with_ping(self, peers):
for p in peers:
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.