Skip to content

Commit

Permalink
feat: add Primitives AT to BlockExecutorProvider (#12994)
Browse files Browse the repository at this point in the history
  • Loading branch information
klkvr authored Nov 29, 2024
1 parent b6b8c47 commit 29289cc
Show file tree
Hide file tree
Showing 52 changed files with 591 additions and 409 deletions.
4 changes: 2 additions & 2 deletions book/sources/exex/hello-world/src/bin/3.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use futures_util::TryStreamExt;
use reth::{api::FullNodeComponents, primitives::Block, providers::BlockReader};
use reth::{api::FullNodeComponents, builder::NodeTypes, primitives::EthPrimitives};
use reth_exex::{ExExContext, ExExEvent, ExExNotification};
use reth_node_ethereum::EthereumNode;
use reth_tracing::tracing::info;

async fn my_exex<Node: FullNodeComponents<Provider: BlockReader<Block = Block>>>(
async fn my_exex<Node: FullNodeComponents<Types: NodeTypes<Primitives = EthPrimitives>>>(
mut ctx: ExExContext<Node>,
) -> eyre::Result<()> {
while let Some(notification) = ctx.notifications.try_next().await? {
Expand Down
4 changes: 2 additions & 2 deletions book/sources/exex/remote/src/exex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use remote_exex::proto::{
self,
remote_ex_ex_server::{RemoteExEx, RemoteExExServer},
};
use reth::{primitives::Block, providers::BlockReader};
use reth::{builder::NodeTypes, primitives::EthPrimitives};
use reth_exex::{ExExContext, ExExEvent, ExExNotification};
use reth_node_api::FullNodeComponents;
use reth_node_ethereum::EthereumNode;
Expand Down Expand Up @@ -45,7 +45,7 @@ impl RemoteExEx for ExExService {
}
}

async fn remote_exex<Node: FullNodeComponents<Provider: BlockReader<Block = Block>>>(
async fn remote_exex<Node: FullNodeComponents<Types: NodeTypes<Primitives = EthPrimitives>>>(
mut ctx: ExExContext<Node>,
notifications: Arc<broadcast::Sender<ExExNotification>>,
) -> eyre::Result<()> {
Expand Down
4 changes: 2 additions & 2 deletions book/sources/exex/remote/src/exex_4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use remote_exex::proto::{
self,
remote_ex_ex_server::{RemoteExEx, RemoteExExServer},
};
use reth::{primitives::Block, providers::BlockReader};
use reth::{builder::NodeTypes, primitives::EthPrimitives};
use reth_exex::{ExExContext, ExExEvent, ExExNotification};
use reth_node_api::FullNodeComponents;
use reth_node_ethereum::EthereumNode;
Expand Down Expand Up @@ -47,7 +47,7 @@ impl RemoteExEx for ExExService {

// ANCHOR: snippet
#[allow(dead_code)]
async fn remote_exex<Node: FullNodeComponents<Provider: BlockReader<Block = Block>>>(
async fn remote_exex<Node: FullNodeComponents<Types: NodeTypes<Primitives = EthPrimitives>>>(
mut ctx: ExExContext<Node>,
notifications: Arc<broadcast::Sender<ExExNotification>>,
) -> eyre::Result<()> {
Expand Down
6 changes: 4 additions & 2 deletions book/sources/exex/tracking-state/src/bin/1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{
};

use futures_util::{FutureExt, TryStreamExt};
use reth::{api::FullNodeComponents, primitives::Block, providers::BlockReader};
use reth::{api::FullNodeComponents, builder::NodeTypes, primitives::EthPrimitives};
use reth_exex::{ExExContext, ExExEvent, ExExNotification};
use reth_node_ethereum::EthereumNode;
use reth_tracing::tracing::info;
Expand All @@ -14,7 +14,9 @@ struct MyExEx<Node: FullNodeComponents> {
ctx: ExExContext<Node>,
}

impl<Node: FullNodeComponents<Provider: BlockReader<Block = Block>>> Future for MyExEx<Node> {
impl<Node: FullNodeComponents<Types: NodeTypes<Primitives = EthPrimitives>>> Future
for MyExEx<Node>
{
type Output = eyre::Result<()>;

fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
Expand Down
6 changes: 4 additions & 2 deletions book/sources/exex/tracking-state/src/bin/2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::{

use alloy_primitives::BlockNumber;
use futures_util::{FutureExt, TryStreamExt};
use reth::{api::FullNodeComponents, primitives::Block, providers::BlockReader};
use reth::{api::FullNodeComponents, builder::NodeTypes, primitives::EthPrimitives};
use reth_exex::{ExExContext, ExExEvent};
use reth_node_ethereum::EthereumNode;
use reth_tracing::tracing::info;
Expand All @@ -25,7 +25,9 @@ impl<Node: FullNodeComponents> MyExEx<Node> {
}
}

impl<Node: FullNodeComponents<Provider: BlockReader<Block = Block>>> Future for MyExEx<Node> {
impl<Node: FullNodeComponents<Types: NodeTypes<Primitives = EthPrimitives>>> Future
for MyExEx<Node>
{
type Output = eyre::Result<()>;

fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
Expand Down
2 changes: 1 addition & 1 deletion crates/blockchain-tree/src/blockchain_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ impl<N: NodeTypesWithDB, E> BlockchainTree<N, E> {
impl<N, E> BlockchainTree<N, E>
where
N: TreeNodeTypes,
E: BlockExecutorProvider,
E: BlockExecutorProvider<Primitives = N::Primitives>,
{
/// Builds the blockchain tree for the node.
///
Expand Down
18 changes: 9 additions & 9 deletions crates/blockchain-tree/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use reth_execution_errors::BlockExecutionError;
use reth_execution_types::{Chain, ExecutionOutcome};
use reth_primitives::{GotExpected, SealedBlockWithSenders, SealedHeader};
use reth_provider::{
providers::{BundleStateProvider, ConsistentDbView, ProviderNodeTypes},
providers::{BundleStateProvider, ConsistentDbView, TreeNodeTypes},
DBProvider, FullExecutionDataProvider, ProviderError, StateRootProvider,
TryIntoHistoricalStateProvider,
};
Expand Down Expand Up @@ -76,8 +76,8 @@ impl AppendableChain {
block_validation_kind: BlockValidationKind,
) -> Result<Self, InsertBlockErrorKind>
where
N: ProviderNodeTypes,
E: BlockExecutorProvider,
N: TreeNodeTypes,
E: BlockExecutorProvider<Primitives = N::Primitives>,
{
let execution_outcome = ExecutionOutcome::default();
let empty = BTreeMap::new();
Expand Down Expand Up @@ -114,8 +114,8 @@ impl AppendableChain {
block_validation_kind: BlockValidationKind,
) -> Result<Self, InsertBlockErrorKind>
where
N: ProviderNodeTypes,
E: BlockExecutorProvider,
N: TreeNodeTypes,
E: BlockExecutorProvider<Primitives = N::Primitives>,
{
let parent_number =
block.number.checked_sub(1).ok_or(BlockchainTreeError::GenesisBlockHasNoParent)?;
Expand Down Expand Up @@ -177,8 +177,8 @@ impl AppendableChain {
) -> Result<(ExecutionOutcome, Option<TrieUpdates>), BlockExecutionError>
where
EDP: FullExecutionDataProvider,
N: ProviderNodeTypes,
E: BlockExecutorProvider,
N: TreeNodeTypes,
E: BlockExecutorProvider<Primitives = N::Primitives>,
{
// some checks are done before blocks comes here.
externals.consensus.validate_header_against_parent(&block, parent_block)?;
Expand Down Expand Up @@ -284,8 +284,8 @@ impl AppendableChain {
block_validation_kind: BlockValidationKind,
) -> Result<(), InsertBlockErrorKind>
where
N: ProviderNodeTypes,
E: BlockExecutorProvider,
N: TreeNodeTypes,
E: BlockExecutorProvider<Primitives = N::Primitives>,
{
let parent_block = self.chain.tip();

Expand Down
6 changes: 3 additions & 3 deletions crates/blockchain-tree/src/shareable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl<N: NodeTypesWithDB, E> ShareableBlockchainTree<N, E> {
impl<N, E> BlockchainTreeEngine for ShareableBlockchainTree<N, E>
where
N: TreeNodeTypes,
E: BlockExecutorProvider,
E: BlockExecutorProvider<Primitives = N::Primitives>,
{
fn buffer_block(&self, block: SealedBlockWithSenders) -> Result<(), InsertBlockError> {
let mut tree = self.tree.write();
Expand Down Expand Up @@ -110,7 +110,7 @@ where
impl<N, E> BlockchainTreeViewer for ShareableBlockchainTree<N, E>
where
N: TreeNodeTypes,
E: BlockExecutorProvider,
E: BlockExecutorProvider<Primitives = N::Primitives>,
{
fn header_by_hash(&self, hash: BlockHash) -> Option<SealedHeader> {
trace!(target: "blockchain_tree", ?hash, "Returning header by hash");
Expand Down Expand Up @@ -173,7 +173,7 @@ where
impl<N, E> BlockchainTreePendingStateProvider for ShareableBlockchainTree<N, E>
where
N: TreeNodeTypes,
E: BlockExecutorProvider,
E: BlockExecutorProvider<Primitives = N::Primitives>,
{
fn find_pending_state_provider(
&self,
Expand Down
4 changes: 2 additions & 2 deletions crates/cli/commands/src/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl<C: ChainSpecParser<ChainSpec: EthChainSpec + EthereumHardforks>> ImportComm
pub async fn execute<N, E, F>(self, executor: F) -> eyre::Result<()>
where
N: CliNodeTypes<ChainSpec = C::ChainSpec>,
E: BlockExecutorProvider,
E: BlockExecutorProvider<Primitives = N::Primitives>,
F: FnOnce(Arc<N::ChainSpec>) -> E,
{
info!(target: "reth::cli", "reth {} starting", SHORT_VERSION);
Expand Down Expand Up @@ -169,7 +169,7 @@ pub fn build_import_pipeline<N, C, E>(
where
N: ProviderNodeTypes + CliNodeTypes,
C: Consensus + 'static,
E: BlockExecutorProvider,
E: BlockExecutorProvider<Primitives = N::Primitives>,
{
if !file_client.has_canonical_blocks() {
eyre::bail!("unable to import non canonical blocks");
Expand Down
4 changes: 2 additions & 2 deletions crates/cli/commands/src/stage/dump/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ where
Receipt = reth_primitives::Receipt,
>,
>,
E: BlockExecutorProvider,
E: BlockExecutorProvider<Primitives = N::Primitives>,
{
let (output_db, tip_block_number) = setup(from, to, &output_datadir.db(), db_tool)?;

Expand Down Expand Up @@ -188,7 +188,7 @@ where
Receipt = reth_primitives::Receipt,
>,
>,
E: BlockExecutorProvider,
E: BlockExecutorProvider<Primitives = N::Primitives>,
{
info!(target: "reth::cli", "Executing stage. [dry-run]");

Expand Down
2 changes: 1 addition & 1 deletion crates/cli/commands/src/stage/dump/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ impl<C: ChainSpecParser<ChainSpec: EthChainSpec + EthereumHardforks>> Command<C>
pub async fn execute<N, E, F>(self, executor: F) -> eyre::Result<()>
where
N: CliNodeTypes<ChainSpec = C::ChainSpec>,
E: BlockExecutorProvider,
E: BlockExecutorProvider<Primitives = N::Primitives>,
F: FnOnce(Arc<C::ChainSpec>) -> E,
{
let Environment { provider_factory, .. } = self.env.init::<N>(AccessRights::RO)?;
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/commands/src/stage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl<C: ChainSpecParser<ChainSpec: EthChainSpec + EthereumHardforks>> Command<C>
pub async fn execute<N, E, F>(self, ctx: CliContext, executor: F) -> eyre::Result<()>
where
N: CliNodeTypes<ChainSpec = C::ChainSpec>,
E: BlockExecutorProvider,
E: BlockExecutorProvider<Primitives = N::Primitives>,
F: FnOnce(Arc<C::ChainSpec>) -> E,
{
match self.command {
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/commands/src/stage/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ impl<C: ChainSpecParser<ChainSpec: EthChainSpec + EthereumHardforks>> Command<C>
pub async fn execute<N, E, F>(self, ctx: CliContext, executor: F) -> eyre::Result<()>
where
N: CliNodeTypes<ChainSpec = C::ChainSpec>,
E: BlockExecutorProvider,
E: BlockExecutorProvider<Primitives = N::Primitives>,
F: FnOnce(Arc<C::ChainSpec>) -> E,
{
// Raise the fd limit of the process.
Expand Down
6 changes: 4 additions & 2 deletions crates/e2e-test-utils/src/rpc.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use alloy_consensus::TxEnvelope;
use alloy_network::eip2718::Decodable2718;
use alloy_primitives::{Bytes, B256};
use alloy_rlp::Encodable;
use reth_chainspec::EthereumHardforks;
use reth_node_api::{FullNodeComponents, NodePrimitives};
use reth_node_builder::{rpc::RpcRegistry, NodeTypes};
Expand All @@ -21,7 +20,10 @@ where
Node: FullNodeComponents<
Types: NodeTypes<
ChainSpec: EthereumHardforks,
Primitives: NodePrimitives<Block: Encodable, Receipt = reth_primitives::Receipt>,
Primitives: NodePrimitives<
Block = reth_primitives::Block,
Receipt = reth_primitives::Receipt,
>,
>,
>,
EthApi: EthApiSpec + EthTransactions + TraceExt,
Expand Down
2 changes: 1 addition & 1 deletion crates/engine/local/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ where
#[allow(clippy::too_many_arguments)]
pub fn new<B, V>(
consensus: Arc<dyn Consensus>,
executor_factory: impl BlockExecutorProvider,
executor_factory: impl BlockExecutorProvider<Primitives = N::Primitives>,
provider: ProviderFactory<N>,
blockchain_db: BlockchainProvider2<N>,
pruner: PrunerWithFactory<ProviderFactory<N>>,
Expand Down
2 changes: 1 addition & 1 deletion crates/engine/service/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl<N, Client, E> EngineService<N, Client, E>
where
N: EngineNodeTypes + PersistenceNodeTypes,
Client: EthBlockClient + 'static,
E: BlockExecutorProvider + 'static,
E: BlockExecutorProvider<Primitives = N::Primitives> + 'static,
{
/// Constructor for `EngineService`.
#[allow(clippy::too_many_arguments)]
Expand Down
4 changes: 2 additions & 2 deletions crates/engine/tree/src/tree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -540,15 +540,15 @@ impl<N, P: Debug, E: Debug, T: EngineTypes + Debug, V: Debug> std::fmt::Debug

impl<N, P, E, T, V> EngineApiTreeHandler<N, P, E, T, V>
where
N: NodePrimitives,
N: NodePrimitives<Block = reth_primitives::Block, Receipt = reth_primitives::Receipt>,
P: DatabaseProviderFactory
+ BlockReader<Block = reth_primitives::Block>
+ StateProviderFactory
+ StateReader<Receipt = reth_primitives::Receipt>
+ Clone
+ 'static,
<P as DatabaseProviderFactory>::Provider: BlockReader,
E: BlockExecutorProvider,
E: BlockExecutorProvider<Primitives = N>,
T: EngineTypes,
V: EngineValidator<T, Block = reth_primitives::Block>,
{
Expand Down
9 changes: 7 additions & 2 deletions crates/ethereum/evm/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use reth_evm::{
system_calls::{OnStateHook, SystemCaller},
ConfigureEvm, TxEnvOverrides,
};
use reth_primitives::{BlockWithSenders, Receipt};
use reth_primitives::{BlockWithSenders, EthPrimitives, Receipt};
use reth_revm::db::State;
use revm_primitives::{
db::{Database, DatabaseCommit},
Expand Down Expand Up @@ -60,6 +60,8 @@ where
EvmConfig:
Clone + Unpin + Sync + Send + 'static + ConfigureEvm<Header = alloy_consensus::Header>,
{
type Primitives = EthPrimitives;

type Strategy<DB: Database<Error: Into<ProviderError> + Display>> =
EthExecutionStrategy<DB, EvmConfig>;

Expand Down Expand Up @@ -122,13 +124,16 @@ where
}
}

impl<DB, EvmConfig> BlockExecutionStrategy<DB> for EthExecutionStrategy<DB, EvmConfig>
impl<DB, EvmConfig> BlockExecutionStrategy for EthExecutionStrategy<DB, EvmConfig>
where
DB: Database<Error: Into<ProviderError> + Display>,
EvmConfig: ConfigureEvm<Header = alloy_consensus::Header>,
{
type DB = DB;
type Error = BlockExecutionError;

type Primitives = EthPrimitives;

fn init(&mut self, tx_env_overrides: Box<dyn TxEnvOverrides>) {
self.tx_env_overrides = Some(tx_env_overrides);
}
Expand Down
2 changes: 1 addition & 1 deletion crates/ethereum/node/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ pub struct EthereumExecutorBuilder;

impl<Types, Node> ExecutorBuilder<Node> for EthereumExecutorBuilder
where
Types: NodeTypesWithEngine<ChainSpec = ChainSpec>,
Types: NodeTypesWithEngine<ChainSpec = ChainSpec, Primitives = EthPrimitives>,
Node: FullNodeTypes<Types = Types>,
{
type EVM = EthEvmConfig;
Expand Down
Loading

0 comments on commit 29289cc

Please sign in to comment.