make sure header PMMR is init correctly based on header_head from db #3362
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.
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
andmainnet
.Tested mining on
usertesting
.@quentinlesceller tested this against
floonet
with stratum miners.