@@ -768,23 +768,29 @@ bool PeerManagerImpl::IsBlockRequested(const uint256& hash)
768
768
769
769
void PeerManagerImpl::MarkBlockAsReceived (const uint256& hash)
770
770
{
771
- std::map<uint256, std::pair<NodeId, std::list<QueuedBlock>::iterator> >::iterator itInFlight = mapBlocksInFlight.find (hash);
772
- if (itInFlight != mapBlocksInFlight.end ()) {
773
- CNodeState *state = State (itInFlight->second .first );
774
- assert (state != nullptr );
775
- if (state->vBlocksInFlight .begin () == itInFlight->second .second ) {
776
- // First block on the queue was received, update the start download time for the next one
777
- state->m_downloading_since = std::max (state->m_downloading_since , GetTime<std::chrono::microseconds>());
778
- }
779
- state->vBlocksInFlight .erase (itInFlight->second .second );
780
- state->nBlocksInFlight --;
781
- if (state->nBlocksInFlight == 0 ) {
782
- // Last validated block on the queue was received.
783
- m_peers_downloading_from--;
784
- }
785
- state->m_stalling_since = 0us;
786
- mapBlocksInFlight.erase (itInFlight);
771
+ auto it = mapBlocksInFlight.find (hash);
772
+ if (it == mapBlocksInFlight.end ()) {
773
+ // Block was not requested
774
+ return ;
775
+ }
776
+
777
+ auto [node_id, list_it] = it->second ;
778
+ CNodeState *state = State (node_id);
779
+ assert (state != nullptr );
780
+
781
+ if (state->vBlocksInFlight .begin () == list_it) {
782
+ // First block on the queue was received, update the start download time for the next one
783
+ state->m_downloading_since = std::max (state->m_downloading_since , GetTime<std::chrono::microseconds>());
784
+ }
785
+ state->vBlocksInFlight .erase (list_it);
786
+
787
+ state->nBlocksInFlight --;
788
+ if (state->nBlocksInFlight == 0 ) {
789
+ // Last validated block on the queue was received.
790
+ m_peers_downloading_from--;
787
791
}
792
+ state->m_stalling_since = 0us;
793
+ mapBlocksInFlight.erase (it);
788
794
}
789
795
790
796
bool PeerManagerImpl::MarkBlockAsInFlight (NodeId nodeid, const CBlockIndex* pindex, std::list<QueuedBlock>::iterator** pit)
0 commit comments