Merge bitcoin/bitcoin#34786: validation: do not add the snapshot to candidates set of the background chainstate

69baddc910 validation: do not add the snapshot block to candidates of bg chainstate (Martin Zumsande)

Pull request description:

  The snapshot block needs to be added to the candidates set of the assumed-valid chain because it will be the tip of that chainstate right after snapshot activation.

  However, adding it also to the background chainstate is not necessary for anything. Before, the index would be in the set without being connectable. It will be eventually added to the set as part of the normal block download - no extra logic is necessary here.

  This simplifies a unit test which had a comment that having the block in the set is "not intended".
  This was suggested [here](https://github.com/bitcoin/bitcoin/pull/34521#discussion_r2849281299) and [here](https://github.com/bitcoin/bitcoin/pull/34521#discussion_r2883024248) in #34521

  Note that adding the snapshot block was harmless, since `FindMostWorkChain()` lazily removes blocks without data from the set, so this does not fix a bug but just simplifies some code.

ACKs for top commit:
  achow101:
    ACK 69baddc910
  Bortlesboat:
    Concept ACK 69baddc910. Removing `TargetBlock()` correctly limits the snapshot-block special-case to cs2 where it's actually needed — the test's own "not intended" comment was the tell.
  sedited:
    ACK 69baddc910
  fjahr:
    ACK 69baddc910
  stratospher:
    ACK 69baddc.

Tree-SHA512: 8942fc422f1898369dd486e37da11758f2ebd4a488d092aa1637ef5bfb85766c4be9ad0718797fb2080f5e8d61383b2ee932bf2bc2f7abc2fb07fe3d72e070c3
This commit is contained in:
Ava Chow
2026-03-24 14:58:05 -07:00
2 changed files with 6 additions and 13 deletions

View File

@@ -4889,7 +4889,7 @@ void Chainstate::PopulateBlockIndexCandidates()
// With assumeutxo, the snapshot block is a candidate for the tip, but it
// may not have BLOCK_VALID_TRANSACTIONS (e.g. if we haven't yet downloaded
// the block), so we special-case it here.
if (pindex == SnapshotBase() || pindex == TargetBlock() ||
if (pindex == SnapshotBase() ||
(pindex->IsValid(BLOCK_VALID_TRANSACTIONS) &&
(pindex->HaveNumChainTxs() || pindex->pprev == nullptr))) {
TryAddBlockIndexCandidate(pindex);