Skip to content

Commit 7a88551

Browse files
committed
p2p: Restrict downloading of blocks for snapshot chain
If the best chain of the peer doesn't include the snapshot block, it is futile to download blocks from this chain, because we couldn't reorg to it. We'd also crash trying to reorg because this scenario is not handled.
1 parent 9057598 commit 7a88551

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/net_processing.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1397,6 +1397,15 @@ void PeerManagerImpl::FindNextBlocksToDownload(const Peer& peer, unsigned int co
13971397
return;
13981398
}
13991399

1400+
// When we sync with AssumeUtxo and discover the snapshot is not in the peer's best chain, abort:
1401+
// We can't reorg to this chain due to missing undo data until the background sync has finished,
1402+
// so downloading blocks from it would be futile.
1403+
const CBlockIndex* snap_base{m_chainman.GetSnapshotBaseBlock()};
1404+
if (snap_base && state->pindexBestKnownBlock->GetAncestor(snap_base->nHeight) != snap_base) {
1405+
LogDebug(BCLog::NET, "Not downloading blocks from peer=%d, which doesn't have the snapshot block in its best chain.\n", peer.m_id);
1406+
return;
1407+
}
1408+
14001409
if (state->pindexLastCommonBlock == nullptr) {
14011410
// Bootstrap quickly by guessing a parent of our best tip is the forking point.
14021411
// Guessing wrong in either direction is not a problem.

0 commit comments

Comments
 (0)