mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat: trait-based storage API (#12616)
Co-authored-by: joshie <93316087+joshieDo@users.noreply.github.com>
This commit is contained in:
5
Cargo.lock
generated
5
Cargo.lock
generated
@ -6683,6 +6683,7 @@ dependencies = [
|
|||||||
"reth-network",
|
"reth-network",
|
||||||
"reth-network-p2p",
|
"reth-network-p2p",
|
||||||
"reth-network-peers",
|
"reth-network-peers",
|
||||||
|
"reth-node-api",
|
||||||
"reth-node-builder",
|
"reth-node-builder",
|
||||||
"reth-node-core",
|
"reth-node-core",
|
||||||
"reth-node-events",
|
"reth-node-events",
|
||||||
@ -7089,10 +7090,12 @@ dependencies = [
|
|||||||
"reth-db",
|
"reth-db",
|
||||||
"reth-engine-local",
|
"reth-engine-local",
|
||||||
"reth-network-peers",
|
"reth-network-peers",
|
||||||
|
"reth-node-api",
|
||||||
"reth-node-builder",
|
"reth-node-builder",
|
||||||
"reth-payload-builder",
|
"reth-payload-builder",
|
||||||
"reth-payload-builder-primitives",
|
"reth-payload-builder-primitives",
|
||||||
"reth-payload-primitives",
|
"reth-payload-primitives",
|
||||||
|
"reth-primitives",
|
||||||
"reth-provider",
|
"reth-provider",
|
||||||
"reth-rpc-layer",
|
"reth-rpc-layer",
|
||||||
"reth-stages-types",
|
"reth-stages-types",
|
||||||
@ -8626,6 +8629,7 @@ dependencies = [
|
|||||||
"reth-node-types",
|
"reth-node-types",
|
||||||
"reth-optimism-primitives",
|
"reth-optimism-primitives",
|
||||||
"reth-primitives",
|
"reth-primitives",
|
||||||
|
"reth-primitives-traits",
|
||||||
"reth-prune-types",
|
"reth-prune-types",
|
||||||
"reth-stages-types",
|
"reth-stages-types",
|
||||||
"reth-storage-api",
|
"reth-storage-api",
|
||||||
@ -9189,6 +9193,7 @@ dependencies = [
|
|||||||
"reth-db-models",
|
"reth-db-models",
|
||||||
"reth-execution-types",
|
"reth-execution-types",
|
||||||
"reth-primitives",
|
"reth-primitives",
|
||||||
|
"reth-primitives-traits",
|
||||||
"reth-prune-types",
|
"reth-prune-types",
|
||||||
"reth-stages-types",
|
"reth-stages-types",
|
||||||
"reth-storage-errors",
|
"reth-storage-errors",
|
||||||
|
|||||||
@ -59,7 +59,7 @@ pub struct Command<C: ChainSpecParser> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<C: ChainSpecParser<ChainSpec = ChainSpec>> Command<C> {
|
impl<C: ChainSpecParser<ChainSpec = ChainSpec>> Command<C> {
|
||||||
fn build_pipeline<N: ProviderNodeTypes<ChainSpec = C::ChainSpec>, Client>(
|
fn build_pipeline<N: ProviderNodeTypes<ChainSpec = C::ChainSpec> + CliNodeTypes, Client>(
|
||||||
&self,
|
&self,
|
||||||
config: &Config,
|
config: &Config,
|
||||||
client: Client,
|
client: Client,
|
||||||
|
|||||||
@ -32,6 +32,7 @@ reth-fs-util.workspace = true
|
|||||||
reth-network = { workspace = true, features = ["serde"] }
|
reth-network = { workspace = true, features = ["serde"] }
|
||||||
reth-network-p2p.workspace = true
|
reth-network-p2p.workspace = true
|
||||||
reth-network-peers = { workspace = true, features = ["secp256k1"] }
|
reth-network-peers = { workspace = true, features = ["secp256k1"] }
|
||||||
|
reth-node-api.workspace = true
|
||||||
reth-node-builder.workspace = true
|
reth-node-builder.workspace = true
|
||||||
reth-node-core.workspace = true
|
reth-node-core.workspace = true
|
||||||
reth-node-events.workspace = true
|
reth-node-events.workspace = true
|
||||||
|
|||||||
@ -10,12 +10,16 @@ use reth_db::{init_db, open_db_read_only, DatabaseEnv};
|
|||||||
use reth_db_common::init::init_genesis;
|
use reth_db_common::init::init_genesis;
|
||||||
use reth_downloaders::{bodies::noop::NoopBodiesDownloader, headers::noop::NoopHeaderDownloader};
|
use reth_downloaders::{bodies::noop::NoopBodiesDownloader, headers::noop::NoopHeaderDownloader};
|
||||||
use reth_evm::noop::NoopBlockExecutorProvider;
|
use reth_evm::noop::NoopBlockExecutorProvider;
|
||||||
|
use reth_node_api::FullNodePrimitives;
|
||||||
use reth_node_builder::{NodeTypesWithDBAdapter, NodeTypesWithEngine};
|
use reth_node_builder::{NodeTypesWithDBAdapter, NodeTypesWithEngine};
|
||||||
use reth_node_core::{
|
use reth_node_core::{
|
||||||
args::{DatabaseArgs, DatadirArgs},
|
args::{DatabaseArgs, DatadirArgs},
|
||||||
dirs::{ChainPath, DataDirPath},
|
dirs::{ChainPath, DataDirPath},
|
||||||
};
|
};
|
||||||
use reth_provider::{providers::StaticFileProvider, ProviderFactory, StaticFileProviderFactory};
|
use reth_provider::{
|
||||||
|
providers::{NodeTypesForProvider, StaticFileProvider},
|
||||||
|
ProviderFactory, StaticFileProviderFactory,
|
||||||
|
};
|
||||||
use reth_stages::{sets::DefaultStages, Pipeline, PipelineTarget};
|
use reth_stages::{sets::DefaultStages, Pipeline, PipelineTarget};
|
||||||
use reth_static_file::StaticFileProducer;
|
use reth_static_file::StaticFileProducer;
|
||||||
use std::{path::PathBuf, sync::Arc};
|
use std::{path::PathBuf, sync::Arc};
|
||||||
@ -191,5 +195,21 @@ impl AccessRights {
|
|||||||
|
|
||||||
/// Helper trait with a common set of requirements for the
|
/// Helper trait with a common set of requirements for the
|
||||||
/// [`NodeTypes`](reth_node_builder::NodeTypes) in CLI.
|
/// [`NodeTypes`](reth_node_builder::NodeTypes) in CLI.
|
||||||
pub trait CliNodeTypes: NodeTypesWithEngine<ChainSpec: EthereumHardforks> {}
|
pub trait CliNodeTypes:
|
||||||
impl<N> CliNodeTypes for N where N: NodeTypesWithEngine<ChainSpec: EthereumHardforks> {}
|
NodeTypesWithEngine
|
||||||
|
+ NodeTypesForProvider<
|
||||||
|
Primitives: FullNodePrimitives<
|
||||||
|
Block: reth_node_api::Block<Body = reth_primitives::BlockBody>,
|
||||||
|
>,
|
||||||
|
>
|
||||||
|
{
|
||||||
|
}
|
||||||
|
impl<N> CliNodeTypes for N where
|
||||||
|
N: NodeTypesWithEngine
|
||||||
|
+ NodeTypesForProvider<
|
||||||
|
Primitives: FullNodePrimitives<
|
||||||
|
Block: reth_node_api::Block<Body = reth_primitives::BlockBody>,
|
||||||
|
>,
|
||||||
|
>
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|||||||
@ -167,7 +167,7 @@ pub fn build_import_pipeline<N, C, E>(
|
|||||||
executor: E,
|
executor: E,
|
||||||
) -> eyre::Result<(Pipeline<N>, impl Stream<Item = NodeEvent>)>
|
) -> eyre::Result<(Pipeline<N>, impl Stream<Item = NodeEvent>)>
|
||||||
where
|
where
|
||||||
N: ProviderNodeTypes,
|
N: ProviderNodeTypes + CliNodeTypes,
|
||||||
C: Consensus + 'static,
|
C: Consensus + 'static,
|
||||||
E: BlockExecutorProvider,
|
E: BlockExecutorProvider,
|
||||||
{
|
{
|
||||||
|
|||||||
@ -113,7 +113,7 @@ impl<C: ChainSpecParser<ChainSpec: EthChainSpec + EthereumHardforks>> Command<C>
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_pipeline<N: ProviderNodeTypes<ChainSpec = C::ChainSpec>>(
|
fn build_pipeline<N: ProviderNodeTypes<ChainSpec = C::ChainSpec> + CliNodeTypes>(
|
||||||
self,
|
self,
|
||||||
config: Config,
|
config: Config,
|
||||||
provider_factory: ProviderFactory<N>,
|
provider_factory: ProviderFactory<N>,
|
||||||
|
|||||||
@ -19,7 +19,9 @@ reth-rpc-layer.workspace = true
|
|||||||
reth-payload-builder = { workspace = true, features = ["test-utils"] }
|
reth-payload-builder = { workspace = true, features = ["test-utils"] }
|
||||||
reth-payload-builder-primitives.workspace = true
|
reth-payload-builder-primitives.workspace = true
|
||||||
reth-payload-primitives.workspace = true
|
reth-payload-primitives.workspace = true
|
||||||
|
reth-primitives.workspace = true
|
||||||
reth-provider.workspace = true
|
reth-provider.workspace = true
|
||||||
|
reth-node-api.workspace = true
|
||||||
reth-node-builder = { workspace = true, features = ["test-utils"] }
|
reth-node-builder = { workspace = true, features = ["test-utils"] }
|
||||||
reth-tokio-util.workspace = true
|
reth-tokio-util.workspace = true
|
||||||
reth-stages-types.workspace = true
|
reth-stages-types.workspace = true
|
||||||
|
|||||||
@ -5,12 +5,12 @@ use std::sync::Arc;
|
|||||||
use node::NodeTestContext;
|
use node::NodeTestContext;
|
||||||
use reth::{
|
use reth::{
|
||||||
args::{DiscoveryArgs, NetworkArgs, RpcServerArgs},
|
args::{DiscoveryArgs, NetworkArgs, RpcServerArgs},
|
||||||
builder::{NodeBuilder, NodeConfig, NodeHandle},
|
builder::{FullNodePrimitives, NodeBuilder, NodeConfig, NodeHandle},
|
||||||
network::PeersHandleProvider,
|
network::PeersHandleProvider,
|
||||||
rpc::server_types::RpcModuleSelection,
|
rpc::server_types::RpcModuleSelection,
|
||||||
tasks::TaskManager,
|
tasks::TaskManager,
|
||||||
};
|
};
|
||||||
use reth_chainspec::{EthChainSpec, EthereumHardforks};
|
use reth_chainspec::EthChainSpec;
|
||||||
use reth_db::{test_utils::TempDatabase, DatabaseEnv};
|
use reth_db::{test_utils::TempDatabase, DatabaseEnv};
|
||||||
use reth_engine_local::LocalPayloadAttributesBuilder;
|
use reth_engine_local::LocalPayloadAttributesBuilder;
|
||||||
use reth_node_builder::{
|
use reth_node_builder::{
|
||||||
@ -18,7 +18,7 @@ use reth_node_builder::{
|
|||||||
FullNodeTypesAdapter, Node, NodeAdapter, NodeComponents, NodeTypesWithDBAdapter,
|
FullNodeTypesAdapter, Node, NodeAdapter, NodeComponents, NodeTypesWithDBAdapter,
|
||||||
NodeTypesWithEngine, PayloadAttributesBuilder, PayloadTypes,
|
NodeTypesWithEngine, PayloadAttributesBuilder, PayloadTypes,
|
||||||
};
|
};
|
||||||
use reth_provider::providers::{BlockchainProvider, BlockchainProvider2};
|
use reth_provider::providers::{BlockchainProvider, BlockchainProvider2, NodeTypesForProvider};
|
||||||
use tracing::{span, Level};
|
use tracing::{span, Level};
|
||||||
use wallet::Wallet;
|
use wallet::Wallet;
|
||||||
|
|
||||||
@ -53,12 +53,14 @@ pub async fn setup<N>(
|
|||||||
attributes_generator: impl Fn(u64) -> <<N as NodeTypesWithEngine>::Engine as PayloadTypes>::PayloadBuilderAttributes + Copy + 'static,
|
attributes_generator: impl Fn(u64) -> <<N as NodeTypesWithEngine>::Engine as PayloadTypes>::PayloadBuilderAttributes + Copy + 'static,
|
||||||
) -> eyre::Result<(Vec<NodeHelperType<N, N::AddOns>>, TaskManager, Wallet)>
|
) -> eyre::Result<(Vec<NodeHelperType<N, N::AddOns>>, TaskManager, Wallet)>
|
||||||
where
|
where
|
||||||
N: Default + Node<TmpNodeAdapter<N>> + NodeTypesWithEngine<ChainSpec: EthereumHardforks>,
|
N: Default + Node<TmpNodeAdapter<N>> + NodeTypesForProvider + NodeTypesWithEngine,
|
||||||
N::ComponentsBuilder: NodeComponentsBuilder<
|
N::ComponentsBuilder: NodeComponentsBuilder<
|
||||||
TmpNodeAdapter<N>,
|
TmpNodeAdapter<N>,
|
||||||
Components: NodeComponents<TmpNodeAdapter<N>, Network: PeersHandleProvider>,
|
Components: NodeComponents<TmpNodeAdapter<N>, Network: PeersHandleProvider>,
|
||||||
>,
|
>,
|
||||||
N::AddOns: RethRpcAddOns<Adapter<N>>,
|
N::AddOns: RethRpcAddOns<Adapter<N>>,
|
||||||
|
N::Primitives:
|
||||||
|
FullNodePrimitives<Block: reth_node_api::Block<Body = reth_primitives::BlockBody>>,
|
||||||
{
|
{
|
||||||
let tasks = TaskManager::current();
|
let tasks = TaskManager::current();
|
||||||
let exec = tasks.executor();
|
let exec = tasks.executor();
|
||||||
@ -120,7 +122,8 @@ pub async fn setup_engine<N>(
|
|||||||
where
|
where
|
||||||
N: Default
|
N: Default
|
||||||
+ Node<TmpNodeAdapter<N, BlockchainProvider2<NodeTypesWithDBAdapter<N, TmpDB>>>>
|
+ Node<TmpNodeAdapter<N, BlockchainProvider2<NodeTypesWithDBAdapter<N, TmpDB>>>>
|
||||||
+ NodeTypesWithEngine<ChainSpec: EthereumHardforks>,
|
+ NodeTypesWithEngine
|
||||||
|
+ NodeTypesForProvider,
|
||||||
N::ComponentsBuilder: NodeComponentsBuilder<
|
N::ComponentsBuilder: NodeComponentsBuilder<
|
||||||
TmpNodeAdapter<N, BlockchainProvider2<NodeTypesWithDBAdapter<N, TmpDB>>>,
|
TmpNodeAdapter<N, BlockchainProvider2<NodeTypesWithDBAdapter<N, TmpDB>>>,
|
||||||
Components: NodeComponents<
|
Components: NodeComponents<
|
||||||
@ -132,6 +135,8 @@ where
|
|||||||
LocalPayloadAttributesBuilder<N::ChainSpec>: PayloadAttributesBuilder<
|
LocalPayloadAttributesBuilder<N::ChainSpec>: PayloadAttributesBuilder<
|
||||||
<<N as NodeTypesWithEngine>::Engine as PayloadTypes>::PayloadAttributes,
|
<<N as NodeTypesWithEngine>::Engine as PayloadTypes>::PayloadAttributes,
|
||||||
>,
|
>,
|
||||||
|
N::Primitives:
|
||||||
|
FullNodePrimitives<Block: reth_node_api::Block<Body = reth_primitives::BlockBody>>,
|
||||||
{
|
{
|
||||||
let tasks = TaskManager::current();
|
let tasks = TaskManager::current();
|
||||||
let exec = tasks.executor();
|
let exec = tasks.executor();
|
||||||
|
|||||||
@ -26,7 +26,7 @@ use reth_node_builder::{
|
|||||||
};
|
};
|
||||||
use reth_payload_builder::{PayloadBuilderHandle, PayloadBuilderService};
|
use reth_payload_builder::{PayloadBuilderHandle, PayloadBuilderService};
|
||||||
use reth_primitives::EthPrimitives;
|
use reth_primitives::EthPrimitives;
|
||||||
use reth_provider::CanonStateSubscriptions;
|
use reth_provider::{CanonStateSubscriptions, EthStorage};
|
||||||
use reth_rpc::EthApi;
|
use reth_rpc::EthApi;
|
||||||
use reth_tracing::tracing::{debug, info};
|
use reth_tracing::tracing::{debug, info};
|
||||||
use reth_transaction_pool::{
|
use reth_transaction_pool::{
|
||||||
@ -74,6 +74,7 @@ impl NodeTypes for EthereumNode {
|
|||||||
type Primitives = EthPrimitives;
|
type Primitives = EthPrimitives;
|
||||||
type ChainSpec = ChainSpec;
|
type ChainSpec = ChainSpec;
|
||||||
type StateCommitment = MerklePatriciaTrie;
|
type StateCommitment = MerklePatriciaTrie;
|
||||||
|
type Storage = EthStorage;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NodeTypesWithEngine for EthereumNode {
|
impl NodeTypesWithEngine for EthereumNode {
|
||||||
@ -94,7 +95,13 @@ pub type EthereumAddOns<N> = RpcAddOns<
|
|||||||
|
|
||||||
impl<Types, N> Node<N> for EthereumNode
|
impl<Types, N> Node<N> for EthereumNode
|
||||||
where
|
where
|
||||||
Types: NodeTypesWithDB + NodeTypesWithEngine<Engine = EthEngineTypes, ChainSpec = ChainSpec>,
|
Types: NodeTypesWithDB
|
||||||
|
+ NodeTypesWithEngine<
|
||||||
|
Engine = EthEngineTypes,
|
||||||
|
ChainSpec = ChainSpec,
|
||||||
|
Primitives = EthPrimitives,
|
||||||
|
Storage = EthStorage,
|
||||||
|
>,
|
||||||
N: FullNodeTypes<Types = Types>,
|
N: FullNodeTypes<Types = Types>,
|
||||||
{
|
{
|
||||||
type ComponentsBuilder = ComponentsBuilder<
|
type ComponentsBuilder = ComponentsBuilder<
|
||||||
|
|||||||
@ -45,10 +45,10 @@ use reth_node_ethereum::{
|
|||||||
EthEngineTypes, EthEvmConfig,
|
EthEngineTypes, EthEvmConfig,
|
||||||
};
|
};
|
||||||
use reth_payload_builder::noop::NoopPayloadBuilderService;
|
use reth_payload_builder::noop::NoopPayloadBuilderService;
|
||||||
use reth_primitives::{Head, SealedBlockWithSenders};
|
use reth_primitives::{EthPrimitives, Head, SealedBlockWithSenders};
|
||||||
use reth_provider::{
|
use reth_provider::{
|
||||||
providers::{BlockchainProvider, StaticFileProvider},
|
providers::{BlockchainProvider, StaticFileProvider},
|
||||||
BlockReader, ProviderFactory,
|
BlockReader, EthStorage, ProviderFactory,
|
||||||
};
|
};
|
||||||
use reth_tasks::TaskManager;
|
use reth_tasks::TaskManager;
|
||||||
use reth_transaction_pool::test_utils::{testing_pool, TestPool};
|
use reth_transaction_pool::test_utils::{testing_pool, TestPool};
|
||||||
@ -118,9 +118,10 @@ where
|
|||||||
pub struct TestNode;
|
pub struct TestNode;
|
||||||
|
|
||||||
impl NodeTypes for TestNode {
|
impl NodeTypes for TestNode {
|
||||||
type Primitives = ();
|
type Primitives = EthPrimitives;
|
||||||
type ChainSpec = ChainSpec;
|
type ChainSpec = ChainSpec;
|
||||||
type StateCommitment = reth_trie_db::MerklePatriciaTrie;
|
type StateCommitment = reth_trie_db::MerklePatriciaTrie;
|
||||||
|
type Storage = EthStorage;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NodeTypesWithEngine for TestNode {
|
impl NodeTypesWithEngine for TestNode {
|
||||||
@ -129,7 +130,14 @@ impl NodeTypesWithEngine for TestNode {
|
|||||||
|
|
||||||
impl<N> Node<N> for TestNode
|
impl<N> Node<N> for TestNode
|
||||||
where
|
where
|
||||||
N: FullNodeTypes<Types: NodeTypesWithEngine<Engine = EthEngineTypes, ChainSpec = ChainSpec>>,
|
N: FullNodeTypes<
|
||||||
|
Types: NodeTypesWithEngine<
|
||||||
|
Engine = EthEngineTypes,
|
||||||
|
ChainSpec = ChainSpec,
|
||||||
|
Primitives = EthPrimitives,
|
||||||
|
Storage = EthStorage,
|
||||||
|
>,
|
||||||
|
>,
|
||||||
{
|
{
|
||||||
type ComponentsBuilder = ComponentsBuilder<
|
type ComponentsBuilder = ComponentsBuilder<
|
||||||
N,
|
N,
|
||||||
|
|||||||
@ -22,8 +22,8 @@ use reth_network::{
|
|||||||
NetworkHandle, NetworkManager,
|
NetworkHandle, NetworkManager,
|
||||||
};
|
};
|
||||||
use reth_node_api::{
|
use reth_node_api::{
|
||||||
FullNodeTypes, FullNodeTypesAdapter, NodeAddOns, NodeTypes, NodeTypesWithDBAdapter,
|
FullNodePrimitives, FullNodeTypes, FullNodeTypesAdapter, NodeAddOns, NodeTypes,
|
||||||
NodeTypesWithEngine,
|
NodeTypesWithDBAdapter, NodeTypesWithEngine,
|
||||||
};
|
};
|
||||||
use reth_node_core::{
|
use reth_node_core::{
|
||||||
cli::config::{PayloadBuilderConfig, RethTransactionPoolConfig},
|
cli::config::{PayloadBuilderConfig, RethTransactionPoolConfig},
|
||||||
@ -31,7 +31,10 @@ use reth_node_core::{
|
|||||||
node_config::NodeConfig,
|
node_config::NodeConfig,
|
||||||
primitives::Head,
|
primitives::Head,
|
||||||
};
|
};
|
||||||
use reth_provider::{providers::BlockchainProvider, ChainSpecProvider, FullProvider};
|
use reth_provider::{
|
||||||
|
providers::{BlockchainProvider, NodeTypesForProvider},
|
||||||
|
ChainSpecProvider, FullProvider,
|
||||||
|
};
|
||||||
use reth_tasks::TaskExecutor;
|
use reth_tasks::TaskExecutor;
|
||||||
use reth_transaction_pool::{PoolConfig, TransactionPool};
|
use reth_transaction_pool::{PoolConfig, TransactionPool};
|
||||||
use revm_primitives::EnvKzgSettings;
|
use revm_primitives::EnvKzgSettings;
|
||||||
@ -240,7 +243,7 @@ where
|
|||||||
/// Configures the types of the node.
|
/// Configures the types of the node.
|
||||||
pub fn with_types<T>(self) -> NodeBuilderWithTypes<RethFullAdapter<DB, T>>
|
pub fn with_types<T>(self) -> NodeBuilderWithTypes<RethFullAdapter<DB, T>>
|
||||||
where
|
where
|
||||||
T: NodeTypesWithEngine<ChainSpec = ChainSpec>,
|
T: NodeTypesWithEngine<ChainSpec = ChainSpec> + NodeTypesForProvider,
|
||||||
{
|
{
|
||||||
self.with_types_and_provider()
|
self.with_types_and_provider()
|
||||||
}
|
}
|
||||||
@ -250,7 +253,7 @@ where
|
|||||||
self,
|
self,
|
||||||
) -> NodeBuilderWithTypes<FullNodeTypesAdapter<NodeTypesWithDBAdapter<T, DB>, P>>
|
) -> NodeBuilderWithTypes<FullNodeTypesAdapter<NodeTypesWithDBAdapter<T, DB>, P>>
|
||||||
where
|
where
|
||||||
T: NodeTypesWithEngine<ChainSpec = ChainSpec>,
|
T: NodeTypesWithEngine<ChainSpec = ChainSpec> + NodeTypesForProvider,
|
||||||
P: FullProvider<NodeTypesWithDBAdapter<T, DB>>,
|
P: FullProvider<NodeTypesWithDBAdapter<T, DB>>,
|
||||||
{
|
{
|
||||||
NodeBuilderWithTypes::new(self.config, self.database)
|
NodeBuilderWithTypes::new(self.config, self.database)
|
||||||
@ -264,7 +267,7 @@ where
|
|||||||
node: N,
|
node: N,
|
||||||
) -> NodeBuilderWithComponents<RethFullAdapter<DB, N>, N::ComponentsBuilder, N::AddOns>
|
) -> NodeBuilderWithComponents<RethFullAdapter<DB, N>, N::ComponentsBuilder, N::AddOns>
|
||||||
where
|
where
|
||||||
N: Node<RethFullAdapter<DB, N>, ChainSpec = ChainSpec>,
|
N: Node<RethFullAdapter<DB, N>, ChainSpec = ChainSpec> + NodeTypesForProvider,
|
||||||
{
|
{
|
||||||
self.with_types().with_components(node.components_builder()).with_add_ons(node.add_ons())
|
self.with_types().with_components(node.components_builder()).with_add_ons(node.add_ons())
|
||||||
}
|
}
|
||||||
@ -301,7 +304,7 @@ where
|
|||||||
/// Configures the types of the node.
|
/// Configures the types of the node.
|
||||||
pub fn with_types<T>(self) -> WithLaunchContext<NodeBuilderWithTypes<RethFullAdapter<DB, T>>>
|
pub fn with_types<T>(self) -> WithLaunchContext<NodeBuilderWithTypes<RethFullAdapter<DB, T>>>
|
||||||
where
|
where
|
||||||
T: NodeTypesWithEngine<ChainSpec = ChainSpec>,
|
T: NodeTypesWithEngine<ChainSpec = ChainSpec> + NodeTypesForProvider,
|
||||||
{
|
{
|
||||||
WithLaunchContext { builder: self.builder.with_types(), task_executor: self.task_executor }
|
WithLaunchContext { builder: self.builder.with_types(), task_executor: self.task_executor }
|
||||||
}
|
}
|
||||||
@ -313,7 +316,7 @@ where
|
|||||||
NodeBuilderWithTypes<FullNodeTypesAdapter<NodeTypesWithDBAdapter<T, DB>, P>>,
|
NodeBuilderWithTypes<FullNodeTypesAdapter<NodeTypesWithDBAdapter<T, DB>, P>>,
|
||||||
>
|
>
|
||||||
where
|
where
|
||||||
T: NodeTypesWithEngine<ChainSpec = ChainSpec>,
|
T: NodeTypesWithEngine<ChainSpec = ChainSpec> + NodeTypesForProvider,
|
||||||
P: FullProvider<NodeTypesWithDBAdapter<T, DB>>,
|
P: FullProvider<NodeTypesWithDBAdapter<T, DB>>,
|
||||||
{
|
{
|
||||||
WithLaunchContext {
|
WithLaunchContext {
|
||||||
@ -332,7 +335,7 @@ where
|
|||||||
NodeBuilderWithComponents<RethFullAdapter<DB, N>, N::ComponentsBuilder, N::AddOns>,
|
NodeBuilderWithComponents<RethFullAdapter<DB, N>, N::ComponentsBuilder, N::AddOns>,
|
||||||
>
|
>
|
||||||
where
|
where
|
||||||
N: Node<RethFullAdapter<DB, N>, ChainSpec = ChainSpec>,
|
N: Node<RethFullAdapter<DB, N>, ChainSpec = ChainSpec> + NodeTypesForProvider,
|
||||||
{
|
{
|
||||||
self.with_types().with_components(node.components_builder()).with_add_ons(node.add_ons())
|
self.with_types().with_components(node.components_builder()).with_add_ons(node.add_ons())
|
||||||
}
|
}
|
||||||
@ -355,13 +358,15 @@ where
|
|||||||
>,
|
>,
|
||||||
>
|
>
|
||||||
where
|
where
|
||||||
N: Node<RethFullAdapter<DB, N>, ChainSpec = ChainSpec>,
|
N: Node<RethFullAdapter<DB, N>, ChainSpec = ChainSpec> + NodeTypesForProvider,
|
||||||
N::AddOns: RethRpcAddOns<
|
N::AddOns: RethRpcAddOns<
|
||||||
NodeAdapter<
|
NodeAdapter<
|
||||||
RethFullAdapter<DB, N>,
|
RethFullAdapter<DB, N>,
|
||||||
<N::ComponentsBuilder as NodeComponentsBuilder<RethFullAdapter<DB, N>>>::Components,
|
<N::ComponentsBuilder as NodeComponentsBuilder<RethFullAdapter<DB, N>>>::Components,
|
||||||
>,
|
>,
|
||||||
>,
|
>,
|
||||||
|
N::Primitives:
|
||||||
|
FullNodePrimitives<Block: reth_node_api::Block<Body = reth_primitives::BlockBody>>,
|
||||||
{
|
{
|
||||||
self.node(node).launch().await
|
self.node(node).launch().await
|
||||||
}
|
}
|
||||||
@ -549,9 +554,11 @@ where
|
|||||||
impl<T, DB, CB, AO> WithLaunchContext<NodeBuilderWithComponents<RethFullAdapter<DB, T>, CB, AO>>
|
impl<T, DB, CB, AO> WithLaunchContext<NodeBuilderWithComponents<RethFullAdapter<DB, T>, CB, AO>>
|
||||||
where
|
where
|
||||||
DB: Database + DatabaseMetrics + DatabaseMetadata + Clone + Unpin + 'static,
|
DB: Database + DatabaseMetrics + DatabaseMetadata + Clone + Unpin + 'static,
|
||||||
T: NodeTypesWithEngine<ChainSpec: EthereumHardforks + EthChainSpec>,
|
T: NodeTypesWithEngine + NodeTypesForProvider,
|
||||||
CB: NodeComponentsBuilder<RethFullAdapter<DB, T>>,
|
CB: NodeComponentsBuilder<RethFullAdapter<DB, T>>,
|
||||||
AO: RethRpcAddOns<NodeAdapter<RethFullAdapter<DB, T>, CB::Components>>,
|
AO: RethRpcAddOns<NodeAdapter<RethFullAdapter<DB, T>, CB::Components>>,
|
||||||
|
T::Primitives:
|
||||||
|
FullNodePrimitives<Block: reth_node_api::Block<Body = reth_primitives::BlockBody>>,
|
||||||
{
|
{
|
||||||
/// Launches the node with the [`DefaultNodeLauncher`] that sets up engine API consensus and rpc
|
/// Launches the node with the [`DefaultNodeLauncher`] that sets up engine API consensus and rpc
|
||||||
pub async fn launch(
|
pub async fn launch(
|
||||||
|
|||||||
@ -26,7 +26,7 @@ use reth_evm::noop::NoopBlockExecutorProvider;
|
|||||||
use reth_fs_util as fs;
|
use reth_fs_util as fs;
|
||||||
use reth_invalid_block_hooks::InvalidBlockWitnessHook;
|
use reth_invalid_block_hooks::InvalidBlockWitnessHook;
|
||||||
use reth_network_p2p::headers::client::HeadersClient;
|
use reth_network_p2p::headers::client::HeadersClient;
|
||||||
use reth_node_api::{FullNodeTypes, NodeTypes, NodeTypesWithDB};
|
use reth_node_api::{FullNodePrimitives, FullNodeTypes, NodeTypes, NodeTypesWithDB};
|
||||||
use reth_node_core::{
|
use reth_node_core::{
|
||||||
args::InvalidBlockHookType,
|
args::InvalidBlockHookType,
|
||||||
dirs::{ChainPath, DataDirPath},
|
dirs::{ChainPath, DataDirPath},
|
||||||
@ -404,9 +404,12 @@ where
|
|||||||
/// Returns the [`ProviderFactory`] for the attached storage after executing a consistent check
|
/// Returns the [`ProviderFactory`] for the attached storage after executing a consistent check
|
||||||
/// between the database and static files. **It may execute a pipeline unwind if it fails this
|
/// between the database and static files. **It may execute a pipeline unwind if it fails this
|
||||||
/// check.**
|
/// check.**
|
||||||
pub async fn create_provider_factory<N: NodeTypesWithDB<DB = DB, ChainSpec = ChainSpec>>(
|
pub async fn create_provider_factory<N>(&self) -> eyre::Result<ProviderFactory<N>>
|
||||||
&self,
|
where
|
||||||
) -> eyre::Result<ProviderFactory<N>> {
|
N: ProviderNodeTypes<DB = DB, ChainSpec = ChainSpec>,
|
||||||
|
N::Primitives:
|
||||||
|
FullNodePrimitives<Block: reth_node_api::Block<Body = reth_primitives::BlockBody>>,
|
||||||
|
{
|
||||||
let factory = ProviderFactory::new(
|
let factory = ProviderFactory::new(
|
||||||
self.right().clone(),
|
self.right().clone(),
|
||||||
self.chain_spec(),
|
self.chain_spec(),
|
||||||
@ -467,9 +470,14 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a new [`ProviderFactory`] and attaches it to the launch context.
|
/// Creates a new [`ProviderFactory`] and attaches it to the launch context.
|
||||||
pub async fn with_provider_factory<N: NodeTypesWithDB<DB = DB, ChainSpec = ChainSpec>>(
|
pub async fn with_provider_factory<N>(
|
||||||
self,
|
self,
|
||||||
) -> eyre::Result<LaunchContextWith<Attached<WithConfigs<ChainSpec>, ProviderFactory<N>>>> {
|
) -> eyre::Result<LaunchContextWith<Attached<WithConfigs<ChainSpec>, ProviderFactory<N>>>>
|
||||||
|
where
|
||||||
|
N: ProviderNodeTypes<DB = DB, ChainSpec = ChainSpec>,
|
||||||
|
N::Primitives:
|
||||||
|
FullNodePrimitives<Block: reth_node_api::Block<Body = reth_primitives::BlockBody>>,
|
||||||
|
{
|
||||||
let factory = self.create_provider_factory().await?;
|
let factory = self.create_provider_factory().await?;
|
||||||
let ctx = LaunchContextWith {
|
let ctx = LaunchContextWith {
|
||||||
inner: self.inner,
|
inner: self.inner,
|
||||||
@ -482,7 +490,7 @@ where
|
|||||||
|
|
||||||
impl<T> LaunchContextWith<Attached<WithConfigs<T::ChainSpec>, ProviderFactory<T>>>
|
impl<T> LaunchContextWith<Attached<WithConfigs<T::ChainSpec>, ProviderFactory<T>>>
|
||||||
where
|
where
|
||||||
T: NodeTypesWithDB<ChainSpec: EthereumHardforks + EthChainSpec>,
|
T: ProviderNodeTypes,
|
||||||
{
|
{
|
||||||
/// Returns access to the underlying database.
|
/// Returns access to the underlying database.
|
||||||
pub const fn database(&self) -> &T::DB {
|
pub const fn database(&self) -> &T::DB {
|
||||||
@ -748,10 +756,7 @@ impl<T, CB>
|
|||||||
Attached<WithConfigs<<T::Types as NodeTypes>::ChainSpec>, WithComponents<T, CB>>,
|
Attached<WithConfigs<<T::Types as NodeTypes>::ChainSpec>, WithComponents<T, CB>>,
|
||||||
>
|
>
|
||||||
where
|
where
|
||||||
T: FullNodeTypes<
|
T: FullNodeTypes<Provider: WithTree, Types: ProviderNodeTypes>,
|
||||||
Provider: WithTree,
|
|
||||||
Types: NodeTypes<ChainSpec: EthChainSpec + EthereumHardforks>,
|
|
||||||
>,
|
|
||||||
CB: NodeComponentsBuilder<T>,
|
CB: NodeComponentsBuilder<T>,
|
||||||
{
|
{
|
||||||
/// Returns the configured `ProviderFactory`.
|
/// Returns the configured `ProviderFactory`.
|
||||||
@ -913,7 +918,7 @@ impl<T, CB>
|
|||||||
where
|
where
|
||||||
T: FullNodeTypes<
|
T: FullNodeTypes<
|
||||||
Provider: WithTree + StateProviderFactory + ChainSpecProvider,
|
Provider: WithTree + StateProviderFactory + ChainSpecProvider,
|
||||||
Types: NodeTypes<ChainSpec: EthereumHardforks>,
|
Types: ProviderNodeTypes,
|
||||||
>,
|
>,
|
||||||
CB: NodeComponentsBuilder<T>,
|
CB: NodeComponentsBuilder<T>,
|
||||||
{
|
{
|
||||||
|
|||||||
@ -19,8 +19,8 @@ use reth_exex::ExExManagerHandle;
|
|||||||
use reth_network::{NetworkSyncUpdater, SyncState};
|
use reth_network::{NetworkSyncUpdater, SyncState};
|
||||||
use reth_network_api::{BlockDownloaderProvider, NetworkEventListenerProvider};
|
use reth_network_api::{BlockDownloaderProvider, NetworkEventListenerProvider};
|
||||||
use reth_node_api::{
|
use reth_node_api::{
|
||||||
BuiltPayload, FullNodeTypes, NodeTypesWithEngine, PayloadAttributesBuilder, PayloadBuilder,
|
BuiltPayload, FullNodePrimitives, FullNodeTypes, NodeTypesWithEngine, PayloadAttributesBuilder,
|
||||||
PayloadTypes,
|
PayloadBuilder, PayloadTypes,
|
||||||
};
|
};
|
||||||
use reth_node_core::{
|
use reth_node_core::{
|
||||||
dirs::{ChainPath, DataDirPath},
|
dirs::{ChainPath, DataDirPath},
|
||||||
@ -77,6 +77,8 @@ where
|
|||||||
LocalPayloadAttributesBuilder<Types::ChainSpec>: PayloadAttributesBuilder<
|
LocalPayloadAttributesBuilder<Types::ChainSpec>: PayloadAttributesBuilder<
|
||||||
<<Types as NodeTypesWithEngine>::Engine as PayloadTypes>::PayloadAttributes,
|
<<Types as NodeTypesWithEngine>::Engine as PayloadTypes>::PayloadAttributes,
|
||||||
>,
|
>,
|
||||||
|
Types::Primitives:
|
||||||
|
FullNodePrimitives<Block: reth_node_api::Block<Body = reth_primitives::BlockBody>>,
|
||||||
{
|
{
|
||||||
type Node = NodeHandle<NodeAdapter<T, CB::Components>, AO>;
|
type Node = NodeHandle<NodeAdapter<T, CB::Components>, AO>;
|
||||||
|
|
||||||
|
|||||||
@ -17,18 +17,18 @@ use reth_beacon_consensus::{
|
|||||||
BeaconConsensusEngine,
|
BeaconConsensusEngine,
|
||||||
};
|
};
|
||||||
use reth_blockchain_tree::{noop::NoopBlockchainTree, BlockchainTreeConfig};
|
use reth_blockchain_tree::{noop::NoopBlockchainTree, BlockchainTreeConfig};
|
||||||
use reth_chainspec::{EthChainSpec, EthereumHardforks};
|
use reth_chainspec::EthChainSpec;
|
||||||
use reth_consensus_debug_client::{DebugConsensusClient, EtherscanBlockProvider, RpcBlockProvider};
|
use reth_consensus_debug_client::{DebugConsensusClient, EtherscanBlockProvider, RpcBlockProvider};
|
||||||
use reth_engine_util::EngineMessageStreamExt;
|
use reth_engine_util::EngineMessageStreamExt;
|
||||||
use reth_exex::ExExManagerHandle;
|
use reth_exex::ExExManagerHandle;
|
||||||
use reth_network::{BlockDownloaderProvider, NetworkEventListenerProvider};
|
use reth_network::{BlockDownloaderProvider, NetworkEventListenerProvider};
|
||||||
use reth_node_api::{AddOnsContext, FullNodeTypes, NodeTypesWithDB, NodeTypesWithEngine};
|
use reth_node_api::{AddOnsContext, FullNodePrimitives, FullNodeTypes, NodeTypesWithEngine};
|
||||||
use reth_node_core::{
|
use reth_node_core::{
|
||||||
dirs::{ChainPath, DataDirPath},
|
dirs::{ChainPath, DataDirPath},
|
||||||
exit::NodeExitFuture,
|
exit::NodeExitFuture,
|
||||||
};
|
};
|
||||||
use reth_node_events::{cl::ConsensusLayerHealthEvents, node};
|
use reth_node_events::{cl::ConsensusLayerHealthEvents, node};
|
||||||
use reth_provider::providers::BlockchainProvider;
|
use reth_provider::providers::{BlockchainProvider, ProviderNodeTypes};
|
||||||
use reth_rpc::eth::RpcNodeCore;
|
use reth_rpc::eth::RpcNodeCore;
|
||||||
use reth_tasks::TaskExecutor;
|
use reth_tasks::TaskExecutor;
|
||||||
use reth_tracing::tracing::{debug, info};
|
use reth_tracing::tracing::{debug, info};
|
||||||
@ -98,10 +98,12 @@ impl DefaultNodeLauncher {
|
|||||||
|
|
||||||
impl<Types, T, CB, AO> LaunchNode<NodeBuilderWithComponents<T, CB, AO>> for DefaultNodeLauncher
|
impl<Types, T, CB, AO> LaunchNode<NodeBuilderWithComponents<T, CB, AO>> for DefaultNodeLauncher
|
||||||
where
|
where
|
||||||
Types: NodeTypesWithDB<ChainSpec: EthereumHardforks + EthChainSpec> + NodeTypesWithEngine,
|
Types: ProviderNodeTypes + NodeTypesWithEngine,
|
||||||
T: FullNodeTypes<Provider = BlockchainProvider<Types>, Types = Types>,
|
T: FullNodeTypes<Provider = BlockchainProvider<Types>, Types = Types>,
|
||||||
CB: NodeComponentsBuilder<T>,
|
CB: NodeComponentsBuilder<T>,
|
||||||
AO: RethRpcAddOns<NodeAdapter<T, CB::Components>>,
|
AO: RethRpcAddOns<NodeAdapter<T, CB::Components>>,
|
||||||
|
Types::Primitives:
|
||||||
|
FullNodePrimitives<Block: reth_node_api::Block<Body = reth_primitives::BlockBody>>,
|
||||||
{
|
{
|
||||||
type Node = NodeHandle<NodeAdapter<T, CB::Components>, AO>;
|
type Node = NodeHandle<NodeAdapter<T, CB::Components>, AO>;
|
||||||
|
|
||||||
|
|||||||
@ -71,6 +71,8 @@ where
|
|||||||
type ChainSpec = <N::Types as NodeTypes>::ChainSpec;
|
type ChainSpec = <N::Types as NodeTypes>::ChainSpec;
|
||||||
|
|
||||||
type StateCommitment = <N::Types as NodeTypes>::StateCommitment;
|
type StateCommitment = <N::Types as NodeTypes>::StateCommitment;
|
||||||
|
|
||||||
|
type Storage = <N::Types as NodeTypes>::Storage;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N, C, AO> NodeTypesWithEngine for AnyNode<N, C, AO>
|
impl<N, C, AO> NodeTypesWithEngine for AnyNode<N, C, AO>
|
||||||
|
|||||||
@ -14,6 +14,7 @@ use reth_exex::ExExManagerHandle;
|
|||||||
use reth_network_p2p::{
|
use reth_network_p2p::{
|
||||||
bodies::downloader::BodyDownloader, headers::downloader::HeaderDownloader, EthBlockClient,
|
bodies::downloader::BodyDownloader, headers::downloader::HeaderDownloader, EthBlockClient,
|
||||||
};
|
};
|
||||||
|
use reth_node_api::FullNodePrimitives;
|
||||||
use reth_provider::{providers::ProviderNodeTypes, ProviderFactory};
|
use reth_provider::{providers::ProviderNodeTypes, ProviderFactory};
|
||||||
use reth_stages::{prelude::DefaultStages, stages::ExecutionStage, Pipeline, StageSet};
|
use reth_stages::{prelude::DefaultStages, stages::ExecutionStage, Pipeline, StageSet};
|
||||||
use reth_static_file::StaticFileProducer;
|
use reth_static_file::StaticFileProducer;
|
||||||
@ -40,6 +41,8 @@ where
|
|||||||
N: ProviderNodeTypes,
|
N: ProviderNodeTypes,
|
||||||
Client: EthBlockClient + 'static,
|
Client: EthBlockClient + 'static,
|
||||||
Executor: BlockExecutorProvider,
|
Executor: BlockExecutorProvider,
|
||||||
|
N::Primitives:
|
||||||
|
FullNodePrimitives<Block: reth_node_api::Block<Body = reth_primitives::BlockBody>>,
|
||||||
{
|
{
|
||||||
// building network downloaders using the fetch client
|
// building network downloaders using the fetch client
|
||||||
let header_downloader = ReverseHeadersDownloaderBuilder::new(config.headers)
|
let header_downloader = ReverseHeadersDownloaderBuilder::new(config.headers)
|
||||||
@ -85,8 +88,12 @@ pub fn build_pipeline<N, H, B, Executor>(
|
|||||||
where
|
where
|
||||||
N: ProviderNodeTypes,
|
N: ProviderNodeTypes,
|
||||||
H: HeaderDownloader<Header = alloy_consensus::Header> + 'static,
|
H: HeaderDownloader<Header = alloy_consensus::Header> + 'static,
|
||||||
B: BodyDownloader<Body = reth_primitives::BlockBody> + 'static,
|
B: BodyDownloader<
|
||||||
|
Body = <<N::Primitives as FullNodePrimitives>::Block as reth_node_api::Block>::Body,
|
||||||
|
> + 'static,
|
||||||
Executor: BlockExecutorProvider,
|
Executor: BlockExecutorProvider,
|
||||||
|
N::Primitives:
|
||||||
|
FullNodePrimitives<Block: reth_node_api::Block<Body = reth_primitives::BlockBody>>,
|
||||||
{
|
{
|
||||||
let mut builder = Pipeline::<N>::builder();
|
let mut builder = Pipeline::<N>::builder();
|
||||||
|
|
||||||
|
|||||||
@ -9,12 +9,11 @@
|
|||||||
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
|
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
|
||||||
#![cfg_attr(not(feature = "std"), no_std)]
|
#![cfg_attr(not(feature = "std"), no_std)]
|
||||||
|
|
||||||
|
use core::{fmt::Debug, marker::PhantomData};
|
||||||
pub use reth_primitives_traits::{
|
pub use reth_primitives_traits::{
|
||||||
Block, BlockBody, FullBlock, FullNodePrimitives, FullReceipt, FullSignedTx, NodePrimitives,
|
Block, BlockBody, FullBlock, FullNodePrimitives, FullReceipt, FullSignedTx, NodePrimitives,
|
||||||
};
|
};
|
||||||
|
|
||||||
use core::marker::PhantomData;
|
|
||||||
|
|
||||||
use reth_chainspec::EthChainSpec;
|
use reth_chainspec::EthChainSpec;
|
||||||
use reth_db_api::{
|
use reth_db_api::{
|
||||||
database_metrics::{DatabaseMetadata, DatabaseMetrics},
|
database_metrics::{DatabaseMetadata, DatabaseMetrics},
|
||||||
@ -35,6 +34,8 @@ pub trait NodeTypes: Send + Sync + Unpin + 'static {
|
|||||||
type ChainSpec: EthChainSpec;
|
type ChainSpec: EthChainSpec;
|
||||||
/// The type used to perform state commitment operations.
|
/// The type used to perform state commitment operations.
|
||||||
type StateCommitment: StateCommitment;
|
type StateCommitment: StateCommitment;
|
||||||
|
/// The type responsible for writing chain primitives to storage.
|
||||||
|
type Storage: Default + Send + Sync + Unpin + Debug + 'static;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The type that configures an Ethereum-like node with an engine for consensus.
|
/// The type that configures an Ethereum-like node with an engine for consensus.
|
||||||
@ -86,6 +87,7 @@ where
|
|||||||
type Primitives = Types::Primitives;
|
type Primitives = Types::Primitives;
|
||||||
type ChainSpec = Types::ChainSpec;
|
type ChainSpec = Types::ChainSpec;
|
||||||
type StateCommitment = Types::StateCommitment;
|
type StateCommitment = Types::StateCommitment;
|
||||||
|
type Storage = Types::Storage;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Types, DB> NodeTypesWithEngine for NodeTypesWithDBAdapter<Types, DB>
|
impl<Types, DB> NodeTypesWithEngine for NodeTypesWithDBAdapter<Types, DB>
|
||||||
@ -105,86 +107,128 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// A [`NodeTypes`] type builder.
|
/// A [`NodeTypes`] type builder.
|
||||||
#[derive(Default, Debug)]
|
#[derive(Debug)]
|
||||||
pub struct AnyNodeTypes<P = (), C = (), S = ()>(PhantomData<P>, PhantomData<C>, PhantomData<S>);
|
pub struct AnyNodeTypes<P = (), C = (), SC = (), S = ()>(
|
||||||
|
PhantomData<P>,
|
||||||
|
PhantomData<C>,
|
||||||
|
PhantomData<SC>,
|
||||||
|
PhantomData<S>,
|
||||||
|
);
|
||||||
|
|
||||||
|
impl<P, C, SC, S> Default for AnyNodeTypes<P, C, SC, S> {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<P, C, SC, S> AnyNodeTypes<P, C, SC, S> {
|
||||||
|
/// Creates a new instance of [`AnyNodeTypes`].
|
||||||
|
pub const fn new() -> Self {
|
||||||
|
Self(PhantomData, PhantomData, PhantomData, PhantomData)
|
||||||
|
}
|
||||||
|
|
||||||
impl<P, C, S> AnyNodeTypes<P, C, S> {
|
|
||||||
/// Sets the `Primitives` associated type.
|
/// Sets the `Primitives` associated type.
|
||||||
pub const fn primitives<T>(self) -> AnyNodeTypes<T, C, S> {
|
pub const fn primitives<T>(self) -> AnyNodeTypes<T, C, SC, S> {
|
||||||
AnyNodeTypes::<T, C, S>(PhantomData::<T>, PhantomData::<C>, PhantomData::<S>)
|
AnyNodeTypes::new()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the `ChainSpec` associated type.
|
/// Sets the `ChainSpec` associated type.
|
||||||
pub const fn chain_spec<T>(self) -> AnyNodeTypes<P, T, S> {
|
pub const fn chain_spec<T>(self) -> AnyNodeTypes<P, T, SC, S> {
|
||||||
AnyNodeTypes::<P, T, S>(PhantomData::<P>, PhantomData::<T>, PhantomData::<S>)
|
AnyNodeTypes::new()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the `StateCommitment` associated type.
|
/// Sets the `StateCommitment` associated type.
|
||||||
pub const fn state_commitment<T>(self) -> AnyNodeTypes<P, C, T> {
|
pub const fn state_commitment<T>(self) -> AnyNodeTypes<P, C, T, S> {
|
||||||
AnyNodeTypes::<P, C, T>(PhantomData::<P>, PhantomData::<C>, PhantomData::<T>)
|
AnyNodeTypes::new()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Sets the `Storage` associated type.
|
||||||
|
pub const fn storage<T>(self) -> AnyNodeTypes<P, C, SC, T> {
|
||||||
|
AnyNodeTypes::new()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<P, C, S> NodeTypes for AnyNodeTypes<P, C, S>
|
impl<P, C, SC, S> NodeTypes for AnyNodeTypes<P, C, SC, S>
|
||||||
where
|
where
|
||||||
P: NodePrimitives + Send + Sync + Unpin + 'static,
|
P: NodePrimitives + Send + Sync + Unpin + 'static,
|
||||||
C: EthChainSpec + 'static,
|
C: EthChainSpec + 'static,
|
||||||
S: StateCommitment,
|
SC: StateCommitment,
|
||||||
|
S: Default + Send + Sync + Unpin + Debug + 'static,
|
||||||
{
|
{
|
||||||
type Primitives = P;
|
type Primitives = P;
|
||||||
type ChainSpec = C;
|
type ChainSpec = C;
|
||||||
type StateCommitment = S;
|
type StateCommitment = SC;
|
||||||
|
type Storage = S;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A [`NodeTypesWithEngine`] type builder.
|
/// A [`NodeTypesWithEngine`] type builder.
|
||||||
#[derive(Default, Debug)]
|
#[derive(Debug)]
|
||||||
pub struct AnyNodeTypesWithEngine<P = (), E = (), C = (), S = ()> {
|
pub struct AnyNodeTypesWithEngine<P = (), E = (), C = (), SC = (), S = ()> {
|
||||||
/// Embedding the basic node types.
|
/// Embedding the basic node types.
|
||||||
base: AnyNodeTypes<P, C, S>,
|
_base: AnyNodeTypes<P, C, SC, S>,
|
||||||
/// Phantom data for the engine.
|
/// Phantom data for the engine.
|
||||||
_engine: PhantomData<E>,
|
_engine: PhantomData<E>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<P, E, C, S> AnyNodeTypesWithEngine<P, E, C, S> {
|
impl<P, E, C, SC, S> Default for AnyNodeTypesWithEngine<P, E, C, SC, S> {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<P, E, C, SC, S> AnyNodeTypesWithEngine<P, E, C, SC, S> {
|
||||||
|
/// Creates a new instance of [`AnyNodeTypesWithEngine`].
|
||||||
|
pub const fn new() -> Self {
|
||||||
|
Self { _base: AnyNodeTypes::new(), _engine: PhantomData }
|
||||||
|
}
|
||||||
|
|
||||||
/// Sets the `Primitives` associated type.
|
/// Sets the `Primitives` associated type.
|
||||||
pub const fn primitives<T>(self) -> AnyNodeTypesWithEngine<T, E, C, S> {
|
pub const fn primitives<T>(self) -> AnyNodeTypesWithEngine<T, E, C, SC, S> {
|
||||||
AnyNodeTypesWithEngine { base: self.base.primitives::<T>(), _engine: PhantomData }
|
AnyNodeTypesWithEngine::new()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the `Engine` associated type.
|
/// Sets the `Engine` associated type.
|
||||||
pub const fn engine<T>(self) -> AnyNodeTypesWithEngine<P, T, C, S> {
|
pub const fn engine<T>(self) -> AnyNodeTypesWithEngine<P, T, C, SC, S> {
|
||||||
AnyNodeTypesWithEngine { base: self.base, _engine: PhantomData::<T> }
|
AnyNodeTypesWithEngine::new()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the `ChainSpec` associated type.
|
/// Sets the `ChainSpec` associated type.
|
||||||
pub const fn chain_spec<T>(self) -> AnyNodeTypesWithEngine<P, E, T, S> {
|
pub const fn chain_spec<T>(self) -> AnyNodeTypesWithEngine<P, E, T, SC, S> {
|
||||||
AnyNodeTypesWithEngine { base: self.base.chain_spec::<T>(), _engine: PhantomData }
|
AnyNodeTypesWithEngine::new()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the `StateCommitment` associated type.
|
/// Sets the `StateCommitment` associated type.
|
||||||
pub const fn state_commitment<T>(self) -> AnyNodeTypesWithEngine<P, E, C, T> {
|
pub const fn state_commitment<T>(self) -> AnyNodeTypesWithEngine<P, E, C, T, S> {
|
||||||
AnyNodeTypesWithEngine { base: self.base.state_commitment::<T>(), _engine: PhantomData }
|
AnyNodeTypesWithEngine::new()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Sets the `Storage` associated type.
|
||||||
|
pub const fn storage<T>(self) -> AnyNodeTypesWithEngine<P, E, C, SC, T> {
|
||||||
|
AnyNodeTypesWithEngine::new()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<P, E, C, S> NodeTypes for AnyNodeTypesWithEngine<P, E, C, S>
|
impl<P, E, C, SC, S> NodeTypes for AnyNodeTypesWithEngine<P, E, C, SC, S>
|
||||||
where
|
where
|
||||||
P: NodePrimitives + Send + Sync + Unpin + 'static,
|
P: NodePrimitives + Send + Sync + Unpin + 'static,
|
||||||
E: EngineTypes + Send + Sync + Unpin,
|
E: EngineTypes + Send + Sync + Unpin,
|
||||||
C: EthChainSpec + 'static,
|
C: EthChainSpec + 'static,
|
||||||
S: StateCommitment,
|
SC: StateCommitment,
|
||||||
|
S: Default + Send + Sync + Unpin + Debug + 'static,
|
||||||
{
|
{
|
||||||
type Primitives = P;
|
type Primitives = P;
|
||||||
type ChainSpec = C;
|
type ChainSpec = C;
|
||||||
type StateCommitment = S;
|
type StateCommitment = SC;
|
||||||
|
type Storage = S;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<P, E, C, S> NodeTypesWithEngine for AnyNodeTypesWithEngine<P, E, C, S>
|
impl<P, E, C, SC, S> NodeTypesWithEngine for AnyNodeTypesWithEngine<P, E, C, SC, S>
|
||||||
where
|
where
|
||||||
P: NodePrimitives + Send + Sync + Unpin + 'static,
|
P: NodePrimitives + Send + Sync + Unpin + 'static,
|
||||||
E: EngineTypes + Send + Sync + Unpin,
|
E: EngineTypes + Send + Sync + Unpin,
|
||||||
C: EthChainSpec + 'static,
|
C: EthChainSpec + 'static,
|
||||||
S: StateCommitment,
|
SC: StateCommitment,
|
||||||
|
S: Default + Send + Sync + Unpin + Debug + 'static,
|
||||||
{
|
{
|
||||||
type Engine = E;
|
type Engine = E;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
use alloy_primitives::B256;
|
use alloy_primitives::B256;
|
||||||
use futures_util::{Stream, StreamExt};
|
use futures_util::{Stream, StreamExt};
|
||||||
|
use reth_cli_commands::common::CliNodeTypes;
|
||||||
use reth_config::Config;
|
use reth_config::Config;
|
||||||
use reth_consensus::Consensus;
|
use reth_consensus::Consensus;
|
||||||
use reth_downloaders::{
|
use reth_downloaders::{
|
||||||
@ -38,7 +39,7 @@ pub(crate) async fn build_import_pipeline<N, C>(
|
|||||||
disable_exec: bool,
|
disable_exec: bool,
|
||||||
) -> eyre::Result<(Pipeline<N>, impl Stream<Item = NodeEvent>)>
|
) -> eyre::Result<(Pipeline<N>, impl Stream<Item = NodeEvent>)>
|
||||||
where
|
where
|
||||||
N: ProviderNodeTypes<ChainSpec = OpChainSpec>,
|
N: CliNodeTypes + ProviderNodeTypes<ChainSpec = OpChainSpec>,
|
||||||
C: Consensus + 'static,
|
C: Consensus + 'static,
|
||||||
{
|
{
|
||||||
if !file_client.has_canonical_blocks() {
|
if !file_client.has_canonical_blocks() {
|
||||||
|
|||||||
@ -13,6 +13,7 @@ workspace = true
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
# reth
|
# reth
|
||||||
reth-chainspec.workspace = true
|
reth-chainspec.workspace = true
|
||||||
|
reth-db.workspace = true
|
||||||
reth-engine-local.workspace = true
|
reth-engine-local.workspace = true
|
||||||
reth-primitives.workspace = true
|
reth-primitives.workspace = true
|
||||||
reth-payload-builder.workspace = true
|
reth-payload-builder.workspace = true
|
||||||
|
|||||||
@ -5,10 +5,12 @@ use std::sync::Arc;
|
|||||||
use alloy_consensus::Header;
|
use alloy_consensus::Header;
|
||||||
use reth_basic_payload_builder::{BasicPayloadJobGenerator, BasicPayloadJobGeneratorConfig};
|
use reth_basic_payload_builder::{BasicPayloadJobGenerator, BasicPayloadJobGeneratorConfig};
|
||||||
use reth_chainspec::{EthChainSpec, Hardforks};
|
use reth_chainspec::{EthChainSpec, Hardforks};
|
||||||
|
use reth_db::transaction::{DbTx, DbTxMut};
|
||||||
use reth_evm::{execute::BasicBlockExecutorProvider, ConfigureEvm};
|
use reth_evm::{execute::BasicBlockExecutorProvider, ConfigureEvm};
|
||||||
use reth_network::{NetworkConfig, NetworkHandle, NetworkManager, PeersInfo};
|
use reth_network::{NetworkConfig, NetworkHandle, NetworkManager, PeersInfo};
|
||||||
use reth_node_api::{
|
use reth_node_api::{
|
||||||
AddOnsContext, EngineValidator, FullNodeComponents, NodeAddOns, PayloadBuilder,
|
AddOnsContext, EngineValidator, FullNodeComponents, FullNodePrimitives, NodeAddOns,
|
||||||
|
PayloadBuilder,
|
||||||
};
|
};
|
||||||
use reth_node_builder::{
|
use reth_node_builder::{
|
||||||
components::{
|
components::{
|
||||||
@ -28,7 +30,11 @@ use reth_optimism_rpc::{
|
|||||||
OpEthApi,
|
OpEthApi,
|
||||||
};
|
};
|
||||||
use reth_payload_builder::{PayloadBuilderHandle, PayloadBuilderService};
|
use reth_payload_builder::{PayloadBuilderHandle, PayloadBuilderService};
|
||||||
use reth_provider::CanonStateSubscriptions;
|
use reth_primitives::{Block, BlockBody, Receipt, TransactionSigned, TxType};
|
||||||
|
use reth_provider::{
|
||||||
|
providers::ChainStorage, BlockBodyWriter, CanonStateSubscriptions, DBProvider, EthStorage,
|
||||||
|
ProviderResult,
|
||||||
|
};
|
||||||
use reth_rpc_server_types::RethRpcModule;
|
use reth_rpc_server_types::RethRpcModule;
|
||||||
use reth_tracing::tracing::{debug, info};
|
use reth_tracing::tracing::{debug, info};
|
||||||
use reth_transaction_pool::{
|
use reth_transaction_pool::{
|
||||||
@ -43,7 +49,42 @@ use crate::{
|
|||||||
txpool::{OpTransactionPool, OpTransactionValidator},
|
txpool::{OpTransactionPool, OpTransactionValidator},
|
||||||
OpEngineTypes,
|
OpEngineTypes,
|
||||||
};
|
};
|
||||||
|
/// Optimism primitive types.
|
||||||
|
#[derive(Debug, Default, Clone, PartialEq, Eq)]
|
||||||
|
pub struct OpPrimitives;
|
||||||
|
|
||||||
|
impl FullNodePrimitives for OpPrimitives {
|
||||||
|
type Block = Block;
|
||||||
|
type SignedTx = TransactionSigned;
|
||||||
|
type TxType = TxType;
|
||||||
|
type Receipt = Receipt;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Storage implementation for Optimism.
|
||||||
|
#[derive(Debug, Default, Clone)]
|
||||||
|
pub struct OpStorage(EthStorage);
|
||||||
|
|
||||||
|
impl<Provider: DBProvider<Tx: DbTxMut>> BlockBodyWriter<Provider, BlockBody> for OpStorage {
|
||||||
|
fn write_block_bodies(
|
||||||
|
&self,
|
||||||
|
provider: &Provider,
|
||||||
|
bodies: Vec<(u64, Option<BlockBody>)>,
|
||||||
|
) -> ProviderResult<()> {
|
||||||
|
self.0.write_block_bodies(provider, bodies)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ChainStorage<OpPrimitives> for OpStorage {
|
||||||
|
fn writer<TX, Types>(
|
||||||
|
&self,
|
||||||
|
) -> impl reth_provider::ChainStorageWriter<reth_provider::DatabaseProvider<TX, Types>, OpPrimitives>
|
||||||
|
where
|
||||||
|
TX: DbTxMut + DbTx + 'static,
|
||||||
|
Types: NodeTypes<Primitives = OpPrimitives>,
|
||||||
|
{
|
||||||
|
self
|
||||||
|
}
|
||||||
|
}
|
||||||
/// Type configuration for a regular Optimism node.
|
/// Type configuration for a regular Optimism node.
|
||||||
#[derive(Debug, Default, Clone)]
|
#[derive(Debug, Default, Clone)]
|
||||||
#[non_exhaustive]
|
#[non_exhaustive]
|
||||||
@ -90,7 +131,14 @@ impl OpNode {
|
|||||||
|
|
||||||
impl<N> Node<N> for OpNode
|
impl<N> Node<N> for OpNode
|
||||||
where
|
where
|
||||||
N: FullNodeTypes<Types: NodeTypesWithEngine<Engine = OpEngineTypes, ChainSpec = OpChainSpec>>,
|
N: FullNodeTypes<
|
||||||
|
Types: NodeTypesWithEngine<
|
||||||
|
Engine = OpEngineTypes,
|
||||||
|
ChainSpec = OpChainSpec,
|
||||||
|
Primitives = OpPrimitives,
|
||||||
|
Storage = OpStorage,
|
||||||
|
>,
|
||||||
|
>,
|
||||||
{
|
{
|
||||||
type ComponentsBuilder = ComponentsBuilder<
|
type ComponentsBuilder = ComponentsBuilder<
|
||||||
N,
|
N,
|
||||||
@ -115,9 +163,10 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl NodeTypes for OpNode {
|
impl NodeTypes for OpNode {
|
||||||
type Primitives = reth_primitives::EthPrimitives; // todo: replace with OpPrimitives when EthPrimitives is only used in reth-ethereum-* crates
|
type Primitives = OpPrimitives;
|
||||||
type ChainSpec = OpChainSpec;
|
type ChainSpec = OpChainSpec;
|
||||||
type StateCommitment = MerklePatriciaTrie;
|
type StateCommitment = MerklePatriciaTrie;
|
||||||
|
type Storage = OpStorage;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NodeTypesWithEngine for OpNode {
|
impl NodeTypesWithEngine for OpNode {
|
||||||
@ -144,7 +193,7 @@ impl<N: FullNodeComponents> OpAddOns<N> {
|
|||||||
impl<N> NodeAddOns<N> for OpAddOns<N>
|
impl<N> NodeAddOns<N> for OpAddOns<N>
|
||||||
where
|
where
|
||||||
N: FullNodeComponents<
|
N: FullNodeComponents<
|
||||||
Types: NodeTypes<ChainSpec = OpChainSpec>,
|
Types: NodeTypes<ChainSpec = OpChainSpec, Primitives = OpPrimitives, Storage = OpStorage>,
|
||||||
PayloadBuilder: PayloadBuilder<PayloadType = <N::Types as NodeTypesWithEngine>::Engine>,
|
PayloadBuilder: PayloadBuilder<PayloadType = <N::Types as NodeTypesWithEngine>::Engine>,
|
||||||
>,
|
>,
|
||||||
OpEngineValidator: EngineValidator<<N::Types as NodeTypesWithEngine>::Engine>,
|
OpEngineValidator: EngineValidator<<N::Types as NodeTypesWithEngine>::Engine>,
|
||||||
@ -172,7 +221,7 @@ where
|
|||||||
impl<N> RethRpcAddOns<N> for OpAddOns<N>
|
impl<N> RethRpcAddOns<N> for OpAddOns<N>
|
||||||
where
|
where
|
||||||
N: FullNodeComponents<
|
N: FullNodeComponents<
|
||||||
Types: NodeTypes<ChainSpec = OpChainSpec>,
|
Types: NodeTypes<ChainSpec = OpChainSpec, Primitives = OpPrimitives, Storage = OpStorage>,
|
||||||
PayloadBuilder: PayloadBuilder<PayloadType = <N::Types as NodeTypesWithEngine>::Engine>,
|
PayloadBuilder: PayloadBuilder<PayloadType = <N::Types as NodeTypesWithEngine>::Engine>,
|
||||||
>,
|
>,
|
||||||
OpEngineValidator: EngineValidator<<N::Types as NodeTypesWithEngine>::Engine>,
|
OpEngineValidator: EngineValidator<<N::Types as NodeTypesWithEngine>::Engine>,
|
||||||
|
|||||||
@ -10,9 +10,9 @@ use reth_codecs::Compact;
|
|||||||
use crate::{BlockHeader, FullBlockHeader, InMemorySize, MaybeSerde};
|
use crate::{BlockHeader, FullBlockHeader, InMemorySize, MaybeSerde};
|
||||||
|
|
||||||
/// Helper trait that unifies all behaviour required by block to support full node operations.
|
/// Helper trait that unifies all behaviour required by block to support full node operations.
|
||||||
pub trait FullBlock: Block<Header: Compact> + Compact {}
|
pub trait FullBlock: Block<Header: Compact> {}
|
||||||
|
|
||||||
impl<T> FullBlock for T where T: Block<Header: FullBlockHeader> + Compact {}
|
impl<T> FullBlock for T where T: Block<Header: FullBlockHeader> {}
|
||||||
|
|
||||||
/// Abstraction of block data type.
|
/// Abstraction of block data type.
|
||||||
// todo: make sealable super-trait, depends on <https://github.com/paradigmxyz/reth/issues/11449>
|
// todo: make sealable super-trait, depends on <https://github.com/paradigmxyz/reth/issues/11449>
|
||||||
|
|||||||
@ -79,6 +79,15 @@ pub mod serde_bincode_compat {
|
|||||||
#[derive(Debug, Clone, Default, PartialEq, Eq)]
|
#[derive(Debug, Clone, Default, PartialEq, Eq)]
|
||||||
pub struct EthPrimitives;
|
pub struct EthPrimitives;
|
||||||
|
|
||||||
|
#[cfg(feature = "reth-codec")]
|
||||||
|
impl reth_primitives_traits::FullNodePrimitives for EthPrimitives {
|
||||||
|
type Block = crate::Block;
|
||||||
|
type SignedTx = crate::TransactionSigned;
|
||||||
|
type TxType = crate::TxType;
|
||||||
|
type Receipt = crate::Receipt;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(feature = "reth-codec"))]
|
||||||
impl NodePrimitives for EthPrimitives {
|
impl NodePrimitives for EthPrimitives {
|
||||||
type Block = crate::Block;
|
type Block = crate::Block;
|
||||||
type SignedTx = crate::TransactionSigned;
|
type SignedTx = crate::TransactionSigned;
|
||||||
|
|||||||
@ -198,7 +198,10 @@ where
|
|||||||
// Write bodies to database. This will NOT write transactions to database as we've already
|
// Write bodies to database. This will NOT write transactions to database as we've already
|
||||||
// written them directly to static files.
|
// written them directly to static files.
|
||||||
provider.append_block_bodies(
|
provider.append_block_bodies(
|
||||||
buffer.into_iter().map(|response| (response.block_number(), response.into_body())),
|
buffer
|
||||||
|
.into_iter()
|
||||||
|
.map(|response| (response.block_number(), response.into_body()))
|
||||||
|
.collect(),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// The stage is "done" if:
|
// The stage is "done" if:
|
||||||
|
|||||||
@ -15,7 +15,7 @@ use reth_db_api::{
|
|||||||
DatabaseError as DbError,
|
DatabaseError as DbError,
|
||||||
};
|
};
|
||||||
use reth_primitives::{
|
use reth_primitives::{
|
||||||
Account, Receipt, SealedBlock, SealedHeader, StaticFileSegment, StorageEntry,
|
Account, EthPrimitives, Receipt, SealedBlock, SealedHeader, StaticFileSegment, StorageEntry,
|
||||||
};
|
};
|
||||||
use reth_provider::{
|
use reth_provider::{
|
||||||
providers::{StaticFileProvider, StaticFileProviderRWRefMut, StaticFileWriter},
|
providers::{StaticFileProvider, StaticFileProviderRWRefMut, StaticFileWriter},
|
||||||
@ -142,7 +142,7 @@ impl TestStageDB {
|
|||||||
|
|
||||||
/// Insert header to static file if `writer` exists, otherwise to DB.
|
/// Insert header to static file if `writer` exists, otherwise to DB.
|
||||||
pub fn insert_header<TX: DbTx + DbTxMut>(
|
pub fn insert_header<TX: DbTx + DbTxMut>(
|
||||||
writer: Option<&mut StaticFileProviderRWRefMut<'_, ()>>,
|
writer: Option<&mut StaticFileProviderRWRefMut<'_, EthPrimitives>>,
|
||||||
tx: &TX,
|
tx: &TX,
|
||||||
header: &SealedHeader,
|
header: &SealedHeader,
|
||||||
td: U256,
|
td: U256,
|
||||||
|
|||||||
@ -17,6 +17,7 @@ reth-chainspec.workspace = true
|
|||||||
reth-blockchain-tree-api.workspace = true
|
reth-blockchain-tree-api.workspace = true
|
||||||
reth-execution-types.workspace = true
|
reth-execution-types.workspace = true
|
||||||
reth-primitives = { workspace = true, features = ["reth-codec", "secp256k1"] }
|
reth-primitives = { workspace = true, features = ["reth-codec", "secp256k1"] }
|
||||||
|
reth-primitives-traits.workspace = true
|
||||||
reth-fs-util.workspace = true
|
reth-fs-util.workspace = true
|
||||||
reth-errors.workspace = true
|
reth-errors.workspace = true
|
||||||
reth-storage-errors.workspace = true
|
reth-storage-errors.workspace = true
|
||||||
@ -111,6 +112,7 @@ serde = [
|
|||||||
"revm/serde",
|
"revm/serde",
|
||||||
"reth-codecs/serde",
|
"reth-codecs/serde",
|
||||||
"reth-optimism-primitives?/serde",
|
"reth-optimism-primitives?/serde",
|
||||||
|
"reth-primitives-traits/serde",
|
||||||
]
|
]
|
||||||
test-utils = [
|
test-utils = [
|
||||||
"reth-db/test-utils",
|
"reth-db/test-utils",
|
||||||
@ -122,6 +124,7 @@ test-utils = [
|
|||||||
"reth-evm/test-utils",
|
"reth-evm/test-utils",
|
||||||
"reth-network-p2p/test-utils",
|
"reth-network-p2p/test-utils",
|
||||||
"reth-primitives/test-utils",
|
"reth-primitives/test-utils",
|
||||||
|
"reth-primitives-traits/test-utils",
|
||||||
"reth-codecs/test-utils",
|
"reth-codecs/test-utils",
|
||||||
"reth-db-api/test-utils",
|
"reth-db-api/test-utils",
|
||||||
"reth-trie-db/test-utils",
|
"reth-trie-db/test-utils",
|
||||||
|
|||||||
26
crates/storage/provider/src/providers/database/chain.rs
Normal file
26
crates/storage/provider/src/providers/database/chain.rs
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
use crate::{providers::NodeTypes, DatabaseProvider};
|
||||||
|
use reth_db::transaction::{DbTx, DbTxMut};
|
||||||
|
use reth_node_types::FullNodePrimitives;
|
||||||
|
use reth_primitives::EthPrimitives;
|
||||||
|
use reth_storage_api::{ChainStorageWriter, EthStorage};
|
||||||
|
|
||||||
|
/// Trait that provides access to implementations of [`ChainStorage`]
|
||||||
|
pub trait ChainStorage<Primitives: FullNodePrimitives>: Send + Sync {
|
||||||
|
/// Provides access to the chain writer.
|
||||||
|
fn writer<TX, Types>(&self) -> impl ChainStorageWriter<DatabaseProvider<TX, Types>, Primitives>
|
||||||
|
where
|
||||||
|
TX: DbTxMut + DbTx + 'static,
|
||||||
|
Types: NodeTypes<Primitives = Primitives>;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ChainStorage<EthPrimitives> for EthStorage {
|
||||||
|
fn writer<TX, Types>(
|
||||||
|
&self,
|
||||||
|
) -> impl ChainStorageWriter<DatabaseProvider<TX, Types>, EthPrimitives>
|
||||||
|
where
|
||||||
|
TX: DbTxMut + DbTx + 'static,
|
||||||
|
Types: NodeTypes<Primitives = EthPrimitives>,
|
||||||
|
{
|
||||||
|
self
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -44,6 +44,9 @@ use super::ProviderNodeTypes;
|
|||||||
|
|
||||||
mod metrics;
|
mod metrics;
|
||||||
|
|
||||||
|
mod chain;
|
||||||
|
pub use chain::*;
|
||||||
|
|
||||||
/// A common provider that fetches data from a database or static file.
|
/// A common provider that fetches data from a database or static file.
|
||||||
///
|
///
|
||||||
/// This provider implements most provider or provider factory traits.
|
/// This provider implements most provider or provider factory traits.
|
||||||
@ -56,19 +59,22 @@ pub struct ProviderFactory<N: NodeTypesWithDB> {
|
|||||||
static_file_provider: StaticFileProvider<N::Primitives>,
|
static_file_provider: StaticFileProvider<N::Primitives>,
|
||||||
/// Optional pruning configuration
|
/// Optional pruning configuration
|
||||||
prune_modes: PruneModes,
|
prune_modes: PruneModes,
|
||||||
|
/// The node storage handler.
|
||||||
|
storage: Arc<N::Storage>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N> fmt::Debug for ProviderFactory<N>
|
impl<N> fmt::Debug for ProviderFactory<N>
|
||||||
where
|
where
|
||||||
N: NodeTypesWithDB<DB: fmt::Debug, ChainSpec: fmt::Debug>,
|
N: NodeTypesWithDB<DB: fmt::Debug, ChainSpec: fmt::Debug, Storage: fmt::Debug>,
|
||||||
{
|
{
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
let Self { db, chain_spec, static_file_provider, prune_modes } = self;
|
let Self { db, chain_spec, static_file_provider, prune_modes, storage } = self;
|
||||||
f.debug_struct("ProviderFactory")
|
f.debug_struct("ProviderFactory")
|
||||||
.field("db", &db)
|
.field("db", &db)
|
||||||
.field("chain_spec", &chain_spec)
|
.field("chain_spec", &chain_spec)
|
||||||
.field("static_file_provider", &static_file_provider)
|
.field("static_file_provider", &static_file_provider)
|
||||||
.field("prune_modes", &prune_modes)
|
.field("prune_modes", &prune_modes)
|
||||||
|
.field("storage", &storage)
|
||||||
.finish()
|
.finish()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -80,7 +86,13 @@ impl<N: NodeTypesWithDB> ProviderFactory<N> {
|
|||||||
chain_spec: Arc<N::ChainSpec>,
|
chain_spec: Arc<N::ChainSpec>,
|
||||||
static_file_provider: StaticFileProvider<N::Primitives>,
|
static_file_provider: StaticFileProvider<N::Primitives>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self { db, chain_spec, static_file_provider, prune_modes: PruneModes::none() }
|
Self {
|
||||||
|
db,
|
||||||
|
chain_spec,
|
||||||
|
static_file_provider,
|
||||||
|
prune_modes: PruneModes::none(),
|
||||||
|
storage: Default::default(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Enables metrics on the static file provider.
|
/// Enables metrics on the static file provider.
|
||||||
@ -121,6 +133,7 @@ impl<N: NodeTypesWithDB<DB = Arc<DatabaseEnv>>> ProviderFactory<N> {
|
|||||||
chain_spec,
|
chain_spec,
|
||||||
static_file_provider,
|
static_file_provider,
|
||||||
prune_modes: PruneModes::none(),
|
prune_modes: PruneModes::none(),
|
||||||
|
storage: Default::default(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -139,6 +152,7 @@ impl<N: ProviderNodeTypes> ProviderFactory<N> {
|
|||||||
self.chain_spec.clone(),
|
self.chain_spec.clone(),
|
||||||
self.static_file_provider.clone(),
|
self.static_file_provider.clone(),
|
||||||
self.prune_modes.clone(),
|
self.prune_modes.clone(),
|
||||||
|
self.storage.clone(),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -153,6 +167,7 @@ impl<N: ProviderNodeTypes> ProviderFactory<N> {
|
|||||||
self.chain_spec.clone(),
|
self.chain_spec.clone(),
|
||||||
self.static_file_provider.clone(),
|
self.static_file_provider.clone(),
|
||||||
self.prune_modes.clone(),
|
self.prune_modes.clone(),
|
||||||
|
self.storage.clone(),
|
||||||
)))
|
)))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -617,6 +632,7 @@ impl<N: NodeTypesWithDB> Clone for ProviderFactory<N> {
|
|||||||
chain_spec: self.chain_spec.clone(),
|
chain_spec: self.chain_spec.clone(),
|
||||||
static_file_provider: self.static_file_provider.clone(),
|
static_file_provider: self.static_file_provider.clone(),
|
||||||
prune_modes: self.prune_modes.clone(),
|
prune_modes: self.prune_modes.clone(),
|
||||||
|
storage: self.storage.clone(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,19 +1,24 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
bundle_state::StorageRevertsIter,
|
bundle_state::StorageRevertsIter,
|
||||||
providers::{database::metrics, static_file::StaticFileWriter, StaticFileProvider},
|
providers::{
|
||||||
|
database::{chain::ChainStorage, metrics},
|
||||||
|
static_file::StaticFileWriter,
|
||||||
|
ProviderNodeTypes, StaticFileProvider,
|
||||||
|
},
|
||||||
to_range,
|
to_range,
|
||||||
traits::{
|
traits::{
|
||||||
AccountExtReader, BlockSource, ChangeSetReader, ReceiptProvider, StageCheckpointWriter,
|
AccountExtReader, BlockSource, ChangeSetReader, ReceiptProvider, StageCheckpointWriter,
|
||||||
},
|
},
|
||||||
writer::UnifiedStorageWriter,
|
writer::UnifiedStorageWriter,
|
||||||
AccountReader, BlockExecutionWriter, BlockHashReader, BlockNumReader, BlockReader, BlockWriter,
|
AccountReader, BlockBodyWriter, BlockExecutionWriter, BlockHashReader, BlockNumReader,
|
||||||
BundleStateInit, ChainStateBlockReader, ChainStateBlockWriter, DBProvider, EvmEnvProvider,
|
BlockReader, BlockWriter, BundleStateInit, ChainStateBlockReader, ChainStateBlockWriter,
|
||||||
HashingWriter, HeaderProvider, HeaderSyncGap, HeaderSyncGapProvider, HistoricalStateProvider,
|
DBProvider, EvmEnvProvider, HashingWriter, HeaderProvider, HeaderSyncGap,
|
||||||
HistoricalStateProviderRef, HistoryWriter, LatestStateProvider, LatestStateProviderRef,
|
HeaderSyncGapProvider, HistoricalStateProvider, HistoricalStateProviderRef, HistoryWriter,
|
||||||
OriginalValuesKnown, ProviderError, PruneCheckpointReader, PruneCheckpointWriter, RevertsInit,
|
LatestStateProvider, LatestStateProviderRef, OriginalValuesKnown, ProviderError,
|
||||||
StageCheckpointReader, StateChangeWriter, StateProviderBox, StateReader, StateWriter,
|
PruneCheckpointReader, PruneCheckpointWriter, RevertsInit, StageCheckpointReader,
|
||||||
StaticFileProviderFactory, StatsReader, StorageReader, StorageTrieWriter, TransactionVariant,
|
StateChangeWriter, StateProviderBox, StateReader, StateWriter, StaticFileProviderFactory,
|
||||||
TransactionsProvider, TransactionsProviderExt, TrieWriter, WithdrawalsProvider,
|
StatsReader, StorageReader, StorageTrieWriter, TransactionVariant, TransactionsProvider,
|
||||||
|
TransactionsProviderExt, TrieWriter, WithdrawalsProvider,
|
||||||
};
|
};
|
||||||
use alloy_consensus::Header;
|
use alloy_consensus::Header;
|
||||||
use alloy_eips::{
|
use alloy_eips::{
|
||||||
@ -47,6 +52,7 @@ use reth_primitives::{
|
|||||||
SealedBlockWithSenders, SealedHeader, StaticFileSegment, StorageEntry, TransactionMeta,
|
SealedBlockWithSenders, SealedHeader, StaticFileSegment, StorageEntry, TransactionMeta,
|
||||||
TransactionSigned, TransactionSignedEcRecovered, TransactionSignedNoHash,
|
TransactionSigned, TransactionSignedEcRecovered, TransactionSignedNoHash,
|
||||||
};
|
};
|
||||||
|
use reth_primitives_traits::{BlockBody as _, FullNodePrimitives};
|
||||||
use reth_prune_types::{PruneCheckpoint, PruneModes, PruneSegment};
|
use reth_prune_types::{PruneCheckpoint, PruneModes, PruneSegment};
|
||||||
use reth_stages_types::{StageCheckpoint, StageId};
|
use reth_stages_types::{StageCheckpoint, StageId};
|
||||||
use reth_storage_api::{StateProvider, StorageChangeSetReader, TryIntoHistoricalStateProvider};
|
use reth_storage_api::{StateProvider, StorageChangeSetReader, TryIntoHistoricalStateProvider};
|
||||||
@ -138,6 +144,8 @@ pub struct DatabaseProvider<TX, N: NodeTypes> {
|
|||||||
static_file_provider: StaticFileProvider<N::Primitives>,
|
static_file_provider: StaticFileProvider<N::Primitives>,
|
||||||
/// Pruning configuration
|
/// Pruning configuration
|
||||||
prune_modes: PruneModes,
|
prune_modes: PruneModes,
|
||||||
|
/// Node storage handler.
|
||||||
|
storage: Arc<N::Storage>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<TX, N: NodeTypes> DatabaseProvider<TX, N> {
|
impl<TX, N: NodeTypes> DatabaseProvider<TX, N> {
|
||||||
@ -224,8 +232,9 @@ impl<TX: DbTxMut, N: NodeTypes> DatabaseProvider<TX, N> {
|
|||||||
chain_spec: Arc<N::ChainSpec>,
|
chain_spec: Arc<N::ChainSpec>,
|
||||||
static_file_provider: StaticFileProvider<N::Primitives>,
|
static_file_provider: StaticFileProvider<N::Primitives>,
|
||||||
prune_modes: PruneModes,
|
prune_modes: PruneModes,
|
||||||
|
storage: Arc<N::Storage>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self { tx, chain_spec, static_file_provider, prune_modes }
|
Self { tx, chain_spec, static_file_provider, prune_modes, storage }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -277,9 +286,7 @@ impl<TX: DbTx + 'static, N: NodeTypes> TryIntoHistoricalStateProvider for Databa
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Tx: DbTx + DbTxMut + 'static, N: NodeTypes<ChainSpec: EthereumHardforks> + 'static>
|
impl<Tx: DbTx + DbTxMut + 'static, N: ProviderNodeTypes + 'static> DatabaseProvider<Tx, N> {
|
||||||
DatabaseProvider<Tx, N>
|
|
||||||
{
|
|
||||||
// TODO: uncomment below, once `reth debug_cmd` has been feature gated with dev.
|
// TODO: uncomment below, once `reth debug_cmd` has been feature gated with dev.
|
||||||
// #[cfg(any(test, feature = "test-utils"))]
|
// #[cfg(any(test, feature = "test-utils"))]
|
||||||
/// Inserts an historical block. **Used for setting up test environments**
|
/// Inserts an historical block. **Used for setting up test environments**
|
||||||
@ -367,8 +374,9 @@ impl<TX: DbTx + 'static, N: NodeTypes> DatabaseProvider<TX, N> {
|
|||||||
chain_spec: Arc<N::ChainSpec>,
|
chain_spec: Arc<N::ChainSpec>,
|
||||||
static_file_provider: StaticFileProvider<N::Primitives>,
|
static_file_provider: StaticFileProvider<N::Primitives>,
|
||||||
prune_modes: PruneModes,
|
prune_modes: PruneModes,
|
||||||
|
storage: Arc<N::Storage>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self { tx, chain_spec, static_file_provider, prune_modes }
|
Self { tx, chain_spec, static_file_provider, prune_modes, storage }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Consume `DbTx` or `DbTxMut`.
|
/// Consume `DbTx` or `DbTxMut`.
|
||||||
@ -2899,8 +2907,8 @@ impl<TX: DbTx + 'static, N: NodeTypes> StateReader for DatabaseProvider<TX, N> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<TX: DbTxMut + DbTx + 'static, N: NodeTypes<ChainSpec: EthereumHardforks> + 'static>
|
impl<TX: DbTxMut + DbTx + 'static, N: ProviderNodeTypes + 'static> BlockExecutionWriter
|
||||||
BlockExecutionWriter for DatabaseProvider<TX, N>
|
for DatabaseProvider<TX, N>
|
||||||
{
|
{
|
||||||
fn take_block_and_execution_range(
|
fn take_block_and_execution_range(
|
||||||
&self,
|
&self,
|
||||||
@ -3101,10 +3109,11 @@ impl<TX: DbTxMut + DbTx + 'static, N: NodeTypes<ChainSpec: EthereumHardforks> +
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<TX: DbTxMut + DbTx + 'static, N: NodeTypes<ChainSpec: EthereumHardforks> + 'static> BlockWriter
|
impl<TX: DbTxMut + DbTx + 'static, N: ProviderNodeTypes + 'static> BlockWriter
|
||||||
for DatabaseProvider<TX, N>
|
for DatabaseProvider<TX, N>
|
||||||
{
|
{
|
||||||
type Body = BlockBody;
|
type Body =
|
||||||
|
<<N::Primitives as FullNodePrimitives>::Block as reth_primitives_traits::Block>::Body;
|
||||||
|
|
||||||
/// Inserts the block into the database, always modifying the following tables:
|
/// Inserts the block into the database, always modifying the following tables:
|
||||||
/// * [`CanonicalHeaders`](tables::CanonicalHeaders)
|
/// * [`CanonicalHeaders`](tables::CanonicalHeaders)
|
||||||
@ -3266,45 +3275,32 @@ impl<TX: DbTxMut + DbTx + 'static, N: NodeTypes<ChainSpec: EthereumHardforks> +
|
|||||||
|
|
||||||
fn append_block_bodies(
|
fn append_block_bodies(
|
||||||
&self,
|
&self,
|
||||||
bodies: impl Iterator<Item = (BlockNumber, Option<BlockBody>)>,
|
bodies: Vec<(BlockNumber, Option<Self::Body>)>,
|
||||||
) -> ProviderResult<()> {
|
) -> ProviderResult<()> {
|
||||||
let mut block_indices_cursor = self.tx.cursor_write::<tables::BlockBodyIndices>()?;
|
let mut block_indices_cursor = self.tx.cursor_write::<tables::BlockBodyIndices>()?;
|
||||||
let mut tx_block_cursor = self.tx.cursor_write::<tables::TransactionBlocks>()?;
|
let mut tx_block_cursor = self.tx.cursor_write::<tables::TransactionBlocks>()?;
|
||||||
let mut ommers_cursor = self.tx.cursor_write::<tables::BlockOmmers>()?;
|
|
||||||
let mut withdrawals_cursor = self.tx.cursor_write::<tables::BlockWithdrawals>()?;
|
|
||||||
|
|
||||||
// Get id for the next tx_num of zero if there are no transactions.
|
// Get id for the next tx_num of zero if there are no transactions.
|
||||||
let mut next_tx_num = tx_block_cursor.last()?.map(|(id, _)| id + 1).unwrap_or_default();
|
let mut next_tx_num = tx_block_cursor.last()?.map(|(id, _)| id + 1).unwrap_or_default();
|
||||||
|
|
||||||
for (block_number, body) in bodies {
|
for (block_number, body) in &bodies {
|
||||||
let tx_count = body.as_ref().map(|b| b.transactions.len() as u64).unwrap_or_default();
|
let tx_count = body.as_ref().map(|b| b.transactions().len() as u64).unwrap_or_default();
|
||||||
let block_indices = StoredBlockBodyIndices { first_tx_num: next_tx_num, tx_count };
|
let block_indices = StoredBlockBodyIndices { first_tx_num: next_tx_num, tx_count };
|
||||||
|
|
||||||
// insert block meta
|
// insert block meta
|
||||||
block_indices_cursor.append(block_number, block_indices)?;
|
block_indices_cursor.append(*block_number, block_indices)?;
|
||||||
|
|
||||||
next_tx_num += tx_count;
|
next_tx_num += tx_count;
|
||||||
let Some(body) = body else { continue };
|
let Some(body) = body else { continue };
|
||||||
|
|
||||||
// write transaction block index
|
// write transaction block index
|
||||||
if !body.transactions.is_empty() {
|
if !body.transactions().is_empty() {
|
||||||
tx_block_cursor.append(block_indices.last_tx_num(), block_number)?;
|
tx_block_cursor.append(block_indices.last_tx_num(), *block_number)?;
|
||||||
}
|
|
||||||
|
|
||||||
// Write ommers if any
|
|
||||||
if !body.ommers.is_empty() {
|
|
||||||
ommers_cursor.append(block_number, StoredBlockOmmers { ommers: body.ommers })?;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Write withdrawals if any
|
|
||||||
if let Some(withdrawals) = body.withdrawals {
|
|
||||||
if !withdrawals.is_empty() {
|
|
||||||
withdrawals_cursor
|
|
||||||
.append(block_number, StoredBlockWithdrawals { withdrawals })?;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.storage.writer().write_block_bodies(self, bodies)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -22,7 +22,7 @@ use reth_chain_state::{ChainInfoTracker, ForkChoiceNotifications, ForkChoiceSubs
|
|||||||
use reth_chainspec::{ChainInfo, EthereumHardforks};
|
use reth_chainspec::{ChainInfo, EthereumHardforks};
|
||||||
use reth_db_api::models::{AccountBeforeTx, StoredBlockBodyIndices};
|
use reth_db_api::models::{AccountBeforeTx, StoredBlockBodyIndices};
|
||||||
use reth_evm::ConfigureEvmEnv;
|
use reth_evm::ConfigureEvmEnv;
|
||||||
use reth_node_types::NodeTypesWithDB;
|
use reth_node_types::{FullNodePrimitives, NodeTypes, NodeTypesWithDB};
|
||||||
use reth_primitives::{
|
use reth_primitives::{
|
||||||
Account, Block, BlockWithSenders, Receipt, SealedBlock, SealedBlockWithSenders, SealedHeader,
|
Account, Block, BlockWithSenders, Receipt, SealedBlock, SealedBlockWithSenders, SealedHeader,
|
||||||
TransactionMeta, TransactionSigned, TransactionSignedNoHash,
|
TransactionMeta, TransactionSigned, TransactionSignedNoHash,
|
||||||
@ -37,6 +37,7 @@ use std::{
|
|||||||
sync::Arc,
|
sync::Arc,
|
||||||
time::Instant,
|
time::Instant,
|
||||||
};
|
};
|
||||||
|
|
||||||
use tracing::trace;
|
use tracing::trace;
|
||||||
|
|
||||||
mod database;
|
mod database;
|
||||||
@ -67,10 +68,35 @@ pub use blockchain_provider::BlockchainProvider2;
|
|||||||
mod consistent;
|
mod consistent;
|
||||||
pub use consistent::ConsistentProvider;
|
pub use consistent::ConsistentProvider;
|
||||||
|
|
||||||
/// Helper trait keeping common requirements of providers for [`NodeTypesWithDB`].
|
/// Helper trait to bound [`NodeTypes`] so that combined with database they satisfy
|
||||||
pub trait ProviderNodeTypes: NodeTypesWithDB<ChainSpec: EthereumHardforks> {}
|
/// [`ProviderNodeTypes`].
|
||||||
|
pub trait NodeTypesForProvider
|
||||||
|
where
|
||||||
|
Self: NodeTypes<
|
||||||
|
ChainSpec: EthereumHardforks,
|
||||||
|
Storage: ChainStorage<Self::Primitives>,
|
||||||
|
Primitives: FullNodePrimitives,
|
||||||
|
>,
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
impl<T> ProviderNodeTypes for T where T: NodeTypesWithDB<ChainSpec: EthereumHardforks> {}
|
impl<T> NodeTypesForProvider for T where
|
||||||
|
T: NodeTypes<
|
||||||
|
ChainSpec: EthereumHardforks,
|
||||||
|
Storage: ChainStorage<T::Primitives>,
|
||||||
|
Primitives: FullNodePrimitives,
|
||||||
|
>
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Helper trait keeping common requirements of providers for [`NodeTypesWithDB`].
|
||||||
|
pub trait ProviderNodeTypes
|
||||||
|
where
|
||||||
|
Self: NodeTypesForProvider + NodeTypesWithDB,
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> ProviderNodeTypes for T where T: NodeTypesForProvider + NodeTypesWithDB {}
|
||||||
|
|
||||||
/// The main type for interacting with the blockchain.
|
/// The main type for interacting with the blockchain.
|
||||||
///
|
///
|
||||||
|
|||||||
@ -1,9 +1,9 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
traits::{BlockSource, ReceiptProvider},
|
traits::{BlockSource, ReceiptProvider},
|
||||||
AccountReader, BlockHashReader, BlockIdReader, BlockNumReader, BlockReader, BlockReaderIdExt,
|
AccountReader, BlockHashReader, BlockIdReader, BlockNumReader, BlockReader, BlockReaderIdExt,
|
||||||
ChainSpecProvider, ChangeSetReader, DatabaseProvider, EvmEnvProvider, HeaderProvider,
|
ChainSpecProvider, ChangeSetReader, DatabaseProvider, EthStorage, EvmEnvProvider,
|
||||||
ReceiptProviderIdExt, StateProvider, StateProviderBox, StateProviderFactory, StateReader,
|
HeaderProvider, ReceiptProviderIdExt, StateProvider, StateProviderBox, StateProviderFactory,
|
||||||
StateRootProvider, TransactionVariant, TransactionsProvider, WithdrawalsProvider,
|
StateReader, StateRootProvider, TransactionVariant, TransactionsProvider, WithdrawalsProvider,
|
||||||
};
|
};
|
||||||
use alloy_consensus::{constants::EMPTY_ROOT_HASH, Header};
|
use alloy_consensus::{constants::EMPTY_ROOT_HASH, Header};
|
||||||
use alloy_eips::{
|
use alloy_eips::{
|
||||||
@ -23,7 +23,7 @@ use reth_evm::ConfigureEvmEnv;
|
|||||||
use reth_execution_types::ExecutionOutcome;
|
use reth_execution_types::ExecutionOutcome;
|
||||||
use reth_node_types::NodeTypes;
|
use reth_node_types::NodeTypes;
|
||||||
use reth_primitives::{
|
use reth_primitives::{
|
||||||
Account, Block, BlockWithSenders, Bytecode, GotExpected, Receipt, SealedBlock,
|
Account, Block, BlockWithSenders, Bytecode, EthPrimitives, GotExpected, Receipt, SealedBlock,
|
||||||
SealedBlockWithSenders, SealedHeader, TransactionMeta, TransactionSigned,
|
SealedBlockWithSenders, SealedHeader, TransactionMeta, TransactionSigned,
|
||||||
TransactionSignedNoHash,
|
TransactionSignedNoHash,
|
||||||
};
|
};
|
||||||
@ -158,9 +158,10 @@ impl MockEthProvider {
|
|||||||
pub struct MockNode;
|
pub struct MockNode;
|
||||||
|
|
||||||
impl NodeTypes for MockNode {
|
impl NodeTypes for MockNode {
|
||||||
type Primitives = ();
|
type Primitives = EthPrimitives;
|
||||||
type ChainSpec = ChainSpec;
|
type ChainSpec = ChainSpec;
|
||||||
type StateCommitment = MerklePatriciaTrie;
|
type StateCommitment = MerklePatriciaTrie;
|
||||||
|
type Storage = EthStorage;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DatabaseProviderFactory for MockEthProvider {
|
impl DatabaseProviderFactory for MockEthProvider {
|
||||||
|
|||||||
@ -1,4 +1,7 @@
|
|||||||
use crate::{providers::StaticFileProvider, HashingWriter, ProviderFactory, TrieWriter};
|
use crate::{
|
||||||
|
providers::{ProviderNodeTypes, StaticFileProvider},
|
||||||
|
HashingWriter, ProviderFactory, TrieWriter,
|
||||||
|
};
|
||||||
use alloy_primitives::B256;
|
use alloy_primitives::B256;
|
||||||
use reth_chainspec::{ChainSpec, MAINNET};
|
use reth_chainspec::{ChainSpec, MAINNET};
|
||||||
use reth_db::{
|
use reth_db::{
|
||||||
@ -6,7 +9,7 @@ use reth_db::{
|
|||||||
DatabaseEnv,
|
DatabaseEnv,
|
||||||
};
|
};
|
||||||
use reth_errors::ProviderResult;
|
use reth_errors::ProviderResult;
|
||||||
use reth_node_types::{NodeTypesWithDB, NodeTypesWithDBAdapter};
|
use reth_node_types::NodeTypesWithDBAdapter;
|
||||||
use reth_primitives::{Account, StorageEntry};
|
use reth_primitives::{Account, StorageEntry};
|
||||||
use reth_trie::StateRoot;
|
use reth_trie::StateRoot;
|
||||||
use reth_trie_db::DatabaseStateRoot;
|
use reth_trie_db::DatabaseStateRoot;
|
||||||
@ -22,10 +25,11 @@ pub use reth_chain_state::test_utils::TestCanonStateSubscriptions;
|
|||||||
|
|
||||||
/// Mock [`reth_node_types::NodeTypes`] for testing.
|
/// Mock [`reth_node_types::NodeTypes`] for testing.
|
||||||
pub type MockNodeTypes = reth_node_types::AnyNodeTypesWithEngine<
|
pub type MockNodeTypes = reth_node_types::AnyNodeTypesWithEngine<
|
||||||
(),
|
reth_primitives::EthPrimitives,
|
||||||
reth_ethereum_engine_primitives::EthEngineTypes,
|
reth_ethereum_engine_primitives::EthEngineTypes,
|
||||||
reth_chainspec::ChainSpec,
|
reth_chainspec::ChainSpec,
|
||||||
reth_trie_db::MerklePatriciaTrie,
|
reth_trie_db::MerklePatriciaTrie,
|
||||||
|
crate::EthStorage,
|
||||||
>;
|
>;
|
||||||
|
|
||||||
/// Mock [`reth_node_types::NodeTypesWithDB`] for testing.
|
/// Mock [`reth_node_types::NodeTypesWithDB`] for testing.
|
||||||
@ -51,7 +55,7 @@ pub fn create_test_provider_factory_with_chain_spec(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Inserts the genesis alloc from the provided chain spec into the trie.
|
/// Inserts the genesis alloc from the provided chain spec into the trie.
|
||||||
pub fn insert_genesis<N: NodeTypesWithDB<ChainSpec = ChainSpec>>(
|
pub fn insert_genesis<N: ProviderNodeTypes<ChainSpec = ChainSpec>>(
|
||||||
provider_factory: &ProviderFactory<N>,
|
provider_factory: &ProviderFactory<N>,
|
||||||
chain_spec: Arc<N::ChainSpec>,
|
chain_spec: Arc<N::ChainSpec>,
|
||||||
) -> ProviderResult<B256> {
|
) -> ProviderResult<B256> {
|
||||||
|
|||||||
@ -50,7 +50,7 @@ pub trait BlockWriter: Send + Sync {
|
|||||||
/// Bodies are passed as [`Option`]s, if body is `None` the corresponding block is empty.
|
/// Bodies are passed as [`Option`]s, if body is `None` the corresponding block is empty.
|
||||||
fn append_block_bodies(
|
fn append_block_bodies(
|
||||||
&self,
|
&self,
|
||||||
bodies: impl Iterator<Item = (BlockNumber, Option<Self::Body>)>,
|
bodies: Vec<(BlockNumber, Option<Self::Body>)>,
|
||||||
) -> ProviderResult<()>;
|
) -> ProviderResult<()>;
|
||||||
|
|
||||||
/// Appends a batch of sealed blocks to the blockchain, including sender information, and
|
/// Appends a batch of sealed blocks to the blockchain, including sender information, and
|
||||||
|
|||||||
@ -18,6 +18,7 @@ reth-db-models.workspace = true
|
|||||||
reth-db-api.workspace = true
|
reth-db-api.workspace = true
|
||||||
reth-execution-types.workspace = true
|
reth-execution-types.workspace = true
|
||||||
reth-primitives.workspace = true
|
reth-primitives.workspace = true
|
||||||
|
reth-primitives-traits.workspace = true
|
||||||
reth-prune-types.workspace = true
|
reth-prune-types.workspace = true
|
||||||
reth-stages-types.workspace = true
|
reth-stages-types.workspace = true
|
||||||
reth-storage-errors.workspace = true
|
reth-storage-errors.workspace = true
|
||||||
|
|||||||
72
crates/storage/storage-api/src/chain.rs
Normal file
72
crates/storage/storage-api/src/chain.rs
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
use crate::DBProvider;
|
||||||
|
use alloy_primitives::BlockNumber;
|
||||||
|
use reth_db::{
|
||||||
|
cursor::DbCursorRW,
|
||||||
|
models::{StoredBlockOmmers, StoredBlockWithdrawals},
|
||||||
|
tables,
|
||||||
|
transaction::DbTxMut,
|
||||||
|
};
|
||||||
|
use reth_primitives_traits::{Block, BlockBody, FullNodePrimitives};
|
||||||
|
use reth_storage_errors::provider::ProviderResult;
|
||||||
|
|
||||||
|
/// Trait that implements how block bodies are written to the storage.
|
||||||
|
///
|
||||||
|
/// Note: Within the current abstraction, this should only write to tables unrelated to
|
||||||
|
/// transactions. Writing of transactions is handled separately.
|
||||||
|
#[auto_impl::auto_impl(&, Arc)]
|
||||||
|
pub trait BlockBodyWriter<Provider, Body: BlockBody> {
|
||||||
|
/// Writes a set of block bodies to the storage.
|
||||||
|
fn write_block_bodies(
|
||||||
|
&self,
|
||||||
|
provider: &Provider,
|
||||||
|
bodies: Vec<(BlockNumber, Option<Body>)>,
|
||||||
|
) -> ProviderResult<()>;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Trait that implements how chain-specific types are written to the storage.
|
||||||
|
pub trait ChainStorageWriter<Provider, Primitives: FullNodePrimitives>:
|
||||||
|
BlockBodyWriter<Provider, <Primitives::Block as Block>::Body>
|
||||||
|
{
|
||||||
|
}
|
||||||
|
impl<T, Provider, Primitives: FullNodePrimitives> ChainStorageWriter<Provider, Primitives> for T where
|
||||||
|
T: BlockBodyWriter<Provider, <Primitives::Block as Block>::Body>
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Ethereum storage implementation.
|
||||||
|
#[derive(Debug, Default, Clone, Copy)]
|
||||||
|
pub struct EthStorage;
|
||||||
|
|
||||||
|
impl<Provider> BlockBodyWriter<Provider, reth_primitives::BlockBody> for EthStorage
|
||||||
|
where
|
||||||
|
Provider: DBProvider<Tx: DbTxMut>,
|
||||||
|
{
|
||||||
|
fn write_block_bodies(
|
||||||
|
&self,
|
||||||
|
provider: &Provider,
|
||||||
|
bodies: Vec<(u64, Option<reth_primitives::BlockBody>)>,
|
||||||
|
) -> ProviderResult<()> {
|
||||||
|
let mut ommers_cursor = provider.tx_ref().cursor_write::<tables::BlockOmmers>()?;
|
||||||
|
let mut withdrawals_cursor =
|
||||||
|
provider.tx_ref().cursor_write::<tables::BlockWithdrawals>()?;
|
||||||
|
|
||||||
|
for (block_number, body) in bodies {
|
||||||
|
let Some(body) = body else { continue };
|
||||||
|
|
||||||
|
// Write ommers if any
|
||||||
|
if !body.ommers.is_empty() {
|
||||||
|
ommers_cursor.append(block_number, StoredBlockOmmers { ommers: body.ommers })?;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write withdrawals if any
|
||||||
|
if let Some(withdrawals) = body.withdrawals {
|
||||||
|
if !withdrawals.is_empty() {
|
||||||
|
withdrawals_cursor
|
||||||
|
.append(block_number, StoredBlockWithdrawals { withdrawals })?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -22,6 +22,9 @@ pub use block_id::*;
|
|||||||
mod block_hash;
|
mod block_hash;
|
||||||
pub use block_hash::*;
|
pub use block_hash::*;
|
||||||
|
|
||||||
|
mod chain;
|
||||||
|
pub use chain::*;
|
||||||
|
|
||||||
mod header;
|
mod header;
|
||||||
pub use header::*;
|
pub use header::*;
|
||||||
|
|
||||||
|
|||||||
@ -42,7 +42,8 @@ use reth::{
|
|||||||
PayloadBuilderConfig,
|
PayloadBuilderConfig,
|
||||||
},
|
},
|
||||||
network::NetworkHandle,
|
network::NetworkHandle,
|
||||||
providers::{CanonStateSubscriptions, StateProviderFactory},
|
primitives::EthPrimitives,
|
||||||
|
providers::{CanonStateSubscriptions, EthStorage, StateProviderFactory},
|
||||||
rpc::eth::EthApi,
|
rpc::eth::EthApi,
|
||||||
tasks::TaskManager,
|
tasks::TaskManager,
|
||||||
transaction_pool::TransactionPool,
|
transaction_pool::TransactionPool,
|
||||||
@ -227,9 +228,10 @@ struct MyCustomNode;
|
|||||||
|
|
||||||
/// Configure the node types
|
/// Configure the node types
|
||||||
impl NodeTypes for MyCustomNode {
|
impl NodeTypes for MyCustomNode {
|
||||||
type Primitives = ();
|
type Primitives = EthPrimitives;
|
||||||
type ChainSpec = ChainSpec;
|
type ChainSpec = ChainSpec;
|
||||||
type StateCommitment = MerklePatriciaTrie;
|
type StateCommitment = MerklePatriciaTrie;
|
||||||
|
type Storage = EthStorage;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Configure the node types with the custom engine types
|
/// Configure the node types with the custom engine types
|
||||||
@ -254,7 +256,14 @@ pub type MyNodeAddOns<N> = RpcAddOns<
|
|||||||
/// This provides a preset configuration for the node
|
/// This provides a preset configuration for the node
|
||||||
impl<N> Node<N> for MyCustomNode
|
impl<N> Node<N> for MyCustomNode
|
||||||
where
|
where
|
||||||
N: FullNodeTypes<Types: NodeTypesWithEngine<Engine = CustomEngineTypes, ChainSpec = ChainSpec>>,
|
N: FullNodeTypes<
|
||||||
|
Types: NodeTypesWithEngine<
|
||||||
|
Engine = CustomEngineTypes,
|
||||||
|
ChainSpec = ChainSpec,
|
||||||
|
Primitives = EthPrimitives,
|
||||||
|
Storage = EthStorage,
|
||||||
|
>,
|
||||||
|
>,
|
||||||
{
|
{
|
||||||
type ComponentsBuilder = ComponentsBuilder<
|
type ComponentsBuilder = ComponentsBuilder<
|
||||||
N,
|
N,
|
||||||
|
|||||||
Reference in New Issue
Block a user