aboutsummaryrefslogtreecommitdiff
path: root/src/net_processing.cpp
diff options
context:
space:
mode:
authorSergi Delgado Segura <sergi.delgado.s@gmail.com>2023-12-20 10:53:49 -0500
committerSergi Delgado Segura <sergi.delgado.s@gmail.com>2024-04-26 11:14:20 -0400
commita8d9a0edc7cef2c31a557ef53eb45520976b0d65 (patch)
treec239e184e88a6b074a1be6e4ca20c8608a9af978 /src/net_processing.cpp
parent3c88eac28e8984893746caebb313dc3b2fca90db (diff)
downloadbitcoin-a8d9a0edc7cef2c31a557ef53eb45520976b0d65.tar.xz
test: adds outbound eviction functional tests, updates comment in ConsiderEviction
Diffstat (limited to 'src/net_processing.cpp')
-rw-r--r--src/net_processing.cpp11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/net_processing.cpp b/src/net_processing.cpp
index 39ffff97d2..f936f1b666 100644
--- a/src/net_processing.cpp
+++ b/src/net_processing.cpp
@@ -5165,16 +5165,19 @@ void PeerManagerImpl::ConsiderEviction(CNode& pto, Peer& peer, std::chrono::seco
// unless it's invalid, in which case we should find that out and
// disconnect from them elsewhere).
if (state.pindexBestKnownBlock != nullptr && state.pindexBestKnownBlock->nChainWork >= m_chainman.ActiveChain().Tip()->nChainWork) {
+ // The outbound peer has sent us a block with at least as much work as our current tip, so reset the timeout if it was set
if (state.m_chain_sync.m_timeout != 0s) {
state.m_chain_sync.m_timeout = 0s;
state.m_chain_sync.m_work_header = nullptr;
state.m_chain_sync.m_sent_getheaders = false;
}
} else if (state.m_chain_sync.m_timeout == 0s || (state.m_chain_sync.m_work_header != nullptr && state.pindexBestKnownBlock != nullptr && state.pindexBestKnownBlock->nChainWork >= state.m_chain_sync.m_work_header->nChainWork)) {
- // Our best block known by this peer is behind our tip, and we're either noticing
- // that for the first time, OR this peer was able to catch up to some earlier point
- // where we checked against our tip.
- // Either way, set a new timeout based on current tip.
+ // At this point we know that the outbound peer has either never sent us a block/header or they have, but its tip is behind ours
+ // AND
+ // we are noticing this for the first time (m_timeout is 0)
+ // OR we noticed this at some point within the last CHAIN_SYNC_TIMEOUT + HEADERS_RESPONSE_TIME seconds and set a timeout
+ // for them, they caught up to our tip at the time of setting the timer but not to our current one (we've also advanced).
+ // Either way, set a new timeout based on our current tip.
state.m_chain_sync.m_timeout = time_in_seconds + CHAIN_SYNC_TIMEOUT;
state.m_chain_sync.m_work_header = m_chainman.ActiveChain().Tip();
state.m_chain_sync.m_sent_getheaders = false;