ZcashFoundation / zebra

Zcash - Financial Privacy in Rust 🦓
https://zfnd.org/zebra/
Apache License 2.0
413 stars 106 forks source link

fix(state): Avoids panicking during contextual validation when a parent block is missing #8883

Closed arya2 closed 1 month ago

arya2 commented 1 month ago

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 empty

Follow-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 to can_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 condition relevant_chain.is_empty() that can never be reached and another test-only condition that is outdated since Zebra can calculate difficulty thresholds with fewer than POW_ADJUSTMENT_BLOCK_SPAN blocks.

PR Author's Checklist

PR Reviewer's Checklist