Skip to content

Commit bb5aa0a

Browse files
committed
test: improve coverage for a resolved stalling situation
This test (which would fail without the previous commit) checks that after the stalling block was received, we don't incorrectly mark another peer as a staller immediately.
1 parent e564cab commit bb5aa0a

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

test/functional/p2p_ibd_stalling.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@
2929

3030

3131
class P2PStaller(P2PDataStore):
32-
def __init__(self, stall_block):
33-
self.stall_block = stall_block
32+
def __init__(self, stall_blocks):
33+
self.stall_blocks = stall_blocks
3434
super().__init__()
3535

3636
def on_getdata(self, message):
3737
for inv in message.inv:
3838
self.getdata_requests.append(inv.hash)
3939
if (inv.type & MSG_TYPE_MASK) == MSG_BLOCK:
40-
if (inv.hash != self.stall_block):
40+
if (inv.hash not in self.stall_blocks):
4141
self.send_without_ping(msg_block(self.block_store[inv.hash]))
4242

4343
def on_getheaders(self, message):
@@ -51,7 +51,7 @@ def set_test_params(self):
5151

5252
def run_test(self):
5353
NUM_BLOCKS = 1025
54-
NUM_PEERS = 4
54+
NUM_PEERS = 5
5555
node = self.nodes[0]
5656
tip = int(node.getbestblockhash(), 16)
5757
blocks = []
@@ -67,6 +67,7 @@ def run_test(self):
6767
height += 1
6868
block_dict[blocks[-1].sha256] = blocks[-1]
6969
stall_block = blocks[0].sha256
70+
second_stall = blocks[500].sha256 # another block we don't provide immediately
7071

7172
headers_message = msg_headers()
7273
headers_message.headers = [CBlockHeader(b) for b in blocks[:NUM_BLOCKS-1]]
@@ -76,12 +77,12 @@ def run_test(self):
7677
self.mocktime = int(time.time()) + 1
7778
node.setmocktime(self.mocktime)
7879
for id in range(NUM_PEERS):
79-
peers.append(node.add_outbound_p2p_connection(P2PStaller(stall_block), p2p_idx=id, connection_type="outbound-full-relay"))
80+
peers.append(node.add_outbound_p2p_connection(P2PStaller([stall_block, second_stall]), p2p_idx=id, connection_type="outbound-full-relay"))
8081
peers[-1].block_store = block_dict
8182
peers[-1].send_and_ping(headers_message)
8283

83-
# Wait until all blocks are received (except for stall_block), so that no other blocks are in flight.
84-
self.wait_until(lambda: sum(len(peer['inflight']) for peer in node.getpeerinfo()) == 1)
84+
# Wait until all blocks are received (except for the stall blocks), so that no other blocks are in flight.
85+
self.wait_until(lambda: sum(len(peer['inflight']) for peer in node.getpeerinfo()) == 2)
8586

8687
self.all_sync_send_with_ping(peers)
8788
# If there was a peer marked for stalling, it would get disconnected
@@ -133,14 +134,15 @@ def run_test(self):
133134
self.wait_until(lambda: self.is_block_requested(peers, stall_block))
134135
self.all_sync_send_with_ping(peers)
135136

136-
self.log.info("Provide the withheld block and check that stalling timeout gets reduced back to 2 seconds")
137-
with node.assert_debug_log(expected_msgs=['Decreased stalling timeout to 2 seconds']):
137+
self.log.info("Provide the first withheld block and check that stalling timeout gets reduced back to 2 seconds")
138+
with node.assert_debug_log(expected_msgs=['Decreased stalling timeout to 2 seconds'], unexpected_msgs=['Stall started']):
138139
for p in peers:
139140
if p.is_connected and (stall_block in p.getdata_requests):
140141
p.send_without_ping(msg_block(block_dict[stall_block]))
142+
self.all_sync_send_with_ping(peers)
141143

142-
self.log.info("Check that all outstanding blocks get connected")
143-
self.wait_until(lambda: node.getblockcount() == NUM_BLOCKS)
144+
self.log.info("Check that all outstanding blocks up to the second stall block get connected")
145+
self.wait_until(lambda: node.getblockcount() == 500)
144146

145147

146148
def all_sync_send_with_ping(self, peers):

0 commit comments

Comments
 (0)