From 3190b1f9f6af289fb230892793402ff4fc62500a Mon Sep 17 00:00:00 2001 From: refcell Date: Thu, 2 Nov 2023 22:37:56 +0100 Subject: [PATCH] move optimism tx meta to new file --- crates/rpc/rpc/src/eth/api/block.rs | 45 ++-------------------- crates/rpc/rpc/src/eth/api/mod.rs | 10 +++-- crates/rpc/rpc/src/eth/api/optimism.rs | 31 +++++++++++++++ crates/rpc/rpc/src/eth/api/transactions.rs | 2 +- 4 files changed, 42 insertions(+), 46 deletions(-) create mode 100644 crates/rpc/rpc/src/eth/api/optimism.rs diff --git a/crates/rpc/rpc/src/eth/api/block.rs b/crates/rpc/rpc/src/eth/api/block.rs index dc8117f356ca..f99de8a78de5 100644 --- a/crates/rpc/rpc/src/eth/api/block.rs +++ b/crates/rpc/rpc/src/eth/api/block.rs @@ -16,43 +16,6 @@ use reth_rpc_types::{Index, RichBlock, TransactionReceipt}; use reth_rpc_types_compat::block::{from_block, uncle_block_from_header}; use reth_transaction_pool::TransactionPool; -#[cfg(feature = "optimism")] -use reth_primitives::U256; -#[cfg(feature = "optimism")] -use revm::L1BlockInfo; -#[cfg(feature = "optimism")] -use std::rc::Rc; - -/// Optimism Transaction Metadata -/// -/// Includes the L1 fee and data gas for the tx along with the L1 -/// block info. In order to pass the [OptimismTxMeta] into the -/// async colored `build_transaction_receipt_with_block_receipts` -/// function, a reference counter for the L1 block info is -/// used so the L1 block info can be shared between receipts. -#[cfg(feature = "optimism")] -#[derive(Debug, Default, Clone)] -pub(crate) struct OptimismTxMeta { - /// The L1 block info. - pub(crate) l1_block_info: Option>, - /// The L1 fee for the block. - pub(crate) l1_fee: Option, - /// The L1 data gas for the block. - pub(crate) l1_data_gas: Option, -} - -#[cfg(feature = "optimism")] -impl OptimismTxMeta { - /// Creates a new [OptimismTxMeta]. - pub(crate) fn new( - l1_block_info: Option>, - l1_fee: Option, - l1_data_gas: Option, - ) -> Self { - Self { l1_block_info, l1_fee, l1_data_gas } - } -} - impl EthApi where Provider: @@ -150,7 +113,7 @@ where ) }) .collect::>>(); - return receipts.map(Some) + return receipts.map(Some); } Ok(None) @@ -167,7 +130,7 @@ where if block_id.is_pending() { // Pending block can be fetched directly without need for caching - return Ok(self.provider().pending_block()?.map(|block| block.body.len())) + return Ok(self.provider().pending_block()?.map(|block| block.body.len())); } let block_hash = match self.provider().block_hash_for_id(block_id)? { @@ -189,10 +152,10 @@ where // Pending block can be fetched directly without need for caching let maybe_pending = self.provider().pending_block()?; return if maybe_pending.is_some() { - return Ok(maybe_pending) + return Ok(maybe_pending); } else { self.local_pending_block().await - } + }; } let block_hash = match self.provider().block_hash_for_id(block_id)? { diff --git a/crates/rpc/rpc/src/eth/api/mod.rs b/crates/rpc/rpc/src/eth/api/mod.rs index 025cb5449ff6..cac5bf7328fb 100644 --- a/crates/rpc/rpc/src/eth/api/mod.rs +++ b/crates/rpc/rpc/src/eth/api/mod.rs @@ -33,6 +33,8 @@ use tokio::sync::{oneshot, Mutex}; mod block; mod call; mod fees; +#[cfg(feature = "optimism")] +mod optimism; mod pending_block; mod server; mod sign; @@ -280,7 +282,7 @@ where pub(crate) async fn local_pending_block(&self) -> EthResult> { let pending = self.pending_block_env_and_cfg()?; if pending.origin.is_actual_pending() { - return Ok(pending.origin.into_actual_pending()) + return Ok(pending.origin.into_actual_pending()); } // no pending block from the CL yet, so we need to build it ourselves via txpool @@ -295,13 +297,13 @@ where pending.origin.header().hash == pending_block.block.parent_hash && now <= pending_block.expires_at { - return Ok(Some(pending_block.block.clone())) + return Ok(Some(pending_block.block.clone())); } } // if we're currently syncing, we're unable to build a pending block if this.network().is_syncing() { - return Ok(None) + return Ok(None); } // we rebuild the block @@ -309,7 +311,7 @@ where Ok(block) => block, Err(err) => { tracing::debug!(target: "rpc", "Failed to build pending block: {:?}", err); - return Ok(None) + return Ok(None); } }; diff --git a/crates/rpc/rpc/src/eth/api/optimism.rs b/crates/rpc/rpc/src/eth/api/optimism.rs new file mode 100644 index 000000000000..44f93c724328 --- /dev/null +++ b/crates/rpc/rpc/src/eth/api/optimism.rs @@ -0,0 +1,31 @@ +use reth_primitives::U256; +use revm::L1BlockInfo; +use std::rc::Rc; + +/// Optimism Transaction Metadata +/// +/// Includes the L1 fee and data gas for the tx along with the L1 +/// block info. In order to pass the [OptimismTxMeta] into the +/// async colored `build_transaction_receipt_with_block_receipts` +/// function, a reference counter for the L1 block info is +/// used so the L1 block info can be shared between receipts. +#[derive(Debug, Default, Clone)] +pub(crate) struct OptimismTxMeta { + /// The L1 block info. + pub(crate) l1_block_info: Option>, + /// The L1 fee for the block. + pub(crate) l1_fee: Option, + /// The L1 data gas for the block. + pub(crate) l1_data_gas: Option, +} + +impl OptimismTxMeta { + /// Creates a new [OptimismTxMeta]. + pub(crate) fn new( + l1_block_info: Option>, + l1_fee: Option, + l1_data_gas: Option, + ) -> Self { + Self { l1_block_info, l1_fee, l1_data_gas } + } +} diff --git a/crates/rpc/rpc/src/eth/api/transactions.rs b/crates/rpc/rpc/src/eth/api/transactions.rs index fd0e7dfb6107..6a12d63c9812 100644 --- a/crates/rpc/rpc/src/eth/api/transactions.rs +++ b/crates/rpc/rpc/src/eth/api/transactions.rs @@ -42,7 +42,7 @@ use revm::{ use revm_primitives::{db::DatabaseCommit, Env, ExecutionResult, ResultAndState, SpecId, State}; #[cfg(feature = "optimism")] -use crate::eth::api::block::OptimismTxMeta; +use crate::eth::api::optimism::OptimismTxMeta; #[cfg(feature = "optimism")] use reth_revm::optimism::RethL1BlockInfo; #[cfg(feature = "optimism")]