Skip to content

Commit e59ea87

Browse files
author
MarcoFalke
committed
Merge bitcoin/bitcoin#22311: test: Add missing syncwithvalidationinterfacequeue in p2p_blockfilters
fadddd1 test: Add missing syncwithvalidationinterfacequeue (MarcoFalke) faa211f test: Misc cleanup (MarcoFalke) fa1668b test: Run pep-8 (MarcoFalke) facd97a scripted-diff: Renames (MarcoFalke) Pull request description: The index on the block filters is running in the background on the validation interface. To avoid intermittent test failures, it needs to be synced. Also other cleanups. ACKs for top commit: lsilva01: Tested ACK bitcoin/bitcoin@fadddd1 on Ubuntu 20.04 Tree-SHA512: d858405db426a2f9d5620059dd88bcead4e3fba3ccc6bd8023f624b768fbcfa2203246fb0b2db620490321730d990f0e78063b21a26988c969cb126d4bd697bd
2 parents d6a5916 + fadddd1 commit e59ea87

File tree

1 file changed

+50
-48
lines changed

1 file changed

+50
-48
lines changed

test/functional/p2p_blockfilters.py

Lines changed: 50 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
assert_equal,
2525
)
2626

27-
class CFiltersClient(P2PInterface):
27+
class FiltersClient(P2PInterface):
2828
def __init__(self):
2929
super().__init__()
3030
# Store the cfilters received.
@@ -39,6 +39,7 @@ def on_cfilter(self, message):
3939
"""Store cfilters received in a list."""
4040
self.cfilters.append(message)
4141

42+
4243
class CompactFiltersTest(BitcoinTestFramework):
4344
def set_test_params(self):
4445
self.setup_clean_chain = True
@@ -51,8 +52,8 @@ def set_test_params(self):
5152

5253
def run_test(self):
5354
# Node 0 supports COMPACT_FILTERS, node 1 does not.
54-
node0 = self.nodes[0].add_p2p_connection(CFiltersClient())
55-
node1 = self.nodes[1].add_p2p_connection(CFiltersClient())
55+
peer_0 = self.nodes[0].add_p2p_connection(FiltersClient())
56+
peer_1 = self.nodes[1].add_p2p_connection(FiltersClient())
5657

5758
# Nodes 0 & 1 share the same first 999 blocks in the chain.
5859
self.nodes[0].generate(999)
@@ -61,16 +62,16 @@ def run_test(self):
6162
# Stale blocks by disconnecting nodes 0 & 1, mining, then reconnecting
6263
self.disconnect_nodes(0, 1)
6364

64-
self.nodes[0].generate(1)
65-
self.wait_until(lambda: self.nodes[0].getblockcount() == 1000)
66-
stale_block_hash = self.nodes[0].getblockhash(1000)
65+
stale_block_hash = self.nodes[0].generate(1)[0]
66+
self.nodes[0].syncwithvalidationinterfacequeue()
67+
assert_equal(self.nodes[0].getblockcount(), 1000)
6768

6869
self.nodes[1].generate(1001)
69-
self.wait_until(lambda: self.nodes[1].getblockcount() == 2000)
70+
assert_equal(self.nodes[1].getblockcount(), 2000)
7071

7172
# Check that nodes have signalled NODE_COMPACT_FILTERS correctly.
72-
assert node0.nServices & NODE_COMPACT_FILTERS != 0
73-
assert node1.nServices & NODE_COMPACT_FILTERS == 0
73+
assert peer_0.nServices & NODE_COMPACT_FILTERS != 0
74+
assert peer_1.nServices & NODE_COMPACT_FILTERS == 0
7475

7576
# Check that the localservices is as expected.
7677
assert int(self.nodes[0].getnetworkinfo()['localservices'], 16) & NODE_COMPACT_FILTERS != 0
@@ -79,17 +80,18 @@ def run_test(self):
7980
self.log.info("get cfcheckpt on chain to be re-orged out.")
8081
request = msg_getcfcheckpt(
8182
filter_type=FILTER_TYPE_BASIC,
82-
stop_hash=int(stale_block_hash, 16)
83+
stop_hash=int(stale_block_hash, 16),
8384
)
84-
node0.send_and_ping(message=request)
85-
response = node0.last_message['cfcheckpt']
85+
peer_0.send_and_ping(message=request)
86+
response = peer_0.last_message['cfcheckpt']
8687
assert_equal(response.filter_type, request.filter_type)
8788
assert_equal(response.stop_hash, request.stop_hash)
8889
assert_equal(len(response.headers), 1)
8990

9091
self.log.info("Reorg node 0 to a new chain.")
9192
self.connect_nodes(0, 1)
9293
self.sync_blocks(timeout=600)
94+
self.nodes[0].syncwithvalidationinterfacequeue()
9395

9496
main_block_hash = self.nodes[0].getblockhash(1000)
9597
assert main_block_hash != stale_block_hash, "node 0 chain did not reorganize"
@@ -98,74 +100,73 @@ def run_test(self):
98100
tip_hash = self.nodes[0].getbestblockhash()
99101
request = msg_getcfcheckpt(
100102
filter_type=FILTER_TYPE_BASIC,
101-
stop_hash=int(tip_hash, 16)
103+
stop_hash=int(tip_hash, 16),
102104
)
103-
node0.send_and_ping(request)
104-
response = node0.last_message['cfcheckpt']
105+
peer_0.send_and_ping(request)
106+
response = peer_0.last_message['cfcheckpt']
105107
assert_equal(response.filter_type, request.filter_type)
106108
assert_equal(response.stop_hash, request.stop_hash)
107109

108110
main_cfcheckpt = self.nodes[0].getblockfilter(main_block_hash, 'basic')['header']
109111
tip_cfcheckpt = self.nodes[0].getblockfilter(tip_hash, 'basic')['header']
110112
assert_equal(
111113
response.headers,
112-
[int(header, 16) for header in (main_cfcheckpt, tip_cfcheckpt)]
114+
[int(header, 16) for header in (main_cfcheckpt, tip_cfcheckpt)],
113115
)
114116

115117
self.log.info("Check that peers can fetch cfcheckpt on stale chain.")
116118
request = msg_getcfcheckpt(
117119
filter_type=FILTER_TYPE_BASIC,
118-
stop_hash=int(stale_block_hash, 16)
120+
stop_hash=int(stale_block_hash, 16),
119121
)
120-
node0.send_and_ping(request)
121-
response = node0.last_message['cfcheckpt']
122+
peer_0.send_and_ping(request)
123+
response = peer_0.last_message['cfcheckpt']
122124

123125
stale_cfcheckpt = self.nodes[0].getblockfilter(stale_block_hash, 'basic')['header']
124126
assert_equal(
125127
response.headers,
126-
[int(header, 16) for header in (stale_cfcheckpt,)]
128+
[int(header, 16) for header in (stale_cfcheckpt, )],
127129
)
128130

129131
self.log.info("Check that peers can fetch cfheaders on active chain.")
130132
request = msg_getcfheaders(
131133
filter_type=FILTER_TYPE_BASIC,
132134
start_height=1,
133-
stop_hash=int(main_block_hash, 16)
135+
stop_hash=int(main_block_hash, 16),
134136
)
135-
node0.send_and_ping(request)
136-
response = node0.last_message['cfheaders']
137+
peer_0.send_and_ping(request)
138+
response = peer_0.last_message['cfheaders']
137139
main_cfhashes = response.hashes
138140
assert_equal(len(main_cfhashes), 1000)
139141
assert_equal(
140142
compute_last_header(response.prev_header, response.hashes),
141-
int(main_cfcheckpt, 16)
143+
int(main_cfcheckpt, 16),
142144
)
143145

144146
self.log.info("Check that peers can fetch cfheaders on stale chain.")
145147
request = msg_getcfheaders(
146148
filter_type=FILTER_TYPE_BASIC,
147149
start_height=1,
148-
stop_hash=int(stale_block_hash, 16)
150+
stop_hash=int(stale_block_hash, 16),
149151
)
150-
node0.send_and_ping(request)
151-
response = node0.last_message['cfheaders']
152+
peer_0.send_and_ping(request)
153+
response = peer_0.last_message['cfheaders']
152154
stale_cfhashes = response.hashes
153155
assert_equal(len(stale_cfhashes), 1000)
154156
assert_equal(
155157
compute_last_header(response.prev_header, response.hashes),
156-
int(stale_cfcheckpt, 16)
158+
int(stale_cfcheckpt, 16),
157159
)
158160

159161
self.log.info("Check that peers can fetch cfilters.")
160162
stop_hash = self.nodes[0].getblockhash(10)
161163
request = msg_getcfilters(
162164
filter_type=FILTER_TYPE_BASIC,
163165
start_height=1,
164-
stop_hash=int(stop_hash, 16)
166+
stop_hash=int(stop_hash, 16),
165167
)
166-
node0.send_message(request)
167-
node0.sync_with_ping()
168-
response = node0.pop_cfilters()
168+
peer_0.send_and_ping(request)
169+
response = peer_0.pop_cfilters()
169170
assert_equal(len(response), 10)
170171

171172
self.log.info("Check that cfilter responses are correct.")
@@ -180,11 +181,10 @@ def run_test(self):
180181
request = msg_getcfilters(
181182
filter_type=FILTER_TYPE_BASIC,
182183
start_height=1000,
183-
stop_hash=int(stale_block_hash, 16)
184+
stop_hash=int(stale_block_hash, 16),
184185
)
185-
node0.send_message(request)
186-
node0.sync_with_ping()
187-
response = node0.pop_cfilters()
186+
peer_0.send_and_ping(request)
187+
response = peer_0.pop_cfilters()
188188
assert_equal(len(response), 1)
189189

190190
cfilter = response[0]
@@ -197,42 +197,42 @@ def run_test(self):
197197
requests = [
198198
msg_getcfcheckpt(
199199
filter_type=FILTER_TYPE_BASIC,
200-
stop_hash=int(main_block_hash, 16)
200+
stop_hash=int(main_block_hash, 16),
201201
),
202202
msg_getcfheaders(
203203
filter_type=FILTER_TYPE_BASIC,
204204
start_height=1000,
205-
stop_hash=int(main_block_hash, 16)
205+
stop_hash=int(main_block_hash, 16),
206206
),
207207
msg_getcfilters(
208208
filter_type=FILTER_TYPE_BASIC,
209209
start_height=1000,
210-
stop_hash=int(main_block_hash, 16)
210+
stop_hash=int(main_block_hash, 16),
211211
),
212212
]
213213
for request in requests:
214-
node1 = self.nodes[1].add_p2p_connection(P2PInterface())
215-
node1.send_message(request)
216-
node1.wait_for_disconnect()
214+
peer_1 = self.nodes[1].add_p2p_connection(P2PInterface())
215+
peer_1.send_message(request)
216+
peer_1.wait_for_disconnect()
217217

218218
self.log.info("Check that invalid requests result in disconnection.")
219219
requests = [
220220
# Requesting too many filters results in disconnection.
221221
msg_getcfilters(
222222
filter_type=FILTER_TYPE_BASIC,
223223
start_height=0,
224-
stop_hash=int(main_block_hash, 16)
224+
stop_hash=int(main_block_hash, 16),
225225
),
226226
# Requesting too many filter headers results in disconnection.
227227
msg_getcfheaders(
228228
filter_type=FILTER_TYPE_BASIC,
229229
start_height=0,
230-
stop_hash=int(tip_hash, 16)
230+
stop_hash=int(tip_hash, 16),
231231
),
232232
# Requesting unknown filter type results in disconnection.
233233
msg_getcfcheckpt(
234234
filter_type=255,
235-
stop_hash=int(main_block_hash, 16)
235+
stop_hash=int(main_block_hash, 16),
236236
),
237237
# Requesting unknown hash results in disconnection.
238238
msg_getcfcheckpt(
@@ -241,9 +241,10 @@ def run_test(self):
241241
),
242242
]
243243
for request in requests:
244-
node0 = self.nodes[0].add_p2p_connection(P2PInterface())
245-
node0.send_message(request)
246-
node0.wait_for_disconnect()
244+
peer_0 = self.nodes[0].add_p2p_connection(P2PInterface())
245+
peer_0.send_message(request)
246+
peer_0.wait_for_disconnect()
247+
247248

248249
def compute_last_header(prev_header, hashes):
249250
"""Compute the last filter header from a starting header and a sequence of filter hashes."""
@@ -252,5 +253,6 @@ def compute_last_header(prev_header, hashes):
252253
header = hash256(ser_uint256(filter_hash) + header)
253254
return uint256_from_str(header)
254255

256+
255257
if __name__ == '__main__':
256258
CompactFiltersTest().main()

0 commit comments

Comments
 (0)