Skip to content

Commit d440848

Browse files
committed
net_processing: simplify PeerManageImpl method args
No need to pass mempool to MarkBlockAsInFlight, or consensusParams to TipMayBeStale or FindNextBlocksToDownload.
1 parent a490f0a commit d440848

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

src/net_processing.cpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -427,14 +427,14 @@ class PeerManagerImpl final : public PeerManager
427427
* Returns false, still setting pit, if the block was already in flight from the same peer
428428
* pit will only be valid as long as the same cs_main lock is being held
429429
*/
430-
bool MarkBlockAsInFlight(CTxMemPool& mempool, NodeId nodeid, const uint256& hash, const CBlockIndex* pindex = nullptr, std::list<QueuedBlock>::iterator** pit = nullptr) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
430+
bool MarkBlockAsInFlight(NodeId nodeid, const uint256& hash, const CBlockIndex* pindex = nullptr, std::list<QueuedBlock>::iterator** pit = nullptr) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
431431

432-
bool TipMayBeStale(const Consensus::Params &consensusParams) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
432+
bool TipMayBeStale() EXCLUSIVE_LOCKS_REQUIRED(cs_main);
433433

434434
/** Update pindexLastCommonBlock and add not-in-flight missing successors to vBlocks, until it has
435435
* at most count entries.
436436
*/
437-
void FindNextBlocksToDownload(NodeId nodeid, unsigned int count, std::vector<const CBlockIndex*>& vBlocks, NodeId& nodeStaller, const Consensus::Params& consensusParams) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
437+
void FindNextBlocksToDownload(NodeId nodeid, unsigned int count, std::vector<const CBlockIndex*>& vBlocks, NodeId& nodeStaller) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
438438

439439
std::map<uint256, std::pair<NodeId, std::list<QueuedBlock>::iterator> > mapBlocksInFlight GUARDED_BY(cs_main);
440440

@@ -655,7 +655,7 @@ bool PeerManagerImpl::MarkBlockAsReceived(const uint256& hash) EXCLUSIVE_LOCKS_R
655655
return false;
656656
}
657657

658-
bool PeerManagerImpl::MarkBlockAsInFlight(CTxMemPool& mempool, NodeId nodeid, const uint256& hash, const CBlockIndex* pindex, std::list<QueuedBlock>::iterator** pit) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
658+
bool PeerManagerImpl::MarkBlockAsInFlight(NodeId nodeid, const uint256& hash, const CBlockIndex* pindex, std::list<QueuedBlock>::iterator** pit) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
659659
{
660660
CNodeState *state = State(nodeid);
661661
assert(state != nullptr);
@@ -673,7 +673,7 @@ bool PeerManagerImpl::MarkBlockAsInFlight(CTxMemPool& mempool, NodeId nodeid, co
673673
MarkBlockAsReceived(hash);
674674

675675
std::list<QueuedBlock>::iterator it = state->vBlocksInFlight.insert(state->vBlocksInFlight.end(),
676-
{hash, pindex, pindex != nullptr, std::unique_ptr<PartiallyDownloadedBlock>(pit ? new PartiallyDownloadedBlock(&mempool) : nullptr)});
676+
{hash, pindex, pindex != nullptr, std::unique_ptr<PartiallyDownloadedBlock>(pit ? new PartiallyDownloadedBlock(&m_mempool) : nullptr)});
677677
state->nBlocksInFlight++;
678678
state->nBlocksInFlightValidHeaders += it->fValidatedHeaders;
679679
if (state->nBlocksInFlight == 1) {
@@ -769,9 +769,10 @@ static void MaybeSetPeerAsAnnouncingHeaderAndIDs(NodeId nodeid, CConnman& connma
769769
}
770770
}
771771

772-
bool PeerManagerImpl::TipMayBeStale(const Consensus::Params &consensusParams) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
772+
bool PeerManagerImpl::TipMayBeStale() EXCLUSIVE_LOCKS_REQUIRED(cs_main)
773773
{
774774
AssertLockHeld(cs_main);
775+
const Consensus::Params& consensusParams = m_chainparams.GetConsensus();
775776
if (m_last_tip_update == 0) {
776777
m_last_tip_update = GetTime();
777778
}
@@ -792,7 +793,7 @@ static bool PeerHasHeader(CNodeState *state, const CBlockIndex *pindex) EXCLUSIV
792793
return false;
793794
}
794795

795-
void PeerManagerImpl::FindNextBlocksToDownload(NodeId nodeid, unsigned int count, std::vector<const CBlockIndex*>& vBlocks, NodeId& nodeStaller, const Consensus::Params& consensusParams) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
796+
void PeerManagerImpl::FindNextBlocksToDownload(NodeId nodeid, unsigned int count, std::vector<const CBlockIndex*>& vBlocks, NodeId& nodeStaller) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
796797
{
797798
if (count == 0)
798799
return;
@@ -821,6 +822,7 @@ void PeerManagerImpl::FindNextBlocksToDownload(NodeId nodeid, unsigned int count
821822
if (state->pindexLastCommonBlock == state->pindexBestKnownBlock)
822823
return;
823824

825+
const Consensus::Params& consensusParams = m_chainparams.GetConsensus();
824826
std::vector<const CBlockIndex*> vToFetch;
825827
const CBlockIndex *pindexWalk = state->pindexLastCommonBlock;
826828
// Never fetch further than the best block we know the peer has, or more than BLOCK_DOWNLOAD_WINDOW + 1 beyond the last
@@ -2119,7 +2121,7 @@ void PeerManagerImpl::ProcessHeadersMessage(CNode& pfrom, const Peer& peer,
21192121
}
21202122
uint32_t nFetchFlags = GetFetchFlags(pfrom);
21212123
vGetData.push_back(CInv(MSG_BLOCK | nFetchFlags, pindex->GetBlockHash()));
2122-
MarkBlockAsInFlight(m_mempool, pfrom.GetId(), pindex->GetBlockHash(), pindex);
2124+
MarkBlockAsInFlight(pfrom.GetId(), pindex->GetBlockHash(), pindex);
21232125
LogPrint(BCLog::NET, "Requesting block %s from peer=%d\n",
21242126
pindex->GetBlockHash().ToString(), pfrom.GetId());
21252127
}
@@ -3468,7 +3470,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
34683470
if ((!fAlreadyInFlight && nodestate->nBlocksInFlight < MAX_BLOCKS_IN_TRANSIT_PER_PEER) ||
34693471
(fAlreadyInFlight && blockInFlightIt->second.first == pfrom.GetId())) {
34703472
std::list<QueuedBlock>::iterator* queuedBlockIt = nullptr;
3471-
if (!MarkBlockAsInFlight(m_mempool, pfrom.GetId(), pindex->GetBlockHash(), pindex, &queuedBlockIt)) {
3473+
if (!MarkBlockAsInFlight(pfrom.GetId(), pindex->GetBlockHash(), pindex, &queuedBlockIt)) {
34723474
if (!(*queuedBlockIt)->partialBlock)
34733475
(*queuedBlockIt)->partialBlock.reset(new PartiallyDownloadedBlock(&m_mempool));
34743476
else {
@@ -4265,7 +4267,7 @@ void PeerManagerImpl::CheckForStaleTipAndEvictPeers()
42654267
if (time_in_seconds > m_stale_tip_check_time) {
42664268
// Check whether our tip is stale, and if so, allow using an extra
42674269
// outbound peer
4268-
if (!fImporting && !fReindex && m_connman.GetNetworkActive() && m_connman.GetUseAddrmanOutgoing() && TipMayBeStale(m_chainparams.GetConsensus())) {
4270+
if (!fImporting && !fReindex && m_connman.GetNetworkActive() && m_connman.GetUseAddrmanOutgoing() && TipMayBeStale()) {
42694271
LogPrintf("Potential stale tip detected, will try using extra outbound peer (last tip update: %d seconds ago)\n", time_in_seconds - m_last_tip_update);
42704272
m_connman.SetTryNewOutboundPeer(true);
42714273
} else if (m_connman.GetTryNewOutboundPeer()) {
@@ -4793,11 +4795,11 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
47934795
if (!pto->fClient && ((fFetch && !pto->m_limited_node) || !::ChainstateActive().IsInitialBlockDownload()) && state.nBlocksInFlight < MAX_BLOCKS_IN_TRANSIT_PER_PEER) {
47944796
std::vector<const CBlockIndex*> vToDownload;
47954797
NodeId staller = -1;
4796-
FindNextBlocksToDownload(pto->GetId(), MAX_BLOCKS_IN_TRANSIT_PER_PEER - state.nBlocksInFlight, vToDownload, staller, consensusParams);
4798+
FindNextBlocksToDownload(pto->GetId(), MAX_BLOCKS_IN_TRANSIT_PER_PEER - state.nBlocksInFlight, vToDownload, staller);
47974799
for (const CBlockIndex *pindex : vToDownload) {
47984800
uint32_t nFetchFlags = GetFetchFlags(*pto);
47994801
vGetData.push_back(CInv(MSG_BLOCK | nFetchFlags, pindex->GetBlockHash()));
4800-
MarkBlockAsInFlight(m_mempool, pto->GetId(), pindex->GetBlockHash(), pindex);
4802+
MarkBlockAsInFlight(pto->GetId(), pindex->GetBlockHash(), pindex);
48014803
LogPrint(BCLog::NET, "Requesting block %s (%d) peer=%d\n", pindex->GetBlockHash().ToString(),
48024804
pindex->nHeight, pto->GetId());
48034805
}

0 commit comments

Comments
 (0)