23
23
24
24
class P2PCompactBlocksBlocksOnly (BitcoinTestFramework ):
25
25
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
28
28
29
29
def setup_network (self ):
30
30
self .setup_nodes ()
@@ -45,18 +45,21 @@ def run_test(self):
45
45
46
46
p2p_conn_blocksonly = self .nodes [0 ].add_p2p_connection (P2PInterface ())
47
47
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 ]:
49
50
assert_equal (conn .message_count ['sendcmpct' ], 2 )
50
51
conn .send_and_ping (msg_sendcmpct (announce = False , version = 2 ))
51
52
52
53
# Nodes:
53
54
# 0 -> blocksonly
54
55
# 1 -> high bandwidth
55
56
# 2 -> miner
57
+ # 3 -> low bandwidth
56
58
#
57
59
# Topology:
58
60
# p2p_conn_blocksonly ---> node0
59
61
# p2p_conn_high_bw ---> node1
62
+ # p2p_conn_low_bw ---> node3
60
63
# node2 (no connections)
61
64
#
62
65
# node2 produces blocks that are passed to the rest of the nodes
@@ -80,6 +83,10 @@ def run_test(self):
80
83
p2p_conn_high_bw .wait_until (lambda : p2p_conn_high_bw .message_count ['sendcmpct' ] == 3 )
81
84
assert_equal (p2p_conn_high_bw .last_message ['sendcmpct' ].announce , True )
82
85
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
+
83
90
self .log .info ("Test that -blocksonly nodes send getdata(BLOCK) instead"
84
91
" of getdata(CMPCT) in BIP152 low bandwidth mode" )
85
92
@@ -93,5 +100,12 @@ def run_test(self):
93
100
p2p_conn_high_bw .sync_send_with_ping ()
94
101
assert_equal (p2p_conn_high_bw .last_message ['getdata' ].inv , [CInv (MSG_CMPCT_BLOCK , block1 .sha256 )])
95
102
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
+
96
110
if __name__ == '__main__' :
97
111
P2PCompactBlocksBlocksOnly ().main ()
0 commit comments