After PruneBlockIndexCandidates()
is called, the candidate set must include the current chain tip or a successor of it.
PruneBlockIndexCandidates()
removes candidates with less work than the active tip. However, because the tip itself is never added to setBlockIndexCandidates
via TryAddBlockIndexCandidate()
, it may be absent from the set. Prior to this patch, if all lower-work candidates were pruned and the tip was not present, setBlockIndexCandidates
could become empty—violating an invariant relied upon by FindMostWorkChain()
.
This patch ensures that PruneBlockIndexCandidates()
explicitly reinserts the current tip after pruning, preserving that invariant.
Fixes #33129