Skip to content

Commit

Permalink
chore(op): implement Call for OpEthApi (#9502)
Browse files Browse the repository at this point in the history
Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
  • Loading branch information
emhane and mattsse authored Jul 16, 2024
1 parent 0a1f652 commit 55dc12d
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 30 deletions.
6 changes: 4 additions & 2 deletions crates/optimism/cli/src/commands/import_receipts.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
//! Command that imports OP mainnet receipts from Bedrock datadir, exported via
//! <https://github.com/testinprod-io/op-geth/pull/1>.
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;
Expand All @@ -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 {
Expand Down
26 changes: 14 additions & 12 deletions crates/optimism/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -38,8 +26,22 @@ pub mod commands;
/// reth's needs for importing. However, this would require patching the diff in <https://github.com/testinprod-io/op-geth/pull/1> 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.
Expand Down
32 changes: 32 additions & 0 deletions crates/optimism/rpc/src/eth/call.rs
Original file line number Diff line number Diff line change
@@ -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<Eth: Call> Call for OpEthApi<Eth> {
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<TxEnv> {
let mut env = Eth::create_txn_env(&self.inner, block_env, request)?;

env.optimism = OptimismFields { enveloped_tx: Some(Bytes::new()), ..Default::default() };

Ok(env)
}
}
13 changes: 2 additions & 11 deletions crates/optimism/rpc/src/eth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pub mod receipt;
pub mod transaction;

mod block;
mod call;
mod pending_block;

use std::{future::Future, sync::Arc};
Expand All @@ -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,
Expand Down Expand Up @@ -121,16 +122,6 @@ impl<Eth: LoadFee> LoadFee for OpEthApi<Eth> {
}
}

impl<Eth: Call> Call for OpEthApi<Eth> {
fn call_gas_limit(&self) -> u64 {
self.inner.call_gas_limit()
}

fn evm_config(&self) -> &impl ConfigureEvm {
self.inner.evm_config()
}
}

impl<Eth: LoadState> LoadState for OpEthApi<Eth> {
fn provider(&self) -> impl StateProviderFactory + ChainSpecProvider {
LoadState::provider(&self.inner)
Expand Down
7 changes: 2 additions & 5 deletions crates/rpc/rpc-eth-api/src/helpers/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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()
Expand All @@ -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)
Expand Down

0 comments on commit 55dc12d

Please sign in to comment.