qa: use NORMAL_GBT_REQUEST_PARAMS consistently
What changed, and why it matters
This commit only changes Bitcoin Core's internal functional test code. It replaces hardcoded {'rules': ['segwit']} parameters with a shared constant NORMAL_GBT_REQUEST_PARAMS when calling getblocktemplate in tests. There is no change to production node code, no change to consensus rules, and no security fix or vulnerability introduced.
No action required. This is a non-security test-only refactoring.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff is a pure test-framework refactoring across five functional test files. It imports NORMAL_GBT_REQUEST_PARAMS from test_framework.blocktools and substitutes it for literal {‘rules’: [‘segwit’]} dictionaries in getblocktemplate() calls. The constant’s value is the same as the replaced literal, so behavior is unchanged. No C++, consensus, P2P, RPC server, or wallet code is modified.
Changed components
test/functional/feature_segwit.pytest/functional/mining_basic.pytest/functional/mining_getblocktemplate_longpoll.pytest/functional/mining_prioritisetransaction.pytest/functional/mining_template_verification.pyInspect captured patch +17 / −13
diff --git a/test/functional/feature_segwit.py b/test/functional/feature_segwit.py
index 35c9459c..05c44352 100755
--- a/test/functional/feature_segwit.py
+++ b/test/functional/feature_segwit.py
@@ -11,6 +11,7 @@ from test_framework.address import (
script_to_p2wsh,
)
from test_framework.blocktools import (
+ NORMAL_GBT_REQUEST_PARAMS,
send_to_witness,
witness_script,
)
@@ -109,7 +110,7 @@ class SegWitTest(BitcoinTestFramework):
self.log.info("Verify sigops are counted in GBT with pre-BIP141 rules before the fork")
txid = self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), 1)
- tmpl = self.nodes[0].getblocktemplate({'rules': ['segwit']})
+ tmpl = self.nodes[0].getblocktemplate(NORMAL_GBT_REQUEST_PARAMS)
assert_equal(tmpl['sizelimit'], 1000000)
assert 'weightlimit' not in tmpl
assert_equal(tmpl['sigoplimit'], 20000)
@@ -221,7 +222,7 @@ class SegWitTest(BitcoinTestFramework):
self.log.info("Verify sigops are counted in GBT with BIP141 rules after the fork")
txid = self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), 1)
raw_tx = self.nodes[0].getrawtransaction(txid, True)
- tmpl = self.nodes[0].getblocktemplate({'rules': ['segwit']})
+ tmpl = self.nodes[0].getblocktemplate(NORMAL_GBT_REQUEST_PARAMS)
assert_greater_than_or_equal(tmpl['sizelimit'], 3999577) # actual maximum size is lower due to minimum mandatory non-witness data
assert_equal(tmpl['weightlimit'], 4000000)
assert_equal(tmpl['sigoplimit'], 80000)
@@ -275,7 +276,7 @@ class SegWitTest(BitcoinTestFramework):
assert txid3 in self.nodes[0].getrawmempool()
# Check that getblocktemplate includes all transactions.
- template = self.nodes[0].getblocktemplate({"rules": ["segwit"]})
+ template = self.nodes[0].getblocktemplate(NORMAL_GBT_REQUEST_PARAMS)
template_txids = [t['txid'] for t in template['transactions']]
assert txid1 in template_txids
assert txid2 in template_txids
diff --git a/test/functional/mining_basic.py b/test/functional/mining_basic.py
index 53ddb0ed..bb53f736 100755
--- a/test/functional/mining_basic.py
+++ b/test/functional/mining_basic.py
@@ -235,7 +235,7 @@ class MiningTest(BitcoinTestFramework):
assert_equal(node.getblocktemplate(template_request={
'data': block.serialize().hex(),
'mode': 'proposal',
- 'rules': ['segwit'],
+ **NORMAL_GBT_REQUEST_PARAMS,
}), None)
bad_block = copy.deepcopy(block)
diff --git a/test/functional/mining_getblocktemplate_longpoll.py b/test/functional/mining_getblocktemplate_longpoll.py
index e36396b3..da5b1de9 100755
--- a/test/functional/mining_getblocktemplate_longpoll.py
+++ b/test/functional/mining_getblocktemplate_longpoll.py
@@ -7,6 +7,7 @@
import random
import threading
+from test_framework.blocktools import NORMAL_GBT_REQUEST_PARAMS
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal, get_rpc_proxy
from test_framework.wallet import MiniWallet
@@ -16,14 +17,14 @@ class LongpollThread(threading.Thread):
def __init__(self, node):
threading.Thread.__init__(self)
# query current longpollid
- template = node.getblocktemplate({'rules': ['segwit']})
+ template = node.getblocktemplate(NORMAL_GBT_REQUEST_PARAMS)
self.longpollid = template['longpollid']
# create a new connection to the node, we can't use the same
# connection from two threads
self.node = get_rpc_proxy(node.url, 1, timeout=600, coveragedir=node.coverage_dir)
def run(self):
- self.node.getblocktemplate({'longpollid': self.longpollid, 'rules': ['segwit']})
+ self.node.getblocktemplate({'longpollid': self.longpollid, **NORMAL_GBT_REQUEST_PARAMS})
class GetBlockTemplateLPTest(BitcoinTestFramework):
def set_test_params(self):
@@ -34,9 +35,9 @@ class GetBlockTemplateLPTest(BitcoinTestFramework):
self.log.info("Warning: this test will take about 70 seconds in the best case. Be patient.")
self.log.info("Test that longpollid doesn't change between successive getblocktemplate() invocations if nothing else happens")
self.generate(self.nodes[0], 10)
- template = self.nodes[0].getblocktemplate({'rules': ['segwit']})
+ template = self.nodes[0].getblocktemplate(NORMAL_GBT_REQUEST_PARAMS)
longpollid = template['longpollid']
- template2 = self.nodes[0].getblocktemplate({'rules': ['segwit']})
+ template2 = self.nodes[0].getblocktemplate(NORMAL_GBT_REQUEST_PARAMS)
assert_equal(template2['longpollid'], longpollid)
self.log.info("Test that longpoll waits if we do nothing")
diff --git a/test/functional/mining_prioritisetransaction.py b/test/functional/mining_prioritisetransaction.py
index 31ed6372..968c96ad 100755
--- a/test/functional/mining_prioritisetransaction.py
+++ b/test/functional/mining_prioritisetransaction.py
@@ -7,6 +7,7 @@
from decimal import Decimal
import time
+from test_framework.blocktools import NORMAL_GBT_REQUEST_PARAMS
from test_framework.messages import (
COIN,
MAX_BLOCK_WEIGHT,
@@ -352,14 +353,14 @@ class PrioritiseTransactionTest(BitcoinTestFramework):
# getblocktemplate to (eventually) return a new block.
mock_time = int(time.time())
self.nodes[0].setmocktime(mock_time)
- template = self.nodes[0].getblocktemplate({'rules': ['segwit']})
+ template = self.nodes[0].getblocktemplate(NORMAL_GBT_REQUEST_PARAMS)
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({'rules': ['segwit']})
+ new_template = self.nodes[0].getblocktemplate(NORMAL_GBT_REQUEST_PARAMS)
assert_not_equal(template, new_template)
diff --git a/test/functional/mining_template_verification.py b/test/functional/mining_template_verification.py
index a30fd960..f00268f6 100755
--- a/test/functional/mining_template_verification.py
+++ b/test/functional/mining_template_verification.py
@@ -14,6 +14,7 @@ import copy
from test_framework.blocktools import (
create_block,
add_witness_commitment,
+ NORMAL_GBT_REQUEST_PARAMS,
)
from test_framework.test_framework import BitcoinTestFramework
@@ -38,7 +39,7 @@ def assert_template(node, block, expect, *, rehash=True, submit=True, solve=True
rsp = node.getblocktemplate(template_request={
'data': block.serialize().hex(),
'mode': 'proposal',
- 'rules': ['segwit'],
+ **NORMAL_GBT_REQUEST_PARAMS,
})
assert_equal(rsp, expect)
# Only attempt to submit invalid templates
@@ -81,7 +82,7 @@ class MiningTemplateVerificationTest(BitcoinTestFramework):
template_request={
"data": block.serialize()[:-1].hex(),
"mode": "proposal",
- "rules": ["segwit"],
+ **NORMAL_GBT_REQUEST_PARAMS,
}
)
@@ -114,7 +115,7 @@ class MiningTemplateVerificationTest(BitcoinTestFramework):
assert_raises_rpc_error(-22, "Block decode failed", node.getblocktemplate, {
'data': bad_block_sn.hex(),
'mode': 'proposal',
- 'rules': ['segwit'],
+ **NORMAL_GBT_REQUEST_PARAMS,
})
def nbits_test(self, node, block):
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.