This is part of the assumeutxo project (parent PR: #15606)
This PR includes the necessary changes for indexing to work with the operation of a background validation chainstate. In short, it
- only emits existing ValidationInterface events for the active chain,
- introduces a BackgroundBlockConnected event for the background chain to support indexation, and
- removes assumptions in the indexing framework that indexation will happen sequentially.
More details below.
Adds BackgroundBlockConnected to the validationinterface and uses it in index maintenance. Ensures that index building will work when part of the chain is validated asynchronously in the background by a second chainstate.
This changeset removes the guarantee that indexes will be built sequentially, as none of the current indexes require this and it is no longer easy to offer this guarantee when multiple chainstates are in use.
Within BaseIndex, we only update m_best_block_index
(which is
essentially the progress marker for how far along the indexing process
is) for chains which we can be certain that all blocks under a given
block on that chain have had indexing performed on them. In other
words, we will not update m_best_block_index
during a BlockConnected
event that comes from an active snapshot chain, i.e. a chain for which
some of the blocks underneath Tip() are not indexed.
Once background validation is completed and no background chainstates
are in use, the indexer will happily use BlockConnected events from the
active chain to update m_best_block_index
as usual. No blocks from the
active chainstate will have been missed for indexing (despite not
previously updating m_best_block_index), so it is safe to perform this
transition without any extra behavior.
Some unnecessary logic from BaseIndex::ChainStateFlushed() is removed, since the locator can no longer be assumed to be an ancestor of the best_block_index (since the “best block” may be on a background chainstate and the locator may have come from an assumed-valid tip well ahead of it).