Skip to content

Commit 49d569c

Browse files
committed
p2p: For assumeutxo, download snapshot chain before background chain
After loading a snapshot, pindexLastCommonBlock is usually already set to some block for existing peers. That means we'd continue syncing the background chain from those peers instead of prioritising the snapshot chain, which defeats the purpose of doing assumeutxo in the first place. Only existing peers are affected by this bug.
1 parent 7a88551 commit 49d569c

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/net_processing.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1406,9 +1406,11 @@ void PeerManagerImpl::FindNextBlocksToDownload(const Peer& peer, unsigned int co
14061406
return;
14071407
}
14081408

1409-
if (state->pindexLastCommonBlock == nullptr) {
1410-
// Bootstrap quickly by guessing a parent of our best tip is the forking point.
1411-
// Guessing wrong in either direction is not a problem.
1409+
// Bootstrap quickly by guessing a parent of our best tip is the forking point.
1410+
// Guessing wrong in either direction is not a problem.
1411+
// Also reset pindexLastCommonBlock after a snapshot was loaded, so that blocks after the snapshot will be prioritised for download.
1412+
if (state->pindexLastCommonBlock == nullptr ||
1413+
(snap_base && state->pindexLastCommonBlock->nHeight < snap_base->nHeight)) {
14121414
state->pindexLastCommonBlock = m_chainman.ActiveChain()[std::min(state->pindexBestKnownBlock->nHeight, m_chainman.ActiveChain().Height())];
14131415
}
14141416

0 commit comments

Comments
 (0)