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

merge bitcoin#13311: Don't edit Chainparams after initialization #4362

Merged
merged 7 commits into from
Sep 2, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 2 additions & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ BITCOIN_CORE_H = \
validation.h \
validationinterface.h \
versionbits.h \
versionbitsinfo.h \
walletinitinterface.h \
wallet/coincontrol.h \
wallet/crypter.h \
Expand Down Expand Up @@ -579,6 +580,7 @@ libdash_common_a_SOURCES = \
script/ismine.cpp \
script/sign.cpp \
script/standard.cpp \
versionbitsinfo.cpp \
warnings.cpp \
$(BITCOIN_CORE_H)

Expand Down
79 changes: 52 additions & 27 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@
#include <tinyformat.h>
#include <util/system.h>
#include <util/strencodings.h>

#include <versionbitsinfo.h>
#include <arith_uint256.h>

#include <assert.h>

#include <boost/algorithm/string/classification.hpp>
#include <boost/algorithm/string/split.hpp>

static CBlock CreateGenesisBlock(const char* pszTimestamp, const CScript& genesisOutputScript, uint32_t nTime, uint32_t nNonce, uint32_t nBits, int32_t nVersion, const CAmount& genesisReward)
{
CMutableTransaction txNew;
Expand Down Expand Up @@ -80,24 +83,6 @@ static CBlock CreateGenesisBlock(uint32_t nTime, uint32_t nNonce, uint32_t nBits
}


void CChainParams::UpdateVersionBitsParameters(Consensus::DeploymentPos d, int64_t nStartTime, int64_t nTimeout, int64_t nWindowSize, int64_t nThresholdStart, int64_t nThresholdMin, int64_t nFalloffCoeff)
{
consensus.vDeployments[d].nStartTime = nStartTime;
consensus.vDeployments[d].nTimeout = nTimeout;
if (nWindowSize != -1) {
consensus.vDeployments[d].nWindowSize = nWindowSize;
}
if (nThresholdStart != -1) {
consensus.vDeployments[d].nThresholdStart = nThresholdStart;
}
if (nThresholdMin != -1) {
consensus.vDeployments[d].nThresholdMin = nThresholdMin;
}
if (nFalloffCoeff != -1) {
consensus.vDeployments[d].nFalloffCoeff = nFalloffCoeff;
}
}

void CChainParams::UpdateDIP3Parameters(int nActivationHeight, int nEnforcementHeight)
{
consensus.DIP0003Height = nActivationHeight;
Expand Down Expand Up @@ -882,7 +867,7 @@ class CDevNetParams : public CChainParams {
*/
class CRegTestParams : public CChainParams {
public:
CRegTestParams() {
explicit CRegTestParams(const ArgsManager& args) {
strNetworkID = "regtest";
consensus.nSubsidyHalvingInterval = 150;
consensus.nMasternodePaymentsStartBlock = 240;
Expand Down Expand Up @@ -963,7 +948,9 @@ class CRegTestParams : public CChainParams {
nDefaultPort = 19899;
nPruneAfterHeight = 1000;

UpdateVersionBitsParametersFromArgs(args);
genesis = CreateGenesisBlock(1417713337, 1096447, 0x207fffff, 1, 50 * COIN);

consensus.hashGenesisBlock = genesis.GetHash();
assert(consensus.hashGenesisBlock == uint256S("0x000008ca1832a4baf228eb1553c03d3a2c8e02399550dd6ea8d65cec3ef23d2e"));
assert(genesis.hashMerkleRoot == uint256S("0xe0028eb9648db56b1ac77cf090b99048a8007e2bb64b68f092c03c7f56a662c7"));
Expand Down Expand Up @@ -1022,8 +1009,50 @@ class CRegTestParams : public CChainParams {
consensus.llmqTypeInstantSend = Consensus::LLMQ_TEST;
consensus.llmqTypePlatform = Consensus::LLMQ_TEST;
}

/**
* Allows modifying the Version Bits regtest parameters.
*/
void UpdateVersionBitsParameters(Consensus::DeploymentPos d, int64_t nStartTime, int64_t nTimeout)
{
consensus.vDeployments[d].nStartTime = nStartTime;
consensus.vDeployments[d].nTimeout = nTimeout;
}
void UpdateVersionBitsParametersFromArgs(const ArgsManager& args);
};

void CRegTestParams::UpdateVersionBitsParametersFromArgs(const ArgsManager& args)
{
if (!args.IsArgSet("-vbparams")) return;

for (const std::string& strDeployment : args.GetArgs("-vbparams")) {
std::vector<std::string> vDeploymentParams;
boost::split(vDeploymentParams, strDeployment, boost::is_any_of(":"));
if (vDeploymentParams.size() != 3) {
throw std::runtime_error("Version bits parameters malformed, expecting deployment:start:end");
}
int64_t nStartTime, nTimeout;
if (!ParseInt64(vDeploymentParams[1], &nStartTime)) {
throw std::runtime_error(strprintf("Invalid nStartTime (%s)", vDeploymentParams[1]));
}
if (!ParseInt64(vDeploymentParams[2], &nTimeout)) {
throw std::runtime_error(strprintf("Invalid nTimeout (%s)", vDeploymentParams[2]));
}
bool found = false;
for (int j=0; j < (int)Consensus::MAX_VERSION_BITS_DEPLOYMENTS; ++j) {
if (vDeploymentParams[0] == VersionBitsDeploymentInfo[j].name) {
UpdateVersionBitsParameters(Consensus::DeploymentPos(j), nStartTime, nTimeout);
found = true;
LogPrintf("Setting version bits activation parameters for %s to start=%ld, timeout=%ld\n", vDeploymentParams[0], nStartTime, nTimeout);
break;
}
}
if (!found) {
throw std::runtime_error(strprintf("Invalid deployment (%s)", vDeploymentParams[0]));
}
}
}

static std::unique_ptr<CChainParams> globalChainParams;

const CChainParams &Params() {
Expand All @@ -1040,7 +1069,8 @@ std::unique_ptr<CChainParams> CreateChainParams(const std::string& chain, bool f
else if (chain == CBaseChainParams::DEVNET) {
return std::unique_ptr<CChainParams>(new CDevNetParams(fHelpOnly));
} else if (chain == CBaseChainParams::REGTEST)
return std::unique_ptr<CChainParams>(new CRegTestParams());
return std::unique_ptr<CChainParams>(new CRegTestParams(gArgs));

throw std::runtime_error(strprintf("%s: Unknown chain %s.", __func__, chain));
}

Expand All @@ -1050,11 +1080,6 @@ void SelectParams(const std::string& network)
globalChainParams = CreateChainParams(network);
}

void UpdateVersionBitsParameters(Consensus::DeploymentPos d, int64_t nStartTime, int64_t nTimeout, int64_t nWindowSize, int64_t nThresholdStart, int64_t nThresholdMin, int64_t nFalloffCoeff)
{
globalChainParams->UpdateVersionBitsParameters(d, nStartTime, nTimeout, nWindowSize, nThresholdStart, nThresholdMin, nFalloffCoeff);
}

void UpdateDIP3Parameters(int nActivationHeight, int nEnforcementHeight)
{
globalChainParams->UpdateDIP3Parameters(nActivationHeight, nEnforcementHeight);
Expand Down Expand Up @@ -1093,4 +1118,4 @@ void UpdateLLMQTestParams(int size, int threshold)
void UpdateLLMQDevnetParams(int size, int threshold)
{
globalChainParams->UpdateLLMQDevnetParams(size, threshold);
}
}
6 changes: 0 additions & 6 deletions src/chainparams.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ class CChainParams
const std::vector<SeedSpec6>& FixedSeeds() const { return vFixedSeeds; }
const CCheckpointData& Checkpoints() const { return checkpointData; }
const ChainTxData& TxData() const { return chainTxData; }
void UpdateVersionBitsParameters(Consensus::DeploymentPos d, int64_t nStartTime, int64_t nTimeout, int64_t nWindowSize, int64_t nThresholdStart, int64_t nThresholdMin, int64_t nFalloffCoeff);
void UpdateDIP3Parameters(int nActivationHeight, int nEnforcementHeight);
void UpdateDIP8Parameters(int nActivationHeight);
void UpdateBudgetParameters(int nMasternodePaymentsStartBlock, int nBudgetPaymentsStartBlock, int nSuperblockStartBlock);
Expand Down Expand Up @@ -152,10 +151,6 @@ const CChainParams &Params();
*/
void SelectParams(const std::string& chain);

/**
* Allows modifying the Version Bits regtest parameters.
*/
void UpdateVersionBitsParameters(Consensus::DeploymentPos d, int64_t nStartTime, int64_t nTimeout, int64_t nWindowSize, int64_t nThresholdStart, int64_t nThresholdMin, int64_t nFalloffCoeff);

/**
* Allows modifying the DIP3 activation and enforcement height
Expand Down Expand Up @@ -196,5 +191,4 @@ void UpdateLLMQTestParams(int size, int threshold);
* Allows modifying parameters of the devnet LLMQ
*/
void UpdateLLMQDevnetParams(int size, int threshold);

#endif // BITCOIN_CHAINPARAMS_H
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()
gArgs.AddArg("-regtest", "Enter regression test mode, which uses a special chain in which blocks can be solved instantly. "
"This is intended for regression testing tools and app development.", true, OptionsCategory::CHAINPARAMS);
gArgs.AddArg("-testnet", "Use the test chain", false, OptionsCategory::CHAINPARAMS);
gArgs.AddArg("-vbparams=deployment:start:end", "Use given start/end times for specified version bits deployment (regtest-only)", true, OptionsCategory::CHAINPARAMS);
}

static std::unique_ptr<CBaseChainParams> globalChainBaseParams;
Expand Down
51 changes: 0 additions & 51 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,6 @@ void SetupServerArgs()
gArgs.AddArg("-limitdescendantsize=<n>", strprintf("Do not accept transactions if any ancestor would have more than <n> kilobytes of in-mempool descendants (default: %u).", DEFAULT_DESCENDANT_SIZE_LIMIT), true, OptionsCategory::DEBUG_TEST);
gArgs.AddArg("-stopafterblockimport", strprintf("Stop running after importing blocks from disk (default: %u)", DEFAULT_STOPAFTERBLOCKIMPORT), true, OptionsCategory::DEBUG_TEST);
gArgs.AddArg("-stopatheight", strprintf("Stop running after reaching the given height in the main chain (default: %u)", DEFAULT_STOPATHEIGHT), true, OptionsCategory::DEBUG_TEST);
gArgs.AddArg("-vbparams=<deployment>:<start>:<end>(:<window>:<threshold>)", "Use given start/end times for specified version bits deployment (regtest-only). Specifying window and threshold is optional.", true, OptionsCategory::DEBUG_TEST);
gArgs.AddArg("-watchquorums=<n>", strprintf("Watch and validate quorum communication (default: %u)", llmq::DEFAULT_WATCH_QUORUMS), true, OptionsCategory::DEBUG_TEST);
gArgs.AddArg("-addrmantest", "Allows to test address relay on localhost", true, OptionsCategory::DEBUG_TEST);

Expand Down Expand Up @@ -1481,56 +1480,6 @@ bool AppInitParameterInteraction()

nMaxTipAge = gArgs.GetArg("-maxtipage", DEFAULT_MAX_TIP_AGE);

if (gArgs.IsArgSet("-vbparams")) {
// Allow overriding version bits parameters for testing
if (!chainparams.MineBlocksOnDemand()) {
return InitError("Version bits parameters may only be overridden on regtest.");
}
for (const std::string& strDeployment : gArgs.GetArgs("-vbparams")) {
std::vector<std::string> vDeploymentParams;
boost::split(vDeploymentParams, strDeployment, boost::is_any_of(":"));
if (vDeploymentParams.size() != 3 && vDeploymentParams.size() != 5 && vDeploymentParams.size() != 7) {
return InitError("Version bits parameters malformed, expecting deployment:start:end or deployment:start:end:window:threshold or deployment:start:end:window:thresholdstart:thresholdmin:falloffcoeff");
}
int64_t nStartTime, nTimeout, nWindowSize = -1, nThresholdStart = -1, nThresholdMin = -1, nFalloffCoeff = -1;
if (!ParseInt64(vDeploymentParams[1], &nStartTime)) {
return InitError(strprintf("Invalid nStartTime (%s)", vDeploymentParams[1]));
}
if (!ParseInt64(vDeploymentParams[2], &nTimeout)) {
return InitError(strprintf("Invalid nTimeout (%s)", vDeploymentParams[2]));
}
if (vDeploymentParams.size() >= 5) {
if (!ParseInt64(vDeploymentParams[3], &nWindowSize)) {
return InitError(strprintf("Invalid nWindowSize (%s)", vDeploymentParams[3]));
}
if (!ParseInt64(vDeploymentParams[4], &nThresholdStart)) {
return InitError(strprintf("Invalid nThresholdStart (%s)", vDeploymentParams[4]));
}
}
if (vDeploymentParams.size() == 7) {
if (!ParseInt64(vDeploymentParams[5], &nThresholdMin)) {
return InitError(strprintf("Invalid nThresholdMin (%s)", vDeploymentParams[5]));
}
if (!ParseInt64(vDeploymentParams[6], &nFalloffCoeff)) {
return InitError(strprintf("Invalid nFalloffCoeff (%s)", vDeploymentParams[6]));
}
}
bool found = false;
for (int j=0; j<(int)Consensus::MAX_VERSION_BITS_DEPLOYMENTS; ++j)
{
if (vDeploymentParams[0].compare(VersionBitsDeploymentInfo[j].name) == 0) {
UpdateVersionBitsParameters(Consensus::DeploymentPos(j), nStartTime, nTimeout, nWindowSize, nThresholdStart, nThresholdMin, nFalloffCoeff);
found = true;
LogPrintf("Setting version bits activation parameters for %s to start=%ld, timeout=%ld, window=%ld, thresholdstart=%ld, thresholdmin=%ld, falloffcoeff=%ld\n",
vDeploymentParams[0], nStartTime, nTimeout, nWindowSize, nThresholdStart, nThresholdMin, nFalloffCoeff);
break;
}
}
if (!found) {
return InitError(strprintf("Invalid deployment (%s)", vDeploymentParams[0]));
}
}
}

if (gArgs.IsArgSet("-dip3params")) {
// Allow overriding dip3 parameters for testing
Expand Down
1 change: 1 addition & 0 deletions src/rpc/blockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <util/validation.h>
#include <hash.h>
#include <validationinterface.h>
#include <versionbitsinfo.h>
#include <warnings.h>

#include <evo/specialtx.h>
Expand Down
1 change: 1 addition & 0 deletions src/rpc/mining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <util/validation.h>
#include <validation.h>
#include <validationinterface.h>
#include <versionbitsinfo.h>
#include <warnings.h>

#include <governance/governance-classes.h>
Expand Down
4 changes: 4 additions & 0 deletions src/test/test_dash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <banman.h>
#include <chainparams.h>
#include <consensus/consensus.h>
#include <consensus/params.h>
#include <consensus/validation.h>
#include <crypto/sha256.h>
#include <index/txindex.h>
Expand Down Expand Up @@ -54,6 +55,9 @@ BasicTestingSetup::BasicTestingSetup(const std::string& chainName)
InitScriptExecutionCache();
CCoinJoin::InitStandardDenominations();
fCheckBlockIndex = true;
// CreateAndProcessBlock() does not support building SegWit blocks, so don't activate in these tests.
// TODO: fix the code to support SegWit blocks.
//gArgs.ForceSetArg("-vbparams", strprintf("segwit:0:%d", (int64_t)Consensus::BIP9Deployment::NO_TIMEOUT));
SelectParams(chainName);
evoDb.reset(new CEvoDB(1 << 20, true, true));
deterministicMNManager.reset(new CDeterministicMNManager(*evoDb));
Expand Down
4 changes: 0 additions & 4 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1902,10 +1902,6 @@ int32_t ComputeBlockVersion(const CBlockIndex* pindexPrev, const Consensus::Para
for (int i = 0; i < (int)Consensus::MAX_VERSION_BITS_DEPLOYMENTS; i++) {
Consensus::DeploymentPos pos = Consensus::DeploymentPos(i);
ThresholdState state = VersionBitsState(pindexPrev, params, pos, versionbitscache);
const struct VBDeploymentInfo& vbinfo = VersionBitsDeploymentInfo[pos];
if (vbinfo.check_mn_protocol && state == ThresholdState::STARTED && fCheckMasternodesUpgraded) {
// TODO implement new logic for MN upgrade checks (e.g. with LLMQ based feature/version voting)
}
if (state == ThresholdState::LOCKED_IN || state == ThresholdState::STARTED) {
nVersion |= VersionBitsMask(params, static_cast<Consensus::DeploymentPos>(i));
}
Expand Down
43 changes: 0 additions & 43 deletions src/versionbits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,49 +5,6 @@
#include <versionbits.h>
#include <consensus/params.h>

const struct VBDeploymentInfo VersionBitsDeploymentInfo[Consensus::MAX_VERSION_BITS_DEPLOYMENTS] = {
{
/*.name =*/ "testdummy",
/*.gbt_force =*/ true,
/*.check_mn_protocol =*/ false,
},
{
/*.name =*/ "csv",
/*.gbt_force =*/ true,
/*.check_mn_protocol =*/ false,
},
{
/*.name =*/ "dip0001",
/*.gbt_force =*/ true,
/*.check_mn_protocol =*/ true,
},
{
/*.name =*/ "bip147",
/*.gbt_force =*/ true,
/*.check_mn_protocol =*/ false,
},
{
/*.name =*/ "dip0003",
/*.gbt_force =*/ true,
/*.check_mn_protocol =*/ false,
},
{
/*.name =*/ "dip0008",
/*.gbt_force =*/ true,
/*.check_mn_protocol =*/ false,
},
{
/*.name =*/ "realloc",
/*.gbt_force =*/ true,
/*.check_mn_protocol =*/ false,
},
{
/*.name =*/ "dip0020",
/*.gbt_force =*/ true,
/*.check_mn_protocol =*/ false,
},
};

ThresholdState AbstractThresholdConditionChecker::GetStateFor(const CBlockIndex* pindexPrev, const Consensus::Params& params, ThresholdConditionCache& cache) const
{
int nPeriod = Period(params);
Expand Down
11 changes: 0 additions & 11 deletions src/versionbits.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,6 @@ enum class ThresholdState {
// will either be nullptr or a block with (height + 1) % Period() == 0.
typedef std::map<const CBlockIndex*, ThresholdState> ThresholdConditionCache;

struct VBDeploymentInfo {
/** Deployment name */
const char *name;
/** Whether GBT clients can safely ignore this rule in simplified usage */
bool gbt_force;
/** Whether to check current MN protocol or not */
bool check_mn_protocol;
};

struct BIP9Stats {
int period;
int threshold;
Expand All @@ -47,8 +38,6 @@ struct BIP9Stats {
bool possible;
};

extern const struct VBDeploymentInfo VersionBitsDeploymentInfo[];

/**
* Abstract class that implements BIP9-style threshold logic, and caches results.
*/
Expand Down
22 changes: 22 additions & 0 deletions src/versionbitsinfo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright (c) 2016-2018 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <versionbitsinfo.h>

#include <consensus/params.h>

const struct VBDeploymentInfo VersionBitsDeploymentInfo[Consensus::MAX_VERSION_BITS_DEPLOYMENTS] = {
{
/*.name =*/ "testdummy",
/*.gbt_force =*/ true,
},
{
/*.name =*/ "csv",
/*.gbt_force =*/ true,
},
{
/*.name =*/ "segwit",
/*.gbt_force =*/ true,
}
};
Loading