execution: more accurate bad block responses #16994
Merged
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.
fixes #16973
The problem is that in the fork validator we always return
consensus.ErrInvalidBlockwhen running the sync loop viaStateStepfails:We already correctly mark the blocks as invalid (when they are indeed invalid) and always unwind with a
BadBlockUnwindReason in those situations.So we can make use of that and simply pass up the
consensus.ErrInvalidBlockfrom theBadBlockUnwindReason up to the caller of the sync loopRunandRunNoInteruptfunctions. This way when we call Run from a fork choice update it can returnconsensus.ErrInvalidBlockcorrectly. Note that for the fork choice update code path we do not return an err from the sync loop run when we hit a bad block (we only unwind with a bad block reason) - because we run it withbadBlockHalt: false.For the
StateStepflow - it runs the execution loop withbadBlockHalt: true. That code path always returns the err so we need to make sure that all relevant error paths returnErrInvalidBlockwhen they should - then we can get rid of the the logic that always doeserrors.Join(consensus.ErrInvalidBlock, err)return for every error fromStateStep.Other parts (inside
StateStep) that returnconsensus.ErrInvalidBlockare:engine.VerifyHeader(inaddAndVerifyBlockStep) - as expectedengine.VerifyUncles(inaddAndVerifyBlockStep) - as expectedAll other errors returned are operational errors and not
consensus.ErrInvalidBlockerrors.