@@ -39,6 +39,7 @@ def on_cfilter(self, message):
39
39
"""Store cfilters received in a list."""
40
40
self .cfilters .append (message )
41
41
42
+
42
43
class CompactFiltersTest (BitcoinTestFramework ):
43
44
def set_test_params (self ):
44
45
self .setup_clean_chain = True
@@ -79,7 +80,7 @@ def run_test(self):
79
80
self .log .info ("get cfcheckpt on chain to be re-orged out." )
80
81
request = msg_getcfcheckpt (
81
82
filter_type = FILTER_TYPE_BASIC ,
82
- stop_hash = int (stale_block_hash , 16 )
83
+ stop_hash = int (stale_block_hash , 16 ),
83
84
)
84
85
peer_0 .send_and_ping (message = request )
85
86
response = peer_0 .last_message ['cfcheckpt' ]
@@ -98,7 +99,7 @@ def run_test(self):
98
99
tip_hash = self .nodes [0 ].getbestblockhash ()
99
100
request = msg_getcfcheckpt (
100
101
filter_type = FILTER_TYPE_BASIC ,
101
- stop_hash = int (tip_hash , 16 )
102
+ stop_hash = int (tip_hash , 16 ),
102
103
)
103
104
peer_0 .send_and_ping (request )
104
105
response = peer_0 .last_message ['cfcheckpt' ]
@@ -109,59 +110,59 @@ def run_test(self):
109
110
tip_cfcheckpt = self .nodes [0 ].getblockfilter (tip_hash , 'basic' )['header' ]
110
111
assert_equal (
111
112
response .headers ,
112
- [int (header , 16 ) for header in (main_cfcheckpt , tip_cfcheckpt )]
113
+ [int (header , 16 ) for header in (main_cfcheckpt , tip_cfcheckpt )],
113
114
)
114
115
115
116
self .log .info ("Check that peers can fetch cfcheckpt on stale chain." )
116
117
request = msg_getcfcheckpt (
117
118
filter_type = FILTER_TYPE_BASIC ,
118
- stop_hash = int (stale_block_hash , 16 )
119
+ stop_hash = int (stale_block_hash , 16 ),
119
120
)
120
121
peer_0 .send_and_ping (request )
121
122
response = peer_0 .last_message ['cfcheckpt' ]
122
123
123
124
stale_cfcheckpt = self .nodes [0 ].getblockfilter (stale_block_hash , 'basic' )['header' ]
124
125
assert_equal (
125
126
response .headers ,
126
- [int (header , 16 ) for header in (stale_cfcheckpt ,)]
127
+ [int (header , 16 ) for header in (stale_cfcheckpt , )],
127
128
)
128
129
129
130
self .log .info ("Check that peers can fetch cfheaders on active chain." )
130
131
request = msg_getcfheaders (
131
132
filter_type = FILTER_TYPE_BASIC ,
132
133
start_height = 1 ,
133
- stop_hash = int (main_block_hash , 16 )
134
+ stop_hash = int (main_block_hash , 16 ),
134
135
)
135
136
peer_0 .send_and_ping (request )
136
137
response = peer_0 .last_message ['cfheaders' ]
137
138
main_cfhashes = response .hashes
138
139
assert_equal (len (main_cfhashes ), 1000 )
139
140
assert_equal (
140
141
compute_last_header (response .prev_header , response .hashes ),
141
- int (main_cfcheckpt , 16 )
142
+ int (main_cfcheckpt , 16 ),
142
143
)
143
144
144
145
self .log .info ("Check that peers can fetch cfheaders on stale chain." )
145
146
request = msg_getcfheaders (
146
147
filter_type = FILTER_TYPE_BASIC ,
147
148
start_height = 1 ,
148
- stop_hash = int (stale_block_hash , 16 )
149
+ stop_hash = int (stale_block_hash , 16 ),
149
150
)
150
151
peer_0 .send_and_ping (request )
151
152
response = peer_0 .last_message ['cfheaders' ]
152
153
stale_cfhashes = response .hashes
153
154
assert_equal (len (stale_cfhashes ), 1000 )
154
155
assert_equal (
155
156
compute_last_header (response .prev_header , response .hashes ),
156
- int (stale_cfcheckpt , 16 )
157
+ int (stale_cfcheckpt , 16 ),
157
158
)
158
159
159
160
self .log .info ("Check that peers can fetch cfilters." )
160
161
stop_hash = self .nodes [0 ].getblockhash (10 )
161
162
request = msg_getcfilters (
162
163
filter_type = FILTER_TYPE_BASIC ,
163
164
start_height = 1 ,
164
- stop_hash = int (stop_hash , 16 )
165
+ stop_hash = int (stop_hash , 16 ),
165
166
)
166
167
peer_0 .send_message (request )
167
168
peer_0 .sync_with_ping ()
@@ -180,7 +181,7 @@ def run_test(self):
180
181
request = msg_getcfilters (
181
182
filter_type = FILTER_TYPE_BASIC ,
182
183
start_height = 1000 ,
183
- stop_hash = int (stale_block_hash , 16 )
184
+ stop_hash = int (stale_block_hash , 16 ),
184
185
)
185
186
peer_0 .send_message (request )
186
187
peer_0 .sync_with_ping ()
@@ -197,17 +198,17 @@ def run_test(self):
197
198
requests = [
198
199
msg_getcfcheckpt (
199
200
filter_type = FILTER_TYPE_BASIC ,
200
- stop_hash = int (main_block_hash , 16 )
201
+ stop_hash = int (main_block_hash , 16 ),
201
202
),
202
203
msg_getcfheaders (
203
204
filter_type = FILTER_TYPE_BASIC ,
204
205
start_height = 1000 ,
205
- stop_hash = int (main_block_hash , 16 )
206
+ stop_hash = int (main_block_hash , 16 ),
206
207
),
207
208
msg_getcfilters (
208
209
filter_type = FILTER_TYPE_BASIC ,
209
210
start_height = 1000 ,
210
- stop_hash = int (main_block_hash , 16 )
211
+ stop_hash = int (main_block_hash , 16 ),
211
212
),
212
213
]
213
214
for request in requests :
@@ -221,18 +222,18 @@ def run_test(self):
221
222
msg_getcfilters (
222
223
filter_type = FILTER_TYPE_BASIC ,
223
224
start_height = 0 ,
224
- stop_hash = int (main_block_hash , 16 )
225
+ stop_hash = int (main_block_hash , 16 ),
225
226
),
226
227
# Requesting too many filter headers results in disconnection.
227
228
msg_getcfheaders (
228
229
filter_type = FILTER_TYPE_BASIC ,
229
230
start_height = 0 ,
230
- stop_hash = int (tip_hash , 16 )
231
+ stop_hash = int (tip_hash , 16 ),
231
232
),
232
233
# Requesting unknown filter type results in disconnection.
233
234
msg_getcfcheckpt (
234
235
filter_type = 255 ,
235
- stop_hash = int (main_block_hash , 16 )
236
+ stop_hash = int (main_block_hash , 16 ),
236
237
),
237
238
# Requesting unknown hash results in disconnection.
238
239
msg_getcfcheckpt (
@@ -245,12 +246,14 @@ def run_test(self):
245
246
peer_0 .send_message (request )
246
247
peer_0 .wait_for_disconnect ()
247
248
249
+
248
250
def compute_last_header (prev_header , hashes ):
249
251
"""Compute the last filter header from a starting header and a sequence of filter hashes."""
250
252
header = ser_uint256 (prev_header )
251
253
for filter_hash in hashes :
252
254
header = hash256 (ser_uint256 (filter_hash ) + header )
253
255
return uint256_from_str (header )
254
256
257
+
255
258
if __name__ == '__main__' :
256
259
CompactFiltersTest ().main ()
0 commit comments