Skip to content

Commit a905954

Browse files
committed
Remove nBlocksInFlight
1 parent 86cff8b commit a905954

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

src/net_processing.cpp

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,6 @@ struct CNodeState {
431431
std::list<QueuedBlock> vBlocksInFlight;
432432
//! When the first entry in vBlocksInFlight started downloading. Don't care when vBlocksInFlight is empty.
433433
std::chrono::microseconds m_downloading_since{0us};
434-
int nBlocksInFlight{0};
435434
//! Whether we consider this a preferred download peer.
436435
bool fPreferredDownload{false};
437436
/** Whether this peer wants invs or cmpctblocks (when possible) for block announcements. */
@@ -1145,8 +1144,7 @@ void PeerManagerImpl::RemoveBlockRequest(const uint256& hash, std::optional<Node
11451144
}
11461145
state->vBlocksInFlight.erase(list_it);
11471146

1148-
state->nBlocksInFlight--;
1149-
if (state->nBlocksInFlight == 0) {
1147+
if (state->vBlocksInFlight.empty()) {
11501148
// Last validated block on the queue was received.
11511149
m_peers_downloading_from--;
11521150
}
@@ -1175,8 +1173,7 @@ bool PeerManagerImpl::BlockRequested(NodeId nodeid, const CBlockIndex& block, st
11751173

11761174
std::list<QueuedBlock>::iterator it = state->vBlocksInFlight.insert(state->vBlocksInFlight.end(),
11771175
{&block, std::unique_ptr<PartiallyDownloadedBlock>(pit ? new PartiallyDownloadedBlock(&m_mempool) : nullptr)});
1178-
state->nBlocksInFlight++;
1179-
if (state->nBlocksInFlight == 1) {
1176+
if (state->vBlocksInFlight.size() == 1) {
11801177
// We're starting a block download (batch) from this peer.
11811178
state->m_downloading_since = GetTime<std::chrono::microseconds>();
11821179
m_peers_downloading_from++;
@@ -1520,7 +1517,7 @@ void PeerManagerImpl::FinalizeNode(const CNode& node)
15201517
m_txrequest.DisconnectedPeer(nodeid);
15211518
if (m_txreconciliation) m_txreconciliation->ForgetPeer(nodeid);
15221519
m_num_preferred_download_peers -= state->fPreferredDownload;
1523-
m_peers_downloading_from -= (state->nBlocksInFlight != 0);
1520+
m_peers_downloading_from -= (!state->vBlocksInFlight.empty());
15241521
assert(m_peers_downloading_from >= 0);
15251522
m_outbound_peers_with_protect_from_disconnect -= state->m_chain_sync.m_protect;
15261523
assert(m_outbound_peers_with_protect_from_disconnect >= 0);
@@ -2681,7 +2678,7 @@ void PeerManagerImpl::HeadersDirectFetchBlocks(CNode& pfrom, const Peer& peer, c
26812678
std::vector<CInv> vGetData;
26822679
// Download as much as possible, from earliest to latest.
26832680
for (const CBlockIndex *pindex : reverse_iterate(vToFetch)) {
2684-
if (nodestate->nBlocksInFlight >= MAX_BLOCKS_IN_TRANSIT_PER_PEER) {
2681+
if (nodestate->vBlocksInFlight.size() >= MAX_BLOCKS_IN_TRANSIT_PER_PEER) {
26852682
// Can't download any more from this peer
26862683
break;
26872684
}
@@ -4301,7 +4298,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
43014298
// We want to be a bit conservative just to be extra careful about DoS
43024299
// possibilities in compact block processing...
43034300
if (pindex->nHeight <= m_chainman.ActiveChain().Height() + 2) {
4304-
if ((!fAlreadyInFlight && nodestate->nBlocksInFlight < MAX_BLOCKS_IN_TRANSIT_PER_PEER) ||
4301+
if ((!fAlreadyInFlight && nodestate->vBlocksInFlight.size() < MAX_BLOCKS_IN_TRANSIT_PER_PEER) ||
43054302
(fAlreadyInFlight && blockInFlightIt->second.first == pfrom.GetId())) {
43064303
std::list<QueuedBlock>::iterator* queuedBlockIt = nullptr;
43074304
if (!BlockRequested(pfrom.GetId(), *pindex, &queuedBlockIt)) {
@@ -5044,14 +5041,14 @@ void PeerManagerImpl::EvictExtraOutboundPeers(std::chrono::seconds now)
50445041
// valid headers chain with at least as much work as our tip.
50455042
CNodeState *node_state = State(pnode->GetId());
50465043
if (node_state == nullptr ||
5047-
(now - pnode->m_connected >= MINIMUM_CONNECT_TIME && node_state->nBlocksInFlight == 0)) {
5044+
(now - pnode->m_connected >= MINIMUM_CONNECT_TIME && node_state->vBlocksInFlight.empty())) {
50485045
pnode->fDisconnect = true;
50495046
LogPrint(BCLog::NET, "disconnecting extra block-relay-only peer=%d (last block received at time %d)\n",
50505047
pnode->GetId(), count_seconds(pnode->m_last_block_time));
50515048
return true;
50525049
} else {
50535050
LogPrint(BCLog::NET, "keeping block-relay-only peer=%d chosen for eviction (connect time: %d, blocks_in_flight: %d)\n",
5054-
pnode->GetId(), count_seconds(pnode->m_connected), node_state->nBlocksInFlight);
5051+
pnode->GetId(), count_seconds(pnode->m_connected), node_state->vBlocksInFlight.size());
50555052
}
50565053
return false;
50575054
});
@@ -5091,13 +5088,13 @@ void PeerManagerImpl::EvictExtraOutboundPeers(std::chrono::seconds now)
50915088
// Also don't disconnect any peer we're trying to download a
50925089
// block from.
50935090
CNodeState &state = *State(pnode->GetId());
5094-
if (now - pnode->m_connected > MINIMUM_CONNECT_TIME && state.nBlocksInFlight == 0) {
5091+
if (now - pnode->m_connected > MINIMUM_CONNECT_TIME && state.vBlocksInFlight.empty()) {
50955092
LogPrint(BCLog::NET, "disconnecting extra outbound peer=%d (last block announcement received at time %d)\n", pnode->GetId(), oldest_block_announcement);
50965093
pnode->fDisconnect = true;
50975094
return true;
50985095
} else {
50995096
LogPrint(BCLog::NET, "keeping outbound peer=%d chosen for eviction (connect time: %d, blocks_in_flight: %d)\n",
5100-
pnode->GetId(), count_seconds(pnode->m_connected), state.nBlocksInFlight);
5097+
pnode->GetId(), count_seconds(pnode->m_connected), state.vBlocksInFlight.size());
51015098
return false;
51025099
}
51035100
});
@@ -5817,18 +5814,18 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
58175814
// Message: getdata (blocks)
58185815
//
58195816
std::vector<CInv> vGetData;
5820-
if (CanServeBlocks(*peer) && ((sync_blocks_and_headers_from_peer && !IsLimitedPeer(*peer)) || !m_chainman.ActiveChainstate().IsInitialBlockDownload()) && state.nBlocksInFlight < MAX_BLOCKS_IN_TRANSIT_PER_PEER) {
5817+
if (CanServeBlocks(*peer) && ((sync_blocks_and_headers_from_peer && !IsLimitedPeer(*peer)) || !m_chainman.ActiveChainstate().IsInitialBlockDownload()) && state.vBlocksInFlight.size() < MAX_BLOCKS_IN_TRANSIT_PER_PEER) {
58215818
std::vector<const CBlockIndex*> vToDownload;
58225819
NodeId staller = -1;
5823-
FindNextBlocksToDownload(*peer, MAX_BLOCKS_IN_TRANSIT_PER_PEER - state.nBlocksInFlight, vToDownload, staller);
5820+
FindNextBlocksToDownload(*peer, MAX_BLOCKS_IN_TRANSIT_PER_PEER - state.vBlocksInFlight.size(), vToDownload, staller);
58245821
for (const CBlockIndex *pindex : vToDownload) {
58255822
uint32_t nFetchFlags = GetFetchFlags(*peer);
58265823
vGetData.push_back(CInv(MSG_BLOCK | nFetchFlags, pindex->GetBlockHash()));
58275824
BlockRequested(pto->GetId(), *pindex);
58285825
LogPrint(BCLog::NET, "Requesting block %s (%d) peer=%d\n", pindex->GetBlockHash().ToString(),
58295826
pindex->nHeight, pto->GetId());
58305827
}
5831-
if (state.nBlocksInFlight == 0 && staller != -1) {
5828+
if (state.vBlocksInFlight.empty() && staller != -1) {
58325829
if (State(staller)->m_stalling_since == 0us) {
58335830
State(staller)->m_stalling_since = current_time;
58345831
LogPrint(BCLog::NET, "Stall started peer=%d\n", staller);

0 commit comments

Comments
 (0)