@@ -91,7 +91,7 @@ def __repr__(self):
91
91
# that the handle_* functions succeeded.
92
92
BLOCKS_EXPECTED = 2
93
93
blocks_checked = 0
94
- expected_blocks = list ()
94
+ expected_blocks = dict ()
95
95
96
96
self .log .info ("hook into the validation:block_connected tracepoint" )
97
97
ctx = USDT (pid = self .nodes [0 ].process .pid )
@@ -104,15 +104,16 @@ def handle_blockconnected(_, data, __):
104
104
nonlocal expected_blocks , blocks_checked
105
105
event = ctypes .cast (data , ctypes .POINTER (Block )).contents
106
106
self .log .info (f"handle_blockconnected(): { event } " )
107
- block = expected_blocks .pop (0 )
108
- assert_equal (block ["hash" ], bytes (event .hash [::- 1 ]).hex ())
107
+ block_hash = bytes (event .hash [::- 1 ]).hex ()
108
+ block = expected_blocks [block_hash ]
109
+ assert_equal (block ["hash" ], block_hash )
109
110
assert_equal (block ["height" ], event .height )
110
111
assert_equal (len (block ["tx" ]), event .transactions )
111
112
assert_equal (len ([tx ["vin" ] for tx in block ["tx" ]]), event .inputs )
112
113
assert_equal (0 , event .sigops ) # no sigops in coinbase tx
113
114
# only plausibility checks
114
115
assert (event .duration > 0 )
115
-
116
+ del expected_blocks [ block_hash ]
116
117
blocks_checked += 1
117
118
118
119
bpf ["block_connected" ].open_perf_buffer (
@@ -122,7 +123,7 @@ def handle_blockconnected(_, data, __):
122
123
block_hashes = self .generatetoaddress (
123
124
self .nodes [0 ], BLOCKS_EXPECTED , ADDRESS_BCRT1_UNSPENDABLE )
124
125
for block_hash in block_hashes :
125
- expected_blocks . append ( self .nodes [0 ].getblock (block_hash , 2 ) )
126
+ expected_blocks [ block_hash ] = self .nodes [0 ].getblock (block_hash , 2 )
126
127
127
128
bpf .perf_buffer_poll (timeout = 200 )
128
129
bpf .cleanup ()
0 commit comments