refactor: Add ChainstateManager::CurrentChainstate() method

CurrentChainstate() is basically the same as ActiveChainstate() except it
requires cs_main to be locked when it is called, instead of locking cs_main
internally.

The name "current" should also be less confusing than "active" because multiple
chainstates can be active, and CurrentChainstate() returns the chainstate
targeting the current network tip, regardless of what chainstates are being
downloaded or how they are used.
This commit is contained in:
Ryan Ofsky
2024-05-30 12:03:47 -04:00
parent a9b7f5614c
commit a229cb9477
4 changed files with 20 additions and 18 deletions

View File

@@ -1387,7 +1387,7 @@ void PeerManagerImpl::FindNextBlocksToDownload(const Peer& peer, unsigned int co
// 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()};
const CBlockIndex* snap_base{m_chainman.CurrentChainstate().SnapshotBase()};
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;