fix(state): Avoids panicking during contextual validation when a parent block is missing #8883
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
We want to avoid panicking when Zebra can't find a parent in its state during contextual validation of a candidate block.
Fixes #8881 (although without fully diagnosing how it was possible).
Solution
Returns a
NotReadyToBeCommitted
error instead of panicking when the relevant chain is emptyFollow-up Work
I'm not completely sure why this was happening in the first place, it may be plausible that because
non_finalized_block_write_sent_hashes()
isn't pruned until after the call tocan_fork_chain_at()
, the missing parent blocks on a side chain were dropped when the block height was finalized. We may want to take another look at it.block_is_valid_for_recent_chain()
definitely needs an update, there's a conditionrelevant_chain.is_empty()
that can never be reached and another test-only condition that is outdated since Zebra can calculate difficulty thresholds with fewer thanPOW_ADJUSTMENT_BLOCK_SPAN
blocks.PR Author's Checklist
PR Reviewer's Checklist