Closes #8050
If we discover an invalid block on a blockchain branch with otherwise valid headers, all the child headers can be marked as INVALID_CHILD. When invalidating mainchain blocks we can easily mark all the invalid children but on a headers-only branch we just stop on the invalid block and search for the next best tip and branch to validate. On restart, during LoadBlockIndex()
we iterate through all the headers we know about sorted by height, and that is when we normally mark these child-headers of invalid ancestors with INVALID_CHILD
.
Issue #8050 illustrates a discrepancy where a headers-only branch is not marked as invalid until the node is restarted. What we do in this PR is check for invalid ancestors while we are scanning the block index for chain tips during rpc getchaintips
itself.
I had to remove a bunch of const
qualifiers from getchaintips
which makes me think that modifying the block index during an RPC is just bad separation of concerns – but it is a solution!