Skip to content

Commit

Permalink
Merge bitcoin/bitcoin#25794: test, tracing: don't rely on `block_conn…
Browse files Browse the repository at this point in the history
…ected` 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
MacroFake committed Aug 10, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
2 parents ebf094f + 0532aa7 commit aac2008
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions test/functional/interface_usdt_validation.py
Original file line number Diff line number Diff line change
@@ -91,7 +91,7 @@ def __repr__(self):
# that the handle_* functions succeeded.
BLOCKS_EXPECTED = 2
blocks_checked = 0
expected_blocks = list()
expected_blocks = dict()

self.log.info("hook into the validation:block_connected tracepoint")
ctx = USDT(pid=self.nodes[0].process.pid)
@@ -104,15 +104,16 @@ def handle_blockconnected(_, data, __):
nonlocal expected_blocks, blocks_checked
event = ctypes.cast(data, ctypes.POINTER(Block)).contents
self.log.info(f"handle_blockconnected(): {event}")
block = expected_blocks.pop(0)
assert_equal(block["hash"], bytes(event.hash[::-1]).hex())
block_hash = bytes(event.hash[::-1]).hex()
block = expected_blocks[block_hash]
assert_equal(block["hash"], block_hash)
assert_equal(block["height"], event.height)
assert_equal(len(block["tx"]), event.transactions)
assert_equal(len([tx["vin"] for tx in block["tx"]]), event.inputs)
assert_equal(0, event.sigops) # no sigops in coinbase tx
# only plausibility checks
assert(event.duration > 0)

del expected_blocks[block_hash]
blocks_checked += 1

bpf["block_connected"].open_perf_buffer(
@@ -122,7 +123,7 @@ def handle_blockconnected(_, data, __):
block_hashes = self.generatetoaddress(
self.nodes[0], BLOCKS_EXPECTED, ADDRESS_BCRT1_UNSPENDABLE)
for block_hash in block_hashes:
expected_blocks.append(self.nodes[0].getblock(block_hash, 2))
expected_blocks[block_hash] = self.nodes[0].getblock(block_hash, 2)

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

0 comments on commit aac2008

Please sign in to comment.