aboutsummaryrefslogtreecommitdiff
path: root/src/net_processing.cpp
diff options
context:
space:
mode:
authorJohn Newbery <john@johnnewbery.com>2021-06-03 13:55:31 +0100
committerJohn Newbery <john@johnnewbery.com>2021-06-03 14:57:37 +0100
commit2c45f832e87acd11fbd144cc0bb8e49816933c70 (patch)
tree9051ef2803bea2418df97339d8910053ac018750 /src/net_processing.cpp
parent62993507336be06490b202b3955d4830a99e9e34 (diff)
downloadbitcoin-2c45f832e87acd11fbd144cc0bb8e49816933c70.tar.xz
[net processing] Tidy up MarkBlockAsReceived()
Diffstat (limited to 'src/net_processing.cpp')
-rw-r--r--src/net_processing.cpp38
1 files changed, 22 insertions, 16 deletions
diff --git a/src/net_processing.cpp b/src/net_processing.cpp
index 0cfb91e353..b016bab710 100644
--- a/src/net_processing.cpp
+++ b/src/net_processing.cpp
@@ -768,23 +768,29 @@ bool PeerManagerImpl::IsBlockRequested(const uint256& hash)
void PeerManagerImpl::MarkBlockAsReceived(const uint256& hash)
{
- std::map<uint256, std::pair<NodeId, std::list<QueuedBlock>::iterator> >::iterator itInFlight = mapBlocksInFlight.find(hash);
- if (itInFlight != mapBlocksInFlight.end()) {
- CNodeState *state = State(itInFlight->second.first);
- assert(state != nullptr);
- if (state->vBlocksInFlight.begin() == itInFlight->second.second) {
- // First block on the queue was received, update the start download time for the next one
- state->m_downloading_since = std::max(state->m_downloading_since, GetTime<std::chrono::microseconds>());
- }
- state->vBlocksInFlight.erase(itInFlight->second.second);
- state->nBlocksInFlight--;
- if (state->nBlocksInFlight == 0) {
- // Last validated block on the queue was received.
- m_peers_downloading_from--;
- }
- state->m_stalling_since = 0us;
- mapBlocksInFlight.erase(itInFlight);
+ auto it = mapBlocksInFlight.find(hash);
+ if (it == mapBlocksInFlight.end()) {
+ // Block was not requested
+ return;
+ }
+
+ auto [node_id, list_it] = it->second;
+ CNodeState *state = State(node_id);
+ assert(state != nullptr);
+
+ if (state->vBlocksInFlight.begin() == list_it) {
+ // First block on the queue was received, update the start download time for the next one
+ state->m_downloading_since = std::max(state->m_downloading_since, GetTime<std::chrono::microseconds>());
+ }
+ state->vBlocksInFlight.erase(list_it);
+
+ state->nBlocksInFlight--;
+ if (state->nBlocksInFlight == 0) {
+ // Last validated block on the queue was received.
+ m_peers_downloading_from--;
}
+ state->m_stalling_since = 0us;
+ mapBlocksInFlight.erase(it);
}
bool PeerManagerImpl::MarkBlockAsInFlight(NodeId nodeid, const CBlockIndex* pindex, std::list<QueuedBlock>::iterator** pit)