check_known now takes total_difficulty into consideration #3298
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.
During block processing we
check_known
and halt processing if the block is "already known".This avoids wasting resources reprocessing blocks from the network.
We treat a block as known if it matches the current chain head (reprocessing a recent block) or if the full block already exists in the local db (reprocessing a historical block).
With the work on "checkpoints" in #3266 there is another case to consider - one of "future blocks". If the chain head is reset or reverted to an earlier block (for any reason) the current block processing refuses to (re)process blocks that are "already known".
We can get into tricky situations where the chain head will refuse to progress because we incorrectly believe a block is "known" yet not actually on the current chain.
This PR makes
check_known
taketotal_difficulty
into account when comparing blocks against current chain head. If the block would increase total difficulty then we want to treat it as "unknown" regardless of local db.This makes is significantly easier to reset the chain head and still have block processing pipeline work correctly for reprocessing subsequent blocks.
Note: This only applies in situations where the chain head is explicitly reset. Under normal block processing the chain head only ever progresses in one direction, with total difficulty strictly increasing.
Added test coverage to demonstrate "forgetting" about an "already known" block, based on total difficulty relative to chain head.