Looks like, according to git range-diff b7ff6a611a...3bdff9a154
, this and the suggestion above were reverted in the latest push? If that was not intentional, then maybe amend this change in the latest commit:
0--- i/test/functional/p2p_ibd_stalling.py
1+++ w/test/functional/p2p_ibd_stalling.py
2@@ -63,29 +63,30 @@ class P2PIBDStallingTest(BitcoinTestFramework):
3 blocks.append(create_block(tip, create_coinbase(height), block_time))
4 blocks[-1].solve()
5 tip = blocks[-1].hash_int
6 block_time += 1
7 height += 1
8 block_dict[blocks[-1].hash_int] = blocks[-1]
9- stall_block = blocks[0].hash_int
10- second_stall = blocks[500].hash_int # another block we don't provide immediately
11+ stall_index = 0
12+ second_stall_index = 500
13+ stall_blocks = [blocks[stall_index].hash_int, blocks[second_stall_index].hash_int]
14
15 headers_message = msg_headers()
16 headers_message.headers = [CBlockHeader(b) for b in blocks[:NUM_BLOCKS-1]]
17 peers = []
18
19 self.log.info("Check that a staller does not get disconnected if the 1024 block lookahead buffer is filled")
20 self.mocktime = int(time.time()) + 1
21 node.setmocktime(self.mocktime)
22 for id in range(NUM_PEERS):
23- peers.append(node.add_outbound_p2p_connection(P2PStaller([stall_block, second_stall]), p2p_idx=id, connection_type="outbound-full-relay"))
24+ peers.append(node.add_outbound_p2p_connection(P2PStaller(stall_blocks), p2p_idx=id, connection_type="outbound-full-relay"))
25 peers[-1].block_store = block_dict
26 peers[-1].send_and_ping(headers_message)
27
28 # Wait until all blocks are received (except for the stall blocks), so that no other blocks are in flight.
29- self.wait_until(lambda: sum(len(peer['inflight']) for peer in node.getpeerinfo()) == 2)
30+ self.wait_until(lambda: sum(len(peer['inflight']) for peer in node.getpeerinfo()) == len(stall_blocks))
31
32 self.all_sync_send_with_ping(peers)
33 # If there was a peer marked for stalling, it would get disconnected
34 self.mocktime += 3
35 node.setmocktime(self.mocktime)
36 self.all_sync_send_with_ping(peers)
37@@ -100,13 +101,13 @@ class P2PIBDStallingTest(BitcoinTestFramework):
38
39 self.log.info("Check that the stalling peer is disconnected after 2 seconds")
40 self.mocktime += 3
41 node.setmocktime(self.mocktime)
42 peers[0].wait_for_disconnect()
43 assert_equal(node.num_test_p2p_connections(), NUM_PEERS - 1)
44- self.wait_until(lambda: self.is_block_requested(peers, stall_block))
45+ self.wait_until(lambda: self.is_block_requested(peers, stall_blocks[0]))
46 # Make sure that SendMessages() is invoked, which assigns the missing block
47 # to another peer and starts the stalling logic for them
48 self.all_sync_send_with_ping(peers)
49
50 self.log.info("Check that the stalling timeout gets doubled to 4 seconds for the next staller")
51 # No disconnect after just 3 seconds
52@@ -115,37 +116,37 @@ class P2PIBDStallingTest(BitcoinTestFramework):
53 self.all_sync_send_with_ping(peers)
54 assert_equal(node.num_test_p2p_connections(), NUM_PEERS - 1)
55
56 self.mocktime += 2
57 node.setmocktime(self.mocktime)
58 self.wait_until(lambda: sum(x.is_connected for x in node.p2ps) == NUM_PEERS - 2)
59- self.wait_until(lambda: self.is_block_requested(peers, stall_block))
60+ self.wait_until(lambda: self.is_block_requested(peers, stall_blocks[0]))
61 self.all_sync_send_with_ping(peers)
62
63 self.log.info("Check that the stalling timeout gets doubled to 8 seconds for the next staller")
64 # No disconnect after just 7 seconds
65 self.mocktime += 7
66 node.setmocktime(self.mocktime)
67 self.all_sync_send_with_ping(peers)
68 assert_equal(node.num_test_p2p_connections(), NUM_PEERS - 2)
69
70 self.mocktime += 2
71 node.setmocktime(self.mocktime)
72 self.wait_until(lambda: sum(x.is_connected for x in node.p2ps) == NUM_PEERS - 3)
73- self.wait_until(lambda: self.is_block_requested(peers, stall_block))
74+ self.wait_until(lambda: self.is_block_requested(peers, stall_blocks[0]))
75 self.all_sync_send_with_ping(peers)
76
77 self.log.info("Provide the first withheld block and check that stalling timeout gets reduced back to 2 seconds")
78 with node.assert_debug_log(expected_msgs=['Decreased stalling timeout to 2 seconds'], unexpected_msgs=['Stall started']):
79 for p in peers:
80- if p.is_connected and (stall_block in p.getdata_requests):
81- p.send_without_ping(msg_block(block_dict[stall_block]))
82+ if p.is_connected and (stall_blocks[0] in p.getdata_requests):
83+ p.send_without_ping(msg_block(block_dict[stall_blocks[0]]))
84 self.all_sync_send_with_ping(peers)
85
86 self.log.info("Check that all outstanding blocks up to the second stall block get connected")
87- self.wait_until(lambda: node.getblockcount() == 500)
88+ self.wait_until(lambda: node.getblockcount() == second_stall_index)
89
90
91 def all_sync_send_with_ping(self, peers):
92 for p in peers:
93 if p.is_connected:
94 p.sync_with_ping()