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
Discard child block with parent_hash not matching hash of imported block #1684
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ghost
assigned goodsoft
Mar 29, 2019
ghost
added
the
in progress
label
Mar 29, 2019
goodsoft
force-pushed
the
gs-fix-consensus-loss
branch
2 times, most recently
from
March 29, 2019 15:51
8c52ac5
to
32bae02
Compare
Pull Request Test Coverage Report for Build 2364a84d-8e6d-423f-8ee2-cbbe12f6f4a6
💛 - Coveralls |
goodsoft
added
ready for review
This PR is ready for reviews.
and removed
in progress
labels
Mar 29, 2019
ghost
added
the
in progress
label
Mar 29, 2019
ayrat555
approved these changes
Apr 2, 2019
zachdaniel
approved these changes
Apr 2, 2019
goodsoft
force-pushed
the
gs-fix-consensus-loss
branch
from
April 2, 2019 14:57
f15eff7
to
df6686b
Compare
ghost
added
the
in progress
label
Apr 2, 2019
As a result of #1657 out-of-place parent blocks are marked as non-consensus more reliably, i.e. they will eventually be fetched even if first attempt is unsuccessful. The `ConsensusEnsurer` module, on the contrary, only tried refetching block once, and left it as-is if the refetch failed. Now it is not needed anymore.
Consider a root block `A`, old chain `-- B -- C` and new one `-- B' -- C'`. Due to asynchronous nature of realtime fetcher it is possible for block `B` to be imported _later_ than the entire chain `-- B' -- C'`. In this case we should discard block `C'` and let it be refetched. When that happens, block `B` gets discarded to make sure block `B'` gets eventually fetched and the chain becomes consistent.
Consider a root block `A`, old chain `-- B -- C` and new one `-- B' -- C'`. Due to asynchronous nature of realtime fetcher it is possible for block `B` to be imported _later_ than the entire chain `-- B' -- C'`. In this case we should discard block `C'` and let it be refetched. When that happens, block `B` gets discarded to make sure block `B'` gets eventually fetched and the chain becomes consistent.
This worker only handled one of invalid consensus cases, i.e. when a parent block lost consensus, but the child one didn't. Even then it worked only when all blocks are reliably and sequentially imported (certainly not our case), and only once on indexer launch. Now this particular case is covered by previous commit, and we don't need this worker at all.
goodsoft
force-pushed
the
gs-fix-consensus-loss
branch
from
April 2, 2019 18:14
df6686b
to
0e15873
Compare
ghost
removed
the
in progress
label
Apr 2, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Motivation
Consider a root block
A
, old chain-- B -- C
and new one-- B' -- C'
. Due to asynchronous nature of realtime fetcher it is possible for blockB
to be imported later than the entire chain-- B' -- C'
.In this case we should discard block
C'
and let it be refetched. When that happens, blockB
gets discarded to make sure blockB'
gets eventually fetched and the chain becomes consistent.Even though it may cause multiple refetches of the same blocks, it eventually forces the chain to be consistent despite asynchronous or failing imports.
Changelog
ConsensusEnsurer
module from indexer, as forcing consensus loss is more reliable and doesn't leave us with inconsistent chain if refetch fails.InvalidConsensus
worker from indexer, as it only handled one corner case in ideal conditions, and only ran once on launch.Upgrading
As new inconsistent blocks could have appeared due to the possibility of race conditions described above, running
priv/repo/migrations/scripts/20190326202921_lose_consensus_for_invalid_blocks.sql
is highly recommended after deploying this fix.