Merge bitcoin/bitcoin#36921: test: fix `mining_prioritisetransaction` check that always passes
What changed, and why it matters
This commit fixes a test-only bug in a Bitcoin Core functional test. The test was supposed to verify that calling prioritisetransaction causes getblocktemplate to rebuild its block template, but it was actually passing for the wrong reason: the two templates always differed because their timestamps came from the clock. The fix makes the test check the actual list of transactions in the template instead, so it correctly detects whether the deprioritised transaction was dropped. There is no change to production code, no vulnerability, and no security risk to users.
No action required. This is a test-quality improvement with no security or operational impact. Reviewers may optionally verify the new test fails if the PrioritiseTransaction counter bump is reverted, as described in the PR description.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change is confined to test/functional/mining_prioritisetransaction.py. It removes an assert_not_equal comparison between two full getblocktemplate responses and replaces it with a focused comparison of transaction txids in the returned template. The original test compared whole templates after a 10-second mocktime advance; because curtime is taken from the wall clock, the templates always differed regardless of whether CTxMemPool::PrioritiseTransaction’s counter bump triggered a rebuild. The new helper template_txids() extracts txids from the transactions field and asserts that the deprioritised tx_id is present before prioritisetransaction and absent after. This makes the test actually exercise the intended behavior from PR #10196.
Changed components
test/functional/mining_prioritisetransaction.pyInspect captured patch +7 / −5
### test/functional/mining_prioritisetransaction.py
@@ -14,7 +14,6 @@
)
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import (
- assert_not_equal,
assert_equal,
assert_raises_rpc_error,
create_lots_of_big_transactions,
@@ -351,18 +350,21 @@ def run_test(self):
# Test that calling prioritisetransaction is sufficient to trigger
# getblocktemplate to (eventually) return a new block.
+ # Compare the template transactions rather than the whole template,
+ # whose curtime follows the clock even when the template is reused.
+ def template_txids():
+ return [tx["txid"] for tx in self.nodes[0].getblocktemplate(NORMAL_GBT_REQUEST_PARAMS)["transactions"]]
+
mock_time = int(time.time())
self.nodes[0].setmocktime(mock_time)
- template = self.nodes[0].getblocktemplate(NORMAL_GBT_REQUEST_PARAMS)
+ assert tx_id in template_txids()
self.nodes[0].prioritisetransaction(txid=tx_id, fee_delta=-int(self.relayfee*COIN))
# Calling prioritisetransaction with the inverse amount should delete its prioritisation entry
assert tx_id not in self.nodes[0].getprioritisedtransactions()
self.nodes[0].setmocktime(mock_time+10)
- new_template = self.nodes[0].getblocktemplate(NORMAL_GBT_REQUEST_PARAMS)
-
- assert_not_equal(template, new_template)
+ assert tx_id not in template_txids()
if __name__ == '__main__':
PrioritiseTransactionTest(__file__).main()Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.