34
34
"""
35
35
from shutil import rmtree
36
36
37
+ from dataclasses import dataclass
37
38
from test_framework .messages import tx_from_hex
38
39
from test_framework .test_framework import BitcoinTestFramework
39
40
from test_framework .util import (
@@ -174,10 +175,18 @@ def run_test(self):
174
175
175
176
# Generate a series of blocks that `n0` will have in the snapshot,
176
177
# but that n1 and n2 don't yet see.
178
+ assert n0 .getblockcount () == START_HEIGHT
179
+ blocks = {START_HEIGHT : Block (n0 .getbestblockhash (), 1 , START_HEIGHT + 1 )}
177
180
for i in range (100 ):
181
+ block_tx = 1
178
182
if i % 3 == 0 :
179
183
self .mini_wallet .send_self_transfer (from_node = n0 )
184
+ block_tx += 1
180
185
self .generate (n0 , nblocks = 1 , sync_fun = self .no_op )
186
+ height = n0 .getblockcount ()
187
+ hash = n0 .getbestblockhash ()
188
+ blocks [height ] = Block (hash , block_tx , blocks [height - 1 ].chain_tx + block_tx )
189
+
181
190
182
191
self .log .info ("-- Testing assumeutxo + some indexes + pruning" )
183
192
@@ -207,7 +216,7 @@ def run_test(self):
207
216
assert_equal (
208
217
dump_output ['txoutset_hash' ],
209
218
"a4bf3407ccb2cc0145c49ebba8fa91199f8a3903daf0883875941497d2493c27" )
210
- assert_equal (dump_output ["nchaintx" ], 334 )
219
+ assert_equal (dump_output ["nchaintx" ], blocks [ SNAPSHOT_BASE_HEIGHT ]. chain_tx )
211
220
assert_equal (n0 .getblockchaininfo ()["blocks" ], SNAPSHOT_BASE_HEIGHT )
212
221
213
222
# Mine more blocks on top of the snapshot that n1 hasn't yet seen. This
@@ -228,6 +237,30 @@ def run_test(self):
228
237
assert_equal (loaded ['coins_loaded' ], SNAPSHOT_BASE_HEIGHT )
229
238
assert_equal (loaded ['base_height' ], SNAPSHOT_BASE_HEIGHT )
230
239
240
+ def check_tx_counts (final : bool ) -> None :
241
+ """Check nTx and nChainTx intermediate values right after loading
242
+ the snapshot, and final values after the snapshot is validated."""
243
+ for height , block in blocks .items ():
244
+ tx = n1 .getblockheader (block .hash )["nTx" ]
245
+ chain_tx = n1 .getchaintxstats (nblocks = 1 , blockhash = block .hash )["txcount" ]
246
+
247
+ # Intermediate nTx of the starting block should be real, but nTx of
248
+ # later blocks should be fake 1 values set by snapshot loading code.
249
+ if final or height == START_HEIGHT :
250
+ assert_equal (tx , block .tx )
251
+ else :
252
+ assert_equal (tx , 1 )
253
+
254
+ # Intermediate nChainTx of the starting block and snapshot block
255
+ # should be real, but others will be fake values set by snapshot
256
+ # loading code.
257
+ if final or height in (START_HEIGHT , SNAPSHOT_BASE_HEIGHT ):
258
+ assert_equal (chain_tx , block .chain_tx )
259
+ else :
260
+ assert_equal (chain_tx , height + 1 )
261
+
262
+ check_tx_counts (final = False )
263
+
231
264
normal , snapshot = n1 .getchainstates ()["chainstates" ]
232
265
assert_equal (normal ['blocks' ], START_HEIGHT )
233
266
assert_equal (normal .get ('snapshot_blockhash' ), None )
@@ -291,6 +324,8 @@ def run_test(self):
291
324
}
292
325
self .wait_until (lambda : n1 .getindexinfo () == completed_idx_state )
293
326
327
+ self .log .info ("Re-check nTx and nChainTx values" )
328
+ check_tx_counts (final = True )
294
329
295
330
for i in (0 , 1 ):
296
331
n = self .nodes [i ]
@@ -365,6 +400,11 @@ def run_test(self):
365
400
self .connect_nodes (0 , 2 )
366
401
self .wait_until (lambda : n2 .getblockcount () == FINAL_HEIGHT )
367
402
403
+ @dataclass
404
+ class Block :
405
+ hash : str
406
+ tx : int
407
+ chain_tx : int
368
408
369
409
if __name__ == '__main__' :
370
410
AssumeutxoTest ().main ()
0 commit comments