Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
klkvr committed Dec 3, 2024
1 parent f78690c commit 9cde895
Show file tree
Hide file tree
Showing 25 changed files with 73 additions and 51 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions crates/engine/invalid-block-hooks/src/witness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use reth_engine_primitives::InvalidBlockHook;
use reth_evm::{
state_change::post_block_balance_increments, system_calls::SystemCaller, ConfigureEvm,
};
use reth_primitives::{NodePrimitives, SealedBlockWithSenders, SealedHeader, TransactionSigned};
use reth_primitives_traits::{HeaderTy, SignedTransaction};
use reth_primitives::{NodePrimitives, SealedBlockWithSenders, SealedHeader};
use reth_primitives_traits::SignedTransaction;
use reth_provider::{BlockExecutionOutput, ChainSpecProvider, StateProviderFactory};
use reth_revm::{
database::StateProviderDatabase, db::states::bundle_state::BundleRetention,
Expand Down Expand Up @@ -63,8 +63,8 @@ where
trie_updates: Option<(&TrieUpdates, B256)>,
) -> eyre::Result<()>
where
N: NodePrimitives<SignedTx = TransactionSigned>,
EvmConfig: ConfigureEvm<Header = N::BlockHeader>,
N: NodePrimitives,
EvmConfig: ConfigureEvm<Header = N::BlockHeader, Transaction = N::SignedTx>,
{
// TODO(alexey): unify with `DebugApi::debug_execution_witness`

Expand Down Expand Up @@ -298,13 +298,13 @@ where

impl<P, EvmConfig, N> InvalidBlockHook<N> for InvalidBlockWitnessHook<P, EvmConfig>
where
N: NodePrimitives<SignedTx = TransactionSigned>,
N: NodePrimitives,
P: StateProviderFactory
+ ChainSpecProvider<ChainSpec: EthChainSpec + EthereumHardforks>
+ Send
+ Sync
+ 'static,
EvmConfig: ConfigureEvm<Header = HeaderTy<N>>,
EvmConfig: ConfigureEvm<Header = N::BlockHeader, Transaction = N::SignedTx>,
{
fn on_invalid_block(
&self,
Expand Down
4 changes: 2 additions & 2 deletions crates/engine/util/src/reorg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ where
S: Stream<Item = BeaconEngineMessage<Engine>>,
Engine: EngineTypes,
Provider: BlockReader<Block = reth_primitives::Block> + StateProviderFactory,
Evm: ConfigureEvm<Header = Header>,
Evm: ConfigureEvm<Header = Header, Transaction = reth_primitives::TransactionSigned>,
Spec: EthereumHardforks,
{
type Item = S::Item;
Expand Down Expand Up @@ -258,7 +258,7 @@ fn create_reorg_head<Provider, Evm, Spec>(
) -> RethResult<(ExecutionPayload, ExecutionPayloadSidecar)>
where
Provider: BlockReader<Block = reth_primitives::Block> + StateProviderFactory,
Evm: ConfigureEvm<Header = Header>,
Evm: ConfigureEvm<Header = Header, Transaction = reth_primitives::TransactionSigned>,
Spec: EthereumHardforks,
{
let chain_spec = payload_validator.chain_spec();
Expand Down
16 changes: 13 additions & 3 deletions crates/ethereum/evm/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,15 @@ impl<EvmConfig> EthExecutionStrategyFactory<EvmConfig> {

impl<EvmConfig> BlockExecutionStrategyFactory for EthExecutionStrategyFactory<EvmConfig>
where
EvmConfig:
Clone + Unpin + Sync + Send + 'static + ConfigureEvm<Header = alloy_consensus::Header>,
EvmConfig: Clone
+ Unpin
+ Sync
+ Send
+ 'static
+ ConfigureEvm<
Header = alloy_consensus::Header,
Transaction = reth_primitives::TransactionSigned,
>,
{
type Primitives = EthPrimitives;

Expand Down Expand Up @@ -128,7 +135,10 @@ where
impl<DB, EvmConfig> BlockExecutionStrategy for EthExecutionStrategy<DB, EvmConfig>
where
DB: Database<Error: Into<ProviderError> + Display>,
EvmConfig: ConfigureEvm<Header = alloy_consensus::Header>,
EvmConfig: ConfigureEvm<
Header = alloy_consensus::Header,
Transaction = reth_primitives::TransactionSigned,
>,
{
type DB = DB;
type Error = BlockExecutionError;
Expand Down
1 change: 1 addition & 0 deletions crates/ethereum/evm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ impl EthEvmConfig {

impl ConfigureEvmEnv for EthEvmConfig {
type Header = Header;
type Transaction = TransactionSigned;
type Error = Infallible;

fn fill_tx_env(&self, tx_env: &mut TxEnv, transaction: &TransactionSigned, sender: Address) {
Expand Down
2 changes: 0 additions & 2 deletions crates/ethereum/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ reth-primitives.workspace = true
reth-revm = { workspace = true, features = ["std"] }
reth-trie-db.workspace = true

alloy-consensus.workspace = true

# revm with required ethereum features
revm = { workspace = true, features = ["secp256k1", "blst", "c-kzg"] }

Expand Down
6 changes: 3 additions & 3 deletions crates/ethereum/node/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
use std::sync::Arc;

use alloy_consensus::Header;
use reth_basic_payload_builder::{BasicPayloadJobGenerator, BasicPayloadJobGeneratorConfig};
use reth_beacon_consensus::EthBeaconConsensus;
use reth_chainspec::ChainSpec;
Expand All @@ -13,7 +12,8 @@ use reth_evm::execute::BasicBlockExecutorProvider;
use reth_evm_ethereum::execute::EthExecutionStrategyFactory;
use reth_network::{NetworkHandle, PeersInfo};
use reth_node_api::{
AddOnsContext, ConfigureEvm, EngineValidator, FullNodeComponents, NodeTypesWithDB, TxTy,
AddOnsContext, ConfigureEvm, EngineValidator, FullNodeComponents, HeaderTy, NodeTypesWithDB,
TxTy,
};
use reth_node_builder::{
components::{
Expand Down Expand Up @@ -242,7 +242,7 @@ impl EthereumPayloadBuilder {
where
Types: NodeTypesWithEngine<ChainSpec = ChainSpec, Primitives = EthPrimitives>,
Node: FullNodeTypes<Types = Types>,
Evm: ConfigureEvm<Header = Header>,
Evm: ConfigureEvm<Header = HeaderTy<Types>, Transaction = TxTy<Node::Types>>,
Pool: TransactionPool<Transaction: PoolTransaction<Consensus = TxTy<Node::Types>>>
+ Unpin
+ 'static,
Expand Down
4 changes: 2 additions & 2 deletions crates/ethereum/payload/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ where
// Default implementation of [PayloadBuilder] for unit type
impl<EvmConfig, Pool, Client> PayloadBuilder<Pool, Client> for EthereumPayloadBuilder<EvmConfig>
where
EvmConfig: ConfigureEvm<Header = Header>,
EvmConfig: ConfigureEvm<Header = Header, Transaction = TransactionSigned>,
Client: StateProviderFactory + ChainSpecProvider<ChainSpec = ChainSpec>,
Pool: TransactionPool<Transaction: PoolTransaction<Consensus = TransactionSigned>>,
{
Expand Down Expand Up @@ -156,7 +156,7 @@ pub fn default_ethereum_payload<EvmConfig, Pool, Client, F>(
best_txs: F,
) -> Result<BuildOutcome<EthBuiltPayload>, PayloadBuilderError>
where
EvmConfig: ConfigureEvm<Header = Header>,
EvmConfig: ConfigureEvm<Header = Header, Transaction = TransactionSigned>,
Client: StateProviderFactory + ChainSpecProvider<ChainSpec = ChainSpec>,
Pool: TransactionPool<Transaction: PoolTransaction<Consensus = TransactionSigned>>,
F: FnOnce(BestTransactionsAttributes) -> BestTransactionsIter<Pool>,
Expand Down
8 changes: 5 additions & 3 deletions crates/evm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ extern crate alloc;
use crate::builder::RethEvmBuilder;
use alloy_consensus::BlockHeader as _;
use alloy_primitives::{Address, Bytes, B256, U256};
use reth_primitives::TransactionSigned;
use reth_primitives_traits::BlockHeader;
use revm::{Database, Evm, GetInspector};
use revm_primitives::{BlockEnv, CfgEnvWithHandlerCfg, Env, EnvWithHandlerCfg, SpecId, TxEnv};
Expand Down Expand Up @@ -116,18 +115,21 @@ pub trait ConfigureEvmEnv: Send + Sync + Unpin + Clone + 'static {
/// The header type used by the EVM.
type Header: BlockHeader;

/// The transaction type.
type Transaction;

/// The error type that is returned by [`Self::next_cfg_and_block_env`].
type Error: core::error::Error + Send + Sync;

/// Returns a [`TxEnv`] from a [`TransactionSigned`] and [`Address`].
fn tx_env(&self, transaction: &TransactionSigned, signer: Address) -> TxEnv {
fn tx_env(&self, transaction: &Self::Transaction, signer: Address) -> TxEnv {
let mut tx_env = TxEnv::default();
self.fill_tx_env(&mut tx_env, transaction, signer);
tx_env
}

/// Fill transaction environment from a [`TransactionSigned`] and the given sender address.
fn fill_tx_env(&self, tx_env: &mut TxEnv, transaction: &TransactionSigned, sender: Address);
fn fill_tx_env(&self, tx_env: &mut TxEnv, transaction: &Self::Transaction, sender: Address);

/// Fill transaction environment with a system contract call.
fn fill_tx_env_system_contract_call(
Expand Down
2 changes: 1 addition & 1 deletion crates/node/api/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub trait FullNodeComponents: FullNodeTypes + Clone + 'static {
type Pool: TransactionPool<Transaction: PoolTransaction<Consensus = TxTy<Self::Types>>> + Unpin;

/// The node's EVM configuration, defining settings for the Ethereum Virtual Machine.
type Evm: ConfigureEvm<Header = HeaderTy<Self::Types>>;
type Evm: ConfigureEvm<Header = HeaderTy<Self::Types>, Transaction = TxTy<Self::Types>>;

/// The type that knows how to execute blocks.
type Executor: BlockExecutorProvider<Primitives = <Self::Types as NodeTypes>::Primitives>;
Expand Down
2 changes: 1 addition & 1 deletion crates/node/builder/src/components/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ where
Pool: TransactionPool<Transaction: PoolTransaction<Consensus = TxTy<Node::Types>>>
+ Unpin
+ 'static,
EVM: ConfigureEvm<Header = HeaderTy<Node::Types>>,
EVM: ConfigureEvm<Header = HeaderTy<Node::Types>, Transaction = TxTy<Node::Types>>,
Executor: BlockExecutorProvider<Primitives = <Node::Types as NodeTypes>::Primitives>,
Cons: FullConsensus<<Node::Types as NodeTypes>::Primitives> + Clone + Unpin + 'static,
{
Expand Down
6 changes: 3 additions & 3 deletions crates/node/builder/src/components/execute.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
//! EVM component for the node builder.
use crate::{BuilderContext, FullNodeTypes};
use reth_evm::execute::BlockExecutorProvider;
use reth_node_api::{ConfigureEvm, HeaderTy};
use reth_node_api::{ConfigureEvm, HeaderTy, TxTy};
use std::future::Future;

/// A type that knows how to build the executor types.
pub trait ExecutorBuilder<Node: FullNodeTypes>: Send {
/// The EVM config to use.
///
/// This provides the node with the necessary configuration to configure an EVM.
type EVM: ConfigureEvm<Header = HeaderTy<Node::Types>>;
type EVM: ConfigureEvm<Header = HeaderTy<Node::Types>, Transaction = TxTy<Node::Types>>;

/// The type that knows how to execute blocks.
type Executor: BlockExecutorProvider<
Expand All @@ -26,7 +26,7 @@ pub trait ExecutorBuilder<Node: FullNodeTypes>: Send {
impl<Node, F, Fut, EVM, Executor> ExecutorBuilder<Node> for F
where
Node: FullNodeTypes,
EVM: ConfigureEvm<Header = HeaderTy<Node::Types>>,
EVM: ConfigureEvm<Header = HeaderTy<Node::Types>, Transaction = TxTy<Node::Types>>,
Executor:
BlockExecutorProvider<Primitives = <Node::Types as reth_node_api::NodeTypes>::Primitives>,
F: FnOnce(&BuilderContext<Node>) -> Fut + Send,
Expand Down
6 changes: 3 additions & 3 deletions crates/node/builder/src/components/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub trait NodeComponents<T: FullNodeTypes>: Clone + Unpin + Send + Sync + 'stati
type Pool: TransactionPool<Transaction: PoolTransaction<Consensus = TxTy<T::Types>>> + Unpin;

/// The node's EVM configuration, defining settings for the Ethereum Virtual Machine.
type Evm: ConfigureEvm<Header = HeaderTy<T::Types>>;
type Evm: ConfigureEvm<Header = HeaderTy<T::Types>, Transaction = TxTy<T::Types>>;

/// The type that knows how to execute blocks.
type Executor: BlockExecutorProvider<Primitives = <T::Types as NodeTypes>::Primitives>;
Expand Down Expand Up @@ -99,7 +99,7 @@ where
Pool: TransactionPool<Transaction: PoolTransaction<Consensus = TxTy<Node::Types>>>
+ Unpin
+ 'static,
EVM: ConfigureEvm<Header = HeaderTy<Node::Types>>,
EVM: ConfigureEvm<Header = HeaderTy<Node::Types>, Transaction = TxTy<Node::Types>>,
Executor: BlockExecutorProvider<Primitives = <Node::Types as NodeTypes>::Primitives>,
Cons: FullConsensus<<Node::Types as NodeTypes>::Primitives> + Clone + Unpin + 'static,
{
Expand Down Expand Up @@ -139,7 +139,7 @@ impl<Node, Pool, EVM, Executor, Cons> Clone for Components<Node, Pool, EVM, Exec
where
Node: FullNodeTypes,
Pool: TransactionPool,
EVM: ConfigureEvm<Header = HeaderTy<Node::Types>>,
EVM: ConfigureEvm<Header = HeaderTy<Node::Types>, Transaction = TxTy<Node::Types>>,
Executor: BlockExecutorProvider,
Cons: Clone,
{
Expand Down
12 changes: 8 additions & 4 deletions crates/optimism/evm/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use reth_optimism_chainspec::OpChainSpec;
use reth_optimism_consensus::validate_block_post_execution;
use reth_optimism_forks::OpHardfork;
use reth_optimism_primitives::OpPrimitives;
use reth_primitives::{BlockWithSenders, Receipt, TxType};
use reth_primitives::{BlockWithSenders, Receipt, TransactionSigned, TxType};
use reth_revm::{Database, State};
use revm_primitives::{db::DatabaseCommit, EnvWithHandlerCfg, ResultAndState, U256};
use tracing::trace;
Expand Down Expand Up @@ -52,8 +52,12 @@ impl<EvmConfig> OpExecutionStrategyFactory<EvmConfig> {

impl<EvmConfig> BlockExecutionStrategyFactory for OpExecutionStrategyFactory<EvmConfig>
where
EvmConfig:
Clone + Unpin + Sync + Send + 'static + ConfigureEvm<Header = alloy_consensus::Header>,
EvmConfig: Clone
+ Unpin
+ Sync
+ Send
+ 'static
+ ConfigureEvm<Header = alloy_consensus::Header, Transaction = TransactionSigned>,
{
type Primitives = OpPrimitives;
type Strategy<DB: Database<Error: Into<ProviderError> + Display>> =
Expand Down Expand Up @@ -115,7 +119,7 @@ where
impl<DB, EvmConfig> BlockExecutionStrategy for OpExecutionStrategy<DB, EvmConfig>
where
DB: Database<Error: Into<ProviderError> + Display>,
EvmConfig: ConfigureEvm<Header = alloy_consensus::Header>,
EvmConfig: ConfigureEvm<Header = alloy_consensus::Header, Transaction = TransactionSigned>,
{
type DB = DB;
type Primitives = OpPrimitives;
Expand Down
1 change: 1 addition & 0 deletions crates/optimism/evm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ impl OpEvmConfig {

impl ConfigureEvmEnv for OpEvmConfig {
type Header = Header;
type Transaction = TransactionSigned;
type Error = DecodeError;

fn fill_tx_env(&self, tx_env: &mut TxEnv, transaction: &TransactionSigned, sender: Address) {
Expand Down
4 changes: 2 additions & 2 deletions crates/optimism/node/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use reth_optimism_rpc::{
OpEthApi, SequencerClient,
};
use reth_payload_builder::{PayloadBuilderHandle, PayloadBuilderService};
use reth_primitives::BlockBody;
use reth_primitives::{BlockBody, TransactionSigned};
use reth_provider::{
providers::ChainStorage, BlockBodyReader, BlockBodyWriter, CanonStateSubscriptions,
ChainSpecProvider, DBProvider, EthStorage, ProviderResult, ReadBodyInput,
Expand Down Expand Up @@ -468,7 +468,7 @@ where
Pool: TransactionPool<Transaction: PoolTransaction<Consensus = TxTy<Node::Types>>>
+ Unpin
+ 'static,
Evm: ConfigureEvm<Header = Header>,
Evm: ConfigureEvm<Header = Header, Transaction = TransactionSigned>,
{
let payload_builder = reth_optimism_payload_builder::OpPayloadBuilder::new(evm_config)
.with_transactions(self.best_transactions)
Expand Down
14 changes: 7 additions & 7 deletions crates/optimism/payload/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl<EvmConfig, Txs> OpPayloadBuilder<EvmConfig, Txs> {
}
impl<EvmConfig, Txs> OpPayloadBuilder<EvmConfig, Txs>
where
EvmConfig: ConfigureEvm<Header = Header>,
EvmConfig: ConfigureEvm<Header = Header, Transaction = TransactionSigned>,
Txs: OpPayloadTransactions,
{
/// Constructs an Optimism payload from the transactions sent via the
Expand Down Expand Up @@ -153,7 +153,7 @@ where

impl<EvmConfig, Txs> OpPayloadBuilder<EvmConfig, Txs>
where
EvmConfig: ConfigureEvm<Header = Header>,
EvmConfig: ConfigureEvm<Header = Header, Transaction = TransactionSigned>,
{
/// Returns the configured [`CfgEnvWithHandlerCfg`] and [`BlockEnv`] for the targeted payload
/// (that has the `parent` as its parent).
Expand Down Expand Up @@ -215,7 +215,7 @@ impl<Pool, Client, EvmConfig, Txs> PayloadBuilder<Pool, Client> for OpPayloadBui
where
Client: StateProviderFactory + ChainSpecProvider<ChainSpec = OpChainSpec>,
Pool: TransactionPool<Transaction: PoolTransaction<Consensus = TransactionSigned>>,
EvmConfig: ConfigureEvm<Header = Header>,
EvmConfig: ConfigureEvm<Header = Header, Transaction = TransactionSigned>,
Txs: OpPayloadTransactions,
{
type Attributes = OpPayloadBuilderAttributes;
Expand Down Expand Up @@ -292,7 +292,7 @@ where
ctx: &OpPayloadBuilderCtx<EvmConfig>,
) -> Result<BuildOutcomeKind<ExecutedPayload>, PayloadBuilderError>
where
EvmConfig: ConfigureEvm<Header = Header>,
EvmConfig: ConfigureEvm<Header = Header, Transaction = TransactionSigned>,
DB: Database<Error = ProviderError>,
{
let Self { pool, best } = self;
Expand Down Expand Up @@ -337,7 +337,7 @@ where
ctx: OpPayloadBuilderCtx<EvmConfig>,
) -> Result<BuildOutcomeKind<OpBuiltPayload>, PayloadBuilderError>
where
EvmConfig: ConfigureEvm<Header = Header>,
EvmConfig: ConfigureEvm<Header = Header, Transaction = TransactionSigned>,
DB: Database<Error = ProviderError> + AsRef<P>,
P: StateRootProvider,
{
Expand Down Expand Up @@ -464,7 +464,7 @@ where
ctx: &OpPayloadBuilderCtx<EvmConfig>,
) -> Result<ExecutionWitness, PayloadBuilderError>
where
EvmConfig: ConfigureEvm<Header = Header>,
EvmConfig: ConfigureEvm<Header = Header, Transaction = TransactionSigned>,
DB: Database<Error = ProviderError> + AsRef<P>,
P: StateProofProvider,
{
Expand Down Expand Up @@ -699,7 +699,7 @@ impl<EvmConfig> OpPayloadBuilderCtx<EvmConfig> {

impl<EvmConfig> OpPayloadBuilderCtx<EvmConfig>
where
EvmConfig: ConfigureEvm<Header = Header>,
EvmConfig: ConfigureEvm<Header = Header, Transaction = TransactionSigned>,
{
/// apply eip-4788 pre block contract call
pub fn apply_pre_beacon_root_contract_call<DB>(
Expand Down
4 changes: 2 additions & 2 deletions crates/optimism/rpc/src/eth/pending_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use alloy_primitives::{BlockNumber, B256};
use reth_chainspec::{EthChainSpec, EthereumHardforks};
use reth_evm::ConfigureEvm;
use reth_optimism_consensus::calculate_receipt_root_no_memo_optimism;
use reth_primitives::{Receipt, SealedBlockWithSenders};
use reth_primitives::{Receipt, SealedBlockWithSenders, TransactionSigned};
use reth_provider::{
BlockReader, BlockReaderIdExt, ChainSpecProvider, EvmEnvProvider, ExecutionOutcome, ProviderTx,
ReceiptProvider, StateProviderFactory,
Expand All @@ -33,7 +33,7 @@ where
+ ChainSpecProvider<ChainSpec: EthChainSpec + EthereumHardforks>
+ StateProviderFactory,
Pool: TransactionPool<Transaction: PoolTransaction<Consensus = ProviderTx<N::Provider>>>,
Evm: ConfigureEvm<Header = Header>,
Evm: ConfigureEvm<Header = Header, Transaction = TransactionSigned>,
>,
{
#[inline]
Expand Down
Loading

0 comments on commit 9cde895

Please sign in to comment.