chore(op): implement Call for OpEthApi (#9502)

Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
Emilia Hane
2024-07-16 17:19:32 +02:00
committed by GitHub
parent 0a1f652b2f
commit 55dc12d741
5 changed files with 54 additions and 30 deletions

View File

@ -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;
@ -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 {

View File

@ -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 <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.

View File

@ -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)
}
}

View File

@ -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<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)

View File

@ -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)