From edd25118d0310964ae97148c31c2ed1d5b43ab63 Mon Sep 17 00:00:00 2001 From: Arsenii Kulikov Date: Wed, 25 Dec 2024 11:59:59 +0400 Subject: [PATCH] chore: make `EthStorage` generic over transaction (#13549) --- crates/optimism/node/src/node.rs | 69 ++----------------------- crates/storage/storage-api/src/chain.rs | 23 ++++++--- 2 files changed, 20 insertions(+), 72 deletions(-) diff --git a/crates/optimism/node/src/node.rs b/crates/optimism/node/src/node.rs index f0db0fae4..8d153e0c4 100644 --- a/crates/optimism/node/src/node.rs +++ b/crates/optimism/node/src/node.rs @@ -8,8 +8,7 @@ use crate::{ }; use alloy_consensus::Header; use reth_basic_payload_builder::{BasicPayloadJobGenerator, BasicPayloadJobGeneratorConfig}; -use reth_chainspec::{EthChainSpec, EthereumHardforks, Hardforks}; -use reth_db::transaction::{DbTx, DbTxMut}; +use reth_chainspec::{EthChainSpec, Hardforks}; use reth_evm::{execute::BasicBlockExecutorProvider, ConfigureEvm}; use reth_network::{NetworkConfig, NetworkHandle, NetworkManager, NetworkPrimitives, PeersInfo}; use reth_node_api::{AddOnsContext, EngineValidator, FullNodeComponents, NodeAddOns, TxTy}; @@ -36,11 +35,8 @@ use reth_optimism_rpc::{ OpEthApi, SequencerClient, }; use reth_payload_builder::{PayloadBuilderHandle, PayloadBuilderService}; -use reth_primitives::{BlockBody, PooledTransaction, TransactionSigned}; -use reth_provider::{ - providers::ChainStorage, BlockBodyReader, BlockBodyWriter, CanonStateSubscriptions, - ChainSpecProvider, DBProvider, EthStorage, ProviderResult, ReadBodyInput, StorageLocation, -}; +use reth_primitives::{PooledTransaction, TransactionSigned}; +use reth_provider::{CanonStateSubscriptions, EthStorage}; use reth_rpc_server_types::RethRpcModule; use reth_tracing::tracing::{debug, info}; use reth_transaction_pool::{ @@ -51,64 +47,7 @@ use reth_trie_db::MerklePatriciaTrie; use std::sync::Arc; /// Storage implementation for Optimism. -#[derive(Debug, Default, Clone)] -pub struct OpStorage(EthStorage); - -impl> BlockBodyWriter for OpStorage { - fn write_block_bodies( - &self, - provider: &Provider, - bodies: Vec<(u64, Option)>, - write_to: StorageLocation, - ) -> ProviderResult<()> { - self.0.write_block_bodies(provider, bodies, write_to) - } - - fn remove_block_bodies_above( - &self, - provider: &Provider, - block: alloy_primitives::BlockNumber, - remove_from: StorageLocation, - ) -> ProviderResult<()> { - self.0.remove_block_bodies_above(provider, block, remove_from) - } -} - -impl> - BlockBodyReader for OpStorage -{ - type Block = reth_primitives::Block; - - fn read_block_bodies( - &self, - provider: &Provider, - inputs: Vec>, - ) -> ProviderResult> { - self.0.read_block_bodies(provider, inputs) - } -} - -impl ChainStorage for OpStorage { - fn reader( - &self, - ) -> impl reth_provider::ChainStorageReader, OpPrimitives> - where - TX: DbTx + 'static, - Types: reth_provider::providers::NodeTypesForProvider, - { - self - } - - fn writer( - &self, - ) -> impl reth_provider::ChainStorageWriter, OpPrimitives> - where - TX: DbTxMut + DbTx + 'static, - Types: NodeTypes, - { - self - } -} +pub type OpStorage = EthStorage; /// Type configuration for a regular Optimism node. #[derive(Debug, Default, Clone)] diff --git a/crates/storage/storage-api/src/chain.rs b/crates/storage/storage-api/src/chain.rs index 978c4f51b..6e26e2666 100644 --- a/crates/storage/storage-api/src/chain.rs +++ b/crates/storage/storage-api/src/chain.rs @@ -8,7 +8,8 @@ use reth_db::{ transaction::{DbTx, DbTxMut}, DbTxUnwindExt, }; -use reth_primitives_traits::{Block, BlockBody, FullNodePrimitives}; +use reth_primitives::TransactionSigned; +use reth_primitives_traits::{Block, BlockBody, FullNodePrimitives, SignedTransaction}; use reth_storage_errors::provider::ProviderResult; /// Trait that implements how block bodies are written to the storage. @@ -78,17 +79,24 @@ impl ChainStorageReader(std::marker::PhantomData); -impl BlockBodyWriter for EthStorage +impl Default for EthStorage { + fn default() -> Self { + Self(Default::default()) + } +} + +impl BlockBodyWriter> for EthStorage where Provider: DBProvider, + T: SignedTransaction, { fn write_block_bodies( &self, provider: &Provider, - bodies: Vec<(u64, Option)>, + bodies: Vec<(u64, Option>)>, _write_to: StorageLocation, ) -> ProviderResult<()> { let mut ommers_cursor = provider.tx_ref().cursor_write::()?; @@ -128,11 +136,12 @@ where } } -impl BlockBodyReader for EthStorage +impl BlockBodyReader for EthStorage where Provider: DBProvider + ChainSpecProvider, + T: SignedTransaction, { - type Block = reth_primitives::Block; + type Block = reth_primitives::Block; fn read_block_bodies( &self,