diff --git a/src/avalanche/test/processor_tests.cpp b/src/avalanche/test/processor_tests.cpp --- a/src/avalanche/test/processor_tests.cpp +++ b/src/avalanche/test/processor_tests.cpp @@ -81,8 +81,8 @@ m_connman = connman.get(); m_node.connman = std::move(connman); m_node.peer_logic = std::make_unique( - *m_connman, m_node.banman.get(), *m_node.scheduler, - *m_node.chainman, *m_node.mempool); + config.GetChainParams(), *m_connman, m_node.banman.get(), + *m_node.scheduler, *m_node.chainman, *m_node.mempool); m_node.chain = interfaces::MakeChain(m_node, config.GetChainParams()); // Get the processor ready. diff --git a/src/init.cpp b/src/init.cpp --- a/src/init.cpp +++ b/src/init.cpp @@ -2271,7 +2271,7 @@ ChainstateManager &chainman = *Assert(node.chainman); node.peer_logic.reset( - new PeerLogicValidation(*node.connman, node.banman.get(), + new PeerLogicValidation(chainparams, *node.connman, node.banman.get(), *node.scheduler, chainman, *node.mempool)); RegisterValidationInterface(node.peer_logic.get()); diff --git a/src/net_processing.h b/src/net_processing.h --- a/src/net_processing.h +++ b/src/net_processing.h @@ -36,9 +36,9 @@ class PeerLogicValidation final : public CValidationInterface, public NetEventsInterface { public: - PeerLogicValidation(CConnman &connman, BanMan *banman, - CScheduler &scheduler, ChainstateManager &chainman, - CTxMemPool &pool); + PeerLogicValidation(const CChainParams &chainparams, CConnman &connman, + BanMan *banman, CScheduler &scheduler, + ChainstateManager &chainman, CTxMemPool &pool); /** * Overridden from CValidationInterface. @@ -133,6 +133,7 @@ */ bool MaybeDiscourageAndDisconnect(CNode &pnode); + const CChainParams &m_chainparams; CConnman &m_connman; /** * Pointer to this node's banman. May be nullptr - check existence before diff --git a/src/net_processing.cpp b/src/net_processing.cpp --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -1487,12 +1487,13 @@ STALE_RELAY_AGE_LIMIT); } -PeerLogicValidation::PeerLogicValidation(CConnman &connman, BanMan *banman, +PeerLogicValidation::PeerLogicValidation(const CChainParams &chainparams, + CConnman &connman, BanMan *banman, CScheduler &scheduler, ChainstateManager &chainman, CTxMemPool &pool) - : m_connman(connman), m_banman(banman), m_chainman(chainman), - m_mempool(pool), m_stale_tip_check_time(0) { + : m_chainparams(chainparams), m_connman(connman), m_banman(banman), + m_chainman(chainman), m_mempool(pool), m_stale_tip_check_time(0) { // Initialize global variables that cannot be constructed at startup. recentRejects.reset(new CRollingBloomFilter(120000, 0.000001)); @@ -1507,7 +1508,7 @@ g_recent_confirmed_transactions.reset( new CRollingBloomFilter(24000, 0.000001)); - const Consensus::Params &consensusParams = Params().GetConsensus(); + const Consensus::Params &consensusParams = chainparams.GetConsensus(); // Stale tip checking and peer eviction are on two different timers, but we // don't want them to get out of sync due to drift in the scheduler, so we // combine them in one function and schedule at the quicker (peer-eviction) @@ -2674,7 +2675,6 @@ const Config &config, CNode &pfrom, const std::string &msg_type, CDataStream &vRecv, int64_t nTimeReceived, const std::atomic &interruptMsgProc) { - const CChainParams &chainparams = config.GetChainParams(); LogPrint(BCLog::NET, "received: %s (%u bytes) peer=%d\n", SanitizeString(msg_type), vRecv.size(), pfrom.GetId()); if (gArgs.IsArgSet("-dropmessagestest") && @@ -2855,7 +2855,7 @@ // Ignore time offsets that are improbable (before the Genesis block) // and may underflow the nTimeOffset calculation. int64_t currentTime = GetTime(); - if (nTime >= int64_t(chainparams.GenesisBlock().nTime)) { + if (nTime >= int64_t(m_chainparams.GenesisBlock().nTime)) { int64_t nTimeOffset = nTime - currentTime; pfrom.nTimeOffset = nTimeOffset; AddTimeData(pfrom.addr, nTimeOffset); @@ -3183,7 +3183,7 @@ // that block relay might require. const int nPrunedBlocksLikelyToHave = MIN_BLOCKS_TO_KEEP - - 3600 / chainparams.GetConsensus().nPowTargetSpacing; + 3600 / m_chainparams.GetConsensus().nPowTargetSpacing; if (fPruneMode && (!pindex->nStatus.hasData() || pindex->nHeight <= ::ChainActive().Tip()->nHeight - @@ -3256,7 +3256,8 @@ } CBlock block; - bool ret = ReadBlockFromDisk(block, pindex, chainparams.GetConsensus()); + bool ret = + ReadBlockFromDisk(block, pindex, m_chainparams.GetConsensus()); assert(ret); SendBlockTransactions(block, req, pfrom, m_connman); @@ -3295,7 +3296,7 @@ return; } - if (!BlockRequestAllowed(pindex, chainparams.GetConsensus())) { + if (!BlockRequestAllowed(pindex, m_chainparams.GetConsensus())) { LogPrint(BCLog::NET, "%s: ignoring request from peer=%i for old block " "header that isn't in the main chain\n", @@ -3607,7 +3608,7 @@ // If we're not close to tip yet, give up and let parallel block // fetch work its magic. if (!fAlreadyInFlight && - !CanDirectFetch(chainparams.GetConsensus())) { + !CanDirectFetch(m_chainparams.GetConsensus())) { return; } @@ -3621,8 +3622,8 @@ std::list::iterator *queuedBlockIt = nullptr; if (!MarkBlockAsInFlight(config, m_mempool, pfrom.GetId(), pindex->GetBlockHash(), - chainparams.GetConsensus(), pindex, - &queuedBlockIt)) { + m_chainparams.GetConsensus(), + pindex, &queuedBlockIt)) { if (!(*queuedBlockIt)->partialBlock) { (*queuedBlockIt) ->partialBlock.reset( @@ -4363,17 +4364,17 @@ } if (msg_type == NetMsgType::GETCFILTERS) { - ProcessGetCFilters(pfrom, vRecv, chainparams, m_connman); + ProcessGetCFilters(pfrom, vRecv, m_chainparams, m_connman); return; } if (msg_type == NetMsgType::GETCFHEADERS) { - ProcessGetCFHeaders(pfrom, vRecv, chainparams, m_connman); + ProcessGetCFHeaders(pfrom, vRecv, m_chainparams, m_connman); return; } if (msg_type == NetMsgType::GETCFCHECKPT) { - ProcessGetCFCheckPt(pfrom, vRecv, chainparams, m_connman); + ProcessGetCFCheckPt(pfrom, vRecv, m_chainparams, m_connman); return; } diff --git a/src/test/denialofservice_tests.cpp b/src/test/denialofservice_tests.cpp --- a/src/test/denialofservice_tests.cpp +++ b/src/test/denialofservice_tests.cpp @@ -79,8 +79,8 @@ auto connman = std::make_unique(config, 0x1337, 0x1337); auto peerLogic = std::make_unique( - *connman, nullptr, *m_node.scheduler, *m_node.chainman, - *m_node.mempool); + config.GetChainParams(), *connman, nullptr, *m_node.scheduler, + *m_node.chainman, *m_node.mempool); // Mock an outbound peer CAddress addr1(ip(0xa0b0c001), NODE_NONE); @@ -163,8 +163,8 @@ auto connman = std::make_unique(config, 0x1337, 0x1337); auto peerLogic = std::make_unique( - *connman, nullptr, *m_node.scheduler, *m_node.chainman, - *m_node.mempool); + config.GetChainParams(), *connman, nullptr, *m_node.scheduler, + *m_node.chainman, *m_node.mempool); const Consensus::Params &consensusParams = config.GetChainParams().GetConsensus(); @@ -243,8 +243,8 @@ DEFAULT_MISBEHAVING_BANTIME); auto connman = std::make_unique(config, 0x1337, 0x1337); auto peerLogic = std::make_unique( - *connman, banman.get(), *m_node.scheduler, *m_node.chainman, - *m_node.mempool); + config.GetChainParams(), *connman, banman.get(), *m_node.scheduler, + *m_node.chainman, *m_node.mempool); banman->ClearBanned(); CAddress addr1(ip(0xa0b0c001), NODE_NONE); @@ -306,8 +306,8 @@ DEFAULT_MISBEHAVING_BANTIME); auto connman = std::make_unique(config, 0x1337, 0x1337); auto peerLogic = std::make_unique( - *connman, banman.get(), *m_node.scheduler, *m_node.chainman, - *m_node.mempool); + config.GetChainParams(), *connman, banman.get(), *m_node.scheduler, + *m_node.chainman, *m_node.mempool); banman->ClearBanned(); int64_t nStartTime = GetTime(); diff --git a/src/test/util/setup_common.cpp b/src/test/util/setup_common.cpp --- a/src/test/util/setup_common.cpp +++ b/src/test/util/setup_common.cpp @@ -205,7 +205,7 @@ // Deterministic randomness for tests. m_node.connman = std::make_unique(config, 0x1337, 0x1337); m_node.peer_logic = std::make_unique( - *m_node.connman, m_node.banman.get(), *m_node.scheduler, + chainparams, *m_node.connman, m_node.banman.get(), *m_node.scheduler, *m_node.chainman, *m_node.mempool); { CConnman::Options options;