mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-06-28 18:01:27 +02:00
Remove nBlocksInFlight
This commit is contained in:
parent
86cff8bf18
commit
a90595478d
@ -431,7 +431,6 @@ struct CNodeState {
|
|||||||
std::list<QueuedBlock> vBlocksInFlight;
|
std::list<QueuedBlock> vBlocksInFlight;
|
||||||
//! When the first entry in vBlocksInFlight started downloading. Don't care when vBlocksInFlight is empty.
|
//! When the first entry in vBlocksInFlight started downloading. Don't care when vBlocksInFlight is empty.
|
||||||
std::chrono::microseconds m_downloading_since{0us};
|
std::chrono::microseconds m_downloading_since{0us};
|
||||||
int nBlocksInFlight{0};
|
|
||||||
//! Whether we consider this a preferred download peer.
|
//! Whether we consider this a preferred download peer.
|
||||||
bool fPreferredDownload{false};
|
bool fPreferredDownload{false};
|
||||||
/** Whether this peer wants invs or cmpctblocks (when possible) for block announcements. */
|
/** 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
|
|||||||
}
|
}
|
||||||
state->vBlocksInFlight.erase(list_it);
|
state->vBlocksInFlight.erase(list_it);
|
||||||
|
|
||||||
state->nBlocksInFlight--;
|
if (state->vBlocksInFlight.empty()) {
|
||||||
if (state->nBlocksInFlight == 0) {
|
|
||||||
// Last validated block on the queue was received.
|
// Last validated block on the queue was received.
|
||||||
m_peers_downloading_from--;
|
m_peers_downloading_from--;
|
||||||
}
|
}
|
||||||
@ -1175,8 +1173,7 @@ bool PeerManagerImpl::BlockRequested(NodeId nodeid, const CBlockIndex& block, st
|
|||||||
|
|
||||||
std::list<QueuedBlock>::iterator it = state->vBlocksInFlight.insert(state->vBlocksInFlight.end(),
|
std::list<QueuedBlock>::iterator it = state->vBlocksInFlight.insert(state->vBlocksInFlight.end(),
|
||||||
{&block, std::unique_ptr<PartiallyDownloadedBlock>(pit ? new PartiallyDownloadedBlock(&m_mempool) : nullptr)});
|
{&block, std::unique_ptr<PartiallyDownloadedBlock>(pit ? new PartiallyDownloadedBlock(&m_mempool) : nullptr)});
|
||||||
state->nBlocksInFlight++;
|
if (state->vBlocksInFlight.size() == 1) {
|
||||||
if (state->nBlocksInFlight == 1) {
|
|
||||||
// We're starting a block download (batch) from this peer.
|
// We're starting a block download (batch) from this peer.
|
||||||
state->m_downloading_since = GetTime<std::chrono::microseconds>();
|
state->m_downloading_since = GetTime<std::chrono::microseconds>();
|
||||||
m_peers_downloading_from++;
|
m_peers_downloading_from++;
|
||||||
@ -1520,7 +1517,7 @@ void PeerManagerImpl::FinalizeNode(const CNode& node)
|
|||||||
m_txrequest.DisconnectedPeer(nodeid);
|
m_txrequest.DisconnectedPeer(nodeid);
|
||||||
if (m_txreconciliation) m_txreconciliation->ForgetPeer(nodeid);
|
if (m_txreconciliation) m_txreconciliation->ForgetPeer(nodeid);
|
||||||
m_num_preferred_download_peers -= state->fPreferredDownload;
|
m_num_preferred_download_peers -= state->fPreferredDownload;
|
||||||
m_peers_downloading_from -= (state->nBlocksInFlight != 0);
|
m_peers_downloading_from -= (!state->vBlocksInFlight.empty());
|
||||||
assert(m_peers_downloading_from >= 0);
|
assert(m_peers_downloading_from >= 0);
|
||||||
m_outbound_peers_with_protect_from_disconnect -= state->m_chain_sync.m_protect;
|
m_outbound_peers_with_protect_from_disconnect -= state->m_chain_sync.m_protect;
|
||||||
assert(m_outbound_peers_with_protect_from_disconnect >= 0);
|
assert(m_outbound_peers_with_protect_from_disconnect >= 0);
|
||||||
@ -2681,7 +2678,7 @@ void PeerManagerImpl::HeadersDirectFetchBlocks(CNode& pfrom, const Peer& peer, c
|
|||||||
std::vector<CInv> vGetData;
|
std::vector<CInv> vGetData;
|
||||||
// Download as much as possible, from earliest to latest.
|
// Download as much as possible, from earliest to latest.
|
||||||
for (const CBlockIndex *pindex : reverse_iterate(vToFetch)) {
|
for (const CBlockIndex *pindex : reverse_iterate(vToFetch)) {
|
||||||
if (nodestate->nBlocksInFlight >= MAX_BLOCKS_IN_TRANSIT_PER_PEER) {
|
if (nodestate->vBlocksInFlight.size() >= MAX_BLOCKS_IN_TRANSIT_PER_PEER) {
|
||||||
// Can't download any more from this peer
|
// Can't download any more from this peer
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -4301,7 +4298,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
|
|||||||
// We want to be a bit conservative just to be extra careful about DoS
|
// We want to be a bit conservative just to be extra careful about DoS
|
||||||
// possibilities in compact block processing...
|
// possibilities in compact block processing...
|
||||||
if (pindex->nHeight <= m_chainman.ActiveChain().Height() + 2) {
|
if (pindex->nHeight <= m_chainman.ActiveChain().Height() + 2) {
|
||||||
if ((!fAlreadyInFlight && nodestate->nBlocksInFlight < MAX_BLOCKS_IN_TRANSIT_PER_PEER) ||
|
if ((!fAlreadyInFlight && nodestate->vBlocksInFlight.size() < MAX_BLOCKS_IN_TRANSIT_PER_PEER) ||
|
||||||
(fAlreadyInFlight && blockInFlightIt->second.first == pfrom.GetId())) {
|
(fAlreadyInFlight && blockInFlightIt->second.first == pfrom.GetId())) {
|
||||||
std::list<QueuedBlock>::iterator* queuedBlockIt = nullptr;
|
std::list<QueuedBlock>::iterator* queuedBlockIt = nullptr;
|
||||||
if (!BlockRequested(pfrom.GetId(), *pindex, &queuedBlockIt)) {
|
if (!BlockRequested(pfrom.GetId(), *pindex, &queuedBlockIt)) {
|
||||||
@ -5044,14 +5041,14 @@ void PeerManagerImpl::EvictExtraOutboundPeers(std::chrono::seconds now)
|
|||||||
// valid headers chain with at least as much work as our tip.
|
// valid headers chain with at least as much work as our tip.
|
||||||
CNodeState *node_state = State(pnode->GetId());
|
CNodeState *node_state = State(pnode->GetId());
|
||||||
if (node_state == nullptr ||
|
if (node_state == nullptr ||
|
||||||
(now - pnode->m_connected >= MINIMUM_CONNECT_TIME && node_state->nBlocksInFlight == 0)) {
|
(now - pnode->m_connected >= MINIMUM_CONNECT_TIME && node_state->vBlocksInFlight.empty())) {
|
||||||
pnode->fDisconnect = true;
|
pnode->fDisconnect = true;
|
||||||
LogPrint(BCLog::NET, "disconnecting extra block-relay-only peer=%d (last block received at time %d)\n",
|
LogPrint(BCLog::NET, "disconnecting extra block-relay-only peer=%d (last block received at time %d)\n",
|
||||||
pnode->GetId(), count_seconds(pnode->m_last_block_time));
|
pnode->GetId(), count_seconds(pnode->m_last_block_time));
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
LogPrint(BCLog::NET, "keeping block-relay-only peer=%d chosen for eviction (connect time: %d, blocks_in_flight: %d)\n",
|
LogPrint(BCLog::NET, "keeping block-relay-only peer=%d chosen for eviction (connect time: %d, blocks_in_flight: %d)\n",
|
||||||
pnode->GetId(), count_seconds(pnode->m_connected), node_state->nBlocksInFlight);
|
pnode->GetId(), count_seconds(pnode->m_connected), node_state->vBlocksInFlight.size());
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
@ -5091,13 +5088,13 @@ void PeerManagerImpl::EvictExtraOutboundPeers(std::chrono::seconds now)
|
|||||||
// Also don't disconnect any peer we're trying to download a
|
// Also don't disconnect any peer we're trying to download a
|
||||||
// block from.
|
// block from.
|
||||||
CNodeState &state = *State(pnode->GetId());
|
CNodeState &state = *State(pnode->GetId());
|
||||||
if (now - pnode->m_connected > MINIMUM_CONNECT_TIME && state.nBlocksInFlight == 0) {
|
if (now - pnode->m_connected > MINIMUM_CONNECT_TIME && state.vBlocksInFlight.empty()) {
|
||||||
LogPrint(BCLog::NET, "disconnecting extra outbound peer=%d (last block announcement received at time %d)\n", pnode->GetId(), oldest_block_announcement);
|
LogPrint(BCLog::NET, "disconnecting extra outbound peer=%d (last block announcement received at time %d)\n", pnode->GetId(), oldest_block_announcement);
|
||||||
pnode->fDisconnect = true;
|
pnode->fDisconnect = true;
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
LogPrint(BCLog::NET, "keeping outbound peer=%d chosen for eviction (connect time: %d, blocks_in_flight: %d)\n",
|
LogPrint(BCLog::NET, "keeping outbound peer=%d chosen for eviction (connect time: %d, blocks_in_flight: %d)\n",
|
||||||
pnode->GetId(), count_seconds(pnode->m_connected), state.nBlocksInFlight);
|
pnode->GetId(), count_seconds(pnode->m_connected), state.vBlocksInFlight.size());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -5817,10 +5814,10 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
|
|||||||
// Message: getdata (blocks)
|
// Message: getdata (blocks)
|
||||||
//
|
//
|
||||||
std::vector<CInv> vGetData;
|
std::vector<CInv> vGetData;
|
||||||
if (CanServeBlocks(*peer) && ((sync_blocks_and_headers_from_peer && !IsLimitedPeer(*peer)) || !m_chainman.ActiveChainstate().IsInitialBlockDownload()) && state.nBlocksInFlight < MAX_BLOCKS_IN_TRANSIT_PER_PEER) {
|
if (CanServeBlocks(*peer) && ((sync_blocks_and_headers_from_peer && !IsLimitedPeer(*peer)) || !m_chainman.ActiveChainstate().IsInitialBlockDownload()) && state.vBlocksInFlight.size() < MAX_BLOCKS_IN_TRANSIT_PER_PEER) {
|
||||||
std::vector<const CBlockIndex*> vToDownload;
|
std::vector<const CBlockIndex*> vToDownload;
|
||||||
NodeId staller = -1;
|
NodeId staller = -1;
|
||||||
FindNextBlocksToDownload(*peer, MAX_BLOCKS_IN_TRANSIT_PER_PEER - state.nBlocksInFlight, vToDownload, staller);
|
FindNextBlocksToDownload(*peer, MAX_BLOCKS_IN_TRANSIT_PER_PEER - state.vBlocksInFlight.size(), vToDownload, staller);
|
||||||
for (const CBlockIndex *pindex : vToDownload) {
|
for (const CBlockIndex *pindex : vToDownload) {
|
||||||
uint32_t nFetchFlags = GetFetchFlags(*peer);
|
uint32_t nFetchFlags = GetFetchFlags(*peer);
|
||||||
vGetData.push_back(CInv(MSG_BLOCK | nFetchFlags, pindex->GetBlockHash()));
|
vGetData.push_back(CInv(MSG_BLOCK | nFetchFlags, pindex->GetBlockHash()));
|
||||||
@ -5828,7 +5825,7 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
|
|||||||
LogPrint(BCLog::NET, "Requesting block %s (%d) peer=%d\n", pindex->GetBlockHash().ToString(),
|
LogPrint(BCLog::NET, "Requesting block %s (%d) peer=%d\n", pindex->GetBlockHash().ToString(),
|
||||||
pindex->nHeight, pto->GetId());
|
pindex->nHeight, pto->GetId());
|
||||||
}
|
}
|
||||||
if (state.nBlocksInFlight == 0 && staller != -1) {
|
if (state.vBlocksInFlight.empty() && staller != -1) {
|
||||||
if (State(staller)->m_stalling_since == 0us) {
|
if (State(staller)->m_stalling_since == 0us) {
|
||||||
State(staller)->m_stalling_since = current_time;
|
State(staller)->m_stalling_since = current_time;
|
||||||
LogPrint(BCLog::NET, "Stall started peer=%d\n", staller);
|
LogPrint(BCLog::NET, "Stall started peer=%d\n", staller);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user