Skip to content

Commit 85e058b

Browse files
committed
[net processing] Remove unnecessary hash arg from MarkBlockAsInFlight()
MarkBlockAsInFlight is always called with a non-null pindex. Just get the block hash from that pindex inside the function.
1 parent a9435e3 commit 85e058b

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/net_processing.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ class PeerManagerImpl final : public PeerManager
472472
* Returns false, still setting pit, if the block was already in flight from the same peer
473473
* pit will only be valid as long as the same cs_main lock is being held
474474
*/
475-
bool MarkBlockAsInFlight(NodeId nodeid, const uint256& hash, const CBlockIndex* pindex = nullptr, std::list<QueuedBlock>::iterator** pit = nullptr) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
475+
bool MarkBlockAsInFlight(NodeId nodeid, const CBlockIndex* pindex, std::list<QueuedBlock>::iterator** pit = nullptr) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
476476

477477
bool TipMayBeStale() EXCLUSIVE_LOCKS_REQUIRED(cs_main);
478478

@@ -782,8 +782,11 @@ bool PeerManagerImpl::MarkBlockAsReceived(const uint256& hash)
782782
return false;
783783
}
784784

785-
bool PeerManagerImpl::MarkBlockAsInFlight(NodeId nodeid, const uint256& hash, const CBlockIndex* pindex, std::list<QueuedBlock>::iterator** pit)
785+
bool PeerManagerImpl::MarkBlockAsInFlight(NodeId nodeid, const CBlockIndex* pindex, std::list<QueuedBlock>::iterator** pit)
786786
{
787+
assert(pindex);
788+
const uint256& hash{pindex->GetBlockHash()};
789+
787790
CNodeState *state = State(nodeid);
788791
assert(state != nullptr);
789792

@@ -807,7 +810,7 @@ bool PeerManagerImpl::MarkBlockAsInFlight(NodeId nodeid, const uint256& hash, co
807810
// We're starting a block download (batch) from this peer.
808811
state->m_downloading_since = GetTime<std::chrono::microseconds>();
809812
}
810-
if (state->nBlocksInFlightValidHeaders == 1 && pindex != nullptr) {
813+
if (state->nBlocksInFlightValidHeaders == 1) {
811814
nPeersWithValidatedDownloads++;
812815
}
813816
itInFlight = mapBlocksInFlight.insert(std::make_pair(hash, std::make_pair(nodeid, it))).first;
@@ -2081,7 +2084,7 @@ void PeerManagerImpl::ProcessHeadersMessage(CNode& pfrom, const Peer& peer,
20812084
}
20822085
uint32_t nFetchFlags = GetFetchFlags(pfrom);
20832086
vGetData.push_back(CInv(MSG_BLOCK | nFetchFlags, pindex->GetBlockHash()));
2084-
MarkBlockAsInFlight(pfrom.GetId(), pindex->GetBlockHash(), pindex);
2087+
MarkBlockAsInFlight(pfrom.GetId(), pindex);
20852088
LogPrint(BCLog::NET, "Requesting block %s from peer=%d\n",
20862089
pindex->GetBlockHash().ToString(), pfrom.GetId());
20872090
}
@@ -3384,7 +3387,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
33843387
if ((!fAlreadyInFlight && nodestate->nBlocksInFlight < MAX_BLOCKS_IN_TRANSIT_PER_PEER) ||
33853388
(fAlreadyInFlight && blockInFlightIt->second.first == pfrom.GetId())) {
33863389
std::list<QueuedBlock>::iterator* queuedBlockIt = nullptr;
3387-
if (!MarkBlockAsInFlight(pfrom.GetId(), pindex->GetBlockHash(), pindex, &queuedBlockIt)) {
3390+
if (!MarkBlockAsInFlight(pfrom.GetId(), pindex, &queuedBlockIt)) {
33883391
if (!(*queuedBlockIt)->partialBlock)
33893392
(*queuedBlockIt)->partialBlock.reset(new PartiallyDownloadedBlock(&m_mempool));
33903393
else {
@@ -4767,7 +4770,7 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
47674770
for (const CBlockIndex *pindex : vToDownload) {
47684771
uint32_t nFetchFlags = GetFetchFlags(*pto);
47694772
vGetData.push_back(CInv(MSG_BLOCK | nFetchFlags, pindex->GetBlockHash()));
4770-
MarkBlockAsInFlight(pto->GetId(), pindex->GetBlockHash(), pindex);
4773+
MarkBlockAsInFlight(pto->GetId(), pindex);
47714774
LogPrint(BCLog::NET, "Requesting block %s (%d) peer=%d\n", pindex->GetBlockHash().ToString(),
47724775
pindex->nHeight, pto->GetId());
47734776
}

0 commit comments

Comments
 (0)