aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAva Chow <github@achow101.com>2024-08-09 17:42:39 -0400
committerAva Chow <github@achow101.com>2024-08-09 17:42:39 -0400
commitc2d15d993ef06d97d4c117012bda6efa3dcbac45 (patch)
tree80d753168c382d3b1d610e3eaf21b9720dc61dea
parent9a696397e736e109ba0de213967431e2bb9f4102 (diff)
parent49d569cb1fdd62a9da8dff51dccaf4680fe3d0eb (diff)
Merge bitcoin/bitcoin#29519: p2p: For assumeutxo, download snapshot chain before background chain
49d569cb1fdd62a9da8dff51dccaf4680fe3d0eb p2p: For assumeutxo, download snapshot chain before background chain (Martin Zumsande) 7a885518d57c6eb818ebef5fd04a575f324ee8b2 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 49d569cb1fdd62a9da8dff51dccaf4680fe3d0eb achow101: ACK 49d569cb1fdd62a9da8dff51dccaf4680fe3d0eb Sjors: tACK 49d569cb1fdd62a9da8dff51dccaf4680fe3d0eb Tree-SHA512: 0eaebe1c29a8510d5ced57e14c09b128ccb34b491692815291df68bf12e2a15b52b1e7bf8d9f34808904e7f7bc20f70b0ad0f7e14df93bbdf456bd12cc02a5d2
-rw-r--r--src/net_processing.cpp17
1 files changed, 14 insertions, 3 deletions
diff --git a/src/net_processing.cpp b/src/net_processing.cpp
index bf2c42548e..13ea3a29be 100644
--- a/src/net_processing.cpp
+++ b/src/net_processing.cpp
@@ -1518,9 +1518,20 @@ void PeerManagerImpl::FindNextBlocksToDownload(const Peer& peer, unsigned int co
return;
}
- if (state->pindexLastCommonBlock == nullptr) {
- // Bootstrap quickly by guessing a parent of our best tip is the forking point.
- // Guessing wrong in either direction is not a problem.
+ // When we sync with AssumeUtxo and discover the snapshot is not in the peer's best chain, abort:
+ // We can't reorg to this chain due to missing undo data until the background sync has finished,
+ // so downloading blocks from it would be futile.
+ const CBlockIndex* snap_base{m_chainman.GetSnapshotBaseBlock()};
+ if (snap_base && state->pindexBestKnownBlock->GetAncestor(snap_base->nHeight) != snap_base) {
+ LogDebug(BCLog::NET, "Not downloading blocks from peer=%d, which doesn't have the snapshot block in its best chain.\n", peer.m_id);
+ return;
+ }
+
+ // Bootstrap quickly by guessing a parent of our best tip is the forking point.
+ // Guessing wrong in either direction is not a problem.
+ // Also reset pindexLastCommonBlock after a snapshot was loaded, so that blocks after the snapshot will be prioritised for download.
+ if (state->pindexLastCommonBlock == nullptr ||
+ (snap_base && state->pindexLastCommonBlock->nHeight < snap_base->nHeight)) {
state->pindexLastCommonBlock = m_chainman.ActiveChain()[std::min(state->pindexBestKnownBlock->nHeight, m_chainman.ActiveChain().Height())];
}