Skip to content

Commit aac2008

Browse files
author
MacroFake
committed
Merge bitcoin/bitcoin#25794: test, tracing: don't rely on block_connected USDT event order in tests
0532aa7 test: don't rely on usdt block_conn event order (0xb10c) Pull request description: Relying on block_connected event order in the USDT interface tests turned out to be brittle. Closes bitcoin/bitcoin#25793 Closes bitcoin/bitcoin#25764 Top commit has no ACKs. Tree-SHA512: 40b5012ac80a8eac9d2f374cd39304488009c29adb474dc5e8c03b96c354be358298d2ddee8de480afecc187e1bf42ee119b7aa6216b086a8bf77b7e1310213c
2 parents ebf094f + 0532aa7 commit aac2008

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

test/functional/interface_usdt_validation.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def __repr__(self):
9191
# that the handle_* functions succeeded.
9292
BLOCKS_EXPECTED = 2
9393
blocks_checked = 0
94-
expected_blocks = list()
94+
expected_blocks = dict()
9595

9696
self.log.info("hook into the validation:block_connected tracepoint")
9797
ctx = USDT(pid=self.nodes[0].process.pid)
@@ -104,15 +104,16 @@ def handle_blockconnected(_, data, __):
104104
nonlocal expected_blocks, blocks_checked
105105
event = ctypes.cast(data, ctypes.POINTER(Block)).contents
106106
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)
109110
assert_equal(block["height"], event.height)
110111
assert_equal(len(block["tx"]), event.transactions)
111112
assert_equal(len([tx["vin"] for tx in block["tx"]]), event.inputs)
112113
assert_equal(0, event.sigops) # no sigops in coinbase tx
113114
# only plausibility checks
114115
assert(event.duration > 0)
115-
116+
del expected_blocks[block_hash]
116117
blocks_checked += 1
117118

118119
bpf["block_connected"].open_perf_buffer(
@@ -122,7 +123,7 @@ def handle_blockconnected(_, data, __):
122123
block_hashes = self.generatetoaddress(
123124
self.nodes[0], BLOCKS_EXPECTED, ADDRESS_BCRT1_UNSPENDABLE)
124125
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)
126127

127128
bpf.perf_buffer_poll(timeout=200)
128129
bpf.cleanup()

0 commit comments

Comments
 (0)