Skip to content

Commit c2d15d9

Browse files
committed
Merge bitcoin#29519: p2p: For assumeutxo, download snapshot chain before background chain
49d569c p2p: For assumeutxo, download snapshot chain before background chain (Martin Zumsande) 7a88551 p2p: Restrict downloading of blocks for snapshot chain (Martin Zumsande) Pull request description: 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. ACKs for top commit: fjahr: re-ACK 49d569c achow101: ACK 49d569c Sjors: tACK 49d569c Tree-SHA512: 0eaebe1c29a8510d5ced57e14c09b128ccb34b491692815291df68bf12e2a15b52b1e7bf8d9f34808904e7f7bc20f70b0ad0f7e14df93bbdf456bd12cc02a5d2
2 parents 9a69639 + 49d569c commit c2d15d9

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/net_processing.cpp

+14-3
Original file line numberDiff line numberDiff line change
@@ -1518,9 +1518,20 @@ void PeerManagerImpl::FindNextBlocksToDownload(const Peer& peer, unsigned int co
15181518
return;
15191519
}
15201520

1521-
if (state->pindexLastCommonBlock == nullptr) {
1522-
// Bootstrap quickly by guessing a parent of our best tip is the forking point.
1523-
// Guessing wrong in either direction is not a problem.
1521+
// When we sync with AssumeUtxo and discover the snapshot is not in the peer's best chain, abort:
1522+
// We can't reorg to this chain due to missing undo data until the background sync has finished,
1523+
// so downloading blocks from it would be futile.
1524+
const CBlockIndex* snap_base{m_chainman.GetSnapshotBaseBlock()};
1525+
if (snap_base && state->pindexBestKnownBlock->GetAncestor(snap_base->nHeight) != snap_base) {
1526+
LogDebug(BCLog::NET, "Not downloading blocks from peer=%d, which doesn't have the snapshot block in its best chain.\n", peer.m_id);
1527+
return;
1528+
}
1529+
1530+
// Bootstrap quickly by guessing a parent of our best tip is the forking point.
1531+
// Guessing wrong in either direction is not a problem.
1532+
// Also reset pindexLastCommonBlock after a snapshot was loaded, so that blocks after the snapshot will be prioritised for download.
1533+
if (state->pindexLastCommonBlock == nullptr ||
1534+
(snap_base && state->pindexLastCommonBlock->nHeight < snap_base->nHeight)) {
15241535
state->pindexLastCommonBlock = m_chainman.ActiveChain()[std::min(state->pindexBestKnownBlock->nHeight, m_chainman.ActiveChain().Height())];
15251536
}
15261537

0 commit comments

Comments
 (0)