fix: BlockSource check for pending block (#14112)

This commit is contained in:
maze
2025-01-31 01:26:51 -08:00
committed by GitHub
parent 4ce5a60c58
commit bd5dde54ef

View File

@ -796,22 +796,26 @@ impl<N: ProviderNodeTypes> BlockReader for ConsistentProvider<N> {
hash: B256,
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
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<Option<Self::Block>> {