feat: ChainStorageReader (#12836)

This commit is contained in:
Arsenii Kulikov
2024-11-25 17:29:25 +04:00
committed by GitHub
parent 04dd005af9
commit 863c5233fc
13 changed files with 227 additions and 157 deletions

View File

@ -15,6 +15,7 @@ use reth_primitives::{
BlockWithSenders, NodePrimitives, Receipts, SealedBlock, SealedBlockWithSenders, SealedHeader,
TransactionMeta, TransactionSigned,
};
use reth_primitives_traits::BlockBody as _;
use reth_storage_api::StateProviderBox;
use reth_trie::{updates::TrieUpdates, HashedPostState};
use std::{collections::BTreeMap, sync::Arc, time::Instant};
@ -547,8 +548,13 @@ where
/// Returns a `TransactionSigned` for the given `TxHash` if found.
pub fn transaction_by_hash(&self, hash: TxHash) -> Option<TransactionSigned> {
for block_state in self.canonical_chain() {
if let Some(tx) =
block_state.block_ref().block().body.transactions().find(|tx| tx.hash() == hash)
if let Some(tx) = block_state
.block_ref()
.block()
.body
.transactions()
.iter()
.find(|tx| tx.hash() == hash)
{
return Some(tx.clone())
}
@ -568,6 +574,7 @@ where
.block()
.body
.transactions()
.iter()
.enumerate()
.find(|(_, tx)| tx.hash() == tx_hash)
{
@ -748,6 +755,7 @@ impl<N: NodePrimitives> BlockState<N> {
.block()
.body
.transactions()
.iter()
.find(|tx| tx.hash() == hash)
.cloned()
})
@ -764,6 +772,7 @@ impl<N: NodePrimitives> BlockState<N> {
.block()
.body
.transactions()
.iter()
.enumerate()
.find(|(_, tx)| tx.hash() == tx_hash)
.map(|(index, tx)| {