diff --git a/src/init.cpp b/src/init.cpp index a8439836f..3692d5f42 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -437,6 +437,7 @@ std::string HelpMessage(HelpMessageMode mode) strUsage += HelpMessageOpt("-fuzzmessagestest=", "Randomly fuzz 1 of every 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 diff --git a/src/main.cpp b/src/main.cpp index fd943a923..dc08483a6 100644 --- a/src/main.cpp +++ b/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", diff --git a/src/main.h b/src/main.h index 6bdb06d43..149175a8e 100644 --- a/src/main.h +++ b/src/main.h @@ -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) diff --git a/src/net.cpp b/src/net.cpp index 18ab53fb8..318cc4059 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -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); } }