Skip to content

Commit faad1e5

Browse files
author
MarcoFalke
committed
Introduce -testactivationheight=name@height setting
1 parent fadb2ef commit faad1e5

File tree

6 files changed

+31
-16
lines changed

6 files changed

+31
-16
lines changed

src/chainparams.cpp

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -487,15 +487,30 @@ class CRegTestParams : public CChainParams {
487487
void UpdateActivationParametersFromArgs(const ArgsManager& args);
488488
};
489489

490-
void CRegTestParams::UpdateActivationParametersFromArgs(const ArgsManager& args)
490+
static void MaybeUpdateHeights(const ArgsManager& args, Consensus::Params& consensus)
491491
{
492-
if (args.IsArgSet("-segwitheight")) {
493-
int64_t height = args.GetArg("-segwitheight", consensus.SegwitHeight);
494-
if (height < 0 || height >= std::numeric_limits<int>::max()) {
495-
throw std::runtime_error(strprintf("Activation height %ld for segwit is out of valid range.", height));
492+
for (const std::string& arg : args.GetArgs("-testactivationheight")) {
493+
const auto found{arg.find('@')};
494+
if (found == std::string::npos) {
495+
throw std::runtime_error(strprintf("Invalid format (%s) for -testactivationheight=name@height.", arg));
496+
}
497+
const auto name{arg.substr(0, found)};
498+
const auto value{arg.substr(found + 1)};
499+
int32_t height;
500+
if (!ParseInt32(value, &height) || height < 0 || height >= std::numeric_limits<int>::max()) {
501+
throw std::runtime_error(strprintf("Invalid height value (%s) for -testactivationheight=name@height.", arg));
502+
}
503+
if (name == "segwit") {
504+
consensus.SegwitHeight = int{height};
505+
} else {
506+
throw std::runtime_error(strprintf("Invalid name (%s) for -testactivationheight=name@height.", arg));
496507
}
497-
consensus.SegwitHeight = static_cast<int>(height);
498508
}
509+
}
510+
511+
void CRegTestParams::UpdateActivationParametersFromArgs(const ArgsManager& args)
512+
{
513+
MaybeUpdateHeights(args, consensus);
499514

500515
if (!args.IsArgSet("-vbparams")) return;
501516

src/chainparamsbase.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ void SetupChainParamsBaseOptions(ArgsManager& argsman)
2020
argsman.AddArg("-chain=<chain>", "Use the chain <chain> (default: main). Allowed values: main, test, signet, regtest", ArgsManager::ALLOW_ANY, OptionsCategory::CHAINPARAMS);
2121
argsman.AddArg("-regtest", "Enter regression test mode, which uses a special chain in which blocks can be solved instantly. "
2222
"This is intended for regression testing tools and app development. Equivalent to -chain=regtest.", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::CHAINPARAMS);
23-
argsman.AddArg("-segwitheight=<n>", "Set the activation height of segwit. (regtest-only)", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
23+
argsman.AddArg("-testactivationheight=name@height.", "Set the activation height of 'name'. (regtest-only)", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
2424
argsman.AddArg("-testnet", "Use the test chain. Equivalent to -chain=test.", ArgsManager::ALLOW_ANY, OptionsCategory::CHAINPARAMS);
2525
argsman.AddArg("-vbparams=deployment:start:end[:min_activation_height]", "Use given start/end times and min_activation_height for specified version bits deployment (regtest-only)", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::CHAINPARAMS);
2626
argsman.AddArg("-signet", "Use the signet chain. Equivalent to -chain=signet. Note that the network is defined by the -signetchallenge parameter", ArgsManager::ALLOW_ANY, OptionsCategory::CHAINPARAMS);

test/functional/feature_nulldummy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def set_test_params(self):
5252
# This script tests NULLDUMMY activation, which is part of the 'segwit' deployment, so we go through
5353
# normal segwit activation here (and don't use the default always-on behaviour).
5454
self.extra_args = [[
55-
f'-segwitheight={COINBASE_MATURITY + 5}',
55+
f'-testactivationheight=segwit@{COINBASE_MATURITY + 5}',
5656
'-addresstype=legacy',
5757
'-par=1', # Use only one script thread to get the exact reject reason for testing
5858
]]

test/functional/feature_presegwit_node_upgrade.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class SegwitUpgradeTest(BitcoinTestFramework):
1616
def set_test_params(self):
1717
self.setup_clean_chain = True
1818
self.num_nodes = 1
19-
self.extra_args = [["-segwitheight=10"]]
19+
self.extra_args = [["-testactivationheight=segwit@10"]]
2020

2121
def run_test(self):
2222
"""A pre-segwit node with insufficiently validated blocks needs to redownload blocks"""
@@ -37,14 +37,14 @@ def run_test(self):
3737
# Restarting the node (with segwit activation height set to 5) should result in a shutdown
3838
# because the blockchain consists of 3 insufficiently validated blocks per segwit consensus rules.
3939
node.assert_start_raises_init_error(
40-
extra_args=["-segwitheight=5"],
40+
extra_args=["-testactivationheight=segwit@5"],
4141
expected_msg=": Witness data for blocks after height 5 requires "
4242
f"validation. Please restart with -reindex..{os.linesep}"
4343
"Please restart with -reindex or -reindex-chainstate to recover.",
4444
)
4545

4646
# As directed, the user restarts the node with -reindex
47-
self.start_node(0, extra_args=["-reindex", "-segwitheight=5"])
47+
self.start_node(0, extra_args=["-reindex", "-testactivationheight=segwit@5"])
4848

4949
# With the segwit consensus rules, the node is able to validate only up to block 4
5050
assert_equal(node.getblockcount(), 4)

test/functional/feature_segwit.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,18 +78,18 @@ def set_test_params(self):
7878
[
7979
"-acceptnonstdtxn=1",
8080
"-rpcserialversion=0",
81-
"-segwitheight=432",
81+
"-testactivationheight=segwit@432",
8282
"-addresstype=legacy",
8383
],
8484
[
8585
"-acceptnonstdtxn=1",
8686
"-rpcserialversion=1",
87-
"-segwitheight=432",
87+
"-testactivationheight=segwit@432",
8888
"-addresstype=legacy",
8989
],
9090
[
9191
"-acceptnonstdtxn=1",
92-
"-segwitheight=432",
92+
"-testactivationheight=segwit@432",
9393
"-addresstype=legacy",
9494
],
9595
]

test/functional/p2p_segwit.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,8 @@ def set_test_params(self):
192192
self.num_nodes = 2
193193
# This test tests SegWit both pre and post-activation, so use the normal BIP9 activation.
194194
self.extra_args = [
195-
["-acceptnonstdtxn=1", "-segwitheight={}".format(SEGWIT_HEIGHT), "[email protected]"],
196-
["-acceptnonstdtxn=0", "-segwitheight={}".format(SEGWIT_HEIGHT)],
195+
["-acceptnonstdtxn=1", f"-testactivationheight=segwit@{SEGWIT_HEIGHT}", "[email protected]"],
196+
["-acceptnonstdtxn=0", f"-testactivationheight=segwit@{SEGWIT_HEIGHT}"],
197197
]
198198
self.supports_cli = False
199199

0 commit comments

Comments
 (0)