From fd392ba0b90a1fe16311782b0a2ef74e411b77ec Mon Sep 17 00:00:00 2001 From: Roman Krasiuk Date: Tue, 14 Nov 2023 11:31:24 -0800 Subject: [PATCH] chore: decriptive panic on non-existing block indices (#5425) --- .../src/bundle_state/bundle_state_with_receipts.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/crates/storage/provider/src/bundle_state/bundle_state_with_receipts.rs b/crates/storage/provider/src/bundle_state/bundle_state_with_receipts.rs index dba187adae..c1ee9b65f4 100644 --- a/crates/storage/provider/src/bundle_state/bundle_state_with_receipts.rs +++ b/crates/storage/provider/src/bundle_state/bundle_state_with_receipts.rs @@ -337,9 +337,12 @@ impl BundleStateWithReceipts { for (idx, receipts) in self.receipts.into_iter().enumerate() { if !receipts.is_empty() { - let (_, body_indices) = bodies_cursor - .seek_exact(self.first_block + idx as u64)? - .expect("body indices exist"); + let block_number = self.first_block + idx as u64; + let (_, body_indices) = + bodies_cursor.seek_exact(block_number)?.unwrap_or_else(|| { + let last_available = bodies_cursor.last().ok().flatten().map(|(number, _)| number); + panic!("body indices for block {block_number} must exist. last available block number: {last_available:?}"); + }); let first_tx_index = body_indices.first_tx_num(); for (tx_idx, receipt) in receipts.into_iter().enumerate() {