Skip to content

Commit 56c87e9

Browse files
committed
Allow changing BIP9 parameters on regtest
1 parent 7a2d402 commit 56c87e9

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

src/chainparams.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,12 @@ class CRegTestParams : public CChainParams {
303303
base58Prefixes[EXT_PUBLIC_KEY] = boost::assign::list_of(0x04)(0x35)(0x87)(0xCF).convert_to_container<std::vector<unsigned char> >();
304304
base58Prefixes[EXT_SECRET_KEY] = boost::assign::list_of(0x04)(0x35)(0x83)(0x94).convert_to_container<std::vector<unsigned char> >();
305305
}
306+
307+
void UpdateBIP9Parameters(Consensus::DeploymentPos d, int64_t nStartTime, int64_t nTimeout)
308+
{
309+
consensus.vDeployments[d].nStartTime = nStartTime;
310+
consensus.vDeployments[d].nTimeout = nTimeout;
311+
}
306312
};
307313
static CRegTestParams regTestParams;
308314

@@ -330,4 +336,9 @@ void SelectParams(const std::string& network)
330336
SelectBaseParams(network);
331337
pCurrentParams = &Params(network);
332338
}
339+
340+
void UpdateRegtestBIP9Parameters(Consensus::DeploymentPos d, int64_t nStartTime, int64_t nTimeout)
341+
{
342+
regTestParams.UpdateBIP9Parameters(d, nStartTime, nTimeout);
343+
}
333344

src/chainparams.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,9 @@ CChainParams& Params(const std::string& chain);
112112
*/
113113
void SelectParams(const std::string& chain);
114114

115+
/**
116+
* Allows modifying the BIP9 regtest parameters.
117+
*/
118+
void UpdateRegtestBIP9Parameters(Consensus::DeploymentPos d, int64_t nStartTime, int64_t nTimeout);
119+
115120
#endif // BITCOIN_CHAINPARAMS_H

src/init.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,7 @@ std::string HelpMessage(HelpMessageMode mode)
410410
strUsage += HelpMessageOpt("-limitancestorsize=<n>", strprintf("Do not accept transactions whose size with all in-mempool ancestors exceeds <n> kilobytes (default: %u)", DEFAULT_ANCESTOR_SIZE_LIMIT));
411411
strUsage += HelpMessageOpt("-limitdescendantcount=<n>", strprintf("Do not accept transactions if any ancestor would have <n> or more in-mempool descendants (default: %u)", DEFAULT_DESCENDANT_LIMIT));
412412
strUsage += HelpMessageOpt("-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));
413+
strUsage += HelpMessageOpt("-bip9params=deployment:start:end", "Use given start/end times for specified bip9 deployment (regtest-only)");
413414
}
414415
string debugCategories = "addrman, alert, bench, coindb, db, http, libevent, lock, mempool, mempoolrej, net, proxy, prune, rand, reindex, rpc, selectcoins, tor, zmq"; // Don't translate these and qt below
415416
if (mode == HMM_BITCOIN_QT)
@@ -975,6 +976,41 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
975976
fEnableReplacement = (std::find(vstrReplacementModes.begin(), vstrReplacementModes.end(), "fee") != vstrReplacementModes.end());
976977
}
977978

979+
if (!mapMultiArgs["-bip9params"].empty()) {
980+
// Allow overriding bip9 parameters for testing
981+
if (!Params().MineBlocksOnDemand()) {
982+
return InitError("BIP9 parameters may only be overridden on regtest.");
983+
}
984+
const vector<string>& deployments = mapMultiArgs["-bip9params"];
985+
for (auto i : deployments) {
986+
std::vector<std::string> vDeploymentParams;
987+
boost::split(vDeploymentParams, i, boost::is_any_of(":"));
988+
if (vDeploymentParams.size() != 3) {
989+
return InitError("BIP9 parameters malformed, expecting deployment:start:end");
990+
}
991+
int64_t nStartTime, nTimeout;
992+
if (!ParseInt64(vDeploymentParams[1], &nStartTime)) {
993+
return InitError(strprintf("Invalid nStartTime (%s)", vDeploymentParams[1]));
994+
}
995+
if (!ParseInt64(vDeploymentParams[2], &nTimeout)) {
996+
return InitError(strprintf("Invalid nTimeout (%s)", vDeploymentParams[2]));
997+
}
998+
bool found = false;
999+
for (int i=0; i<(int)Consensus::MAX_VERSION_BITS_DEPLOYMENTS; ++i)
1000+
{
1001+
if (vDeploymentParams[0].compare(VersionBitsDeploymentInfo[i].name) == 0) {
1002+
UpdateRegtestBIP9Parameters(Consensus::DeploymentPos(i), nStartTime, nTimeout);
1003+
found = true;
1004+
LogPrintf("Setting BIP9 activation parameters for %s to start=%ld, timeout=%ld\n", vDeploymentParams[0], nStartTime, nTimeout);
1005+
break;
1006+
}
1007+
}
1008+
if (!found) {
1009+
return InitError(strprintf("Invalid deployment (%s)", vDeploymentParams[0]));
1010+
}
1011+
}
1012+
}
1013+
9781014
// ********************************************************* Step 4: application initialization: dir lock, daemonize, pidfile, debug log
9791015

9801016
// Initialize elliptic curve code

0 commit comments

Comments
 (0)