Skip to content

Commit a79ad65

Browse files
[test] Test that getdata(CMPCT) is still sent on regular low bandwidth connections.
Co-authored-by: Amiti Uttarwar <[email protected]>
1 parent 5e231c1 commit a79ad65

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

test/functional/p2p_compactblocks_blocksonly.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323

2424
class P2PCompactBlocksBlocksOnly(BitcoinTestFramework):
2525
def set_test_params(self):
26-
self.extra_args = [["-blocksonly"], [], []]
27-
self.num_nodes = 3
26+
self.extra_args = [["-blocksonly"], [], [], []]
27+
self.num_nodes = 4
2828

2929
def setup_network(self):
3030
self.setup_nodes()
@@ -45,18 +45,21 @@ def run_test(self):
4545

4646
p2p_conn_blocksonly = self.nodes[0].add_p2p_connection(P2PInterface())
4747
p2p_conn_high_bw = self.nodes[1].add_p2p_connection(P2PInterface())
48-
for conn in [p2p_conn_blocksonly, p2p_conn_high_bw]:
48+
p2p_conn_low_bw = self.nodes[3].add_p2p_connection(P2PInterface())
49+
for conn in [p2p_conn_blocksonly, p2p_conn_high_bw, p2p_conn_low_bw]:
4950
assert_equal(conn.message_count['sendcmpct'], 2)
5051
conn.send_and_ping(msg_sendcmpct(announce=False, version=2))
5152

5253
# Nodes:
5354
# 0 -> blocksonly
5455
# 1 -> high bandwidth
5556
# 2 -> miner
57+
# 3 -> low bandwidth
5658
#
5759
# Topology:
5860
# p2p_conn_blocksonly ---> node0
5961
# p2p_conn_high_bw ---> node1
62+
# p2p_conn_low_bw ---> node3
6063
# node2 (no connections)
6164
#
6265
# node2 produces blocks that are passed to the rest of the nodes
@@ -80,6 +83,10 @@ def run_test(self):
8083
p2p_conn_high_bw.wait_until(lambda: p2p_conn_high_bw.message_count['sendcmpct'] == 3)
8184
assert_equal(p2p_conn_high_bw.last_message['sendcmpct'].announce, True)
8285

86+
# Don't send a block from the p2p_conn_low_bw so the low bandwidth node
87+
# doesn't select it for BIP152 high bandwidth relay.
88+
self.nodes[3].submitblock(block0.serialize().hex())
89+
8390
self.log.info("Test that -blocksonly nodes send getdata(BLOCK) instead"
8491
" of getdata(CMPCT) in BIP152 low bandwidth mode")
8592

@@ -93,5 +100,12 @@ def run_test(self):
93100
p2p_conn_high_bw.sync_send_with_ping()
94101
assert_equal(p2p_conn_high_bw.last_message['getdata'].inv, [CInv(MSG_CMPCT_BLOCK, block1.sha256)])
95102

103+
self.log.info("Test that getdata(CMPCT) is still sent on BIP152 low bandwidth connections"
104+
" when no -blocksonly nodes are involved")
105+
106+
p2p_conn_low_bw.send_and_ping(msg_headers(headers=[CBlockHeader(block1)]))
107+
p2p_conn_low_bw.sync_with_ping()
108+
assert_equal(p2p_conn_low_bw.last_message['getdata'].inv, [CInv(MSG_CMPCT_BLOCK, block1.sha256)])
109+
96110
if __name__ == '__main__':
97111
P2PCompactBlocksBlocksOnly().main()

0 commit comments

Comments
 (0)