simplify when block_sums and spent_index are added to the db #3253
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.
Store
spent_index
when callingapply_block()
andblock_sums
when callingverify_block_sums()
.This lets us simplify
process_block
andadd_block
and makes it a little clearer when/where these are added to the db (via the current batch). We do not need to pass the data around and return it from various fns.Conceptually we have 2 (nested) places where we commit data to the db -
We do this via a child batch - this child batch includes the update to chain head, indices etc. and is rolled back along with the MMR changes if the block does not increase total work.
We apply everything transactionally (db + MMRs via txhashset extension) then discard this transaction.
The outer db transaction is then committed to commit the block itself to the db (unless validation failed or other error).
This PR moves the block_sums and spent_index into the child batch. This is safe to do we rebuild both for all blocks along a fork being processed. And we only make assumptions about them being present in the db for the main chain itself.