0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-03-05 14:06:27 -05:00

test: persist -v2transport over restarts and respect -v2transport=0

Before, a global -v2transport provided to the test would be dropped
when restarting the node within a test and specifying any extra_args.

Fix this by adding "v2transport=1" to args (not extra_args) based
on the global parameter, and deciding for each (re)start of the node
based on this default and test-specific extra_args
(which take precedence over args) whether v2 should be used.
This commit is contained in:
Martin Zumsande 2023-11-03 16:54:19 -04:00
parent d9007f51a7
commit 68a9001751
2 changed files with 11 additions and 4 deletions

View file

@ -508,8 +508,6 @@ class BitcoinTestFramework(metaclass=BitcoinTestMetaClass):
assert_equal(len(binary_cli), num_nodes) assert_equal(len(binary_cli), num_nodes)
for i in range(num_nodes): for i in range(num_nodes):
args = list(extra_args[i]) args = list(extra_args[i])
if self.options.v2transport and ("-v2transport=0" not in args):
args.append("-v2transport=1")
test_node_i = TestNode( test_node_i = TestNode(
i, i,
get_datadir_path(self.options.tmpdir, i), get_datadir_path(self.options.tmpdir, i),
@ -528,6 +526,7 @@ class BitcoinTestFramework(metaclass=BitcoinTestMetaClass):
start_perf=self.options.perf, start_perf=self.options.perf,
use_valgrind=self.options.valgrind, use_valgrind=self.options.valgrind,
descriptors=self.options.descriptors, descriptors=self.options.descriptors,
v2transport=self.options.v2transport,
) )
self.nodes.append(test_node_i) self.nodes.append(test_node_i)
if not test_node_i.version_is_at_least(170000): if not test_node_i.version_is_at_least(170000):
@ -602,7 +601,7 @@ class BitcoinTestFramework(metaclass=BitcoinTestMetaClass):
ip_port = "127.0.0.1:" + str(p2p_port(b)) ip_port = "127.0.0.1:" + str(p2p_port(b))
if peer_advertises_v2 is None: if peer_advertises_v2 is None:
peer_advertises_v2 = self.options.v2transport peer_advertises_v2 = from_connection.use_v2transport
if peer_advertises_v2: if peer_advertises_v2:
from_connection.addnode(node=ip_port, command="onetry", v2transport=True) from_connection.addnode(node=ip_port, command="onetry", v2transport=True)

View file

@ -67,7 +67,7 @@ class TestNode():
To make things easier for the test writer, any unrecognised messages will To make things easier for the test writer, any unrecognised messages will
be dispatched to the RPC connection.""" be dispatched to the RPC connection."""
def __init__(self, i, datadir_path, *, chain, rpchost, timewait, timeout_factor, bitcoind, bitcoin_cli, coverage_dir, cwd, extra_conf=None, extra_args=None, use_cli=False, start_perf=False, use_valgrind=False, version=None, descriptors=False): def __init__(self, i, datadir_path, *, chain, rpchost, timewait, timeout_factor, bitcoind, bitcoin_cli, coverage_dir, cwd, extra_conf=None, extra_args=None, use_cli=False, start_perf=False, use_valgrind=False, version=None, descriptors=False, v2transport=False):
""" """
Kwargs: Kwargs:
start_perf (bool): If True, begin profiling the node with `perf` as soon as start_perf (bool): If True, begin profiling the node with `perf` as soon as
@ -126,6 +126,12 @@ class TestNode():
if self.version_is_at_least(239000): if self.version_is_at_least(239000):
self.args.append("-loglevel=trace") self.args.append("-loglevel=trace")
# Default behavior from global -v2transport flag is added to args to persist it over restarts.
# May be overwritten in individual tests, using extra_args.
self.default_to_v2 = v2transport
if self.default_to_v2:
self.args.append("-v2transport=1")
self.cli = TestNodeCLI(bitcoin_cli, self.datadir_path) self.cli = TestNodeCLI(bitcoin_cli, self.datadir_path)
self.use_cli = use_cli self.use_cli = use_cli
self.start_perf = start_perf self.start_perf = start_perf
@ -198,6 +204,8 @@ class TestNode():
if extra_args is None: if extra_args is None:
extra_args = self.extra_args extra_args = self.extra_args
self.use_v2transport = "-v2transport=1" in extra_args or (self.default_to_v2 and "-v2transport=0" not in extra_args)
# Add a new stdout and stderr file each time bitcoind is started # Add a new stdout and stderr file each time bitcoind is started
if stderr is None: if stderr is None:
stderr = tempfile.NamedTemporaryFile(dir=self.stderr_dir, delete=False) stderr = tempfile.NamedTemporaryFile(dir=self.stderr_dir, delete=False)