From bd5dde54ef586ad23fcf431976536aed347aed2f Mon Sep 17 00:00:00 2001 From: maze Date: Fri, 31 Jan 2025 01:26:51 -0800 Subject: [PATCH] fix: `BlockSource` check for pending block (#14112) --- .../provider/src/providers/consistent.rs | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/crates/storage/provider/src/providers/consistent.rs b/crates/storage/provider/src/providers/consistent.rs index a94a3cc51..901e3f785 100644 --- a/crates/storage/provider/src/providers/consistent.rs +++ b/crates/storage/provider/src/providers/consistent.rs @@ -796,22 +796,26 @@ impl BlockReader for ConsistentProvider { hash: B256, source: BlockSource, ) -> ProviderResult> { - 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 + if matches!(source, BlockSource::Canonical | BlockSource::Any) { + return 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())), + ) + } + + if matches!(source, BlockSource::Pending | BlockSource::Any) { + if let Some(block) = self .canonical_in_memory_state .pending_block() - .filter(|block| block.hash() == hash) - .map(|block| block.into_block())), + .filter(|b| b.hash() == hash) + .map(|b| b.into_block()) + { + return Ok(Some(block)) + } } + + Ok(None) } fn block(&self, id: BlockHashOrNumber) -> ProviderResult> {