mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat: integrate TxEnv conversions (#14630)
This commit is contained in:
7
Cargo.lock
generated
7
Cargo.lock
generated
@ -261,8 +261,9 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "alloy-evm"
|
name = "alloy-evm"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/alloy-rs/evm?rev=3a57c0d#3a57c0db813d45ddf9b5dcbe4756ae2ce3fc2569"
|
source = "git+https://github.com/alloy-rs/evm?rev=beb6832#beb68324d7e05ae2eafad9f726a94cb0b63d15a5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"alloy-consensus",
|
||||||
"alloy-primitives",
|
"alloy-primitives",
|
||||||
"revm",
|
"revm",
|
||||||
"revm-optimism",
|
"revm-optimism",
|
||||||
@ -368,7 +369,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "alloy-op-evm"
|
name = "alloy-op-evm"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/alloy-rs/evm?rev=3a57c0d#3a57c0db813d45ddf9b5dcbe4756ae2ce3fc2569"
|
source = "git+https://github.com/alloy-rs/evm?rev=beb6832#beb68324d7e05ae2eafad9f726a94cb0b63d15a5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"alloy-evm",
|
"alloy-evm",
|
||||||
"alloy-primitives",
|
"alloy-primitives",
|
||||||
@ -7702,6 +7703,7 @@ version = "1.2.0"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"alloy-consensus",
|
"alloy-consensus",
|
||||||
"alloy-eips",
|
"alloy-eips",
|
||||||
|
"alloy-evm",
|
||||||
"alloy-network",
|
"alloy-network",
|
||||||
"alloy-primitives",
|
"alloy-primitives",
|
||||||
"alloy-rlp",
|
"alloy-rlp",
|
||||||
@ -8717,6 +8719,7 @@ version = "1.2.0"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"alloy-consensus",
|
"alloy-consensus",
|
||||||
"alloy-eips",
|
"alloy-eips",
|
||||||
|
"alloy-evm",
|
||||||
"alloy-network",
|
"alloy-network",
|
||||||
"alloy-primitives",
|
"alloy-primitives",
|
||||||
"alloy-rlp",
|
"alloy-rlp",
|
||||||
|
|||||||
@ -623,8 +623,8 @@ snmalloc-rs = { version = "0.3.7", features = ["build_cc"] }
|
|||||||
crunchy = "=0.2.2"
|
crunchy = "=0.2.2"
|
||||||
|
|
||||||
[patch.crates-io]
|
[patch.crates-io]
|
||||||
alloy-evm = { git = "https://github.com/alloy-rs/evm", rev = "3a57c0d" }
|
alloy-evm = { git = "https://github.com/alloy-rs/evm", rev = "beb6832" }
|
||||||
alloy-op-evm = { git = "https://github.com/alloy-rs/evm", rev = "3a57c0d" }
|
alloy-op-evm = { git = "https://github.com/alloy-rs/evm", rev = "beb6832" }
|
||||||
|
|
||||||
revm = { git = "https://github.com/bluealloy/revm", rev = "a8a9893b" }
|
revm = { git = "https://github.com/bluealloy/revm", rev = "a8a9893b" }
|
||||||
revm-bytecode = { git = "https://github.com/bluealloy/revm", rev = "a8a9893b" }
|
revm-bytecode = { git = "https://github.com/bluealloy/revm", rev = "a8a9893b" }
|
||||||
|
|||||||
@ -13,8 +13,8 @@ reth-tracing = { path = "../../crates/tracing" }
|
|||||||
reth-node-api = { path = "../../crates/node/api" }
|
reth-node-api = { path = "../../crates/node/api" }
|
||||||
|
|
||||||
[patch.crates-io]
|
[patch.crates-io]
|
||||||
alloy-evm = { git = "https://github.com/alloy-rs/evm", rev = "3a57c0d" }
|
alloy-evm = { git = "https://github.com/alloy-rs/evm", rev = "beb6832" }
|
||||||
alloy-op-evm = { git = "https://github.com/alloy-rs/evm", rev = "3a57c0d" }
|
alloy-op-evm = { git = "https://github.com/alloy-rs/evm", rev = "beb6832" }
|
||||||
|
|
||||||
revm = { git = "https://github.com/bluealloy/revm", rev = "a8b9b1e" }
|
revm = { git = "https://github.com/bluealloy/revm", rev = "a8b9b1e" }
|
||||||
revm-bytecode = { git = "https://github.com/bluealloy/revm", rev = "a8b9b1e" }
|
revm-bytecode = { git = "https://github.com/bluealloy/revm", rev = "a8b9b1e" }
|
||||||
|
|||||||
@ -7,6 +7,7 @@ use crate::{
|
|||||||
use alloc::{boxed::Box, sync::Arc, vec::Vec};
|
use alloc::{boxed::Box, sync::Arc, vec::Vec};
|
||||||
use alloy_consensus::{Header, Transaction};
|
use alloy_consensus::{Header, Transaction};
|
||||||
use alloy_eips::{eip4895::Withdrawals, eip6110, eip7685::Requests};
|
use alloy_eips::{eip4895::Withdrawals, eip6110, eip7685::Requests};
|
||||||
|
use alloy_evm::FromRecoveredTx;
|
||||||
use alloy_primitives::{Address, B256};
|
use alloy_primitives::{Address, B256};
|
||||||
use reth_chainspec::{ChainSpec, EthereumHardfork, EthereumHardforks, MAINNET};
|
use reth_chainspec::{ChainSpec, EthereumHardfork, EthereumHardforks, MAINNET};
|
||||||
use reth_evm::{
|
use reth_evm::{
|
||||||
@ -16,7 +17,7 @@ use reth_evm::{
|
|||||||
},
|
},
|
||||||
state_change::post_block_balance_increments,
|
state_change::post_block_balance_increments,
|
||||||
system_calls::{OnStateHook, StateChangePostBlockSource, StateChangeSource, SystemCaller},
|
system_calls::{OnStateHook, StateChangePostBlockSource, StateChangeSource, SystemCaller},
|
||||||
ConfigureEvm, ConfigureEvmEnv, Database, Evm,
|
ConfigureEvm, Database, Evm,
|
||||||
};
|
};
|
||||||
use reth_execution_types::BlockExecutionResult;
|
use reth_execution_types::BlockExecutionResult;
|
||||||
use reth_primitives::{
|
use reth_primitives::{
|
||||||
@ -76,7 +77,7 @@ where
|
|||||||
DB: Database,
|
DB: Database,
|
||||||
{
|
{
|
||||||
let evm = self.evm_config.evm_for_block(db, block.header());
|
let evm = self.evm_config.evm_for_block(db, block.header());
|
||||||
EthExecutionStrategy::new(evm, block.sealed_block(), &self.chain_spec, &self.evm_config)
|
EthExecutionStrategy::new(evm, block.sealed_block(), &self.chain_spec)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,11 +119,9 @@ impl<'a> From<&'a SealedBlock> for EthBlockExecutionInput<'a> {
|
|||||||
|
|
||||||
/// Block execution strategy for Ethereum.
|
/// Block execution strategy for Ethereum.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct EthExecutionStrategy<'a, Evm, EvmConfig> {
|
pub struct EthExecutionStrategy<'a, Evm> {
|
||||||
/// Reference to the [`ChainSpec`].
|
/// Reference to the [`ChainSpec`].
|
||||||
chain_spec: &'a ChainSpec,
|
chain_spec: &'a ChainSpec,
|
||||||
/// How to configure the EVM.
|
|
||||||
evm_config: EvmConfig,
|
|
||||||
|
|
||||||
/// Input for block execution.
|
/// Input for block execution.
|
||||||
input: EthBlockExecutionInput<'a>,
|
input: EthBlockExecutionInput<'a>,
|
||||||
@ -137,18 +136,16 @@ pub struct EthExecutionStrategy<'a, Evm, EvmConfig> {
|
|||||||
gas_used: u64,
|
gas_used: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, Evm, EvmConfig> EthExecutionStrategy<'a, Evm, EvmConfig> {
|
impl<'a, Evm> EthExecutionStrategy<'a, Evm> {
|
||||||
/// Creates a new [`EthExecutionStrategy`]
|
/// Creates a new [`EthExecutionStrategy`]
|
||||||
pub fn new(
|
pub fn new(
|
||||||
evm: Evm,
|
evm: Evm,
|
||||||
input: impl Into<EthBlockExecutionInput<'a>>,
|
input: impl Into<EthBlockExecutionInput<'a>>,
|
||||||
chain_spec: &'a ChainSpec,
|
chain_spec: &'a ChainSpec,
|
||||||
evm_config: EvmConfig,
|
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
evm,
|
evm,
|
||||||
chain_spec,
|
chain_spec,
|
||||||
evm_config,
|
|
||||||
input: input.into(),
|
input: input.into(),
|
||||||
receipts: Vec::new(),
|
receipts: Vec::new(),
|
||||||
gas_used: 0,
|
gas_used: 0,
|
||||||
@ -157,11 +154,10 @@ impl<'a, Evm, EvmConfig> EthExecutionStrategy<'a, Evm, EvmConfig> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'db, DB, E, EvmConfig> BlockExecutionStrategy for EthExecutionStrategy<'_, E, EvmConfig>
|
impl<'db, DB, E> BlockExecutionStrategy for EthExecutionStrategy<'_, E>
|
||||||
where
|
where
|
||||||
DB: Database + 'db,
|
DB: Database + 'db,
|
||||||
E: Evm<DB = &'db mut State<DB>, Tx = EvmConfig::TxEnv>,
|
E: Evm<DB = &'db mut State<DB>, Tx: FromRecoveredTx<TransactionSigned>>,
|
||||||
EvmConfig: ConfigureEvmEnv<Transaction = TransactionSigned>,
|
|
||||||
{
|
{
|
||||||
type Error = BlockExecutionError;
|
type Error = BlockExecutionError;
|
||||||
type Primitives = EthPrimitives;
|
type Primitives = EthPrimitives;
|
||||||
@ -194,12 +190,11 @@ where
|
|||||||
.into())
|
.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
let tx_env = self.evm_config.tx_env(tx.clone());
|
|
||||||
let hash = tx.hash();
|
let hash = tx.hash();
|
||||||
|
|
||||||
// Execute transaction.
|
// Execute transaction.
|
||||||
let result_and_state =
|
let result_and_state =
|
||||||
self.evm.transact(tx_env).map_err(move |err| BlockExecutionError::evm(err, *hash))?;
|
self.evm.transact(&tx).map_err(move |err| BlockExecutionError::evm(err, *hash))?;
|
||||||
self.system_caller
|
self.system_caller
|
||||||
.on_state(StateChangeSource::Transaction(self.receipts.len()), &result_and_state.state);
|
.on_state(StateChangeSource::Transaction(self.receipts.len()), &result_and_state.state);
|
||||||
let ResultAndState { result, state } = result_and_state;
|
let ResultAndState { result, state } = result_and_state;
|
||||||
|
|||||||
@ -17,8 +17,8 @@
|
|||||||
|
|
||||||
extern crate alloc;
|
extern crate alloc;
|
||||||
|
|
||||||
use alloc::{borrow::Borrow, sync::Arc};
|
use alloc::sync::Arc;
|
||||||
use alloy_consensus::{transaction::Recovered, BlockHeader, Header};
|
use alloy_consensus::{BlockHeader, Header};
|
||||||
pub use alloy_evm::EthEvm;
|
pub use alloy_evm::EthEvm;
|
||||||
use alloy_evm::EthEvmFactory;
|
use alloy_evm::EthEvmFactory;
|
||||||
use alloy_primitives::U256;
|
use alloy_primitives::U256;
|
||||||
@ -26,7 +26,6 @@ use core::{convert::Infallible, fmt::Debug};
|
|||||||
use reth_chainspec::{ChainSpec, EthChainSpec, MAINNET};
|
use reth_chainspec::{ChainSpec, EthChainSpec, MAINNET};
|
||||||
use reth_evm::{ConfigureEvm, ConfigureEvmEnv, EvmEnv, NextBlockEnvAttributes};
|
use reth_evm::{ConfigureEvm, ConfigureEvmEnv, EvmEnv, NextBlockEnvAttributes};
|
||||||
use reth_primitives::TransactionSigned;
|
use reth_primitives::TransactionSigned;
|
||||||
use reth_primitives_traits::transaction::execute::FillTxEnv;
|
|
||||||
use reth_revm::{
|
use reth_revm::{
|
||||||
context::{BlockEnv, CfgEnv, TxEnv},
|
context::{BlockEnv, CfgEnv, TxEnv},
|
||||||
context_interface::block::BlobExcessGasAndPrice,
|
context_interface::block::BlobExcessGasAndPrice,
|
||||||
@ -77,17 +76,6 @@ impl ConfigureEvmEnv for EthEvmConfig {
|
|||||||
type TxEnv = TxEnv;
|
type TxEnv = TxEnv;
|
||||||
type Spec = SpecId;
|
type Spec = SpecId;
|
||||||
|
|
||||||
fn tx_env<T: Borrow<Self::Transaction>>(
|
|
||||||
&self,
|
|
||||||
transaction: impl Borrow<Recovered<T>>,
|
|
||||||
) -> Self::TxEnv {
|
|
||||||
let transaction = transaction.borrow();
|
|
||||||
|
|
||||||
let mut tx_env = TxEnv::default();
|
|
||||||
transaction.tx().borrow().fill_tx_env(&mut tx_env, transaction.signer());
|
|
||||||
tx_env
|
|
||||||
}
|
|
||||||
|
|
||||||
fn evm_env(&self, header: &Self::Header) -> EvmEnv {
|
fn evm_env(&self, header: &Self::Header) -> EvmEnv {
|
||||||
let spec = config::revm_spec(self.chain_spec(), header);
|
let spec = config::revm_spec(self.chain_spec(), header);
|
||||||
|
|
||||||
|
|||||||
@ -190,7 +190,6 @@ where
|
|||||||
withdrawals: Some(&attributes.withdrawals),
|
withdrawals: Some(&attributes.withdrawals),
|
||||||
},
|
},
|
||||||
&chain_spec,
|
&chain_spec,
|
||||||
&evm_config,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
strategy.apply_pre_execution_changes().map_err(|err| {
|
strategy.apply_pre_execution_changes().map_err(|err| {
|
||||||
|
|||||||
@ -18,6 +18,7 @@ reth-primitives-traits.workspace = true
|
|||||||
reth-zstd-compressors = { workspace = true, optional = true }
|
reth-zstd-compressors = { workspace = true, optional = true }
|
||||||
|
|
||||||
# ethereum
|
# ethereum
|
||||||
|
alloy-evm.workspace = true
|
||||||
alloy-eips = { workspace = true, features = ["k256"] }
|
alloy-eips = { workspace = true, features = ["k256"] }
|
||||||
alloy-primitives.workspace = true
|
alloy-primitives.workspace = true
|
||||||
alloy-network = { workspace = true, optional = true }
|
alloy-network = { workspace = true, optional = true }
|
||||||
@ -68,6 +69,7 @@ std = [
|
|||||||
"alloy-serde?/std",
|
"alloy-serde?/std",
|
||||||
"alloy-rpc-types-eth?/std",
|
"alloy-rpc-types-eth?/std",
|
||||||
"revm-context/std",
|
"revm-context/std",
|
||||||
|
"alloy-evm/std",
|
||||||
]
|
]
|
||||||
reth-codec = [
|
reth-codec = [
|
||||||
"std",
|
"std",
|
||||||
|
|||||||
@ -10,6 +10,7 @@ use alloy_eips::{
|
|||||||
eip2930::AccessList,
|
eip2930::AccessList,
|
||||||
eip7702::SignedAuthorization,
|
eip7702::SignedAuthorization,
|
||||||
};
|
};
|
||||||
|
use alloy_evm::FromRecoveredTx;
|
||||||
use alloy_primitives::{
|
use alloy_primitives::{
|
||||||
keccak256, Address, Bytes, ChainId, PrimitiveSignature as Signature, TxHash, TxKind, B256, U256,
|
keccak256, Address, Bytes, ChainId, PrimitiveSignature as Signature, TxHash, TxKind, B256, U256,
|
||||||
};
|
};
|
||||||
@ -19,7 +20,7 @@ use reth_primitives_traits::{
|
|||||||
crypto::secp256k1::{recover_signer, recover_signer_unchecked},
|
crypto::secp256k1::{recover_signer, recover_signer_unchecked},
|
||||||
sync::OnceLock,
|
sync::OnceLock,
|
||||||
transaction::{error::TransactionConversionError, signed::RecoveryError},
|
transaction::{error::TransactionConversionError, signed::RecoveryError},
|
||||||
FillTxEnv, InMemorySize, SignedTransaction,
|
InMemorySize, SignedTransaction,
|
||||||
};
|
};
|
||||||
use revm_context::TxEnv;
|
use revm_context::TxEnv;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
@ -750,10 +751,10 @@ impl reth_codecs::Compact for TransactionSigned {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FillTxEnv<TxEnv> for TransactionSigned {
|
impl FromRecoveredTx<TransactionSigned> for TxEnv {
|
||||||
fn fill_tx_env(&self, tx_env: &mut TxEnv, sender: Address) {
|
fn from_recovered_tx(tx: &TransactionSigned, sender: Address) -> Self {
|
||||||
*tx_env = match self.as_ref() {
|
match tx.as_ref() {
|
||||||
Transaction::Legacy(tx) => TxEnv {
|
Transaction::Legacy(tx) => Self {
|
||||||
gas_limit: tx.gas_limit,
|
gas_limit: tx.gas_limit,
|
||||||
gas_price: tx.gas_price,
|
gas_price: tx.gas_price,
|
||||||
gas_priority_fee: None,
|
gas_priority_fee: None,
|
||||||
@ -769,7 +770,7 @@ impl FillTxEnv<TxEnv> for TransactionSigned {
|
|||||||
tx_type: 0,
|
tx_type: 0,
|
||||||
caller: sender,
|
caller: sender,
|
||||||
},
|
},
|
||||||
Transaction::Eip2930(tx) => TxEnv {
|
Transaction::Eip2930(tx) => Self {
|
||||||
gas_limit: tx.gas_limit,
|
gas_limit: tx.gas_limit,
|
||||||
gas_price: tx.gas_price,
|
gas_price: tx.gas_price,
|
||||||
gas_priority_fee: None,
|
gas_priority_fee: None,
|
||||||
@ -785,7 +786,7 @@ impl FillTxEnv<TxEnv> for TransactionSigned {
|
|||||||
tx_type: 1,
|
tx_type: 1,
|
||||||
caller: sender,
|
caller: sender,
|
||||||
},
|
},
|
||||||
Transaction::Eip1559(tx) => TxEnv {
|
Transaction::Eip1559(tx) => Self {
|
||||||
gas_limit: tx.gas_limit,
|
gas_limit: tx.gas_limit,
|
||||||
gas_price: tx.max_fee_per_gas,
|
gas_price: tx.max_fee_per_gas,
|
||||||
gas_priority_fee: Some(tx.max_priority_fee_per_gas),
|
gas_priority_fee: Some(tx.max_priority_fee_per_gas),
|
||||||
@ -801,7 +802,7 @@ impl FillTxEnv<TxEnv> for TransactionSigned {
|
|||||||
tx_type: 2,
|
tx_type: 2,
|
||||||
caller: sender,
|
caller: sender,
|
||||||
},
|
},
|
||||||
Transaction::Eip4844(tx) => TxEnv {
|
Transaction::Eip4844(tx) => Self {
|
||||||
gas_limit: tx.gas_limit,
|
gas_limit: tx.gas_limit,
|
||||||
gas_price: tx.max_fee_per_gas,
|
gas_price: tx.max_fee_per_gas,
|
||||||
gas_priority_fee: Some(tx.max_priority_fee_per_gas),
|
gas_priority_fee: Some(tx.max_priority_fee_per_gas),
|
||||||
@ -817,7 +818,7 @@ impl FillTxEnv<TxEnv> for TransactionSigned {
|
|||||||
tx_type: 3,
|
tx_type: 3,
|
||||||
caller: sender,
|
caller: sender,
|
||||||
},
|
},
|
||||||
Transaction::Eip7702(tx) => TxEnv {
|
Transaction::Eip7702(tx) => Self {
|
||||||
gas_limit: tx.gas_limit,
|
gas_limit: tx.gas_limit,
|
||||||
gas_price: tx.max_fee_per_gas,
|
gas_price: tx.max_fee_per_gas,
|
||||||
gas_priority_fee: Some(tx.max_priority_fee_per_gas),
|
gas_priority_fee: Some(tx.max_priority_fee_per_gas),
|
||||||
|
|||||||
@ -17,10 +17,9 @@
|
|||||||
|
|
||||||
extern crate alloc;
|
extern crate alloc;
|
||||||
|
|
||||||
use alloc::borrow::Borrow;
|
|
||||||
use alloy_consensus::transaction::Recovered;
|
|
||||||
use alloy_eips::eip2930::AccessList;
|
use alloy_eips::eip2930::AccessList;
|
||||||
pub use alloy_evm::evm::EvmFactory;
|
pub use alloy_evm::evm::EvmFactory;
|
||||||
|
use alloy_evm::{FromRecoveredTx, IntoTxEnv};
|
||||||
use alloy_primitives::{Address, B256};
|
use alloy_primitives::{Address, B256};
|
||||||
use core::fmt::Debug;
|
use core::fmt::Debug;
|
||||||
use reth_primitives_traits::{BlockHeader, SignedTransaction};
|
use reth_primitives_traits::{BlockHeader, SignedTransaction};
|
||||||
@ -155,7 +154,7 @@ pub trait ConfigureEvmEnv: Send + Sync + Unpin + Clone {
|
|||||||
type Transaction: SignedTransaction;
|
type Transaction: SignedTransaction;
|
||||||
|
|
||||||
/// Transaction environment used by EVM.
|
/// Transaction environment used by EVM.
|
||||||
type TxEnv: TransactionEnv;
|
type TxEnv: TransactionEnv + FromRecoveredTx<Self::Transaction> + IntoTxEnv<Self::TxEnv>;
|
||||||
|
|
||||||
/// The error type that is returned by [`Self::next_evm_env`].
|
/// The error type that is returned by [`Self::next_evm_env`].
|
||||||
type Error: core::error::Error + Send + Sync + 'static;
|
type Error: core::error::Error + Send + Sync + 'static;
|
||||||
@ -164,10 +163,9 @@ pub trait ConfigureEvmEnv: Send + Sync + Unpin + Clone {
|
|||||||
type Spec: Debug + Copy + Send + Sync + 'static;
|
type Spec: Debug + Copy + Send + Sync + 'static;
|
||||||
|
|
||||||
/// Returns a [`TxEnv`] from a transaction and [`Address`].
|
/// Returns a [`TxEnv`] from a transaction and [`Address`].
|
||||||
fn tx_env<T: Borrow<Self::Transaction>>(
|
fn tx_env(&self, transaction: impl IntoTxEnv<Self::TxEnv>) -> Self::TxEnv {
|
||||||
&self,
|
transaction.into_tx_env()
|
||||||
transaction: impl Borrow<Recovered<T>>,
|
}
|
||||||
) -> Self::TxEnv;
|
|
||||||
|
|
||||||
/// Creates a new [`EvmEnv`] for the given header.
|
/// Creates a new [`EvmEnv`] for the given header.
|
||||||
fn evm_env(&self, header: &Self::Header) -> EvmEnv<Self::Spec>;
|
fn evm_env(&self, header: &Self::Header) -> EvmEnv<Self::Spec>;
|
||||||
|
|||||||
@ -8,6 +8,7 @@ use alloc::{boxed::Box, sync::Arc, vec::Vec};
|
|||||||
use alloy_consensus::{
|
use alloy_consensus::{
|
||||||
transaction::Recovered, BlockHeader, Eip658Value, Header, Receipt, Transaction as _, TxReceipt,
|
transaction::Recovered, BlockHeader, Eip658Value, Header, Receipt, Transaction as _, TxReceipt,
|
||||||
};
|
};
|
||||||
|
use alloy_evm::FromRecoveredTx;
|
||||||
use op_alloy_consensus::OpDepositReceipt;
|
use op_alloy_consensus::OpDepositReceipt;
|
||||||
use reth_evm::{
|
use reth_evm::{
|
||||||
execute::{
|
execute::{
|
||||||
@ -96,7 +97,6 @@ where
|
|||||||
evm,
|
evm,
|
||||||
block.sealed_block(),
|
block.sealed_block(),
|
||||||
&self.chain_spec,
|
&self.chain_spec,
|
||||||
&self.evm_config,
|
|
||||||
self.receipt_builder.as_ref(),
|
self.receipt_builder.as_ref(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -134,19 +134,16 @@ impl<'a, B: Block> From<&'a SealedBlock<B>> for OpBlockExecutionInput {
|
|||||||
|
|
||||||
/// Block execution strategy for Optimism.
|
/// Block execution strategy for Optimism.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct OpExecutionStrategy<'a, Evm, N: NodePrimitives, ChainSpec, EvmConfig: ConfigureEvm> {
|
pub struct OpExecutionStrategy<'a, E: Evm, N: NodePrimitives, ChainSpec> {
|
||||||
/// Chainspec.
|
/// Chainspec.
|
||||||
chain_spec: ChainSpec,
|
chain_spec: ChainSpec,
|
||||||
/// How to configure the EVM.
|
|
||||||
evm_config: EvmConfig,
|
|
||||||
/// Receipt builder.
|
/// Receipt builder.
|
||||||
receipt_builder:
|
receipt_builder: &'a dyn OpReceiptBuilder<N::SignedTx, E::HaltReason, Receipt = N::Receipt>,
|
||||||
&'a dyn OpReceiptBuilder<N::SignedTx, HaltReasonFor<EvmConfig>, Receipt = N::Receipt>,
|
|
||||||
|
|
||||||
/// Input for block execution.
|
/// Input for block execution.
|
||||||
input: OpBlockExecutionInput,
|
input: OpBlockExecutionInput,
|
||||||
/// The EVM used by strategy.
|
/// The EVM used by strategy.
|
||||||
evm: Evm,
|
evm: E,
|
||||||
/// Receipts of executed transactions.
|
/// Receipts of executed transactions.
|
||||||
receipts: Vec<N::Receipt>,
|
receipts: Vec<N::Receipt>,
|
||||||
/// Total gas used by executed transactions.
|
/// Total gas used by executed transactions.
|
||||||
@ -157,23 +154,18 @@ pub struct OpExecutionStrategy<'a, Evm, N: NodePrimitives, ChainSpec, EvmConfig:
|
|||||||
system_caller: SystemCaller<ChainSpec>,
|
system_caller: SystemCaller<ChainSpec>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, Evm, N, ChainSpec, EvmConfig> OpExecutionStrategy<'a, Evm, N, ChainSpec, EvmConfig>
|
impl<'a, E, N, ChainSpec> OpExecutionStrategy<'a, E, N, ChainSpec>
|
||||||
where
|
where
|
||||||
|
E: Evm,
|
||||||
N: NodePrimitives,
|
N: NodePrimitives,
|
||||||
ChainSpec: OpHardforks,
|
ChainSpec: OpHardforks,
|
||||||
EvmConfig: ConfigureEvm,
|
|
||||||
{
|
{
|
||||||
/// Creates a new [`OpExecutionStrategy`]
|
/// Creates a new [`OpExecutionStrategy`]
|
||||||
pub fn new(
|
pub fn new(
|
||||||
evm: Evm,
|
evm: E,
|
||||||
input: impl Into<OpBlockExecutionInput>,
|
input: impl Into<OpBlockExecutionInput>,
|
||||||
chain_spec: ChainSpec,
|
chain_spec: ChainSpec,
|
||||||
evm_config: EvmConfig,
|
receipt_builder: &'a dyn OpReceiptBuilder<N::SignedTx, E::HaltReason, Receipt = N::Receipt>,
|
||||||
receipt_builder: &'a dyn OpReceiptBuilder<
|
|
||||||
N::SignedTx,
|
|
||||||
HaltReasonFor<EvmConfig>,
|
|
||||||
Receipt = N::Receipt,
|
|
||||||
>,
|
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let input = input.into();
|
let input = input.into();
|
||||||
Self {
|
Self {
|
||||||
@ -181,7 +173,6 @@ where
|
|||||||
evm,
|
evm,
|
||||||
system_caller: SystemCaller::new(chain_spec.clone()),
|
system_caller: SystemCaller::new(chain_spec.clone()),
|
||||||
chain_spec,
|
chain_spec,
|
||||||
evm_config,
|
|
||||||
receipt_builder,
|
receipt_builder,
|
||||||
receipts: Vec::new(),
|
receipts: Vec::new(),
|
||||||
gas_used: 0,
|
gas_used: 0,
|
||||||
@ -190,14 +181,12 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'db, DB, E, N, ChainSpec, EvmConfig> BlockExecutionStrategy
|
impl<'db, DB, E, N, ChainSpec> BlockExecutionStrategy for OpExecutionStrategy<'_, E, N, ChainSpec>
|
||||||
for OpExecutionStrategy<'_, E, N, ChainSpec, EvmConfig>
|
|
||||||
where
|
where
|
||||||
DB: Database + 'db,
|
DB: Database + 'db,
|
||||||
E: Evm<DB = &'db mut State<DB>, Tx = EvmConfig::TxEnv, HaltReason = HaltReasonFor<EvmConfig>>,
|
E: Evm<DB = &'db mut State<DB>, Tx: FromRecoveredTx<N::SignedTx>>,
|
||||||
N: NodePrimitives<SignedTx: OpTransaction, Receipt: DepositReceipt>,
|
N: NodePrimitives<SignedTx: OpTransaction, Receipt: DepositReceipt>,
|
||||||
ChainSpec: OpHardforks,
|
ChainSpec: OpHardforks,
|
||||||
EvmConfig: ConfigureEvmFor<N>,
|
|
||||||
{
|
{
|
||||||
type Primitives = N;
|
type Primitives = N;
|
||||||
type Error = BlockExecutionError;
|
type Error = BlockExecutionError;
|
||||||
@ -248,12 +237,11 @@ where
|
|||||||
.transpose()
|
.transpose()
|
||||||
.map_err(|_| OpBlockExecutionError::AccountLoadFailed(tx.signer()))?;
|
.map_err(|_| OpBlockExecutionError::AccountLoadFailed(tx.signer()))?;
|
||||||
|
|
||||||
let tx_env = self.evm_config.tx_env(&tx);
|
|
||||||
let hash = tx.tx_hash();
|
let hash = tx.tx_hash();
|
||||||
|
|
||||||
// Execute transaction.
|
// Execute transaction.
|
||||||
let result_and_state =
|
let result_and_state =
|
||||||
self.evm.transact(tx_env).map_err(move |err| BlockExecutionError::evm(err, *hash))?;
|
self.evm.transact(&tx).map_err(move |err| BlockExecutionError::evm(err, *hash))?;
|
||||||
|
|
||||||
trace!(
|
trace!(
|
||||||
target: "evm",
|
target: "evm",
|
||||||
|
|||||||
@ -11,10 +11,10 @@
|
|||||||
extern crate alloc;
|
extern crate alloc;
|
||||||
|
|
||||||
use alloc::sync::Arc;
|
use alloc::sync::Arc;
|
||||||
use alloy_consensus::{transaction::Recovered, BlockHeader, Header};
|
use alloy_consensus::{BlockHeader, Header};
|
||||||
use alloy_op_evm::OpEvmFactory;
|
use alloy_op_evm::OpEvmFactory;
|
||||||
use alloy_primitives::U256;
|
use alloy_primitives::U256;
|
||||||
use core::{borrow::Borrow, fmt::Debug};
|
use core::fmt::Debug;
|
||||||
use op_alloy_consensus::EIP1559ParamError;
|
use op_alloy_consensus::EIP1559ParamError;
|
||||||
use reth_chainspec::EthChainSpec;
|
use reth_chainspec::EthChainSpec;
|
||||||
use reth_evm::{ConfigureEvm, ConfigureEvmEnv, EvmEnv, NextBlockEnvAttributes};
|
use reth_evm::{ConfigureEvm, ConfigureEvmEnv, EvmEnv, NextBlockEnvAttributes};
|
||||||
@ -22,7 +22,6 @@ use reth_optimism_chainspec::OpChainSpec;
|
|||||||
use reth_optimism_consensus::next_block_base_fee;
|
use reth_optimism_consensus::next_block_base_fee;
|
||||||
use reth_optimism_forks::OpHardforks;
|
use reth_optimism_forks::OpHardforks;
|
||||||
use reth_optimism_primitives::OpTransactionSigned;
|
use reth_optimism_primitives::OpTransactionSigned;
|
||||||
use reth_primitives_traits::FillTxEnv;
|
|
||||||
use revm::{
|
use revm::{
|
||||||
context::{BlockEnv, CfgEnv, TxEnv},
|
context::{BlockEnv, CfgEnv, TxEnv},
|
||||||
context_interface::block::BlobExcessGasAndPrice,
|
context_interface::block::BlobExcessGasAndPrice,
|
||||||
@ -74,17 +73,6 @@ impl<ChainSpec: EthChainSpec + OpHardforks + 'static> ConfigureEvmEnv for OpEvmC
|
|||||||
type TxEnv = OpTransaction<TxEnv>;
|
type TxEnv = OpTransaction<TxEnv>;
|
||||||
type Spec = OpSpecId;
|
type Spec = OpSpecId;
|
||||||
|
|
||||||
fn tx_env<T: Borrow<Self::Transaction>>(
|
|
||||||
&self,
|
|
||||||
transaction: impl Borrow<Recovered<T>>,
|
|
||||||
) -> Self::TxEnv {
|
|
||||||
let transaction = transaction.borrow();
|
|
||||||
|
|
||||||
let mut tx_env = Default::default();
|
|
||||||
transaction.tx().borrow().fill_tx_env(&mut tx_env, transaction.signer());
|
|
||||||
tx_env
|
|
||||||
}
|
|
||||||
|
|
||||||
fn evm_env(&self, header: &Self::Header) -> EvmEnv<Self::Spec> {
|
fn evm_env(&self, header: &Self::Header) -> EvmEnv<Self::Spec> {
|
||||||
let spec = config::revm_spec(self.chain_spec(), header);
|
let spec = config::revm_spec(self.chain_spec(), header);
|
||||||
|
|
||||||
|
|||||||
@ -369,7 +369,6 @@ impl<Txs> OpBuilder<'_, Txs> {
|
|||||||
beneficiary: ctx.evm_env.block_env.beneficiary,
|
beneficiary: ctx.evm_env.block_env.beneficiary,
|
||||||
},
|
},
|
||||||
&ctx.chain_spec,
|
&ctx.chain_spec,
|
||||||
&ctx.evm_config,
|
|
||||||
ctx.receipt_builder.as_ref(),
|
ctx.receipt_builder.as_ref(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@ -18,6 +18,7 @@ reth-codecs = { workspace = true, optional = true, features = ["op"] }
|
|||||||
reth-zstd-compressors = { workspace = true, optional = true }
|
reth-zstd-compressors = { workspace = true, optional = true }
|
||||||
|
|
||||||
# ethereum
|
# ethereum
|
||||||
|
alloy-evm.workspace = true
|
||||||
alloy-primitives.workspace = true
|
alloy-primitives.workspace = true
|
||||||
alloy-consensus.workspace = true
|
alloy-consensus.workspace = true
|
||||||
alloy-rlp.workspace = true
|
alloy-rlp.workspace = true
|
||||||
@ -75,6 +76,7 @@ std = [
|
|||||||
"alloy-serde?/std",
|
"alloy-serde?/std",
|
||||||
"revm-context/std",
|
"revm-context/std",
|
||||||
"serde_json/std",
|
"serde_json/std",
|
||||||
|
"alloy-evm/std",
|
||||||
]
|
]
|
||||||
alloy-compat = ["dep:alloy-network", "dep:alloy-serde", "dep:alloy-rpc-types-eth", "op-alloy-consensus/alloy-compat"]
|
alloy-compat = ["dep:alloy-network", "dep:alloy-serde", "dep:alloy-rpc-types-eth", "op-alloy-consensus/alloy-compat"]
|
||||||
reth-codec = [
|
reth-codec = [
|
||||||
|
|||||||
@ -10,6 +10,7 @@ use alloy_eips::{
|
|||||||
eip2930::AccessList,
|
eip2930::AccessList,
|
||||||
eip7702::SignedAuthorization,
|
eip7702::SignedAuthorization,
|
||||||
};
|
};
|
||||||
|
use alloy_evm::FromRecoveredTx;
|
||||||
use alloy_primitives::{
|
use alloy_primitives::{
|
||||||
keccak256, Address, Bytes, PrimitiveSignature as Signature, TxHash, TxKind, Uint, B256,
|
keccak256, Address, Bytes, PrimitiveSignature as Signature, TxHash, TxKind, Uint, B256,
|
||||||
};
|
};
|
||||||
@ -29,7 +30,7 @@ use reth_primitives_traits::{
|
|||||||
crypto::secp256k1::{recover_signer, recover_signer_unchecked},
|
crypto::secp256k1::{recover_signer, recover_signer_unchecked},
|
||||||
sync::OnceLock,
|
sync::OnceLock,
|
||||||
transaction::{error::TransactionConversionError, signed::RecoveryError},
|
transaction::{error::TransactionConversionError, signed::RecoveryError},
|
||||||
FillTxEnv, InMemorySize, SignedTransaction,
|
InMemorySize, SignedTransaction,
|
||||||
};
|
};
|
||||||
use revm_context::TxEnv;
|
use revm_context::TxEnv;
|
||||||
use revm_optimism::transaction::deposit::DepositTransactionParts;
|
use revm_optimism::transaction::deposit::DepositTransactionParts;
|
||||||
@ -213,11 +214,11 @@ impl OpTransaction for OpTransactionSigned {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FillTxEnv<revm_optimism::OpTransaction<TxEnv>> for OpTransactionSigned {
|
impl FromRecoveredTx<OpTransactionSigned> for revm_optimism::OpTransaction<TxEnv> {
|
||||||
fn fill_tx_env(&self, tx_env: &mut revm_optimism::OpTransaction<TxEnv>, sender: Address) {
|
fn from_recovered_tx(tx: &OpTransactionSigned, sender: Address) -> Self {
|
||||||
let envelope = self.encoded_2718();
|
let envelope = tx.encoded_2718();
|
||||||
|
|
||||||
let base = match &self.transaction {
|
let base = match &tx.transaction {
|
||||||
OpTypedTransaction::Legacy(tx) => TxEnv {
|
OpTypedTransaction::Legacy(tx) => TxEnv {
|
||||||
gas_limit: tx.gas_limit,
|
gas_limit: tx.gas_limit,
|
||||||
gas_price: tx.gas_price,
|
gas_price: tx.gas_price,
|
||||||
@ -300,10 +301,10 @@ impl FillTxEnv<revm_optimism::OpTransaction<TxEnv>> for OpTransactionSigned {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
*tx_env = revm_optimism::OpTransaction {
|
Self {
|
||||||
base,
|
base,
|
||||||
enveloped_tx: Some(envelope.into()),
|
enveloped_tx: Some(envelope.into()),
|
||||||
deposit: if let OpTypedTransaction::Deposit(tx) = &self.transaction {
|
deposit: if let OpTypedTransaction::Deposit(tx) = &tx.transaction {
|
||||||
DepositTransactionParts {
|
DepositTransactionParts {
|
||||||
is_system_transaction: tx.is_system_transaction,
|
is_system_transaction: tx.is_system_transaction,
|
||||||
source_hash: tx.source_hash,
|
source_hash: tx.source_hash,
|
||||||
@ -312,7 +313,7 @@ impl FillTxEnv<revm_optimism::OpTransaction<TxEnv>> for OpTransactionSigned {
|
|||||||
} else {
|
} else {
|
||||||
Default::default()
|
Default::default()
|
||||||
},
|
},
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -41,10 +41,9 @@ use reth_node_ethereum::{
|
|||||||
node::{EthereumAddOns, EthereumPayloadBuilder},
|
node::{EthereumAddOns, EthereumPayloadBuilder},
|
||||||
BasicBlockExecutorProvider, EthExecutionStrategyFactory, EthereumNode,
|
BasicBlockExecutorProvider, EthExecutionStrategyFactory, EthereumNode,
|
||||||
};
|
};
|
||||||
use reth_primitives::{EthPrimitives, Recovered, TransactionSigned};
|
use reth_primitives::{EthPrimitives, TransactionSigned};
|
||||||
use reth_tracing::{RethTracer, Tracer};
|
use reth_tracing::{RethTracer, Tracer};
|
||||||
use std::{
|
use std::{
|
||||||
borrow::Borrow,
|
|
||||||
convert::Infallible,
|
convert::Infallible,
|
||||||
sync::{Arc, OnceLock},
|
sync::{Arc, OnceLock},
|
||||||
};
|
};
|
||||||
@ -106,13 +105,6 @@ impl ConfigureEvmEnv for MyEvmConfig {
|
|||||||
type TxEnv = TxEnv;
|
type TxEnv = TxEnv;
|
||||||
type Spec = SpecId;
|
type Spec = SpecId;
|
||||||
|
|
||||||
fn tx_env<T: Borrow<Self::Transaction>>(
|
|
||||||
&self,
|
|
||||||
transaction: impl Borrow<Recovered<T>>,
|
|
||||||
) -> Self::TxEnv {
|
|
||||||
self.inner.tx_env(transaction)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn evm_env(&self, header: &Self::Header) -> EvmEnv {
|
fn evm_env(&self, header: &Self::Header) -> EvmEnv {
|
||||||
self.inner.evm_env(header)
|
self.inner.evm_env(header)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -33,10 +33,10 @@ use reth_node_ethereum::{
|
|||||||
evm::EthEvm, node::EthereumAddOns, BasicBlockExecutorProvider, EthEvmConfig,
|
evm::EthEvm, node::EthereumAddOns, BasicBlockExecutorProvider, EthEvmConfig,
|
||||||
EthExecutionStrategyFactory, EthereumNode,
|
EthExecutionStrategyFactory, EthereumNode,
|
||||||
};
|
};
|
||||||
use reth_primitives::{EthPrimitives, Recovered, TransactionSigned};
|
use reth_primitives::{EthPrimitives, TransactionSigned};
|
||||||
use reth_tracing::{RethTracer, Tracer};
|
use reth_tracing::{RethTracer, Tracer};
|
||||||
use schnellru::{ByLength, LruMap};
|
use schnellru::{ByLength, LruMap};
|
||||||
use std::{borrow::Borrow, collections::HashMap, convert::Infallible, sync::Arc};
|
use std::{collections::HashMap, convert::Infallible, sync::Arc};
|
||||||
|
|
||||||
/// Type alias for the LRU cache used within the [`PrecompileCache`].
|
/// Type alias for the LRU cache used within the [`PrecompileCache`].
|
||||||
type PrecompileLRUCache = LruMap<(SpecId, Bytes, u64), Result<InterpreterResult, PrecompileErrors>>;
|
type PrecompileLRUCache = LruMap<(SpecId, Bytes, u64), Result<InterpreterResult, PrecompileErrors>>;
|
||||||
@ -186,13 +186,6 @@ impl ConfigureEvmEnv for MyEvmConfig {
|
|||||||
type TxEnv = TxEnv;
|
type TxEnv = TxEnv;
|
||||||
type Spec = SpecId;
|
type Spec = SpecId;
|
||||||
|
|
||||||
fn tx_env<T: Borrow<Self::Transaction>>(
|
|
||||||
&self,
|
|
||||||
transaction: impl Borrow<Recovered<T>>,
|
|
||||||
) -> Self::TxEnv {
|
|
||||||
self.inner.tx_env(transaction)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn evm_env(&self, header: &Self::Header) -> EvmEnv {
|
fn evm_env(&self, header: &Self::Header) -> EvmEnv {
|
||||||
self.inner.evm_env(header)
|
self.inner.evm_env(header)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user