Skip to content

Commit 68a9001

Browse files
committed
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.
1 parent d9007f5 commit 68a9001

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

test/functional/test_framework/test_framework.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -508,8 +508,6 @@ def get_bin_from_version(version, bin_name, bin_default):
508508
assert_equal(len(binary_cli), num_nodes)
509509
for i in range(num_nodes):
510510
args = list(extra_args[i])
511-
if self.options.v2transport and ("-v2transport=0" not in args):
512-
args.append("-v2transport=1")
513511
test_node_i = TestNode(
514512
i,
515513
get_datadir_path(self.options.tmpdir, i),
@@ -528,6 +526,7 @@ def get_bin_from_version(version, bin_name, bin_default):
528526
start_perf=self.options.perf,
529527
use_valgrind=self.options.valgrind,
530528
descriptors=self.options.descriptors,
529+
v2transport=self.options.v2transport,
531530
)
532531
self.nodes.append(test_node_i)
533532
if not test_node_i.version_is_at_least(170000):
@@ -602,7 +601,7 @@ def connect_nodes(self, a, b, *, peer_advertises_v2=None, wait_for_connect: bool
602601
ip_port = "127.0.0.1:" + str(p2p_port(b))
603602

604603
if peer_advertises_v2 is None:
605-
peer_advertises_v2 = self.options.v2transport
604+
peer_advertises_v2 = from_connection.use_v2transport
606605

607606
if peer_advertises_v2:
608607
from_connection.addnode(node=ip_port, command="onetry", v2transport=True)

test/functional/test_framework/test_node.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class TestNode():
6767
To make things easier for the test writer, any unrecognised messages will
6868
be dispatched to the RPC connection."""
6969

70-
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):
70+
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):
7171
"""
7272
Kwargs:
7373
start_perf (bool): If True, begin profiling the node with `perf` as soon as
@@ -126,6 +126,12 @@ def __init__(self, i, datadir_path, *, chain, rpchost, timewait, timeout_factor,
126126
if self.version_is_at_least(239000):
127127
self.args.append("-loglevel=trace")
128128

129+
# Default behavior from global -v2transport flag is added to args to persist it over restarts.
130+
# May be overwritten in individual tests, using extra_args.
131+
self.default_to_v2 = v2transport
132+
if self.default_to_v2:
133+
self.args.append("-v2transport=1")
134+
129135
self.cli = TestNodeCLI(bitcoin_cli, self.datadir_path)
130136
self.use_cli = use_cli
131137
self.start_perf = start_perf
@@ -198,6 +204,8 @@ def start(self, extra_args=None, *, cwd=None, stdout=None, stderr=None, env=None
198204
if extra_args is None:
199205
extra_args = self.extra_args
200206

207+
self.use_v2transport = "-v2transport=1" in extra_args or (self.default_to_v2 and "-v2transport=0" not in extra_args)
208+
201209
# Add a new stdout and stderr file each time bitcoind is started
202210
if stderr is None:
203211
stderr = tempfile.NamedTemporaryFile(dir=self.stderr_dir, delete=False)

0 commit comments

Comments
 (0)