Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simplify when block_sums and spent_index are added to the db #3253

Merged
merged 3 commits into from
Mar 10, 2020

Conversation

antiochp
Copy link
Member

@antiochp antiochp commented Feb 28, 2020

Store spent_index when calling apply_block() and block_sums when calling verify_block_sums().

This lets us simplify process_block and add_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 -

  1. We commit the block itself to the db if we process the block successfully (fork or otherwise)
  2. We only commit the following data iff this block also increases total work -
    • chain head
    • various index entries

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.

@antiochp antiochp force-pushed the simplify_block_saving branch from 4394bd0 to c71bc03 Compare March 2, 2020 17:50
@antiochp antiochp marked this pull request as ready for review March 2, 2020 17:57
@antiochp antiochp changed the title [DNM] simplify when block_sums and spent_index are added to the db simplify when block_sums and spent_index are added to the db Mar 2, 2020
Copy link
Contributor

@jaspervdm jaspervdm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still relatively new to this part of the code so it took me a bit but I've convinced myself this is correct, so 👍. Just 1 small suggestion

chain/src/pipe.rs Outdated Show resolved Hide resolved
@antiochp
Copy link
Member Author

Related - #3267 (in terms of the outer and child lmdb transactions).

@antiochp antiochp force-pushed the simplify_block_saving branch from aabc01b to c4af801 Compare March 10, 2020 14:14
@antiochp antiochp merged commit 3bbf60e into mimblewimble:master Mar 10, 2020
@antiochp antiochp deleted the simplify_block_saving branch March 10, 2020 14:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants