From 55dc12d74158c0750710d70bba942ca8ec60c7a2 Mon Sep 17 00:00:00 2001 From: Emilia Hane Date: Tue, 16 Jul 2024 17:19:32 +0200 Subject: [PATCH] chore(op): implement `Call` for `OpEthApi` (#9502) Co-authored-by: Matthias Seitz --- .../cli/src/commands/import_receipts.rs | 6 ++-- crates/optimism/cli/src/lib.rs | 26 ++++++++------- crates/optimism/rpc/src/eth/call.rs | 32 +++++++++++++++++++ crates/optimism/rpc/src/eth/mod.rs | 13 ++------ crates/rpc/rpc-eth-api/src/helpers/call.rs | 7 ++-- 5 files changed, 54 insertions(+), 30 deletions(-) create mode 100644 crates/optimism/rpc/src/eth/call.rs diff --git a/crates/optimism/cli/src/commands/import_receipts.rs b/crates/optimism/cli/src/commands/import_receipts.rs index 99c7da40e04e..fade01da44ca 100644 --- a/crates/optimism/cli/src/commands/import_receipts.rs +++ b/crates/optimism/cli/src/commands/import_receipts.rs @@ -1,7 +1,8 @@ //! Command that imports OP mainnet receipts from Bedrock datadir, exported via //! . -use crate::file_codec_ovm_receipt::HackReceiptFileCodec; +use std::path::{Path, PathBuf}; + use clap::Parser; use reth_cli_commands::common::{AccessRights, Environment, EnvironmentArgs}; use reth_db::tables; @@ -20,9 +21,10 @@ use reth_provider::{ }; use reth_stages::StageId; use reth_static_file_types::StaticFileSegment; -use std::path::{Path, PathBuf}; use tracing::{debug, error, info, trace}; +use crate::file_codec_ovm_receipt::HackReceiptFileCodec; + /// Initializes the database with the genesis block. #[derive(Debug, Parser)] pub struct ImportReceiptsOpCommand { diff --git a/crates/optimism/cli/src/lib.rs b/crates/optimism/cli/src/lib.rs index 1b750bd89289..6260a8e9044e 100644 --- a/crates/optimism/cli/src/lib.rs +++ b/crates/optimism/cli/src/lib.rs @@ -10,18 +10,6 @@ // The `optimism` feature must be enabled to use this crate. #![cfg(feature = "optimism")] -use chainspec::OpChainSpecParser; -use clap::{command, value_parser, Parser}; -use commands::Commands; -use reth_chainspec::ChainSpec; -use reth_cli::chainspec::ChainSpecParser; -use reth_cli_commands::node::NoArgs; -use reth_node_core::{ - args::{utils::chain_help, LogArgs}, - version::{LONG_VERSION, SHORT_VERSION}, -}; -use std::{ffi::OsString, fmt, sync::Arc}; - /// Optimism chain specification parser. pub mod chainspec; /// Optimism CLI commands. @@ -38,8 +26,22 @@ pub mod commands; /// reth's needs for importing. However, this would require patching the diff in to export the `Receipt` and not `HackReceipt` type (originally /// made for op-erigon's import needs). pub mod file_codec_ovm_receipt; + pub use commands::{import::ImportOpCommand, import_receipts::ImportReceiptsOpCommand}; +use std::{ffi::OsString, fmt, sync::Arc}; + +use chainspec::OpChainSpecParser; +use clap::{command, value_parser, Parser}; +use commands::Commands; +use reth_chainspec::ChainSpec; +use reth_cli::chainspec::ChainSpecParser; +use reth_cli_commands::node::NoArgs; +use reth_node_core::{ + args::{utils::chain_help, LogArgs}, + version::{LONG_VERSION, SHORT_VERSION}, +}; + /// The main reth cli interface. /// /// This is the entrypoint to the executable. diff --git a/crates/optimism/rpc/src/eth/call.rs b/crates/optimism/rpc/src/eth/call.rs new file mode 100644 index 000000000000..03aa9a1f40a5 --- /dev/null +++ b/crates/optimism/rpc/src/eth/call.rs @@ -0,0 +1,32 @@ +use reth_evm::ConfigureEvm; +use reth_primitives::{ + revm_primitives::{BlockEnv, OptimismFields, TxEnv}, + Bytes, +}; +use reth_rpc_eth_api::helpers::Call; +use reth_rpc_eth_types::EthResult; +use reth_rpc_types::TransactionRequest; + +use crate::OpEthApi; + +impl Call for OpEthApi { + fn call_gas_limit(&self) -> u64 { + self.inner.call_gas_limit() + } + + fn evm_config(&self) -> &impl ConfigureEvm { + self.inner.evm_config() + } + + fn create_txn_env( + &self, + block_env: &BlockEnv, + request: TransactionRequest, + ) -> EthResult { + let mut env = Eth::create_txn_env(&self.inner, block_env, request)?; + + env.optimism = OptimismFields { enveloped_tx: Some(Bytes::new()), ..Default::default() }; + + Ok(env) + } +} diff --git a/crates/optimism/rpc/src/eth/mod.rs b/crates/optimism/rpc/src/eth/mod.rs index d8e0de756cac..1178ac1a77da 100644 --- a/crates/optimism/rpc/src/eth/mod.rs +++ b/crates/optimism/rpc/src/eth/mod.rs @@ -4,6 +4,7 @@ pub mod receipt; pub mod transaction; mod block; +mod call; mod pending_block; use std::{future::Future, sync::Arc}; @@ -17,7 +18,7 @@ use reth_provider::{BlockReaderIdExt, ChainSpecProvider, HeaderProvider, StatePr use reth_rpc::eth::DevSigner; use reth_rpc_eth_api::{ helpers::{ - AddDevSigners, Call, EthApiSpec, EthCall, EthFees, EthSigner, EthState, LoadFee, LoadState, + AddDevSigners, EthApiSpec, EthCall, EthFees, EthSigner, EthState, LoadFee, LoadState, SpawnBlocking, Trace, UpdateRawTxForwarder, }, RawTransactionForwarder, @@ -121,16 +122,6 @@ impl LoadFee for OpEthApi { } } -impl Call for OpEthApi { - fn call_gas_limit(&self) -> u64 { - self.inner.call_gas_limit() - } - - fn evm_config(&self) -> &impl ConfigureEvm { - self.inner.evm_config() - } -} - impl LoadState for OpEthApi { fn provider(&self) -> impl StateProviderFactory + ChainSpecProvider { LoadState::provider(&self.inner) diff --git a/crates/rpc/rpc-eth-api/src/helpers/call.rs b/crates/rpc/rpc-eth-api/src/helpers/call.rs index 2b4a277bd5a0..a61f45dfb8d6 100644 --- a/crates/rpc/rpc-eth-api/src/helpers/call.rs +++ b/crates/rpc/rpc-eth-api/src/helpers/call.rs @@ -29,8 +29,6 @@ use reth_rpc_types::{ }; use revm::{Database, DatabaseCommit}; use revm_inspectors::access_list::AccessListInspector; -#[cfg(feature = "optimism")] -use revm_primitives::OptimismFields; use tracing::trace; use super::{LoadBlock, LoadPendingBlock, LoadState, LoadTransaction, SpawnBlocking, Trace}; @@ -824,6 +822,7 @@ pub trait Call: LoadState + SpawnBlocking { )?; let gas_limit = gas.unwrap_or_else(|| block_env.gas_limit.min(U256::from(u64::MAX)).to()); + let env = TxEnv { gas_limit: gas_limit .try_into() @@ -841,10 +840,8 @@ pub trait Call: LoadState + SpawnBlocking { blob_hashes: blob_versioned_hashes.unwrap_or_default(), max_fee_per_blob_gas, // EIP-7702 fields - authorization_list: None, // authorization_list: TODO - #[cfg(feature = "optimism")] - optimism: OptimismFields { enveloped_tx: Some(Bytes::new()), ..Default::default() }, + ..Default::default() }; Ok(env)