Skip to content

Commit b03de9c

Browse files
committed
[net processing] Remove CNodeState.nBlocksInFlightValidHeaders
nBlocksInFlightValidHeaders always has the same value as nBlocksInFlight, since we only download blocks with valid headers.
1 parent b4e29f2 commit b03de9c

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

src/net_processing.cpp

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,6 @@ struct CNodeState {
629629
//! When the first entry in vBlocksInFlight started downloading. Don't care when vBlocksInFlight is empty.
630630
std::chrono::microseconds m_downloading_since{0us};
631631
int nBlocksInFlight{0};
632-
int nBlocksInFlightValidHeaders{0};
633632
//! Whether we consider this a preferred download peer.
634633
bool fPreferredDownload{false};
635634
//! Whether this peer wants invs or headers (when possible) for block announcements.
@@ -766,17 +765,16 @@ bool PeerManagerImpl::MarkBlockAsReceived(const uint256& hash)
766765
if (itInFlight != mapBlocksInFlight.end()) {
767766
CNodeState *state = State(itInFlight->second.first);
768767
assert(state != nullptr);
769-
state->nBlocksInFlightValidHeaders -= 1;
770-
if (state->nBlocksInFlightValidHeaders == 0) {
771-
// Last validated block on the queue was received.
772-
nPeersWithValidatedDownloads--;
773-
}
774768
if (state->vBlocksInFlight.begin() == itInFlight->second.second) {
775769
// First block on the queue was received, update the start download time for the next one
776770
state->m_downloading_since = std::max(state->m_downloading_since, GetTime<std::chrono::microseconds>());
777771
}
778772
state->vBlocksInFlight.erase(itInFlight->second.second);
779773
state->nBlocksInFlight--;
774+
if (state->nBlocksInFlight == 0) {
775+
// Last validated block on the queue was received.
776+
nPeersWithValidatedDownloads--;
777+
}
780778
state->m_stalling_since = 0us;
781779
mapBlocksInFlight.erase(itInFlight);
782780
return true;
@@ -807,12 +805,9 @@ bool PeerManagerImpl::MarkBlockAsInFlight(NodeId nodeid, const CBlockIndex* pind
807805
std::list<QueuedBlock>::iterator it = state->vBlocksInFlight.insert(state->vBlocksInFlight.end(),
808806
{hash, pindex, std::unique_ptr<PartiallyDownloadedBlock>(pit ? new PartiallyDownloadedBlock(&m_mempool) : nullptr)});
809807
state->nBlocksInFlight++;
810-
state->nBlocksInFlightValidHeaders += 1;
811808
if (state->nBlocksInFlight == 1) {
812809
// We're starting a block download (batch) from this peer.
813810
state->m_downloading_since = GetTime<std::chrono::microseconds>();
814-
}
815-
if (state->nBlocksInFlightValidHeaders == 1) {
816811
nPeersWithValidatedDownloads++;
817812
}
818813
itInFlight = mapBlocksInFlight.insert(std::make_pair(hash, std::make_pair(nodeid, it))).first;
@@ -1139,7 +1134,7 @@ void PeerManagerImpl::FinalizeNode(const CNode& node)
11391134
WITH_LOCK(g_cs_orphans, m_orphanage.EraseForPeer(nodeid));
11401135
m_txrequest.DisconnectedPeer(nodeid);
11411136
nPreferredDownload -= state->fPreferredDownload;
1142-
nPeersWithValidatedDownloads -= (state->nBlocksInFlightValidHeaders != 0);
1137+
nPeersWithValidatedDownloads -= (state->nBlocksInFlight != 0);
11431138
assert(nPeersWithValidatedDownloads >= 0);
11441139
m_outbound_peers_with_protect_from_disconnect -= state->m_chain_sync.m_protect;
11451140
assert(m_outbound_peers_with_protect_from_disconnect >= 0);
@@ -4717,7 +4712,7 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
47174712
// to unreasonably increase our timeout.
47184713
if (state.vBlocksInFlight.size() > 0) {
47194714
QueuedBlock &queuedBlock = state.vBlocksInFlight.front();
4720-
int nOtherPeersWithValidatedDownloads = nPeersWithValidatedDownloads - (state.nBlocksInFlightValidHeaders > 0);
4715+
int nOtherPeersWithValidatedDownloads = nPeersWithValidatedDownloads - 1;
47214716
if (current_time > state.m_downloading_since + std::chrono::seconds{consensusParams.nPowTargetSpacing} * (BLOCK_DOWNLOAD_TIMEOUT_BASE + BLOCK_DOWNLOAD_TIMEOUT_PER_PEER * nOtherPeersWithValidatedDownloads)) {
47224717
LogPrintf("Timeout downloading block %s from peer=%d, disconnecting\n", queuedBlock.hash.ToString(), pto->GetId());
47234718
pto->fDisconnect = true;

0 commit comments

Comments
 (0)