@@ -431,7 +431,6 @@ struct CNodeState {
431
431
std::list<QueuedBlock> vBlocksInFlight;
432
432
// ! When the first entry in vBlocksInFlight started downloading. Don't care when vBlocksInFlight is empty.
433
433
std::chrono::microseconds m_downloading_since{0us};
434
- int nBlocksInFlight{0 };
435
434
// ! Whether we consider this a preferred download peer.
436
435
bool fPreferredDownload {false };
437
436
/* * 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
1145
1144
}
1146
1145
state->vBlocksInFlight .erase (list_it);
1147
1146
1148
- state->nBlocksInFlight --;
1149
- if (state->nBlocksInFlight == 0 ) {
1147
+ if (state->vBlocksInFlight .empty ()) {
1150
1148
// Last validated block on the queue was received.
1151
1149
m_peers_downloading_from--;
1152
1150
}
@@ -1175,8 +1173,7 @@ bool PeerManagerImpl::BlockRequested(NodeId nodeid, const CBlockIndex& block, st
1175
1173
1176
1174
std::list<QueuedBlock>::iterator it = state->vBlocksInFlight .insert (state->vBlocksInFlight .end (),
1177
1175
{&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 ) {
1180
1177
// We're starting a block download (batch) from this peer.
1181
1178
state->m_downloading_since = GetTime<std::chrono::microseconds>();
1182
1179
m_peers_downloading_from++;
@@ -1520,7 +1517,7 @@ void PeerManagerImpl::FinalizeNode(const CNode& node)
1520
1517
m_txrequest.DisconnectedPeer (nodeid);
1521
1518
if (m_txreconciliation) m_txreconciliation->ForgetPeer (nodeid);
1522
1519
m_num_preferred_download_peers -= state->fPreferredDownload ;
1523
- m_peers_downloading_from -= (state->nBlocksInFlight != 0 );
1520
+ m_peers_downloading_from -= (! state->vBlocksInFlight . empty () );
1524
1521
assert (m_peers_downloading_from >= 0 );
1525
1522
m_outbound_peers_with_protect_from_disconnect -= state->m_chain_sync .m_protect ;
1526
1523
assert (m_outbound_peers_with_protect_from_disconnect >= 0 );
@@ -2681,7 +2678,7 @@ void PeerManagerImpl::HeadersDirectFetchBlocks(CNode& pfrom, const Peer& peer, c
2681
2678
std::vector<CInv> vGetData;
2682
2679
// Download as much as possible, from earliest to latest.
2683
2680
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) {
2685
2682
// Can't download any more from this peer
2686
2683
break ;
2687
2684
}
@@ -4301,7 +4298,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
4301
4298
// We want to be a bit conservative just to be extra careful about DoS
4302
4299
// possibilities in compact block processing...
4303
4300
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) ||
4305
4302
(fAlreadyInFlight && blockInFlightIt->second .first == pfrom.GetId ())) {
4306
4303
std::list<QueuedBlock>::iterator* queuedBlockIt = nullptr ;
4307
4304
if (!BlockRequested (pfrom.GetId (), *pindex, &queuedBlockIt)) {
@@ -5044,14 +5041,14 @@ void PeerManagerImpl::EvictExtraOutboundPeers(std::chrono::seconds now)
5044
5041
// valid headers chain with at least as much work as our tip.
5045
5042
CNodeState *node_state = State (pnode->GetId ());
5046
5043
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 () )) {
5048
5045
pnode->fDisconnect = true ;
5049
5046
LogPrint (BCLog::NET, " disconnecting extra block-relay-only peer=%d (last block received at time %d)\n " ,
5050
5047
pnode->GetId (), count_seconds (pnode->m_last_block_time ));
5051
5048
return true ;
5052
5049
} else {
5053
5050
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 () );
5055
5052
}
5056
5053
return false ;
5057
5054
});
@@ -5091,13 +5088,13 @@ void PeerManagerImpl::EvictExtraOutboundPeers(std::chrono::seconds now)
5091
5088
// Also don't disconnect any peer we're trying to download a
5092
5089
// block from.
5093
5090
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 () ) {
5095
5092
LogPrint (BCLog::NET, " disconnecting extra outbound peer=%d (last block announcement received at time %d)\n " , pnode->GetId (), oldest_block_announcement);
5096
5093
pnode->fDisconnect = true ;
5097
5094
return true ;
5098
5095
} else {
5099
5096
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 () );
5101
5098
return false ;
5102
5099
}
5103
5100
});
@@ -5817,18 +5814,18 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
5817
5814
// Message: getdata (blocks)
5818
5815
//
5819
5816
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) {
5821
5818
std::vector<const CBlockIndex*> vToDownload;
5822
5819
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);
5824
5821
for (const CBlockIndex *pindex : vToDownload) {
5825
5822
uint32_t nFetchFlags = GetFetchFlags (*peer);
5826
5823
vGetData.push_back (CInv (MSG_BLOCK | nFetchFlags, pindex->GetBlockHash ()));
5827
5824
BlockRequested (pto->GetId (), *pindex);
5828
5825
LogPrint (BCLog::NET, " Requesting block %s (%d) peer=%d\n " , pindex->GetBlockHash ().ToString (),
5829
5826
pindex->nHeight , pto->GetId ());
5830
5827
}
5831
- if (state.nBlocksInFlight == 0 && staller != -1 ) {
5828
+ if (state.vBlocksInFlight . empty () && staller != -1 ) {
5832
5829
if (State (staller)->m_stalling_since == 0us) {
5833
5830
State (staller)->m_stalling_since = current_time;
5834
5831
LogPrint (BCLog::NET, " Stall started peer=%d\n " , staller);
0 commit comments