Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/net_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2634,6 +2634,15 @@ bool PeerManagerImpl::TryLowWorkHeadersSync(Peer& peer, CNode& pfrom, const CBlo
// otherwise they don't have more headers after this so no point in
// trying to sync their too-little-work chain.
if (headers.size() == m_opts.max_headers_result) {
// chain_start_header may refer to a block deep in the chain that
// has been trimmed from memory by -trim_headers. The HeadersSyncState
// constructor calls GetBlockHeader() on it via m_last_header_received,
// which asserts untrimmed. Reload from disk first if needed.
CBlockIndex tmpBlockIndexFull;
const CBlockIndex* chain_start_untrimmed = chain_start_header->trimmed()
? chain_start_header->untrim_to(&tmpBlockIndexFull)
: chain_start_header;

// Note: we could advance to the last header in this set that is
// known to us, rather than starting at the first header (which we
// may already have); however this is unlikely to matter much since
Expand All @@ -2645,7 +2654,7 @@ bool PeerManagerImpl::TryLowWorkHeadersSync(Peer& peer, CNode& pfrom, const CBlo
// 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(),
chain_start_header, minimum_chain_work));
chain_start_untrimmed, minimum_chain_work));

// Now a HeadersSyncState object for tracking this synchronization
// is created, process the headers using it as normal. Failures are
Expand Down
Loading