@@ -629,7 +629,6 @@ struct CNodeState {
629
629
// ! When the first entry in vBlocksInFlight started downloading. Don't care when vBlocksInFlight is empty.
630
630
std::chrono::microseconds m_downloading_since{0us};
631
631
int nBlocksInFlight{0 };
632
- int nBlocksInFlightValidHeaders{0 };
633
632
// ! Whether we consider this a preferred download peer.
634
633
bool fPreferredDownload {false };
635
634
// ! Whether this peer wants invs or headers (when possible) for block announcements.
@@ -766,17 +765,16 @@ bool PeerManagerImpl::MarkBlockAsReceived(const uint256& hash)
766
765
if (itInFlight != mapBlocksInFlight.end ()) {
767
766
CNodeState *state = State (itInFlight->second .first );
768
767
assert (state != nullptr );
769
- state->nBlocksInFlightValidHeaders -= 1 ;
770
- if (state->nBlocksInFlightValidHeaders == 0 ) {
771
- // Last validated block on the queue was received.
772
- nPeersWithValidatedDownloads--;
773
- }
774
768
if (state->vBlocksInFlight .begin () == itInFlight->second .second ) {
775
769
// First block on the queue was received, update the start download time for the next one
776
770
state->m_downloading_since = std::max (state->m_downloading_since , GetTime<std::chrono::microseconds>());
777
771
}
778
772
state->vBlocksInFlight .erase (itInFlight->second .second );
779
773
state->nBlocksInFlight --;
774
+ if (state->nBlocksInFlight == 0 ) {
775
+ // Last validated block on the queue was received.
776
+ nPeersWithValidatedDownloads--;
777
+ }
780
778
state->m_stalling_since = 0us;
781
779
mapBlocksInFlight.erase (itInFlight);
782
780
return true ;
@@ -807,12 +805,9 @@ bool PeerManagerImpl::MarkBlockAsInFlight(NodeId nodeid, const CBlockIndex* pind
807
805
std::list<QueuedBlock>::iterator it = state->vBlocksInFlight .insert (state->vBlocksInFlight .end (),
808
806
{hash, pindex, std::unique_ptr<PartiallyDownloadedBlock>(pit ? new PartiallyDownloadedBlock (&m_mempool) : nullptr )});
809
807
state->nBlocksInFlight ++;
810
- state->nBlocksInFlightValidHeaders += 1 ;
811
808
if (state->nBlocksInFlight == 1 ) {
812
809
// We're starting a block download (batch) from this peer.
813
810
state->m_downloading_since = GetTime<std::chrono::microseconds>();
814
- }
815
- if (state->nBlocksInFlightValidHeaders == 1 ) {
816
811
nPeersWithValidatedDownloads++;
817
812
}
818
813
itInFlight = mapBlocksInFlight.insert (std::make_pair (hash, std::make_pair (nodeid, it))).first ;
@@ -1139,7 +1134,7 @@ void PeerManagerImpl::FinalizeNode(const CNode& node)
1139
1134
WITH_LOCK (g_cs_orphans, m_orphanage.EraseForPeer (nodeid));
1140
1135
m_txrequest.DisconnectedPeer (nodeid);
1141
1136
nPreferredDownload -= state->fPreferredDownload ;
1142
- nPeersWithValidatedDownloads -= (state->nBlocksInFlightValidHeaders != 0 );
1137
+ nPeersWithValidatedDownloads -= (state->nBlocksInFlight != 0 );
1143
1138
assert (nPeersWithValidatedDownloads >= 0 );
1144
1139
m_outbound_peers_with_protect_from_disconnect -= state->m_chain_sync .m_protect ;
1145
1140
assert (m_outbound_peers_with_protect_from_disconnect >= 0 );
@@ -4717,7 +4712,7 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
4717
4712
// to unreasonably increase our timeout.
4718
4713
if (state.vBlocksInFlight .size () > 0 ) {
4719
4714
QueuedBlock &queuedBlock = state.vBlocksInFlight .front ();
4720
- int nOtherPeersWithValidatedDownloads = nPeersWithValidatedDownloads - (state. nBlocksInFlightValidHeaders > 0 ) ;
4715
+ int nOtherPeersWithValidatedDownloads = nPeersWithValidatedDownloads - 1 ;
4721
4716
if (current_time > state.m_downloading_since + std::chrono::seconds{consensusParams.nPowTargetSpacing } * (BLOCK_DOWNLOAD_TIMEOUT_BASE + BLOCK_DOWNLOAD_TIMEOUT_PER_PEER * nOtherPeersWithValidatedDownloads)) {
4722
4717
LogPrintf (" Timeout downloading block %s from peer=%d, disconnecting\n " , queuedBlock.hash .ToString (), pto->GetId ());
4723
4718
pto->fDisconnect = true ;
0 commit comments