Skip to content

make sure header PMMR is init correctly based on header_head from db #3362

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

Merged
merged 3 commits into from
Jun 22, 2020

Conversation

antiochp
Copy link
Member

@antiochp antiochp commented Jun 19, 2020

We had logic in chain init to make sure header_head was consistent with the header PMMR (in the case where it was missing from the db after migration to 3.x.x).

This PR adds logic to ensure the inverse of this - that the header PMMR is consistent with header_head from the db in the case where the header PMMR contains unwanted rightmost data.
The PMMR is append-only and there may be headers appended that we want to discard.
The header_head in the db is our "source of truth".

We simply (re)set the PMMR handle last_pos to discard data to the right.
Then we can safely "rewind" the header PMMR to the pos corresponding header_head from db.


Also tweaked the order of operations slightly when processing block headers.
We now validate the header before applying it to our header PMMR (to validate the roots).
Otherwise we potentially leave the header PMMR in a bad state if the roots are valid but the header ends up being invalid for some other reason.
This is likely the reason why a node gets into a bad state. We can now recover from this on startup but we want to avoid it happening in the first place.


Tested with sync (and staying in sync) on both floonet and mainnet.
Tested mining on usertesting.
@quentinlesceller tested this against floonet with stratum miners.

@antiochp antiochp added this to the 4.0.0 milestone Jun 19, 2020
and avoid applying header to header PMMR before validation
as this potentially leaves the PMMR in a tricky state to rewind from
@quentinlesceller quentinlesceller merged commit 20b4500 into mimblewimble:master Jun 22, 2020
@antiochp antiochp deleted the chain_init_header_head branch June 22, 2020 21:43
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