Allow changing network upgrade parameters on regtest
Derived from upstream commit 56c87e92110f05d7452f1e85bf755246ffc77206:
Allow changing BIP9 parameters on regtest
This commit is contained in:
@@ -402,6 +402,12 @@ public:
|
|||||||
vFoundersRewardAddress = { "t2FwcEhFdNXuFMv1tcYwaBJtYVtMj8b1uTg" };
|
vFoundersRewardAddress = { "t2FwcEhFdNXuFMv1tcYwaBJtYVtMj8b1uTg" };
|
||||||
assert(vFoundersRewardAddress.size() <= consensus.GetLastFoundersRewardBlockHeight());
|
assert(vFoundersRewardAddress.size() <= consensus.GetLastFoundersRewardBlockHeight());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UpdateNetworkUpgradeParameters(Consensus::UpgradeIndex idx, int nActivationHeight)
|
||||||
|
{
|
||||||
|
assert(idx > Consensus::BASE_SPROUT && idx < Consensus::MAX_NETWORK_UPGRADES);
|
||||||
|
consensus.vUpgrades[idx].nActivationHeight = nActivationHeight;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
static CRegTestParams regTestParams;
|
static CRegTestParams regTestParams;
|
||||||
|
|
||||||
@@ -475,3 +481,8 @@ std::string CChainParams::GetFoundersRewardAddressAtIndex(int i) const {
|
|||||||
assert(i >= 0 && i < vFoundersRewardAddress.size());
|
assert(i >= 0 && i < vFoundersRewardAddress.size());
|
||||||
return vFoundersRewardAddress[i];
|
return vFoundersRewardAddress[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UpdateNetworkUpgradeParameters(Consensus::UpgradeIndex idx, int nActivationHeight)
|
||||||
|
{
|
||||||
|
regTestParams.UpdateNetworkUpgradeParameters(idx, nActivationHeight);
|
||||||
|
}
|
||||||
|
|||||||
@@ -134,4 +134,9 @@ void SelectParams(CBaseChainParams::Network network);
|
|||||||
*/
|
*/
|
||||||
bool SelectParamsFromCommandLine();
|
bool SelectParamsFromCommandLine();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allows modifying the network upgrade regtest parameters.
|
||||||
|
*/
|
||||||
|
void UpdateNetworkUpgradeParameters(Consensus::UpgradeIndex idx, int nActivationHeight);
|
||||||
|
|
||||||
#endif // BITCOIN_CHAINPARAMS_H
|
#endif // BITCOIN_CHAINPARAMS_H
|
||||||
|
|||||||
36
src/init.cpp
36
src/init.cpp
@@ -16,6 +16,7 @@
|
|||||||
#endif
|
#endif
|
||||||
#include "checkpoints.h"
|
#include "checkpoints.h"
|
||||||
#include "compat/sanity.h"
|
#include "compat/sanity.h"
|
||||||
|
#include "consensus/upgrades.h"
|
||||||
#include "consensus/validation.h"
|
#include "consensus/validation.h"
|
||||||
#include "httpserver.h"
|
#include "httpserver.h"
|
||||||
#include "httprpc.h"
|
#include "httprpc.h"
|
||||||
@@ -44,8 +45,10 @@
|
|||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <boost/algorithm/string/classification.hpp>
|
||||||
#include <boost/algorithm/string/predicate.hpp>
|
#include <boost/algorithm/string/predicate.hpp>
|
||||||
#include <boost/algorithm/string/replace.hpp>
|
#include <boost/algorithm/string/replace.hpp>
|
||||||
|
#include <boost/algorithm/string/split.hpp>
|
||||||
#include <boost/bind.hpp>
|
#include <boost/bind.hpp>
|
||||||
#include <boost/filesystem.hpp>
|
#include <boost/filesystem.hpp>
|
||||||
#include <boost/function.hpp>
|
#include <boost/function.hpp>
|
||||||
@@ -448,6 +451,7 @@ std::string HelpMessage(HelpMessageMode mode)
|
|||||||
strUsage += HelpMessageOpt("-fuzzmessagestest=<n>", "Randomly fuzz 1 of every <n> network messages");
|
strUsage += HelpMessageOpt("-fuzzmessagestest=<n>", "Randomly fuzz 1 of every <n> network messages");
|
||||||
strUsage += HelpMessageOpt("-flushwallet", strprintf("Run a thread to flush wallet periodically (default: %u)", 1));
|
strUsage += HelpMessageOpt("-flushwallet", strprintf("Run a thread to flush wallet periodically (default: %u)", 1));
|
||||||
strUsage += HelpMessageOpt("-stopafterblockimport", strprintf("Stop running after importing blocks from disk (default: %u)", 0));
|
strUsage += HelpMessageOpt("-stopafterblockimport", strprintf("Stop running after importing blocks from disk (default: %u)", 0));
|
||||||
|
strUsage += HelpMessageOpt("-nuparams=hexBranchId:activationHeight", "Use given activation height for specified network upgrade (regtest-only)");
|
||||||
}
|
}
|
||||||
string debugCategories = "addrman, alert, bench, coindb, db, estimatefee, http, libevent, lock, mempool, net, partitioncheck, pow, proxy, prune, "
|
string debugCategories = "addrman, alert, bench, coindb, db, estimatefee, http, libevent, lock, mempool, net, partitioncheck, pow, proxy, prune, "
|
||||||
"rand, reindex, rpc, selectcoins, tor, zmq, zrpc, zrpcunsafe (implies zrpc)"; // Don't translate these
|
"rand, reindex, rpc, selectcoins, tor, zmq, zrpc, zrpcunsafe (implies zrpc)"; // Don't translate these
|
||||||
@@ -1035,6 +1039,38 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!mapMultiArgs["-nuparams"].empty()) {
|
||||||
|
// Allow overriding network upgrade parameters for testing
|
||||||
|
if (Params().NetworkIDString() != "regtest") {
|
||||||
|
return InitError("Network upgrade parameters may only be overridden on regtest.");
|
||||||
|
}
|
||||||
|
const vector<string>& deployments = mapMultiArgs["-nuparams"];
|
||||||
|
for (auto i : deployments) {
|
||||||
|
std::vector<std::string> vDeploymentParams;
|
||||||
|
boost::split(vDeploymentParams, i, boost::is_any_of(":"));
|
||||||
|
if (vDeploymentParams.size() != 2) {
|
||||||
|
return InitError("Network upgrade parameters malformed, expecting hexBranchId:activationHeight");
|
||||||
|
}
|
||||||
|
int nActivationHeight;
|
||||||
|
if (!ParseInt32(vDeploymentParams[1], &nActivationHeight)) {
|
||||||
|
return InitError(strprintf("Invalid nActivationHeight (%s)", vDeploymentParams[1]));
|
||||||
|
}
|
||||||
|
bool found = false;
|
||||||
|
// Exclude Sprout from upgrades
|
||||||
|
for (auto i = Consensus::BASE_SPROUT + 1; i < Consensus::MAX_NETWORK_UPGRADES; ++i)
|
||||||
|
{
|
||||||
|
if (vDeploymentParams[0].compare(HexInt(NetworkUpgradeInfo[i].nBranchId)) == 0) {
|
||||||
|
UpdateNetworkUpgradeParameters(Consensus::UpgradeIndex(i), nActivationHeight);
|
||||||
|
found = true;
|
||||||
|
LogPrintf("Setting network upgrade activation parameters for %s to height=%d\n", vDeploymentParams[0], nActivationHeight);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!found) {
|
||||||
|
return InitError(strprintf("Invalid network upgrade (%s)", vDeploymentParams[0]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ********************************************************* Step 4: application initialization: dir lock, daemonize, pidfile, debug log
|
// ********************************************************* Step 4: application initialization: dir lock, daemonize, pidfile, debug log
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <iomanip>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
@@ -46,6 +47,13 @@ string SanitizeFilename(const string& str)
|
|||||||
return strResult;
|
return strResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string HexInt(uint32_t val)
|
||||||
|
{
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << std::setfill('0') << std::setw(sizeof(uint32_t) * 2) << std::hex << val;
|
||||||
|
return ss.str();
|
||||||
|
}
|
||||||
|
|
||||||
const signed char p_util_hexdigit[256] =
|
const signed char p_util_hexdigit[256] =
|
||||||
{ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
|
{ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
|
||||||
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
|
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
|
||||||
|
|||||||
@@ -24,6 +24,7 @@
|
|||||||
|
|
||||||
std::string SanitizeFilename(const std::string& str);
|
std::string SanitizeFilename(const std::string& str);
|
||||||
std::string SanitizeString(const std::string& str);
|
std::string SanitizeString(const std::string& str);
|
||||||
|
std::string HexInt(uint32_t val);
|
||||||
std::vector<unsigned char> ParseHex(const char* psz);
|
std::vector<unsigned char> ParseHex(const char* psz);
|
||||||
std::vector<unsigned char> ParseHex(const std::string& str);
|
std::vector<unsigned char> ParseHex(const std::string& str);
|
||||||
signed char HexDigit(char c);
|
signed char HexDigit(char c);
|
||||||
|
|||||||
Reference in New Issue
Block a user