mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-09-13 22:41:25 +02:00
net: Trigger process abort when behind start block MTP
We should not proceed syncing headers from peers when the local system clock is incorrectly set. A node with a system clock set too far back will typically fail early during startup when the chainstate detects the tip to be too far in the future. This means that in practice we don't expect the failure to ever happen in net_processing.cpp. An exception is thrown from HeadersSyncState() in order to only compute the error condition once. An alternative would be to compute it a second time in TryLowWorkHeadersSync() to guard against calling HeadersSyncState(), and have an assert inside HeadersSyncState(). We shut down the process so possible resource leaks due to the exception should not be an issue, although none have been spotted. Throwing an exception also keeps the unit test straightforward. Co-authored-by: Lőrinc <pap.lorinc@gmail.com>
This commit is contained in:
@@ -3030,8 +3030,19 @@ bool PeerManagerImpl::TryLowWorkHeadersSync(Peer& peer, CNode& pfrom, const CBlo
|
||||
// of headers is known, some header in this set must be new, so
|
||||
// advancing to the first unknown header would be a small effect.
|
||||
LOCK(peer.m_headers_sync_mutex);
|
||||
peer.m_headers_sync.reset(new HeadersSyncState(peer.m_id, m_chainparams.GetConsensus(),
|
||||
m_chainparams.HeadersSync(), chain_start_header, minimum_chain_work));
|
||||
try {
|
||||
peer.m_headers_sync.reset(new HeadersSyncState(peer.m_id, m_chainparams.GetConsensus(),
|
||||
m_chainparams.HeadersSync(), chain_start_header, minimum_chain_work));
|
||||
} catch (const HeadersSyncState::SystemClockError& e) {
|
||||
// Typically we would expect the chain state loading logic to
|
||||
// already have verified that the tip of the locally stored
|
||||
// chain is <= system clock + MAX_FUTURE_BLOCK_TIME. Getting
|
||||
// here is really unexpected.
|
||||
const auto msg{strprintf("Failure when attempting to initiate headers sync: %s", e.what())};
|
||||
std::cerr << msg << std::endl;
|
||||
LogError("%s", msg);
|
||||
std::abort();
|
||||
}
|
||||
|
||||
// Now a HeadersSyncState object for tracking this synchronization
|
||||
// is created, process the headers using it as normal. Failures are
|
||||
|
||||
Reference in New Issue
Block a user