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): remove optimism feature for LoadReceipts #9504

Merged
merged 26 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 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
d3218a3
Remove optimism LoadReceipt impl on EthApi
emhane Jul 15, 2024
b4208be
Fix syntax
emhane Jul 15, 2024
c600a25
Merge branch 'main' into emhane/op-load-receipt
emhane Jul 16, 2024
e5eed1c
Merge branch 'main' into emhane/op-load-receipt
emhane Jul 16, 2024
24c8696
Fix merge conflicts
emhane Jul 16, 2024
dccd19a
Merge branch 'main' into emhane/op-load-receipt
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
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/optimism/rpc/src/eth/receipt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ where
}
}

/// Applies OP specific fields to a receipt.
/// Applies OP specific fields to a receipt builder.
pub fn op_receipt_fields(
resp_builder: ReceiptBuilder,
tx: &TransactionSigned,
Expand Down
10 changes: 6 additions & 4 deletions crates/optimism/rpc/src/eth/transaction.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
//! Loads and formats OP transaction RPC response.
//! Loads and formats OP transaction RPC response.

use std::sync::Arc;

use reth_evm_optimism::RethL1BlockInfo;
use reth_primitives::TransactionSigned;
use reth_provider::BlockReaderIdExt;
use reth_provider::{BlockReaderIdExt, TransactionsProvider};
use reth_rpc_eth_api::{
helpers::{EthApiSpec, EthSigner, EthTransactions, LoadTransaction},
RawTransactionForwarder,
Expand All @@ -17,7 +19,7 @@ impl<Eth: EthTransactions> EthTransactions for OpEthApi<Eth> {
EthTransactions::provider(&self.inner)
}

fn raw_tx_forwarder(&self) -> Option<std::sync::Arc<dyn RawTransactionForwarder>> {
fn raw_tx_forwarder(&self) -> Option<Arc<dyn RawTransactionForwarder>> {
self.inner.raw_tx_forwarder()
}

Expand All @@ -29,7 +31,7 @@ impl<Eth: EthTransactions> EthTransactions for OpEthApi<Eth> {
impl<Eth: LoadTransaction> LoadTransaction for OpEthApi<Eth> {
type Pool = Eth::Pool;

fn provider(&self) -> impl reth_provider::TransactionsProvider {
fn provider(&self) -> impl TransactionsProvider {
LoadTransaction::provider(&self.inner)
}

Expand Down
2 changes: 0 additions & 2 deletions crates/rpc/rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ reth-network-peers.workspace = true
reth-evm.workspace = true
reth-rpc-eth-types.workspace = true
reth-rpc-server-types.workspace = true
reth-evm-optimism = { workspace = true, optional = true }
reth-node-api.workspace = true

# eth
Expand Down Expand Up @@ -94,6 +93,5 @@ optimism = [
"reth-rpc-eth-api/optimism",
"reth-revm/optimism",
"jsonrpsee-types",
"reth-evm-optimism",
"reth-rpc-eth-types/optimism",
]
1 change: 0 additions & 1 deletion crates/rpc/rpc/src/eth/helpers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ mod fees;
#[cfg(feature = "optimism")]
pub mod optimism;
mod pending_block;
#[cfg(not(feature = "optimism"))]
mod receipt;
mod spec;
mod state;
Expand Down
133 changes: 2 additions & 131 deletions crates/rpc/rpc/src/eth/helpers/optimism.rs
Original file line number Diff line number Diff line change
@@ -1,138 +1,9 @@
//! Loads and formats OP transaction RPC response.

use jsonrpsee_types::error::ErrorObject;
use reth_evm_optimism::RethL1BlockInfo;
use reth_primitives::{Receipt, TransactionMeta, TransactionSigned};
use reth_provider::{BlockIdReader, ChainSpecProvider};
use reth_rpc_eth_api::helpers::LoadReceipt;
use reth_rpc_eth_types::{EthApiError, EthResult, EthStateCache, ReceiptBuilder};
use reth_rpc_eth_types::EthApiError;
use reth_rpc_server_types::result::internal_rpc_err;
use reth_rpc_types::{AnyTransactionReceipt, OptimismTransactionReceiptFields, ToRpcError};
use revm::L1BlockInfo;

use crate::EthApi;

/// L1 fee and data gas for a transaction, along with the L1 block info.
#[derive(Debug, Default, Clone)]
pub struct OptimismTxMeta {
/// The L1 block info.
pub l1_block_info: Option<L1BlockInfo>,
/// The L1 fee for the block.
pub l1_fee: Option<u128>,
/// The L1 data gas for the block.
pub l1_data_gas: Option<u128>,
}

impl OptimismTxMeta {
/// Creates a new [`OptimismTxMeta`].
pub const fn new(
l1_block_info: Option<L1BlockInfo>,
l1_fee: Option<u128>,
l1_data_gas: Option<u128>,
) -> Self {
Self { l1_block_info, l1_fee, l1_data_gas }
}
}

impl<Provider, Pool, Network, EvmConfig> EthApi<Provider, Pool, Network, EvmConfig>
where
Provider: BlockIdReader + ChainSpecProvider,
{
/// Builds [`OptimismTxMeta`] object using the provided [`TransactionSigned`], L1 block
/// info and block timestamp. The [`L1BlockInfo`] is used to calculate the l1 fee and l1 data
/// gas for the transaction. If the [`L1BlockInfo`] is not provided, the meta info will be
/// empty.
pub fn build_op_tx_meta(
&self,
tx: &TransactionSigned,
l1_block_info: Option<L1BlockInfo>,
block_timestamp: u64,
) -> EthResult<OptimismTxMeta> {
let Some(l1_block_info) = l1_block_info else { return Ok(OptimismTxMeta::default()) };

let (l1_fee, l1_data_gas) = if !tx.is_deposit() {
let envelope_buf = tx.envelope_encoded();

let inner_l1_fee = l1_block_info
.l1_tx_data_fee(
&self.inner.provider().chain_spec(),
block_timestamp,
&envelope_buf,
tx.is_deposit(),
)
.map_err(|_| OptimismEthApiError::L1BlockFeeError)?;
let inner_l1_data_gas = l1_block_info
.l1_data_gas(&self.inner.provider().chain_spec(), block_timestamp, &envelope_buf)
.map_err(|_| OptimismEthApiError::L1BlockGasError)?;
(
Some(inner_l1_fee.saturating_to::<u128>()),
Some(inner_l1_data_gas.saturating_to::<u128>()),
)
} else {
(None, None)
};

Ok(OptimismTxMeta::new(Some(l1_block_info), l1_fee, l1_data_gas))
}
}

impl<Provider, Pool, Network, EvmConfig> LoadReceipt for EthApi<Provider, Pool, Network, EvmConfig>
where
Self: Send + Sync,
Provider: BlockIdReader + ChainSpecProvider,
{
#[inline]
fn cache(&self) -> &EthStateCache {
self.inner.cache()
}

async fn build_transaction_receipt(
&self,
tx: TransactionSigned,
meta: TransactionMeta,
receipt: Receipt,
) -> EthResult<AnyTransactionReceipt> {
let (block, receipts) = self
.cache()
.get_block_and_receipts(meta.block_hash)
.await?
.ok_or(EthApiError::UnknownBlockNumber)?;

let block = block.unseal();
let l1_block_info = reth_evm_optimism::extract_l1_info(&block).ok();
let optimism_tx_meta = self.build_op_tx_meta(&tx, l1_block_info, block.timestamp)?;

let resp_builder = ReceiptBuilder::new(&tx, meta, &receipt, &receipts)?;
let resp_builder = op_receipt_fields(resp_builder, &tx, &receipt, optimism_tx_meta);

Ok(resp_builder.build())
}
}

/// Applies OP specific fields to a receipt.
fn op_receipt_fields(
resp_builder: ReceiptBuilder,
tx: &TransactionSigned,
receipt: &Receipt,
optimism_tx_meta: OptimismTxMeta,
) -> ReceiptBuilder {
let mut op_fields = OptimismTransactionReceiptFields::default();

if tx.is_deposit() {
op_fields.deposit_nonce = receipt.deposit_nonce.map(reth_primitives::U64::from);
op_fields.deposit_receipt_version =
receipt.deposit_receipt_version.map(reth_primitives::U64::from);
} else if let Some(l1_block_info) = optimism_tx_meta.l1_block_info {
op_fields.l1_fee = optimism_tx_meta.l1_fee;
op_fields.l1_gas_used = optimism_tx_meta.l1_data_gas.map(|dg| {
dg + l1_block_info.l1_fee_overhead.unwrap_or_default().saturating_to::<u128>()
});
op_fields.l1_fee_scalar = Some(f64::from(l1_block_info.l1_base_fee_scalar) / 1_000_000.0);
op_fields.l1_gas_price = Some(l1_block_info.l1_base_fee.saturating_to());
}

resp_builder.add_other_fields(op_fields.into())
}
use reth_rpc_types::ToRpcError;

/// Optimism specific errors, that extend [`EthApiError`].
#[derive(Debug, thiserror::Error)]
Expand Down
Loading