Skip to content

Commit

Permalink
fix: BlockSource check for pending block
Browse files Browse the repository at this point in the history
  • Loading branch information
0xMaze committed Jan 30, 2025
1 parent d3cec5a commit 5caaf29
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions crates/storage/provider/src/providers/consistent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -797,20 +797,32 @@ impl<N: ProviderNodeTypes> BlockReader for ConsistentProvider<N> {
source: BlockSource,
) -> ProviderResult<Option<Self::Block>> {
match source {
BlockSource::Any | BlockSource::Canonical => {
// Note: it's fine to return the unsealed block because the caller already has
// the hash
self.get_in_memory_or_storage_by_block(
hash.into(),
|db_provider| db_provider.find_block_by_hash(hash, source),
|block_state| Ok(Some(block_state.block_ref().recovered_block().clone_block())),
)
}
BlockSource::Pending => Ok(self
.canonical_in_memory_state
.pending_block()
.filter(|block| block.hash() == hash)
.map(|block| block.into_block())),
BlockSource::Canonical => self.get_in_memory_or_storage_by_block(
hash.into(),
|db_provider| db_provider.find_block_by_hash(hash, source),
|block_state| Ok(Some(block_state.block_ref().recovered_block().clone_block())),
),
BlockSource::Any => {
if let Some(block) = self
.canonical_in_memory_state
.pending_block()
.filter(|block| block.hash() == hash)
.map(|block| block.into_block())
{
return Ok(Some(block));
}

self.get_in_memory_or_storage_by_block(
hash.into(),
|db_provider| db_provider.find_block_by_hash(hash, BlockSource::Canonical),
|block_state| Ok(Some(block_state.block_ref().recovered_block().clone_block())),
)
}
}
}

Expand Down

0 comments on commit 5caaf29

Please sign in to comment.