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

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

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 requested a review from quentinlesceller Jun 19, 2020
@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
10 checks passed
10 checks passed
@azure-pipelines
mimblewimble.grin Build #20200620.1 succeeded
Details
@azure-pipelines
mimblewimble.grin (linux api/util/store) linux api/util/store succeeded
Details
@azure-pipelines
mimblewimble.grin (linux chain/core/keychain) linux chain/core/keychain succeeded
Details
@azure-pipelines
mimblewimble.grin (linux pool/p2p/src) linux pool/p2p/src succeeded
Details
@azure-pipelines
mimblewimble.grin (linux release) linux release succeeded
Details
@azure-pipelines
mimblewimble.grin (linux servers) linux servers succeeded
Details
@azure-pipelines
mimblewimble.grin (macos release) macos release succeeded
Details
@azure-pipelines
mimblewimble.grin (macos test) macos test succeeded
Details
@azure-pipelines
mimblewimble.grin (windows release) windows release succeeded
Details
@azure-pipelines
mimblewimble.grin (windows test) windows test succeeded
Details
@antiochp antiochp deleted the antiochp:chain_init_header_head branch Jun 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants