Skip to content

Commit 8e9801b

Browse files
author
merge-script
committed
Merge bitcoin/bitcoin#22818: test: Activate all regtest softforks at height 1, unless overridden
fa4db86 test: Activate all regtest softforks at height 1, unless overridden (MarcoFalke) faad1e5 Introduce -testactivationheight=name@height setting (MarcoFalke) fadb2ef test: Add extra_args argument to TestChain100Setup constructor (MarcoFalke) faa4698 test: Remove version argument from build_next_block in p2p_segwit test (MarcoFalke) fa086ef test: Remove unused ~TestChain100Setup (MarcoFalke) Pull request description: All softforks that are active at the tip of mainnet, should also be active from genesis in regtest. Otherwise their rules might not be enforced in user testing, thus making their testing less useful. To still allow tests to check pre-softfork rules, a runtime argument can change the activation height. ACKs for top commit: laanwj: Code review ACK fa4db86 theStack: re-ACK fa4db86 Tree-SHA512: 6397d46ff56ebc48c007a4cda633904d6ac085bc76b4ecf83097c546c7eec93ac0c44b88083b2611b9091c8d1fb8ee1e314065de078ef15e922c015de7ade8bf
2 parents b7e3600 + fa4db86 commit 8e9801b

19 files changed

+96
-90
lines changed

doc/release-notes.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,8 @@ Tests
113113
-----
114114

115115
- For the `regtest` network the activation heights of several softforks were
116-
changed.
117-
* BIP 34 (blockheight in coinbase) from 500 to 2 (#16333)
118-
* BIP 66 (DERSIG) from 1251 to 102 (#22632)
119-
* BIP 65 (CLTV) from 1351 to 111 (#21862)
116+
set to block height 1. They can be changed by the runtime setting
117+
`-testactivationheight=name@height`. (#22818)
120118

121119
Credits
122120
=======

src/chainparams.cpp

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -390,12 +390,12 @@ class CRegTestParams : public CChainParams {
390390
consensus.signet_challenge.clear();
391391
consensus.nSubsidyHalvingInterval = 150;
392392
consensus.BIP16Exception = uint256();
393-
consensus.BIP34Height = 2; // BIP34 activated on regtest (Block at height 1 not enforced for testing purposes)
393+
consensus.BIP34Height = 1; // Always active unless overridden
394394
consensus.BIP34Hash = uint256();
395-
consensus.BIP65Height = 111; // BIP65 activated on regtest (Block at height 110 and earlier not enforced for testing purposes)
396-
consensus.BIP66Height = 102; // BIP66 activated on regtest (Block at height 101 and earlier not enforced for testing purposes)
397-
consensus.CSVHeight = 432; // CSV activated on regtest (Used in rpc activation tests)
398-
consensus.SegwitHeight = 0; // SEGWIT is always activated on regtest unless overridden
395+
consensus.BIP65Height = 1; // Always active unless overridden
396+
consensus.BIP66Height = 1; // Always active unless overridden
397+
consensus.CSVHeight = 1; // Always active unless overridden
398+
consensus.SegwitHeight = 1; // Always active unless overridden
399399
consensus.MinBIP9WarningHeight = 0;
400400
consensus.powLimit = uint256S("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
401401
consensus.nPowTargetTimespan = 14 * 24 * 60 * 60; // two weeks
@@ -487,15 +487,38 @@ 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 if (name == "bip34") {
506+
consensus.BIP34Height = int{height};
507+
} else if (name == "dersig") {
508+
consensus.BIP66Height = int{height};
509+
} else if (name == "cltv") {
510+
consensus.BIP65Height = int{height};
511+
} else if (name == "csv") {
512+
consensus.CSVHeight = int{height};
513+
} else {
514+
throw std::runtime_error(strprintf("Invalid name (%s) for -testactivationheight=name@height.", arg));
496515
}
497-
consensus.SegwitHeight = static_cast<int>(height);
498516
}
517+
}
518+
519+
void CRegTestParams::UpdateActivationParametersFromArgs(const ArgsManager& args)
520+
{
521+
MaybeUpdateHeights(args, consensus);
499522

500523
if (!args.IsArgSet("-vbparams")) return;
501524

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' (segwit, bip34, dersig, cltv, csv). (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);

src/test/txvalidationcache_tests.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,19 @@
1313

1414
#include <boost/test/unit_test.hpp>
1515

16+
struct Dersig100Setup : public TestChain100Setup {
17+
Dersig100Setup()
18+
: TestChain100Setup{{"-testactivationheight=dersig@102"}} {}
19+
};
20+
1621
bool CheckInputScripts(const CTransaction& tx, TxValidationState& state,
1722
const CCoinsViewCache& inputs, unsigned int flags, bool cacheSigStore,
1823
bool cacheFullScriptStore, PrecomputedTransactionData& txdata,
1924
std::vector<CScriptCheck>* pvChecks) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
2025

2126
BOOST_AUTO_TEST_SUITE(txvalidationcache_tests)
2227

23-
BOOST_FIXTURE_TEST_CASE(tx_mempool_block_doublespend, TestChain100Setup)
28+
BOOST_FIXTURE_TEST_CASE(tx_mempool_block_doublespend, Dersig100Setup)
2429
{
2530
// Make sure skipping validation of transactions that were
2631
// validated going into the memory pool does not allow
@@ -153,7 +158,7 @@ static void ValidateCheckInputsForAllFlags(const CTransaction &tx, uint32_t fail
153158
}
154159
}
155160

156-
BOOST_FIXTURE_TEST_CASE(checkinputs_test, TestChain100Setup)
161+
BOOST_FIXTURE_TEST_CASE(checkinputs_test, Dersig100Setup)
157162
{
158163
// Test that passing CheckInputScripts with one set of script flags doesn't imply
159164
// that we would pass again with a different set of flags.

src/test/util/setup_common.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,8 @@ TestingSetup::TestingSetup(const std::string& chainName, const std::vector<const
205205
}
206206
}
207207

208-
TestChain100Setup::TestChain100Setup()
208+
TestChain100Setup::TestChain100Setup(const std::vector<const char*>& extra_args)
209+
: TestingSetup{CBaseChainParams::REGTEST, extra_args}
209210
{
210211
SetMockTime(1598887952);
211212
constexpr std::array<unsigned char, 32> vchKey = {
@@ -321,11 +322,6 @@ CMutableTransaction TestChain100Setup::CreateValidMempoolTransaction(CTransactio
321322
return mempool_txn;
322323
}
323324

324-
TestChain100Setup::~TestChain100Setup()
325-
{
326-
gArgs.ForceSetArg("-segwitheight", "0");
327-
}
328-
329325
CTxMemPoolEntry TestMemPoolEntryHelper::FromTx(const CMutableTransaction& tx) const
330326
{
331327
return FromTx(MakeTransactionRef(tx));

src/test/util/setup_common.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ class CScript;
113113
/**
114114
* Testing fixture that pre-creates a 100-block REGTEST-mode block chain
115115
*/
116-
struct TestChain100Setup : public RegTestingSetup {
117-
TestChain100Setup();
116+
struct TestChain100Setup : public TestingSetup {
117+
TestChain100Setup(const std::vector<const char*>& extra_args = {});
118118

119119
/**
120120
* Create a new block with just given transactions, coinbase paying to
@@ -156,8 +156,6 @@ struct TestChain100Setup : public RegTestingSetup {
156156
CAmount output_amount = CAmount(1 * COIN),
157157
bool submit = true);
158158

159-
~TestChain100Setup();
160-
161159
std::vector<CTransactionRef> m_coinbase_txns; // For convenience, coinbase transactions
162160
CKey coinbaseKey; // private/public key needed to spend coinbase transactions
163161
};

test/functional/feature_bip68_sequence.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,14 @@ class BIP68Test(BitcoinTestFramework):
4141
def set_test_params(self):
4242
self.num_nodes = 2
4343
self.extra_args = [
44-
["-acceptnonstdtxn=1"],
45-
["-acceptnonstdtxn=0"],
44+
[
45+
'-testactivationheight=csv@432',
46+
"-acceptnonstdtxn=1",
47+
],
48+
[
49+
'-testactivationheight=csv@432',
50+
"-acceptnonstdtxn=0",
51+
],
4652
]
4753

4854
def skip_test_if_missing_module(self):

test/functional/feature_block.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,10 @@ class FullBlockTest(BitcoinTestFramework):
8282
def set_test_params(self):
8383
self.num_nodes = 1
8484
self.setup_clean_chain = True
85-
self.extra_args = [['-acceptnonstdtxn=1']] # This is a consensus block test, we don't care about tx policy
85+
self.extra_args = [[
86+
'-acceptnonstdtxn=1', # This is a consensus block test, we don't care about tx policy
87+
'-testactivationheight=bip34@2',
88+
]]
8689

8790
def run_test(self):
8891
node = self.nodes[0] # convenience reference to the node

test/functional/feature_cltv.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
"""
99

1010
from test_framework.blocktools import (
11-
CLTV_HEIGHT,
1211
create_block,
1312
create_coinbase,
1413
)
@@ -76,10 +75,14 @@ def cltv_validate(tx, height):
7675
cltv_modify_tx(tx, prepend_scriptsig=scheme[0], nsequence=scheme[1], nlocktime=scheme[2])
7776

7877

78+
CLTV_HEIGHT = 111
79+
80+
7981
class BIP65Test(BitcoinTestFramework):
8082
def set_test_params(self):
8183
self.num_nodes = 1
8284
self.extra_args = [[
85+
f'-testactivationheight=cltv@{CLTV_HEIGHT}',
8386
8487
'-par=1', # Use only one script thread to get the exact reject reason for testing
8588
'-acceptnonstdtxn=1', # cltv_invalidate is nonstandard

test/functional/feature_csv_activation.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
import time
4242

4343
from test_framework.blocktools import (
44-
CSV_ACTIVATION_HEIGHT,
4544
create_block,
4645
create_coinbase,
4746
)
@@ -89,12 +88,16 @@ def all_rlt_txs(txs):
8988
return [tx['tx'] for tx in txs]
9089

9190

91+
CSV_ACTIVATION_HEIGHT = 432
92+
93+
9294
class BIP68_112_113Test(BitcoinTestFramework):
9395
def set_test_params(self):
9496
self.num_nodes = 1
9597
self.setup_clean_chain = True
9698
self.extra_args = [[
9799
100+
f'-testactivationheight=csv@{CSV_ACTIVATION_HEIGHT}',
98101
'-par=1', # Use only one script thread to get the exact reject reason for testing
99102
]]
100103
self.supports_cli = False

0 commit comments

Comments
 (0)