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,7 +81,7 @@ 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, + config, *m_connman, m_node.banman.get(), *m_node.scheduler, *m_node.chainman, *m_node.mempool); m_node.chain = interfaces::MakeChain(m_node, config.GetChainParams()); diff --git a/src/init.cpp b/src/init.cpp --- a/src/init.cpp +++ b/src/init.cpp @@ -2272,7 +2272,7 @@ ChainstateManager &chainman = *Assert(node.chainman); node.peer_logic.reset( - new PeerLogicValidation(*node.connman, node.banman.get(), + new PeerLogicValidation(config, *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,7 +36,7 @@ class PeerLogicValidation final : public CValidationInterface, public NetEventsInterface { public: - PeerLogicValidation(CConnman &connman, BanMan *banman, + PeerLogicValidation(const Config &config, CConnman &connman, BanMan *banman, CScheduler &scheduler, ChainstateManager &chainman, CTxMemPool &pool); @@ -111,9 +111,8 @@ EXCLUSIVE_LOCKS_REQUIRED(cs_main); /** Process a single message from a peer. Public for fuzz testing */ - void ProcessMessage(const Config &config, CNode &pfrom, - const std::string &msg_type, CDataStream &vRecv, - int64_t nTimeReceived, + void ProcessMessage(CNode &pfrom, const std::string &msg_type, + CDataStream &vRecv, int64_t nTimeReceived, const std::atomic &interruptMsgProc); private: @@ -127,6 +126,7 @@ */ bool MaybeDiscourageAndDisconnect(CNode &pnode); + const Config &m_config; 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 @@ -1402,12 +1402,13 @@ STALE_RELAY_AGE_LIMIT); } -PeerLogicValidation::PeerLogicValidation(CConnman &connman, BanMan *banman, +PeerLogicValidation::PeerLogicValidation(const Config &config, + 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_config(config), 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)); @@ -1422,7 +1423,8 @@ g_recent_confirmed_transactions.reset( new CRollingBloomFilter(24000, 0.000001)); - const Consensus::Params &consensusParams = Params().GetConsensus(); + const Consensus::Params &consensusParams = + m_config.GetChainParams().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) @@ -2574,10 +2576,9 @@ } void PeerLogicValidation::ProcessMessage( - const Config &config, CNode &pfrom, const std::string &msg_type, - CDataStream &vRecv, int64_t nTimeReceived, - const std::atomic &interruptMsgProc) { - const CChainParams &chainparams = config.GetChainParams(); + CNode &pfrom, const std::string &msg_type, CDataStream &vRecv, + int64_t nTimeReceived, const std::atomic &interruptMsgProc) { + const CChainParams &chainparams = m_config.GetChainParams(); LogPrint(BCLog::NET, "received: %s (%u bytes) peer=%d\n", SanitizeString(msg_type), vRecv.size(), pfrom.GetId()); if (gArgs.IsArgSet("-dropmessagestest") && @@ -2674,7 +2675,7 @@ // Be shy and don't send version until we hear if (pfrom.IsInboundConn()) { - PushNodeVersion(config, pfrom, m_connman, GetAdjustedTime()); + PushNodeVersion(m_config, pfrom, m_connman, GetAdjustedTime()); } m_connman.PushMessage( @@ -3023,7 +3024,7 @@ pfrom.vRecvGetData.insert(pfrom.vRecvGetData.end(), vInv.begin(), vInv.end()); - ProcessGetData(config, pfrom, m_connman, m_mempool, interruptMsgProc); + ProcessGetData(m_config, pfrom, m_connman, m_mempool, interruptMsgProc); return; } @@ -3054,7 +3055,7 @@ a_recent_block = most_recent_block; } BlockValidationState state; - if (!ActivateBestChain(config, state, a_recent_block)) { + if (!ActivateBestChain(m_config, state, a_recent_block)) { LogPrint(BCLog::NET, "failed to activate chain (%s)\n", state.ToString()); } @@ -3276,7 +3277,7 @@ EraseTxRequest(txid); if (!AlreadyHave(CInv(MSG_TX, txid), m_mempool) && - AcceptToMemoryPool(config, m_mempool, state, ptx, + AcceptToMemoryPool(m_config, m_mempool, state, ptx, false /* bypass_limits */, Amount::zero() /* nAbsurdFee */)) { m_mempool.check(&::ChainstateActive().CoinsTip()); @@ -3301,7 +3302,7 @@ // Recursively process any orphan transactions that depended on this // one - ProcessOrphanTx(config, m_connman, m_mempool, + ProcessOrphanTx(m_config, m_connman, m_mempool, pfrom.orphan_work_set); } else if (state.GetResult() == TxValidationResult::TX_MISSING_INPUTS) { // It may be the case that the orphans parents have all been @@ -3436,7 +3437,7 @@ const CBlockIndex *pindex = nullptr; BlockValidationState state; - if (!m_chainman.ProcessNewBlockHeaders(config, {cmpctblock.header}, + if (!m_chainman.ProcessNewBlockHeaders(m_config, {cmpctblock.header}, state, &pindex)) { if (state.IsInvalid()) { MaybePunishNodeForBlock(pfrom.GetId(), state, @@ -3522,14 +3523,14 @@ (fAlreadyInFlight && blockInFlightIt->second.first == pfrom.GetId())) { std::list::iterator *queuedBlockIt = nullptr; - if (!MarkBlockAsInFlight(config, m_mempool, pfrom.GetId(), + if (!MarkBlockAsInFlight(m_config, m_mempool, pfrom.GetId(), pindex->GetBlockHash(), chainparams.GetConsensus(), pindex, &queuedBlockIt)) { if (!(*queuedBlockIt)->partialBlock) { (*queuedBlockIt) ->partialBlock.reset( - new PartiallyDownloadedBlock(config, + new PartiallyDownloadedBlock(m_config, &m_mempool)); } else { // The block was already in flight using compact @@ -3583,7 +3584,7 @@ // peer, or this peer has too many blocks outstanding to // download from. Optimistically try to reconstruct anyway // since we might be able to without any round trips. - PartiallyDownloadedBlock tempBlock(config, &m_mempool); + PartiallyDownloadedBlock tempBlock(m_config, &m_mempool); ReadStatus status = tempBlock.InitData(cmpctblock, vExtraTxnForCompact); if (status != READ_STATUS_OK) { @@ -3615,8 +3616,8 @@ } // cs_main if (fProcessBLOCKTXN) { - return ProcessMessage(config, pfrom, NetMsgType::BLOCKTXN, - blockTxnMsg, nTimeReceived, interruptMsgProc); + return ProcessMessage(pfrom, NetMsgType::BLOCKTXN, blockTxnMsg, + nTimeReceived, interruptMsgProc); } if (fRevertToHeaderProcessing) { @@ -3625,7 +3626,7 @@ // disconnect the peer if the header turns out to be for an invalid // block. Note that if a peer tries to build on an invalid chain, // that will be detected and the peer will be banned. - return ProcessHeadersMessage(config, pfrom, m_connman, m_mempool, + return ProcessHeadersMessage(m_config, pfrom, m_connman, m_mempool, m_chainman, {cmpctblock.header}, /*via_compact_block=*/true); } @@ -3648,7 +3649,7 @@ // we have a chain with at least nMinimumChainWork), and we ignore // compact blocks with less work than our tip, it is safe to treat // reconstructed compact blocks as having been requested. - m_chainman.ProcessNewBlock(config, pblock, + m_chainman.ProcessNewBlock(m_config, pblock, /*fForceProcessing=*/true, &fNewBlock); if (fNewBlock) { pfrom.nLastBlockTime = GetTime(); @@ -3757,7 +3758,7 @@ // disk-space attacks), but this should be safe due to the // protections in the compact block handler -- see related comment // in compact block optimistic reconstruction handling. - m_chainman.ProcessNewBlock(config, pblock, + m_chainman.ProcessNewBlock(m_config, pblock, /*fForceProcessing=*/true, &fNewBlock); if (fNewBlock) { pfrom.nLastBlockTime = GetTime(); @@ -3796,7 +3797,7 @@ ReadCompactSize(vRecv); } - return ProcessHeadersMessage(config, pfrom, m_connman, m_mempool, + return ProcessHeadersMessage(m_config, pfrom, m_connman, m_mempool, m_chainman, headers, /*via_compact_block=*/false); } @@ -3834,7 +3835,8 @@ mapBlockSource.emplace(hash, std::make_pair(pfrom.GetId(), true)); } bool fNewBlock = false; - m_chainman.ProcessNewBlock(config, pblock, forceProcessing, &fNewBlock); + m_chainman.ProcessNewBlock(m_config, pblock, forceProcessing, + &fNewBlock); if (fNewBlock) { pfrom.nLastBlockTime = GetTime(); } else { @@ -4011,7 +4013,7 @@ LogPrintf("Avalanche rejected %s, parking\n", pindex->GetBlockHash().GetHex()); BlockValidationState state; - ::ChainstateActive().ParkBlock(config, state, pindex); + ::ChainstateActive().ParkBlock(m_config, state, pindex); if (!state.IsValid()) { LogPrintf("ERROR: Database error: %s\n", state.GetRejectReason()); @@ -4029,7 +4031,7 @@ } BlockValidationState state; - if (!ActivateBestChain(config, state)) { + if (!ActivateBestChain(m_config, state)) { LogPrint(BCLog::NET, "failed to activate chain (%s)\n", state.ToString()); } @@ -4464,8 +4466,7 @@ } try { - ProcessMessage(config, *pfrom, msg_type, vRecv, msg.m_time, - interruptMsgProc); + ProcessMessage(*pfrom, msg_type, vRecv, msg.m_time, interruptMsgProc); if (interruptMsgProc) { return false; } 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,7 +79,7 @@ auto connman = std::make_unique(config, 0x1337, 0x1337); auto peerLogic = std::make_unique( - *connman, nullptr, *m_node.scheduler, *m_node.chainman, + config, *connman, nullptr, *m_node.scheduler, *m_node.chainman, *m_node.mempool); // Mock an outbound peer @@ -163,7 +163,7 @@ auto connman = std::make_unique(config, 0x1337, 0x1337); auto peerLogic = std::make_unique( - *connman, nullptr, *m_node.scheduler, *m_node.chainman, + config, *connman, nullptr, *m_node.scheduler, *m_node.chainman, *m_node.mempool); const Consensus::Params &consensusParams = @@ -243,7 +243,7 @@ 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, + config, *connman, banman.get(), *m_node.scheduler, *m_node.chainman, *m_node.mempool); banman->ClearBanned(); @@ -306,7 +306,7 @@ 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, + config, *connman, banman.get(), *m_node.scheduler, *m_node.chainman, *m_node.mempool); banman->ClearBanned(); diff --git a/src/test/fuzz/process_message.cpp b/src/test/fuzz/process_message.cpp --- a/src/test/fuzz/process_message.cpp +++ b/src/test/fuzz/process_message.cpp @@ -114,7 +114,7 @@ g_setup->m_node.peer_logic->InitializeNode(config, &p2p_node); try { g_setup->m_node.peer_logic->ProcessMessage( - config, p2p_node, random_message_type, random_bytes_data_stream, + p2p_node, random_message_type, random_bytes_data_stream, GetTimeMillis(), std::atomic{false}); } catch (const std::ios_base::failure &e) { const std::string exception_message{e.what()}; 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, + config, *m_node.connman, m_node.banman.get(), *m_node.scheduler, *m_node.chainman, *m_node.mempool); { CConnman::Options options;