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

cleanup rebuild sync MMR logic #3001

Closed
wants to merge 2 commits into from

Conversation

antiochp
Copy link
Member

@antiochp antiochp commented Aug 26, 2019

This PR cleans up (and optimizes) how we rebuild the sync MMR during node startup.

We do not need to truncate the sync MMR and rebuild it from the genesis header, we can simply "rewind and apply header fork" based on current sync MMR state and the current head of the header chain. In the common case we will not need to rewind any headers and we can simply "fast forward" the recent headers to allow the sync MMR to catch up to the header MMR.

This saves a significant amount of time when starting a node up if shutdown overnight for example.
Rebuilding a sync MMR from scratch was taking 5s or so on a reasonably fast laptop.

As part of this we have now made the "reset head" logic more explicit, passing in the new head updating as necessary.

This PR also cleans up and simplifies how we apply headers to the MMR when processing, either as part of sync or when processing "header first". This makes processing new headers and processing headers from the local db as part of a fork more consistent.

Previous behavior -

  • rewind MMR to fork point if necessary
  • apply headers to MMR up to and including previous header
  • apply new header to MMR
  • validate and store new header in the db

Simplified behavior -

  • validate and store new header in the db
  • rewind MMR to fork point if necessary
  • apply headers to MMR up to and including new header

@antiochp
Copy link
Member Author

Closing as this is rolled up in #3004

@antiochp antiochp closed this Aug 27, 2019
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.

1 participant