Add regtest-only -nurejectoldversions option
This enables us to write RPC tests for network upgrades before they have been activated on testnet.
This commit is contained in:
parent
9b3a261831
commit
9ea5f6907f
|
@ -437,6 +437,7 @@ std::string HelpMessage(HelpMessageMode mode)
|
|||
strUsage += HelpMessageOpt("-fuzzmessagestest=<n>", "Randomly fuzz 1 of every <n> network messages");
|
||||
strUsage += HelpMessageOpt("-stopafterblockimport", strprintf("Stop running after importing blocks from disk (default: %u)", DEFAULT_STOPAFTERBLOCKIMPORT));
|
||||
strUsage += HelpMessageOpt("-nuparams=hexBranchId:activationHeight", "Use given activation height for specified network upgrade (regtest-only)");
|
||||
strUsage += HelpMessageOpt("-nurejectoldversions", strprintf("Reject peers that don't know about the current epoch (regtest-only) (default: %u)", DEFAULT_NU_REJECT_OLD_VERSIONS));
|
||||
}
|
||||
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
|
||||
|
@ -1083,6 +1084,12 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
|
|||
}
|
||||
}
|
||||
|
||||
if (mapArgs.count("-nurejectoldversions")) {
|
||||
if (Params().NetworkIDString() != "regtest") {
|
||||
return InitError("-nurejectoldversions may only be set on regtest.");
|
||||
}
|
||||
}
|
||||
|
||||
// ********************************************************* Step 4: application initialization: dir lock, daemonize, pidfile, debug log
|
||||
|
||||
// Initialize libsodium
|
||||
|
|
16
src/main.cpp
16
src/main.cpp
|
@ -5349,8 +5349,12 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
|
|||
// Reject incoming connections from nodes that don't know about the current epoch
|
||||
const Consensus::Params& consensusParams = chainparams.GetConsensus();
|
||||
auto currentEpoch = CurrentEpoch(GetHeight(), consensusParams);
|
||||
if (pfrom->nVersion < consensusParams.vUpgrades[currentEpoch].nProtocolVersion)
|
||||
{
|
||||
if (pfrom->nVersion < consensusParams.vUpgrades[currentEpoch].nProtocolVersion &&
|
||||
!(
|
||||
chainparams.NetworkIDString() == "regtest" &&
|
||||
!GetBoolArg("-nurejectoldversions", DEFAULT_NU_REJECT_OLD_VERSIONS)
|
||||
)
|
||||
) {
|
||||
LogPrintf("peer=%d using obsolete version %i; disconnecting\n", pfrom->id, pfrom->nVersion);
|
||||
pfrom->PushMessage("reject", strCommand, REJECT_OBSOLETE,
|
||||
strprintf("Version must be %d or greater",
|
||||
|
@ -5482,8 +5486,12 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
|
|||
// 1. The version message has been received
|
||||
// 2. Peer version is below the minimum version for the current epoch
|
||||
else if (pfrom->nVersion < chainparams.GetConsensus().vUpgrades[
|
||||
CurrentEpoch(GetHeight(), chainparams.GetConsensus())].nProtocolVersion)
|
||||
{
|
||||
CurrentEpoch(GetHeight(), chainparams.GetConsensus())].nProtocolVersion &&
|
||||
!(
|
||||
chainparams.NetworkIDString() == "regtest" &&
|
||||
!GetBoolArg("-nurejectoldversions", DEFAULT_NU_REJECT_OLD_VERSIONS)
|
||||
)
|
||||
) {
|
||||
LogPrintf("peer=%d using obsolete version %i; disconnecting\n", pfrom->id, pfrom->nVersion);
|
||||
pfrom->PushMessage("reject", strCommand, REJECT_OBSOLETE,
|
||||
strprintf("Version must be %d or greater",
|
||||
|
|
|
@ -111,6 +111,9 @@ static const bool DEFAULT_CHECKPOINTS_ENABLED = true;
|
|||
static const bool DEFAULT_TXINDEX = false;
|
||||
static const unsigned int DEFAULT_BANSCORE_THRESHOLD = 100;
|
||||
|
||||
/** Default for -nurejectoldversions */
|
||||
static const bool DEFAULT_NU_REJECT_OLD_VERSIONS = true;
|
||||
|
||||
#define equihash_parameters_acceptable(N, K) \
|
||||
((CBlockHeader::HEADER_SIZE + equihash_solution_size(N, K))*MAX_HEADERS_RESULTS < \
|
||||
MAX_PROTOCOL_MESSAGE_LENGTH-1000)
|
||||
|
|
|
@ -832,7 +832,12 @@ static bool AttemptToEvictConnection(bool fPreferNewConnection) {
|
|||
{
|
||||
// Find any nodes which don't support the protocol version for the next upgrade
|
||||
for (const CNodeRef &node : vEvictionCandidates) {
|
||||
if (node->nVersion < params.vUpgrades[idx].nProtocolVersion) {
|
||||
if (node->nVersion < params.vUpgrades[idx].nProtocolVersion &&
|
||||
!(
|
||||
Params().NetworkIDString() == "regtest" &&
|
||||
!GetBoolArg("-nurejectoldversions", DEFAULT_NU_REJECT_OLD_VERSIONS)
|
||||
)
|
||||
) {
|
||||
vTmpEvictionCandidates.push_back(node);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue