Skip to content

Commit

Permalink
fix: don't unwrap missing requests (paradigmxyz#11646)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse authored and ebo committed Oct 14, 2024
1 parent f9ac5e5 commit a336efd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
10 changes: 10 additions & 0 deletions crates/storage/codecs/src/alloy/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,14 @@ mod tests {
let len = header.to_compact(&mut encoded_header);
assert_eq!(header, Header::from_compact(&encoded_header, len).0);
}

#[test]
fn test_extra_fields_missing() {
let mut header = HOLESKY_BLOCK;
header.extra_fields = None;

let mut encoded_header = vec![];
let len = header.to_compact(&mut encoded_header);
assert_eq!(header, Header::from_compact(&encoded_header, len).0);
}
}
12 changes: 4 additions & 8 deletions crates/storage/provider/src/providers/database/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2151,10 +2151,8 @@ impl<TX: DbTx, Spec: Send + Sync + EthereumHardforks> RequestsProvider
) -> ProviderResult<Option<Requests>> {
if self.chain_spec.is_prague_active_at_timestamp(timestamp) {
if let Some(number) = self.convert_hash_or_number(id)? {
// If we are past Prague, then all blocks should have a requests list, even if
// empty
let requests = self.tx.get::<tables::BlockRequests>(number)?.unwrap_or_default();
return Ok(Some(requests))
let requests = self.tx.get::<tables::BlockRequests>(number)?;
return Ok(requests)
}
}
Ok(None)
Expand Down Expand Up @@ -3483,10 +3481,8 @@ impl<TX: DbTxMut + DbTx + 'static, Spec: Send + Sync + EthereumHardforks + 'stat
}

if let Some(requests) = block.block.body.requests {
if !requests.0.is_empty() {
self.tx.put::<tables::BlockRequests>(block_number, requests)?;
durations_recorder.record_relative(metrics::Action::InsertBlockRequests);
}
self.tx.put::<tables::BlockRequests>(block_number, requests)?;
durations_recorder.record_relative(metrics::Action::InsertBlockRequests);
}

let block_indices = StoredBlockBodyIndices { first_tx_num, tx_count };
Expand Down

0 comments on commit a336efd

Please sign in to comment.