From 4c040252d7f9ccac103f95b589d01e8f8db0f67a Mon Sep 17 00:00:00 2001 From: Arya Date: Fri, 20 Sep 2024 01:54:05 -0400 Subject: [PATCH] Returns an error instead of panicking when the relevant chain is empty --- zebra-state/src/service/check.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/zebra-state/src/service/check.rs b/zebra-state/src/service/check.rs index b20ca0fd4c5..ced63bfea16 100644 --- a/zebra-state/src/service/check.rs +++ b/zebra-state/src/service/check.rs @@ -67,9 +67,16 @@ where .take(POW_ADJUSTMENT_BLOCK_SPAN) .collect(); - let parent_block = relevant_chain - .first() - .expect("state must contain parent block to do contextual validation"); + let Some(parent_block) = relevant_chain.first() else { + warn!( + ?semantically_verified, + ?finalized_tip_height, + "state must contain parent block to do contextual validation" + ); + + return Err(ValidateContextError::NotReadyToBeCommitted); + }; + let parent_block = parent_block.borrow(); let parent_height = parent_block .coinbase_height()