mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-03-10 09:06:15 +01:00
[net processing] Remove CNodeState.nBlocksInFlightValidHeaders
nBlocksInFlightValidHeaders always has the same value as nBlocksInFlight, since we only download blocks with valid headers.
This commit is contained in:
parent
b4e29f2436
commit
b03de9c753
1 changed files with 6 additions and 11 deletions
|
@ -629,7 +629,6 @@ struct CNodeState {
|
||||||
//! 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};
|
int nBlocksInFlight{0};
|
||||||
int nBlocksInFlightValidHeaders{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 headers (when possible) for block announcements.
|
//! Whether this peer wants invs or headers (when possible) for block announcements.
|
||||||
|
@ -766,17 +765,16 @@ bool PeerManagerImpl::MarkBlockAsReceived(const uint256& hash)
|
||||||
if (itInFlight != mapBlocksInFlight.end()) {
|
if (itInFlight != mapBlocksInFlight.end()) {
|
||||||
CNodeState *state = State(itInFlight->second.first);
|
CNodeState *state = State(itInFlight->second.first);
|
||||||
assert(state != nullptr);
|
assert(state != nullptr);
|
||||||
state->nBlocksInFlightValidHeaders -= 1;
|
|
||||||
if (state->nBlocksInFlightValidHeaders == 0) {
|
|
||||||
// Last validated block on the queue was received.
|
|
||||||
nPeersWithValidatedDownloads--;
|
|
||||||
}
|
|
||||||
if (state->vBlocksInFlight.begin() == itInFlight->second.second) {
|
if (state->vBlocksInFlight.begin() == itInFlight->second.second) {
|
||||||
// First block on the queue was received, update the start download time for the next one
|
// First block on the queue was received, update the start download time for the next one
|
||||||
state->m_downloading_since = std::max(state->m_downloading_since, GetTime<std::chrono::microseconds>());
|
state->m_downloading_since = std::max(state->m_downloading_since, GetTime<std::chrono::microseconds>());
|
||||||
}
|
}
|
||||||
state->vBlocksInFlight.erase(itInFlight->second.second);
|
state->vBlocksInFlight.erase(itInFlight->second.second);
|
||||||
state->nBlocksInFlight--;
|
state->nBlocksInFlight--;
|
||||||
|
if (state->nBlocksInFlight == 0) {
|
||||||
|
// Last validated block on the queue was received.
|
||||||
|
nPeersWithValidatedDownloads--;
|
||||||
|
}
|
||||||
state->m_stalling_since = 0us;
|
state->m_stalling_since = 0us;
|
||||||
mapBlocksInFlight.erase(itInFlight);
|
mapBlocksInFlight.erase(itInFlight);
|
||||||
return true;
|
return true;
|
||||||
|
@ -807,12 +805,9 @@ bool PeerManagerImpl::MarkBlockAsInFlight(NodeId nodeid, const CBlockIndex* pind
|
||||||
std::list<QueuedBlock>::iterator it = state->vBlocksInFlight.insert(state->vBlocksInFlight.end(),
|
std::list<QueuedBlock>::iterator it = state->vBlocksInFlight.insert(state->vBlocksInFlight.end(),
|
||||||
{hash, pindex, std::unique_ptr<PartiallyDownloadedBlock>(pit ? new PartiallyDownloadedBlock(&m_mempool) : nullptr)});
|
{hash, pindex, std::unique_ptr<PartiallyDownloadedBlock>(pit ? new PartiallyDownloadedBlock(&m_mempool) : nullptr)});
|
||||||
state->nBlocksInFlight++;
|
state->nBlocksInFlight++;
|
||||||
state->nBlocksInFlightValidHeaders += 1;
|
|
||||||
if (state->nBlocksInFlight == 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>();
|
||||||
}
|
|
||||||
if (state->nBlocksInFlightValidHeaders == 1) {
|
|
||||||
nPeersWithValidatedDownloads++;
|
nPeersWithValidatedDownloads++;
|
||||||
}
|
}
|
||||||
itInFlight = mapBlocksInFlight.insert(std::make_pair(hash, std::make_pair(nodeid, it))).first;
|
itInFlight = mapBlocksInFlight.insert(std::make_pair(hash, std::make_pair(nodeid, it))).first;
|
||||||
|
@ -1139,7 +1134,7 @@ void PeerManagerImpl::FinalizeNode(const CNode& node)
|
||||||
WITH_LOCK(g_cs_orphans, m_orphanage.EraseForPeer(nodeid));
|
WITH_LOCK(g_cs_orphans, m_orphanage.EraseForPeer(nodeid));
|
||||||
m_txrequest.DisconnectedPeer(nodeid);
|
m_txrequest.DisconnectedPeer(nodeid);
|
||||||
nPreferredDownload -= state->fPreferredDownload;
|
nPreferredDownload -= state->fPreferredDownload;
|
||||||
nPeersWithValidatedDownloads -= (state->nBlocksInFlightValidHeaders != 0);
|
nPeersWithValidatedDownloads -= (state->nBlocksInFlight != 0);
|
||||||
assert(nPeersWithValidatedDownloads >= 0);
|
assert(nPeersWithValidatedDownloads >= 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);
|
||||||
|
@ -4717,7 +4712,7 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
|
||||||
// to unreasonably increase our timeout.
|
// to unreasonably increase our timeout.
|
||||||
if (state.vBlocksInFlight.size() > 0) {
|
if (state.vBlocksInFlight.size() > 0) {
|
||||||
QueuedBlock &queuedBlock = state.vBlocksInFlight.front();
|
QueuedBlock &queuedBlock = state.vBlocksInFlight.front();
|
||||||
int nOtherPeersWithValidatedDownloads = nPeersWithValidatedDownloads - (state.nBlocksInFlightValidHeaders > 0);
|
int nOtherPeersWithValidatedDownloads = nPeersWithValidatedDownloads - 1;
|
||||||
if (current_time > state.m_downloading_since + std::chrono::seconds{consensusParams.nPowTargetSpacing} * (BLOCK_DOWNLOAD_TIMEOUT_BASE + BLOCK_DOWNLOAD_TIMEOUT_PER_PEER * nOtherPeersWithValidatedDownloads)) {
|
if (current_time > state.m_downloading_since + std::chrono::seconds{consensusParams.nPowTargetSpacing} * (BLOCK_DOWNLOAD_TIMEOUT_BASE + BLOCK_DOWNLOAD_TIMEOUT_PER_PEER * nOtherPeersWithValidatedDownloads)) {
|
||||||
LogPrintf("Timeout downloading block %s from peer=%d, disconnecting\n", queuedBlock.hash.ToString(), pto->GetId());
|
LogPrintf("Timeout downloading block %s from peer=%d, disconnecting\n", queuedBlock.hash.ToString(), pto->GetId());
|
||||||
pto->fDisconnect = true;
|
pto->fDisconnect = true;
|
||||||
|
|
Loading…
Add table
Reference in a new issue