Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(op): implement Call for OpEthApi #9502

Merged
merged 24 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
0f89de1
feat: API scaffolding
mattsse Jul 10, 2024
758eaf4
Merge branch 'main' into matt/builder3
emhane Jul 10, 2024
57de37f
Add NodeAddOns generic to NodeComponentsBuilder
emhane Jul 10, 2024
1e94e8d
Move eth config and builder ctx to reth-rpc-eth-types & make RpcRegis…
emhane Jul 11, 2024
a4115f2
Remove NodeAddOnBuilders trait and defer instantiation of eth api bui…
emhane Jul 12, 2024
28b7116
fixup! Remove NodeAddOnBuilders trait and defer instantiation of eth …
emhane Jul 12, 2024
a97ba95
Fix conflicts
emhane Jul 12, 2024
5955c2c
Fix lint for lib
emhane Jul 12, 2024
8008698
Fix docs
emhane Jul 12, 2024
2ba7df9
Merge branch 'main' into emhane/node-addons
emhane Jul 12, 2024
8dd44b5
Plug-in OpEthApi to node builder
emhane Jul 12, 2024
4e5ad50
Fix lint remaining targets
emhane Jul 13, 2024
a90a55a
Fix spelling
emhane Jul 13, 2024
9f67cf1
fixup! Fix spelling
emhane Jul 13, 2024
c9a2a7c
Enable optimism feature for reth-optimism-rpc in reth-node-optimism
emhane Jul 13, 2024
dd96713
fixup! Enable optimism feature for reth-optimism-rpc in reth-node-opt…
emhane Jul 13, 2024
31b8a12
Fix doctests
emhane Jul 13, 2024
64f5eee
Merge branch 'main' into emhane/node-addons
emhane Jul 14, 2024
4c23365
Remove unused trait
emhane Jul 14, 2024
86843a6
Remove redundant trait SpawnEthApi
emhane Jul 14, 2024
d726bab
Implement Call for OpEthApi
emhane Jul 15, 2024
83c1928
Remove redundant lint attribute
emhane Jul 15, 2024
14737d4
Merge branch 'main' into emhane/op-ethapi-call
emhane Jul 16, 2024
87569e3
Fix merge conflicts
emhane Jul 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading