feat: make nodetypes stateless and move evm to components (#7992)

This commit is contained in:
Matthias Seitz
2024-04-30 18:56:34 +02:00
committed by GitHub
parent 581682605c
commit d04d9556fa
20 changed files with 402 additions and 171 deletions

View File

@ -1,4 +1,4 @@
//! Traits for configuring a node
//! Traits for configuring a node.
use crate::{primitives::NodePrimitives, ConfigureEvm, EngineTypes};
use reth_db::{
@ -15,21 +15,20 @@ use std::marker::PhantomData;
/// The type that configures the essential types of an ethereum like node.
///
/// This includes the primitive types of a node, the engine API types for communication with the
/// consensus layer, and the EVM configuration type for setting up the Ethereum Virtual Machine.
/// consensus layer.
///
/// This trait is intended to be stateless and only define the types of the node.
pub trait NodeTypes: Send + Sync + 'static {
/// The node's primitive types, defining basic operations and structures.
type Primitives: NodePrimitives;
/// The node's engine types, defining the interaction with the consensus engine.
type Engine: EngineTypes;
/// The node's EVM configuration, defining settings for the Ethereum Virtual Machine.
type Evm: ConfigureEvm;
/// Returns the node's evm config.
fn evm_config(&self) -> Self::Evm;
}
/// A helper trait that is downstream of the [NodeTypes] trait and adds stateful components to the
/// node.
///
/// Its types are configured by node internally and are not intended to be user configurable.
pub trait FullNodeTypes: NodeTypes + 'static {
/// Underlying database type used by the node to store and retrieve data.
type DB: Database + DatabaseMetrics + DatabaseMetadata + Clone + Unpin + 'static;
@ -41,7 +40,7 @@ pub trait FullNodeTypes: NodeTypes + 'static {
#[derive(Debug)]
pub struct FullNodeTypesAdapter<Types, DB, Provider> {
/// An instance of the user configured node types.
pub types: Types,
pub types: PhantomData<Types>,
/// The database type used by the node.
pub db: PhantomData<DB>,
/// The provider type used by the node.
@ -49,9 +48,15 @@ pub struct FullNodeTypesAdapter<Types, DB, Provider> {
}
impl<Types, DB, Provider> FullNodeTypesAdapter<Types, DB, Provider> {
/// Create a new adapter from the given node types.
pub fn new(types: Types) -> Self {
Self { types, db: Default::default(), provider: Default::default() }
/// Create a new adapter with the configured types.
pub fn new() -> Self {
Self { types: Default::default(), db: Default::default(), provider: Default::default() }
}
}
impl<Types, DB, Provider> Default for FullNodeTypesAdapter<Types, DB, Provider> {
fn default() -> Self {
Self::new()
}
}
@ -63,11 +68,6 @@ where
{
type Primitives = Types::Primitives;
type Engine = Types::Engine;
type Evm = Types::Evm;
fn evm_config(&self) -> Self::Evm {
self.types.evm_config()
}
}
impl<Types, DB, Provider> FullNodeTypes for FullNodeTypesAdapter<Types, DB, Provider>
@ -85,9 +85,15 @@ pub trait FullNodeComponents: FullNodeTypes + 'static {
/// The transaction pool of the node.
type Pool: TransactionPool + Unpin;
/// The node's EVM configuration, defining settings for the Ethereum Virtual Machine.
type Evm: ConfigureEvm;
/// Returns the transaction pool of the node.
fn pool(&self) -> &Self::Pool;
/// Returns the node's evm config.
fn evm_config(&self) -> &Self::Evm;
/// Returns the provider of the node.
fn provider(&self) -> &Self::Provider;