test: Allow mining_getblocktemplate_longpoll.py --usecli
What changed, and why it matters
This is a test-only change that lets one of Bitcoin Core's automated functional tests run in a mode where it calls the node through the command-line bitcoin-cli tool instead of only through the Python RPC library. It does not change any production code, consensus rules, wallet handling, or network behavior that real users rely on.
No security action needed; this is a routine test-framework improvement.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit modifies the test framework’s TestNode.create_new_rpc_connection() to support an AUTO/AUTHPROXY/CLI mode selection and a configurable client timeout. It also updates mining_getblocktemplate_longpoll.py to use that helper and removes its self.supports_cli = False flag. The production RPC server and getblocktemplate logic are untouched.
Changed components
test/functional/mining_getblocktemplate_longpoll.pytest/functional/test_framework/test_node.pyInspect captured patch +23 / −15
diff --git a/test/functional/mining_getblocktemplate_longpoll.py b/test/functional/mining_getblocktemplate_longpoll.py
index e36396b3..e2293f96 100755
--- a/test/functional/mining_getblocktemplate_longpoll.py
+++ b/test/functional/mining_getblocktemplate_longpoll.py
@@ -8,7 +8,7 @@ import random
import threading
from test_framework.test_framework import BitcoinTestFramework
-from test_framework.util import assert_equal, get_rpc_proxy
+from test_framework.util import assert_equal
from test_framework.wallet import MiniWallet
@@ -18,9 +18,8 @@ class LongpollThread(threading.Thread):
# query current longpollid
template = node.getblocktemplate({'rules': ['segwit']})
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)
+ # create a new connection to the node for this thread
+ self.node = node.create_new_rpc_connection(client_timeout=600)
def run(self):
self.node.getblocktemplate({'longpollid': self.longpollid, 'rules': ['segwit']})
@@ -28,7 +27,6 @@ class LongpollThread(threading.Thread):
class GetBlockTemplateLPTest(BitcoinTestFramework):
def set_test_params(self):
self.num_nodes = 2
- self.supports_cli = False
def run_test(self):
self.log.info("Warning: this test will take about 70 seconds in the best case. Be patient.")
diff --git a/test/functional/test_framework/test_node.py b/test/functional/test_framework/test_node.py
index c3384007..6254e5f0 100755
--- a/test/functional/test_framework/test_node.py
+++ b/test/functional/test_framework/test_node.py
@@ -76,6 +76,9 @@ class ErrorMatch(Enum):
PARTIAL_REGEX = 3
+RPCConnectionType = Enum("RPCConnectionType", ["AUTO", "AUTHPROXY", "CLI"])
+
+
class TestNode():
"""A class for representing a bitcoind node under test.
@@ -301,16 +304,23 @@ class TestNode():
if self.start_perf:
self._start_perf()
- def create_new_rpc_connection(self):
+ def create_new_rpc_connection(self, *, mode="AUTO", client_timeout=None):
"""Create an additional RPC connection, likely to be used in a new thread."""
- rpc = get_rpc_proxy(
- rpc_url(self.datadir_path, self.index, self.chain, self.rpchost),
- self.index,
- timeout=self.rpc_timeout // 2, # Shorter timeout to allow for one retry in case of ETIMEDOUT
- coveragedir=self.coverage_dir,
- )
- rpc.auth_service_proxy_instance.reuse_http_connections = self.reuse_http_connections
- return rpc
+ mode = RPCConnectionType[mode]
+ if mode == RPCConnectionType.AUTO:
+ mode = RPCConnectionType.CLI if self.use_cli else RPCConnectionType.AUTHPROXY
+ client_timeout = client_timeout or (self.rpc_timeout // 2) # Shorter timeout to allow for one retry in case of ETIMEDOUT
+ if mode == RPCConnectionType.AUTHPROXY:
+ rpc = get_rpc_proxy(
+ rpc_url(self.datadir_path, self.index, self.chain, self.rpchost),
+ self.index,
+ timeout=client_timeout,
+ coveragedir=self.coverage_dir,
+ )
+ rpc.auth_service_proxy_instance.reuse_http_connections = self.reuse_http_connections
+ return rpc
+ else: # mode==CLI
+ return self.cli(f"-rpcclienttimeout={client_timeout}")
def wait_for_rpc_connection(self, *, wait_for_import=True):
"""Sets up an RPC connection to the bitcoind process. Returns False if unable to connect."""
@@ -333,7 +343,7 @@ class TestNode():
raise FailedToStartError(self._node_msg(
f'bitcoind exited with status {self.process.returncode} during initialization. {str_error}'))
try:
- rpc = self.create_new_rpc_connection()
+ rpc = self.create_new_rpc_connection(mode="AUTHPROXY")
rpc.getblockcount()
# If the call to getblockcount() succeeds then the RPC connection is up
if self.version_is_at_least(190000) and wait_for_import:
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.