From 6e21438b01b6c0b2af23b85fbe3a22ca5994d756 Mon Sep 17 00:00:00 2001 From: joshieDo <93316087+joshieDo@users.noreply.github.com> Date: Tue, 1 Oct 2024 16:03:35 +0100 Subject: [PATCH 1/9] add get_in_memory_or_storage_by_block --- .../src/providers/blockchain_provider.rs | 198 +++++++++--------- 1 file changed, 98 insertions(+), 100 deletions(-) diff --git a/crates/storage/provider/src/providers/blockchain_provider.rs b/crates/storage/provider/src/providers/blockchain_provider.rs index 7e375daba942..a5fdc231a8a0 100644 --- a/crates/storage/provider/src/providers/blockchain_provider.rs +++ b/crates/storage/provider/src/providers/blockchain_provider.rs @@ -7,7 +7,7 @@ use crate::{ RequestsProvider, StageCheckpointReader, StateProviderBox, StateProviderFactory, StateReader, StaticFileProviderFactory, TransactionVariant, TransactionsProvider, WithdrawalsProvider, }; -use alloy_eips::{BlockHashOrNumber, BlockId, BlockNumHash, BlockNumberOrTag}; +use alloy_eips::{BlockHashOrNumber, BlockId, BlockNumHash, BlockNumberOrTag, HashOrNumber}; use alloy_primitives::{Address, BlockHash, BlockNumber, Sealable, TxHash, TxNumber, B256, U256}; use alloy_rpc_types_engine::ForkchoiceState; use reth_chain_state::{ @@ -294,6 +294,32 @@ impl BlockchainProvider2 { Ok(None) } + + /// Fetches data from either in-memory state or storage by [`BlockHashOrNumber`]. + fn get_in_memory_or_storage_by_block( + &self, + id: BlockHashOrNumber, + fetch_from_db: S, + fetch_from_block_state: M, + ) -> ProviderResult> + where + S: FnOnce(DatabaseProviderRO) -> ProviderResult>, + M: Fn(Arc) -> ProviderResult>, + { + let block_state = match id { + BlockHashOrNumber::Hash(block_hash) => { + self.canonical_in_memory_state.state_by_hash(block_hash) + } + BlockHashOrNumber::Number(block_number) => { + self.canonical_in_memory_state.state_by_number(block_number) + } + }; + + if let Some(block_state) = block_state { + return fetch_from_block_state(block_state) + } + fetch_from_db(self.database_provider_ro()?) + } } impl BlockchainProvider2 { @@ -390,11 +416,11 @@ impl HeaderProvider for BlockchainProvider2 { } fn sealed_header(&self, number: BlockNumber) -> ProviderResult> { - if let Some(block_state) = self.canonical_in_memory_state.state_by_number(number) { - return Ok(Some(block_state.block().block().header.clone())); - } - - self.database.sealed_header(number) + self.get_in_memory_or_storage_by_block( + number.into(), + |db_provider| db_provider.sealed_header(number), + |block_state| Ok(Some(block_state.block().block().header.clone())), + ) } fn sealed_headers_range( @@ -427,11 +453,11 @@ impl HeaderProvider for BlockchainProvider2 { impl BlockHashReader for BlockchainProvider2 { fn block_hash(&self, number: u64) -> ProviderResult> { - if let Some(block_state) = self.canonical_in_memory_state.state_by_number(number) { - return Ok(Some(block_state.hash())); - } - - self.database.block_hash(number) + self.get_in_memory_or_storage_by_block( + number.into(), + |db_provider| db_provider.block_hash(number), + |block_state| Ok(Some(block_state.hash())), + ) } fn canonical_hashes_range( @@ -465,11 +491,11 @@ impl BlockNumReader for BlockchainProvider2 { } fn block_number(&self, hash: B256) -> ProviderResult> { - if let Some(block_state) = self.canonical_in_memory_state.state_by_hash(hash) { - return Ok(Some(block_state.number())); - } - - self.database.block_number(hash) + self.get_in_memory_or_storage_by_block( + hash.into(), + |db_provider| db_provider.block_number(hash), + |block_state| Ok(Some(block_state.number())), + ) } } @@ -491,13 +517,13 @@ impl BlockReader for BlockchainProvider2 { fn find_block_by_hash(&self, hash: B256, source: BlockSource) -> ProviderResult> { match source { BlockSource::Any | BlockSource::Canonical => { - // check in memory first // Note: it's fine to return the unsealed block because the caller already has // the hash - if let Some(block_state) = self.canonical_in_memory_state.state_by_hash(hash) { - return Ok(Some(block_state.block().block().clone().unseal())); - } - self.database.find_block_by_hash(hash, source) + 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().block().clone().unseal())), + ) } BlockSource::Pending => { Ok(self.canonical_in_memory_state.pending_block().map(|block| block.unseal())) @@ -508,12 +534,11 @@ impl BlockReader for BlockchainProvider2 { fn block(&self, id: BlockHashOrNumber) -> ProviderResult> { match id { BlockHashOrNumber::Hash(hash) => self.find_block_by_hash(hash, BlockSource::Any), - BlockHashOrNumber::Number(num) => { - if let Some(block_state) = self.canonical_in_memory_state.state_by_number(num) { - return Ok(Some(block_state.block().block().clone().unseal())); - } - self.database.block_by_number(num) - } + BlockHashOrNumber::Number(num) => self.get_in_memory_or_storage_by_block( + num.into(), + |db_provider| db_provider.block_by_number(num), + |block_state| Ok(Some(block_state.block().block().clone().unseal())), + ), } } @@ -538,11 +563,11 @@ impl BlockReader for BlockchainProvider2 { return Ok(Some(Vec::new())); } - // Check in-memory state first - self.canonical_in_memory_state - .state_by_number(number) - .map(|o| o.block().block().body.ommers.clone()) - .map_or_else(|| self.database.ommers(id), |ommers| Ok(Some(ommers))) + self.get_in_memory_or_storage_by_block( + id, + |db_provider| db_provider.ommers(id), + |block_state| Ok(Some(block_state.block().block().body.ommers.clone())), + ) } None => self.database.ommers(id), } @@ -593,23 +618,15 @@ impl BlockReader for BlockchainProvider2 { id: BlockHashOrNumber, transaction_kind: TransactionVariant, ) -> ProviderResult> { - match id { - BlockHashOrNumber::Hash(hash) => { - if let Some(block_state) = self.canonical_in_memory_state.state_by_hash(hash) { - let block = block_state.block().block().clone(); - let senders = block_state.block().senders().clone(); - return Ok(Some(BlockWithSenders { block: block.unseal(), senders })); - } - } - BlockHashOrNumber::Number(num) => { - if let Some(block_state) = self.canonical_in_memory_state.state_by_number(num) { - let block = block_state.block().block().clone(); - let senders = block_state.block().senders().clone(); - return Ok(Some(BlockWithSenders { block: block.unseal(), senders })); - } - } - } - self.database.block_with_senders(id, transaction_kind) + self.get_in_memory_or_storage_by_block( + id, + |db_provider| db_provider.block_with_senders(id, transaction_kind), + |block_state| { + let block = block_state.block().block().clone(); + let senders = block_state.block().senders().clone(); + Ok(Some(BlockWithSenders { block: block.unseal(), senders })) + }, + ) } fn sealed_block_with_senders( @@ -617,23 +634,15 @@ impl BlockReader for BlockchainProvider2 { id: BlockHashOrNumber, transaction_kind: TransactionVariant, ) -> ProviderResult> { - match id { - BlockHashOrNumber::Hash(hash) => { - if let Some(block_state) = self.canonical_in_memory_state.state_by_hash(hash) { - let block = block_state.block().block().clone(); - let senders = block_state.block().senders().clone(); - return Ok(Some(SealedBlockWithSenders { block, senders })); - } - } - BlockHashOrNumber::Number(num) => { - if let Some(block_state) = self.canonical_in_memory_state.state_by_number(num) { - let block = block_state.block().block().clone(); - let senders = block_state.block().senders().clone(); - return Ok(Some(SealedBlockWithSenders { block, senders })); - } - } - } - self.database.sealed_block_with_senders(id, transaction_kind) + self.get_in_memory_or_storage_by_block( + id, + |db_provider| db_provider.sealed_block_with_senders(id, transaction_kind), + |block_state| { + let block = block_state.block().block().clone(); + let senders = block_state.block().senders().clone(); + Ok(Some(SealedBlockWithSenders { block, senders })) + }, + ) } fn block_range(&self, range: RangeInclusive) -> ProviderResult> { @@ -898,20 +907,11 @@ impl ReceiptProvider for BlockchainProvider2 { } fn receipts_by_block(&self, block: BlockHashOrNumber) -> ProviderResult>> { - match block { - BlockHashOrNumber::Hash(hash) => { - if let Some(block_state) = self.canonical_in_memory_state.state_by_hash(hash) { - return Ok(Some(block_state.executed_block_receipts())); - } - } - BlockHashOrNumber::Number(number) => { - if let Some(block_state) = self.canonical_in_memory_state.state_by_number(number) { - return Ok(Some(block_state.executed_block_receipts())); - } - } - } - - self.database.receipts_by_block(block) + self.get_in_memory_or_storage_by_block( + block, + |db_provider| db_provider.receipts_by_block(block), + |block_state| Ok(Some(block_state.executed_block_receipts())), + ) } fn receipts_by_tx_range( @@ -963,25 +963,23 @@ impl WithdrawalsProvider for BlockchainProvider2 { return Ok(None) } - let Some(number) = self.convert_hash_or_number(id)? else { return Ok(None) }; - - if let Some(block) = self.canonical_in_memory_state.state_by_number(number) { - Ok(block.block().block().body.withdrawals.clone()) - } else { - self.database.withdrawals_by_block(id, timestamp) - } + self.get_in_memory_or_storage_by_block( + id, + |db_provider| db_provider.withdrawals_by_block(id, timestamp), + |block_state| Ok(block_state.block().block().body.withdrawals.clone()), + ) } fn latest_withdrawal(&self) -> ProviderResult> { let best_block_num = self.best_block_number()?; - // If the best block is in memory, use that. Otherwise, use the latest withdrawal in the - // database. - if let Some(block) = self.canonical_in_memory_state.state_by_number(best_block_num) { - Ok(block.block().block().body.withdrawals.clone().and_then(|mut w| w.pop())) - } else { - self.database.latest_withdrawal() - } + self.get_in_memory_or_storage_by_block( + best_block_num.into(), + |db_provider| db_provider.latest_withdrawal(), + |block_state| { + Ok(block_state.block().block().body.withdrawals.clone().and_then(|mut w| w.pop())) + }, + ) } } @@ -994,12 +992,12 @@ impl RequestsProvider for BlockchainProvider2 { if !self.database.chain_spec().is_prague_active_at_timestamp(timestamp) { return Ok(None) } - let Some(number) = self.convert_hash_or_number(id)? else { return Ok(None) }; - if let Some(block) = self.canonical_in_memory_state.state_by_number(number) { - Ok(block.block().block().body.requests.clone()) - } else { - self.database.requests_by_block(id, timestamp) - } + + self.get_in_memory_or_storage_by_block( + id, + |db_provider| db_provider.requests_by_block(id, timestamp), + |block_state| Ok(block_state.block().block().body.requests.clone()), + ) } } From 07f7be257d4e697ed18921b653bba8c30190138e Mon Sep 17 00:00:00 2001 From: joshieDo <93316087+joshieDo@users.noreply.github.com> Date: Tue, 1 Oct 2024 16:13:10 +0100 Subject: [PATCH 2/9] rm unused import --- crates/storage/provider/src/providers/blockchain_provider.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/storage/provider/src/providers/blockchain_provider.rs b/crates/storage/provider/src/providers/blockchain_provider.rs index babaff547267..14c435222978 100644 --- a/crates/storage/provider/src/providers/blockchain_provider.rs +++ b/crates/storage/provider/src/providers/blockchain_provider.rs @@ -7,7 +7,7 @@ use crate::{ RequestsProvider, StageCheckpointReader, StateProviderBox, StateProviderFactory, StateReader, StaticFileProviderFactory, TransactionVariant, TransactionsProvider, WithdrawalsProvider, }; -use alloy_eips::{BlockHashOrNumber, BlockId, BlockNumHash, BlockNumberOrTag, HashOrNumber}; +use alloy_eips::{BlockHashOrNumber, BlockId, BlockNumHash, BlockNumberOrTag}; use alloy_primitives::{Address, BlockHash, BlockNumber, Sealable, TxHash, TxNumber, B256, U256}; use alloy_rpc_types_engine::ForkchoiceState; use reth_chain_state::{ From a7c5e8e76798c6959cc13a569f6e83ccf753b59b Mon Sep 17 00:00:00 2001 From: joshieDo <93316087+joshieDo@users.noreply.github.com> Date: Tue, 1 Oct 2024 20:29:03 +0200 Subject: [PATCH 3/9] fix history_by_block_hash --- .../src/providers/blockchain_provider.rs | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/crates/storage/provider/src/providers/blockchain_provider.rs b/crates/storage/provider/src/providers/blockchain_provider.rs index 14c435222978..1bcec0a4bd01 100644 --- a/crates/storage/provider/src/providers/blockchain_provider.rs +++ b/crates/storage/provider/src/providers/blockchain_provider.rs @@ -301,10 +301,10 @@ impl BlockchainProvider2 { id: BlockHashOrNumber, fetch_from_db: S, fetch_from_block_state: M, - ) -> ProviderResult> + ) -> ProviderResult where - S: FnOnce(DatabaseProviderRO) -> ProviderResult>, - M: Fn(Arc) -> ProviderResult>, + S: FnOnce(DatabaseProviderRO) -> ProviderResult, + M: Fn(Arc) -> ProviderResult, { let block_state = match id { BlockHashOrNumber::Hash(block_hash) => { @@ -1112,17 +1112,18 @@ impl StateProviderFactory for BlockchainProvider2 { fn history_by_block_hash(&self, block_hash: BlockHash) -> ProviderResult { trace!(target: "providers::blockchain", ?block_hash, "Getting history by block hash"); - if let Ok(state) = self.database.history_by_block_hash(block_hash) { - // This could be tracked by a block in the database block - Ok(state) - } else if let Some(state) = self.canonical_in_memory_state.state_by_hash(block_hash) { - // ... or this could be tracked by the in memory state - let state_provider = self.block_state_provider(state)?; - Ok(Box::new(state_provider)) - } else { - // if we couldn't find it anywhere, then we should return an error - Err(ProviderError::StateForHashNotFound(block_hash)) - } + + Ok(self.get_in_memory_or_storage_by_block( + block_hash.into(), + |_| { + // TODO(joshie): port history_by_block_hash to DatabaseProvider and use db_provider + self.database.history_by_block_hash(block_hash) + }, + |block_state| { + let state_provider = self.block_state_provider(block_state)?; + Ok(Box::new(state_provider)) + }, + )?) } fn state_by_block_hash(&self, hash: BlockHash) -> ProviderResult { From 62495485c319f4a2ca4c0a5614c5d92450c973c1 Mon Sep 17 00:00:00 2001 From: joshieDo <93316087+joshieDo@users.noreply.github.com> Date: Tue, 1 Oct 2024 20:33:55 +0200 Subject: [PATCH 4/9] add to header and header_by_number --- .../src/providers/blockchain_provider.rs | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/crates/storage/provider/src/providers/blockchain_provider.rs b/crates/storage/provider/src/providers/blockchain_provider.rs index 1bcec0a4bd01..2105ee6b7fb2 100644 --- a/crates/storage/provider/src/providers/blockchain_provider.rs +++ b/crates/storage/provider/src/providers/blockchain_provider.rs @@ -364,19 +364,19 @@ impl StaticFileProviderFactory for BlockchainProvider2 impl HeaderProvider for BlockchainProvider2 { fn header(&self, block_hash: &BlockHash) -> ProviderResult> { - if let Some(block_state) = self.canonical_in_memory_state.state_by_hash(*block_hash) { - return Ok(Some(block_state.block().block().header.header().clone())); - } - - self.database.header(block_hash) + self.get_in_memory_or_storage_by_block( + block_hash.into(), + |db_provider| db_provider.header(block_hash), + |block_state| Ok(Some(block_state.block().block().header.header().clone())), + ) } fn header_by_number(&self, num: BlockNumber) -> ProviderResult> { - if let Some(block_state) = self.canonical_in_memory_state.state_by_number(num) { - return Ok(Some(block_state.block().block().header.header().clone())); - } - - self.database.header_by_number(num) + self.get_in_memory_or_storage_by_block( + num.into(), + |db_provider| db_provider.header_by_number(num), + |block_state| Ok(Some(block_state.block().block().header.header().clone())), + ) } fn header_td(&self, hash: &BlockHash) -> ProviderResult> { From ba276a5c9b80064959f7f4de9d128ce7c84a69f7 Mon Sep 17 00:00:00 2001 From: joshieDo <93316087+joshieDo@users.noreply.github.com> Date: Tue, 1 Oct 2024 20:36:57 +0200 Subject: [PATCH 5/9] add comment --- crates/storage/provider/src/providers/blockchain_provider.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/storage/provider/src/providers/blockchain_provider.rs b/crates/storage/provider/src/providers/blockchain_provider.rs index 2105ee6b7fb2..0ad8b78b8a87 100644 --- a/crates/storage/provider/src/providers/blockchain_provider.rs +++ b/crates/storage/provider/src/providers/blockchain_provider.rs @@ -295,7 +295,7 @@ impl BlockchainProvider2 { Ok(None) } - /// Fetches data from either in-memory state or storage by [`BlockHashOrNumber`]. + /// Fetches data from either in-memory state or persistent storage by [`BlockHashOrNumber`]. fn get_in_memory_or_storage_by_block( &self, id: BlockHashOrNumber, @@ -365,7 +365,7 @@ impl StaticFileProviderFactory for BlockchainProvider2 impl HeaderProvider for BlockchainProvider2 { fn header(&self, block_hash: &BlockHash) -> ProviderResult> { self.get_in_memory_or_storage_by_block( - block_hash.into(), + (*block_hash).into(), |db_provider| db_provider.header(block_hash), |block_state| Ok(Some(block_state.block().block().header.header().clone())), ) From b59428268c43ce97e00e9c9bad19ef0d660b8566 Mon Sep 17 00:00:00 2001 From: joshieDo <93316087+joshieDo@users.noreply.github.com> Date: Tue, 1 Oct 2024 20:37:33 +0200 Subject: [PATCH 6/9] add comment --- crates/storage/provider/src/providers/blockchain_provider.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/storage/provider/src/providers/blockchain_provider.rs b/crates/storage/provider/src/providers/blockchain_provider.rs index 0ad8b78b8a87..a81b98ba5bfb 100644 --- a/crates/storage/provider/src/providers/blockchain_provider.rs +++ b/crates/storage/provider/src/providers/blockchain_provider.rs @@ -241,7 +241,7 @@ impl BlockchainProvider2 { Ok(self.canonical_in_memory_state.state_provider_from_state(state, latest_historical)) } - /// Fetches data from either in-memory state or storage by [`TxNumber`]. + /// Fetches data from either in-memory state or persistent storage by [`TxNumber`]. fn get_in_memory_or_storage_by_tx_id( &self, id: TxNumber, From d794d1a187e968e85e5d0c1e2557dc6feff5a62f Mon Sep 17 00:00:00 2001 From: joshieDo <93316087+joshieDo@users.noreply.github.com> Date: Tue, 1 Oct 2024 20:42:58 +0200 Subject: [PATCH 7/9] clippy --- crates/storage/provider/src/providers/blockchain_provider.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/storage/provider/src/providers/blockchain_provider.rs b/crates/storage/provider/src/providers/blockchain_provider.rs index c086e5aa01f6..6bcdfbf69ae7 100644 --- a/crates/storage/provider/src/providers/blockchain_provider.rs +++ b/crates/storage/provider/src/providers/blockchain_provider.rs @@ -1097,7 +1097,7 @@ impl StateProviderFactory for BlockchainProvider2 { fn history_by_block_hash(&self, block_hash: BlockHash) -> ProviderResult { trace!(target: "providers::blockchain", ?block_hash, "Getting history by block hash"); - Ok(self.get_in_memory_or_storage_by_block( + self.get_in_memory_or_storage_by_block( block_hash.into(), |_| { // TODO(joshie): port history_by_block_hash to DatabaseProvider and use db_provider @@ -1107,7 +1107,7 @@ impl StateProviderFactory for BlockchainProvider2 { let state_provider = self.block_state_provider(block_state)?; Ok(Box::new(state_provider)) }, - )?) + ) } fn state_by_block_hash(&self, hash: BlockHash) -> ProviderResult { From 1b51a3e6299643793a505f9b2e6b5493daf7b32f Mon Sep 17 00:00:00 2001 From: joshieDo <93316087+joshieDo@users.noreply.github.com> Date: Tue, 1 Oct 2024 20:44:52 +0200 Subject: [PATCH 8/9] add to transactions_by_block --- .../src/providers/blockchain_provider.rs | 21 +++++++------------ 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/crates/storage/provider/src/providers/blockchain_provider.rs b/crates/storage/provider/src/providers/blockchain_provider.rs index 6bcdfbf69ae7..69548f17987f 100644 --- a/crates/storage/provider/src/providers/blockchain_provider.rs +++ b/crates/storage/provider/src/providers/blockchain_provider.rs @@ -241,7 +241,8 @@ impl BlockchainProvider2 { Ok(self.canonical_in_memory_state.state_provider_from_state(state, latest_historical)) } - /// Fetches data from either in-memory state or persistent storage by transaction [`HashOrNumber`]. + /// Fetches data from either in-memory state or persistent storage by transaction + /// [`HashOrNumber`]. fn get_in_memory_or_storage_by_tx( &self, id: HashOrNumber, @@ -759,19 +760,11 @@ impl TransactionsProvider for BlockchainProvider2 { &self, id: BlockHashOrNumber, ) -> ProviderResult>> { - match id { - BlockHashOrNumber::Hash(hash) => { - if let Some(block_state) = self.canonical_in_memory_state.state_by_hash(hash) { - return Ok(Some(block_state.block().block().body.transactions.clone())); - } - } - BlockHashOrNumber::Number(number) => { - if let Some(block_state) = self.canonical_in_memory_state.state_by_number(number) { - return Ok(Some(block_state.block().block().body.transactions.clone())); - } - } - } - self.database.transactions_by_block(id) + self.get_in_memory_or_storage_by_block( + id, + |provider| provider.transactions_by_block(id), + |block_state| Ok(Some(block_state.block().block().body.transactions.clone())), + ) } fn transactions_by_block_range( From 6da5d50842999aa8306c2014c5f7de2ad7a0659e Mon Sep 17 00:00:00 2001 From: joshieDo <93316087+joshieDo@users.noreply.github.com> Date: Tue, 1 Oct 2024 20:52:48 +0200 Subject: [PATCH 9/9] dont convert to number where unnecessary --- .../src/providers/blockchain_provider.rs | 41 +++++++++---------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/crates/storage/provider/src/providers/blockchain_provider.rs b/crates/storage/provider/src/providers/blockchain_provider.rs index 69548f17987f..4f3e24a59595 100644 --- a/crates/storage/provider/src/providers/blockchain_provider.rs +++ b/crates/storage/provider/src/providers/blockchain_provider.rs @@ -549,14 +549,11 @@ impl BlockReader for BlockchainProvider2 { } fn block(&self, id: BlockHashOrNumber) -> ProviderResult> { - match id { - BlockHashOrNumber::Hash(hash) => self.find_block_by_hash(hash, BlockSource::Any), - BlockHashOrNumber::Number(num) => self.get_in_memory_or_storage_by_block( - num.into(), - |db_provider| db_provider.block_by_number(num), - |block_state| Ok(Some(block_state.block().block().clone().unseal())), - ), - } + self.get_in_memory_or_storage_by_block( + id, + |db_provider| db_provider.block(id), + |block_state| Ok(Some(block_state.block().block().clone().unseal())), + ) } fn pending_block(&self) -> ProviderResult> { @@ -572,22 +569,22 @@ impl BlockReader for BlockchainProvider2 { } fn ommers(&self, id: BlockHashOrNumber) -> ProviderResult>> { - match self.convert_hash_or_number(id)? { - Some(number) => { - // If the Paris (Merge) hardfork block is known and block is after it, return empty - // ommers. - if self.database.chain_spec().final_paris_total_difficulty(number).is_some() { - return Ok(Some(Vec::new())); + self.get_in_memory_or_storage_by_block( + id, + |db_provider| db_provider.ommers(id), + |block_state| { + if self + .database + .chain_spec() + .final_paris_total_difficulty(block_state.number()) + .is_some() + { + return Ok(Some(Vec::new())) } - self.get_in_memory_or_storage_by_block( - id, - |db_provider| db_provider.ommers(id), - |block_state| Ok(Some(block_state.block().block().body.ommers.clone())), - ) - } - None => self.database.ommers(id), - } + Ok(Some(block_state.block().block().body.ommers.clone())) + }, + ) } fn block_body_indices(