Skip to content

Commit

Permalink
p2p: For assumeutxo, download snapshot chain before background chain
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mzumsande committed Feb 29, 2024
1 parent 9057598 commit ac547ea
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/net_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1397,9 +1397,12 @@ void PeerManagerImpl::FindNextBlocksToDownload(const Peer& peer, unsigned int co
return;
}

if (state->pindexLastCommonBlock == nullptr) {
std::optional<int> snapshot_height{m_chainman.GetSnapshotBaseHeight()};
if (state->pindexLastCommonBlock == nullptr ||
(snapshot_height.has_value() && state->pindexLastCommonBlock->nHeight < snapshot_height.value())) {
// Bootstrap quickly by guessing a parent of our best tip is the forking point.
// Guessing wrong in either direction is not a problem.
// Also applies after loading a snapshot, when we want to prioritise loading the snapshot chain and therefore need to skip ahead.
state->pindexLastCommonBlock = m_chainman.ActiveChain()[std::min(state->pindexBestKnownBlock->nHeight, m_chainman.ActiveChain().Height())];
}

Expand Down

0 comments on commit ac547ea

Please sign in to comment.