Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: fire up test chains by first block: bitcoin#22818, dip1, dip8, dip20, brr - 3/n #6214

Merged
merged 5 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions doc/release-notes-6189.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,5 @@ Tests
-----

- For the `regtest` network the activation heights of several softforks were
changed. (dash#6189)
* BIP 34 (blockheight in coinbase) from 500 to 2
* BIP 66 (DERSIG) from 1251 to 102
* BIP 65 (CLTV) from 1351 to 111
set to block height 1. They can be changed by the runtime setting
`-testactivationheight=name@height`. (dash#6214)
57 changes: 48 additions & 9 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -794,19 +794,19 @@ class CRegTestParams : public CChainParams {
consensus.nGovernanceMinQuorum = 1;
consensus.nGovernanceFilterElements = 100;
consensus.nMasternodeMinimumConfirmations = 1;
consensus.BIP34Height = 2; // BIP34 activated on regtest (Block at height 1 not enforced for testing purposes)
consensus.BIP34Height = 1; // Always active unless overridden
consensus.BIP34Hash = uint256();
consensus.BIP65Height = 111; // BIP65 activated on regtest (Block at height 110 and earlier not enforced for testing purposes)
consensus.BIP66Height = 102; // BIP66 activated on regtest (Block at height 101 and earlier not enforced for testing purposes)
consensus.BIP147Height = 432; // BIP147 activated on regtest (Used in functional tests)
consensus.CSVHeight = 432; // CSV activated on regtest (Used in rpc activation tests)
consensus.DIP0001Height = 2000;
consensus.BIP65Height = 1; // Always active unless overridden
consensus.BIP66Height = 1; // Always active unless overridden
consensus.BIP147Height = 1; // Always active unless overridden
consensus.CSVHeight = 1; // Always active unless overridden
consensus.DIP0001Height = 1; // Always active unless overridden
consensus.DIP0003Height = 432;
consensus.DIP0003EnforcementHeight = 500;
consensus.DIP0003EnforcementHash = uint256();
consensus.DIP0008Height = 432;
consensus.BRRHeight = 1000; // see block_reward_reallocation_tests
consensus.DIP0020Height = 300;
consensus.DIP0008Height = 1; // Always active unless overridden
consensus.BRRHeight = 1; // Always active unless overridden
consensus.DIP0020Height = 1;
consensus.DIP0024Height = 900;
consensus.DIP0024QuorumsHeight = 900;
consensus.V19Height = 900;
Expand Down Expand Up @@ -1031,8 +1031,47 @@ class CRegTestParams : public CChainParams {
void UpdateLLMQInstantSendDIP0024FromArgs(const ArgsManager& args);
};

static void MaybeUpdateHeights(const ArgsManager& args, Consensus::Params& consensus)
{
for (const std::string& arg : args.GetArgs("-testactivationheight")) {
const auto found{arg.find('@')};
if (found == std::string::npos) {
throw std::runtime_error(strprintf("Invalid format (%s) for -testactivationheight=name@height.", arg));
}
const auto name{arg.substr(0, found)};
const auto value{arg.substr(found + 1)};
int32_t height;
if (!ParseInt32(value, &height) || height < 0 || height >= std::numeric_limits<int>::max()) {
throw std::runtime_error(strprintf("Invalid height value (%s) for -testactivationheight=name@height.", arg));
}
if (name == "bip147") {
consensus.BIP147Height = int{height};
} else if (name == "bip34") {
consensus.BIP34Height = int{height};
} else if (name == "dersig") {
consensus.BIP66Height = int{height};
} else if (name == "cltv") {
consensus.BIP65Height = int{height};
} else if (name == "csv") {
consensus.CSVHeight = int{height};
} else if (name == "brr") {
consensus.BRRHeight = int{height};
} else if (name == "dip0001") {
consensus.DIP0001Height = int{height};
} else if (name == "dip0008") {
consensus.DIP0008Height = int{height};
} else if (name == "dip0020") {
consensus.DIP0020Height = int{height};
} else {
throw std::runtime_error(strprintf("Invalid name (%s) for -testactivationheight=name@height.", arg));
}
}
}

void CRegTestParams::UpdateActivationParametersFromArgs(const ArgsManager& args)
{
MaybeUpdateHeights(args, consensus);

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

for (const std::string& strDeployment : args.GetArgs("-vbparams")) {
Expand Down
1 change: 1 addition & 0 deletions src/chainparamsbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ void SetupChainParamsBaseOptions(ArgsManager& argsman)
argsman.AddArg("-dip3params=<activation>:<enforcement>", "Override DIP3 activation and enforcement heights (regtest-only)", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::CHAINPARAMS);
argsman.AddArg("-dip8params=<activation>", "Override DIP8 activation height (regtest-only)", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::CHAINPARAMS);
argsman.AddArg("-bip147height=<activation>", "Override BIP147 activation height (regtest-only)", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::CHAINPARAMS);
argsman.AddArg("-testactivationheight=name@height.", "Set the activation height of 'name' (bip147, bip34, dersig, cltv, csv, brr, dip0001, dip0008, dip0020). (regtest-only)", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
argsman.AddArg("-highsubsidyblocks=<n>", "The number of blocks with a higher than normal subsidy to mine at the start of a chain. Block after that height will have fixed subsidy base. (default: 0, devnet-only)", ArgsManager::ALLOW_ANY, OptionsCategory::CHAINPARAMS);
argsman.AddArg("-highsubsidyfactor=<n>", "The factor to multiply the normal block subsidy by while in the highsubsidyblocks window of a chain (default: 1, devnet-only)", ArgsManager::ALLOW_ANY, OptionsCategory::CHAINPARAMS);
argsman.AddArg("-llmqchainlocks=<quorum name>", "Override the default LLMQ type used for ChainLocks. Allows using ChainLocks with smaller LLMQs. (default: llmq_devnet, devnet-only)", ArgsManager::ALLOW_ANY, OptionsCategory::CHAINPARAMS);
Expand Down
3 changes: 0 additions & 3 deletions src/dsnotificationinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,6 @@ void CDSNotificationInterface::UpdatedBlockTip(const CBlockIndex *pindexNew, con

m_mn_sync.UpdatedBlockTip(WITH_LOCK(::cs_main, return m_chainman.m_best_header), pindexNew, fInitialDownload);

// Update global DIP0001 activation status
fDIP0001ActiveAtTip = pindexNew->nHeight >= Params().GetConsensus().DIP0001Height;

if (fInitialDownload)
return;

Expand Down
3 changes: 1 addition & 2 deletions src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
#include <util/time.h>
#include <util/translation.h>
#include <util/wpipe.h>
#include <validation.h> // for fDIP0001ActiveAtTip

#include <masternode/meta.h>
#include <masternode/sync.h>
Expand Down Expand Up @@ -4079,7 +4078,7 @@ bool CConnman::OutboundTargetReached(bool historicalBlockServingLimit) const
{
// keep a large enough buffer to at least relay each block once
const std::chrono::seconds timeLeftInCycle = GetMaxOutboundTimeLeftInCycle_();
const uint64_t buffer = timeLeftInCycle / std::chrono::minutes{10} * MaxBlockSize(fDIP0001ActiveAtTip);
const uint64_t buffer = timeLeftInCycle / std::chrono::minutes{10} * MaxBlockSize();
if (buffer >= nMaxOutboundLimit || nMaxOutboundTotalBytesSentInCycle >= nMaxOutboundLimit - buffer)
return true;
}
Expand Down
6 changes: 5 additions & 1 deletion src/test/block_reward_reallocation_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ using SimpleUTXOMap = std::map<COutPoint, std::pair<int, CAmount>>;
struct TestChainBRRBeforeActivationSetup : public TestChainSetup
{
// Force fast DIP3 activation
TestChainBRRBeforeActivationSetup() : TestChainSetup(497, {"-dip3params=30:50", "-vbparams=mn_rr:0:999999999999:0:20:16:12:5:1"}) {}
TestChainBRRBeforeActivationSetup() :
TestChainSetup(497, {"-dip3params=30:50", "-testactivationheight=brr@1000",
"-vbparams=mn_rr:0:999999999999:0:20:16:12:5:1"})
{
}
};

static SimpleUTXOMap BuildSimpleUtxoMap(const std::vector<CTransactionRef>& txs)
Expand Down
8 changes: 7 additions & 1 deletion src/test/txvalidation_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@
#include <boost/test/unit_test.hpp>


struct TestChain100NoDIP0001Setup : public TestChain100Setup {
TestChain100NoDIP0001Setup()
: TestChain100Setup{{"-testactivationheight=dip0001@2000"}} {}
};


BOOST_AUTO_TEST_SUITE(txvalidation_tests)

/**
Expand Down Expand Up @@ -69,7 +75,7 @@ inline CTransactionRef create_placeholder_tx(size_t num_inputs, size_t num_outpu
return MakeTransactionRef(mtx);
}

BOOST_FIXTURE_TEST_CASE(package_tests, TestChain100Setup)
BOOST_FIXTURE_TEST_CASE(package_tests, TestChain100NoDIP0001Setup)
{
LOCK(cs_main);
unsigned int initialPoolSize = m_node.mempool->size();
Expand Down
9 changes: 7 additions & 2 deletions src/test/txvalidationcache_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,16 @@

#include <boost/test/unit_test.hpp>

struct Dersig100Setup : public TestChain100Setup {
Dersig100Setup()
: TestChain100Setup{{"-testactivationheight=dersig@102"}} {}
};

bool CheckInputScripts(const CTransaction& tx, TxValidationState &state, const CCoinsViewCache &inputs, unsigned int flags, bool cacheSigStore, bool cacheFullScriptStore, PrecomputedTransactionData& txdata, std::vector<CScriptCheck> *pvChecks);

BOOST_AUTO_TEST_SUITE(txvalidationcache_tests)

BOOST_FIXTURE_TEST_CASE(tx_mempool_block_doublespend, TestChain100Setup)
BOOST_FIXTURE_TEST_CASE(tx_mempool_block_doublespend, Dersig100Setup)
{
// Make sure skipping validation of transactions that were
// validated going into the memory pool does not allow
Expand Down Expand Up @@ -144,7 +149,7 @@ static void ValidateCheckInputsForAllFlags(const CTransaction &tx, uint32_t fail
}
}

BOOST_FIXTURE_TEST_CASE(checkinputs_test, TestChain100Setup)
BOOST_FIXTURE_TEST_CASE(checkinputs_test, Dersig100Setup)
{
// Test that passing CheckInputScripts with one set of script flags doesn't imply
// that we would pass again with a different set of flags.
Expand Down
7 changes: 6 additions & 1 deletion src/test/util/setup_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,11 @@ TestingSetup::~TestingSetup()
m_node.banman.reset();
}

TestChain100Setup::TestChain100Setup(const std::vector<const char*>& extra_args)
: TestChainSetup{100, extra_args}
{
}

TestChainSetup::TestChainSetup(int num_blocks, const std::vector<const char*>& extra_args)
: RegTestingSetup(extra_args)
{
Expand Down Expand Up @@ -336,7 +341,7 @@ TestChainSetup::TestChainSetup(int num_blocks, const std::vector<const char*>& e
/* TestChainDIP3Setup */
{ 431, uint256S("0x49db248651517f3fc3725fbbc7087db90552d487d11e0962b0148fc4788aeb77") },
/* TestChainBRRBeforeActivationSetup */
{ 497, uint256S("0x15445246f9f9fd4fdb1021dd8278ace7246b3e3cb545e1632a277d3a02eb011f") },
{ 497, uint256S("0x626036f6adff51fbbdd0c609e827ef6a3730ce2498a3eb33edeb27092d006170") },
/* TestChainV19BeforeActivationSetup */
{ 894, uint256S("0x03cbf1871d7d915cda10aded00ced45f71a4e2acf6a3c7a77a1ff488267dd1cd") },
/* TestChainV19Setup */
Expand Down
2 changes: 1 addition & 1 deletion src/test/util/setup_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ struct TestChainSetup : public RegTestingSetup
* Testing fixture that pre-creates a 100-block REGTEST-mode block chain
*/
struct TestChain100Setup : public TestChainSetup {
TestChain100Setup() : TestChainSetup(100) {}
TestChain100Setup(const std::vector<const char*>& extra_args = {});
};

struct TestChainDIP3Setup : public TestChainSetup
Expand Down
3 changes: 0 additions & 3 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,6 @@ bool fCheckBlockIndex = false;
bool fCheckpointsEnabled = DEFAULT_CHECKPOINTS_ENABLED;
int64_t nMaxTipAge = DEFAULT_MAX_TIP_AGE;

// TODO: drop this global variable. Used by net.cpp module only
std::atomic<bool> fDIP0001ActiveAtTip{false};

uint256 hashAssumeValid;
arith_uint256 nMinimumChainWork;

Expand Down
2 changes: 0 additions & 2 deletions src/validation.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,6 @@ extern int64_t nMaxTipAge;
extern bool fLargeWorkForkFound;
extern bool fLargeWorkInvalidChainFound;

extern std::atomic<bool> fDIP0001ActiveAtTip;

/** Block hash whose ancestors we will assume to have valid scripts without checking them. */
extern uint256 hashAssumeValid;

Expand Down
10 changes: 8 additions & 2 deletions test/functional/feature_bip68_sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,14 @@ class BIP68Test(BitcoinTestFramework):
def set_test_params(self):
self.num_nodes = 2
self.extra_args = [
["-acceptnonstdtxn=1"],
["-acceptnonstdtxn=0"],
[
'-testactivationheight=csv@432',
"-acceptnonstdtxn=1",
],
[
'-testactivationheight=csv@432',
"-acceptnonstdtxn=0",
],
]

def skip_test_if_missing_module(self):
Expand Down
14 changes: 11 additions & 3 deletions test/functional/feature_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
create_coinbase,
create_tx_with_script,
get_legacy_sigopcount_block,
MAX_BLOCK_SIGOPS,
)
from test_framework.key import ECKey
from test_framework.messages import (
Expand All @@ -22,7 +21,6 @@
CTransaction,
CTxIn,
CTxOut,
MAX_BLOCK_SIZE,
uint256_from_compact,
uint256_from_str,
)
Expand Down Expand Up @@ -53,6 +51,11 @@
from test_framework.util import assert_equal
from data import invalid_txs

# This functional test assumes DIP0001 is disabled
# Blocks after activation DIP0001 can not have a transaction bigger than 100k bytes
MAX_BLOCK_SIZE = 1000000
MAX_BLOCK_SIGOPS = 20000

# Use this class for tests that require behavior other than normal p2p behavior.
# For now, it is used to serialize a bloated varint (b64).
class CBrokenBlock(CBlock):
Expand Down Expand Up @@ -83,7 +86,12 @@ def set_test_params(self):
# which causes RPC to hang, so we need to increase RPC timeouts
self.rpc_timeout = 180
# Must set '-dip3params=2000:2000' to create pre-dip3 blocks only
self.extra_args = [['-dip3params=2000:2000', '-acceptnonstdtxn=1']] # This is a consensus block test, we don't care about tx policy
self.extra_args = [[
'-dip3params=2000:2000',
'-acceptnonstdtxn=1', # This is a consensus block test, we don't care about tx policy
'-testactivationheight=bip34@2',
'-testactivationheight=dip0001@2000',
]]

def setup_nodes(self):
self.add_nodes(self.num_nodes, self.extra_args)
Expand Down
5 changes: 4 additions & 1 deletion test/functional/feature_cltv.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"""

from test_framework.blocktools import (
CLTV_HEIGHT,
create_block,
create_coinbase,
)
Expand Down Expand Up @@ -79,10 +78,14 @@ def cltv_validate(tx, height):
cltv_modify_tx(tx, prepend_scriptsig=scheme[0], nsequence=scheme[1], nlocktime=scheme[2])


CLTV_HEIGHT = 111


class BIP65Test(BitcoinTestFramework):
def set_test_params(self):
self.num_nodes = 1
self.extra_args = [[
f'-testactivationheight=cltv@{CLTV_HEIGHT}',
'[email protected]',
'-dip3params=9000:9000',
'-par=1', # Use only one script thread to get the exact reject reason for testing
Expand Down
5 changes: 4 additions & 1 deletion test/functional/feature_csv_activation.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
from itertools import product

from test_framework.blocktools import (
CSV_ACTIVATION_HEIGHT,
create_block,
create_coinbase,
TIME_GENESIS_BLOCK,
Expand Down Expand Up @@ -89,6 +88,9 @@ def all_rlt_txs(txs):
return [tx['tx'] for tx in txs]


CSV_ACTIVATION_HEIGHT = 432


class BIP68_112_113Test(BitcoinTestFramework):
def set_test_params(self):
self.num_nodes = 1
Expand All @@ -98,6 +100,7 @@ def set_test_params(self):
'-peertimeout=999999', # bump because mocktime might cause a disconnect otherwise
'[email protected]',
'-dip3params=2000:2000',
f'-testactivationheight=csv@{CSV_ACTIVATION_HEIGHT}',
'-par=1', # Use only one script thread to get the exact reject reason for testing
]]
self.supports_cli = False
Expand Down
16 changes: 11 additions & 5 deletions test/functional/feature_dersig.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"""

from test_framework.blocktools import (
DERSIG_HEIGHT,
create_block,
create_coinbase,
)
Expand Down Expand Up @@ -43,10 +42,18 @@ def unDERify(tx):
tx.vin[0].scriptSig = CScript(newscript)


DERSIG_HEIGHT = 102


class BIP66Test(BitcoinTestFramework):
def set_test_params(self):
self.num_nodes = 1
self.extra_args = [['[email protected]', '-dip3params=9000:9000', '-par=1', '-vbparams=v20:0:999999999999:0:480:384:288:5:0']] # Use only one script thread to get the exact reject reason for testing
self.extra_args = [[
f'-testactivationheight=dersig@{DERSIG_HEIGHT}',
'[email protected]',
'-dip3params=9000:9000',
'-par=1', # Use only one script thread to get the exact log msg for testing
'-vbparams=v20:0:999999999999:0:480:384:288:5:0']]
self.setup_clean_chain = True
self.rpc_timeout = 240

Expand Down Expand Up @@ -81,7 +88,6 @@ def run_test(self):
tip = self.nodes[0].getbestblockhash()
block_time = self.nodes[0].getblockheader(tip)['mediantime'] + 1
block = create_block(int(tip, 16), create_coinbase(DERSIG_HEIGHT - 1), block_time)
block.nVersion = 2
block.vtx.append(spendtx)
block.hashMerkleRoot = block.calc_merkle_root()
block.rehash()
Expand All @@ -108,7 +114,7 @@ def run_test(self):
peer.sync_with_ping()

self.log.info("Test that transactions with non-DER signatures cannot appear in a block")
block.nVersion = 3
block.nVersion = 4

spendtx = self.create_tx(self.coinbase_txids[1])
unDERify(spendtx)
Expand All @@ -129,7 +135,7 @@ def run_test(self):
assert_equal(int(self.nodes[0].getbestblockhash(), 16), tip)
peer.sync_with_ping()

self.log.info("Test that a version 3 block with a DERSIG-compliant transaction is accepted")
self.log.info("Test that a block with a DERSIG-compliant transaction is accepted")
block.vtx[1] = self.create_tx(self.coinbase_txids[1])
block.hashMerkleRoot = block.calc_merkle_root()
block.rehash()
Expand Down
Loading
Loading