diff --git a/src/net_processing.h b/src/net_processing.h --- a/src/net_processing.h +++ b/src/net_processing.h @@ -110,8 +110,7 @@ * Evict extra outbound peers. If we think our tip may be stale, connect to * an extra outbound. */ - void - CheckForStaleTipAndEvictPeers(const Consensus::Params &consensusParams); + void CheckForStaleTipAndEvictPeers(); /** * If we have extra outbound peers, try to disconnect the one with the * oldest block announcement. diff --git a/src/net_processing.cpp b/src/net_processing.cpp --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -1528,7 +1528,6 @@ g_recent_confirmed_transactions.reset( new CRollingBloomFilter(24000, 0.000001)); - 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) @@ -1537,8 +1536,8 @@ EXTRA_PEER_CHECK_INTERVAL < STALE_CHECK_INTERVAL, "peer eviction timer should be less than stale tip check timer"); scheduler.scheduleEvery( - [this, &consensusParams]() { - this->CheckForStaleTipAndEvictPeers(consensusParams); + [this]() { + this->CheckForStaleTipAndEvictPeers(); return true; }, std::chrono::seconds{EXTRA_PEER_CHECK_INTERVAL}); @@ -5099,8 +5098,7 @@ } } -void PeerManager::CheckForStaleTipAndEvictPeers( - const Consensus::Params &consensusParams) { +void PeerManager::CheckForStaleTipAndEvictPeers() { LOCK(cs_main); int64_t time_in_seconds = GetTime(); @@ -5114,7 +5112,8 @@ // Check whether our tip is stale, and if so, allow using an extra outbound // peer. if (!fImporting && !fReindex && m_connman.GetNetworkActive() && - m_connman.GetUseAddrmanOutgoing() && TipMayBeStale(consensusParams)) { + m_connman.GetUseAddrmanOutgoing() && + TipMayBeStale(m_chainparams.GetConsensus())) { LogPrintf("Potential stale tip detected, will try using extra outbound " "peer (last tip update: %d seconds ago)\n", time_in_seconds - g_last_tip_update); @@ -5144,8 +5143,7 @@ bool PeerManager::SendMessages(const Config &config, CNode *pto, std::atomic &interruptMsgProc) { - const Consensus::Params &consensusParams = - config.GetChainParams().GetConsensus(); + const Consensus::Params &consensusParams = m_chainparams.GetConsensus(); // We must call MaybeDiscourageAndDisconnect first, to ensure that we'll // disconnect misbehaving peers even before the version handshake is 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 @@ -183,7 +183,7 @@ AddRandomOutboundPeer(config, vNodes, *peerLogic, connman.get()); } - peerLogic->CheckForStaleTipAndEvictPeers(consensusParams); + peerLogic->CheckForStaleTipAndEvictPeers(); // No nodes should be marked for disconnection while we have no extra peers for (const CNode *node : vNodes) { @@ -194,7 +194,7 @@ // Now tip should definitely be stale, and we should look for an extra // outbound peer - peerLogic->CheckForStaleTipAndEvictPeers(consensusParams); + peerLogic->CheckForStaleTipAndEvictPeers(); BOOST_CHECK(connman->GetTryNewOutboundPeer()); // Still no peers should be marked for disconnection @@ -207,7 +207,7 @@ // required time connected check should be satisfied). AddRandomOutboundPeer(config, vNodes, *peerLogic, connman.get()); - peerLogic->CheckForStaleTipAndEvictPeers(consensusParams); + peerLogic->CheckForStaleTipAndEvictPeers(); for (int i = 0; i < max_outbound_full_relay; ++i) { BOOST_CHECK(vNodes[i]->fDisconnect == false); } @@ -220,7 +220,7 @@ // peer, and check that the next newest node gets evicted. UpdateLastBlockAnnounceTime(vNodes.back()->GetId(), GetTime()); - peerLogic->CheckForStaleTipAndEvictPeers(consensusParams); + peerLogic->CheckForStaleTipAndEvictPeers(); for (int i = 0; i < max_outbound_full_relay - 1; ++i) { BOOST_CHECK(vNodes[i]->fDisconnect == false); }