core: add Indexer interface and index server logic (WIP) #32292
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR implements the new indexer interface (
core.Indexer
) that greatly simplifies the implementation of chain indexers. The serving mechanism is integrated intocore.BlockChain
which makes it possible to guarantee that a chain index always stays in sync with the canonical chain. New heads are always delivered before chain events are sent, ensuring that any consumer of these events can also rely on the chain index being in sync. Required historic chain sections are delivered asynchronously on demand. It is always guaranteed that any delivered blocks(including historic ones) are part of the canonical chain ending with the latest delivered/reverted head.Note that the interface currently only delivers headers and receipts which are required by the log indexer. If we want to make it more general purpose then we should somehow make it configurable (delivering full blocks and receipts could be optional).
Also note that the PR also adds two new features to
core.BlockChain
that I wanted to add for a very long time:GetReceipts(hash common.Hash, number uint64) types.Receipts
which saves an unnecessary hash -> number lookup (an expensive random db read).GetCanonicalHashes(numbers []uint64) ([]common.Hash, error)
which reads multiple canonical hashes under thechainMu
mutex lock, guaranteeing that they are consistent with each other.