blockchain: Cache tip and parent at init. #1100
Merged
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 modifies the startup logic to cache the tip and parent blocks in the main chain block cache at initialization time which is desirable because all of the transactions which come in to the mempool need access to the these blocks to construct their utxo views due to the potential for invalidation of the outputs in the previous block through voting.
Without caching them, the blocks end up being loaded from the database again every time a new transaction enters the mempool until the blocks eventually get cached when a new block is connected which is majorly inefficient.