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

feat: remove AnyNetwork usage #12280

Merged
merged 2 commits into from
Nov 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 0 additions & 5 deletions Cargo.lock

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

96 changes: 29 additions & 67 deletions crates/optimism/rpc/src/eth/receipt.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Loads and formats OP receipt RPC response.

use alloy_eips::eip2718::Encodable2718;
use alloy_rpc_types::{AnyReceiptEnvelope, Log, TransactionReceipt};
use alloy_rpc_types::{Log, TransactionReceipt};
use op_alloy_consensus::{
DepositTransaction, OpDepositReceipt, OpDepositReceiptWithBloom, OpReceiptEnvelope,
};
Expand All @@ -13,7 +13,7 @@ use reth_optimism_forks::OptimismHardforks;
use reth_primitives::{Receipt, TransactionMeta, TransactionSigned, TxType};
use reth_provider::ChainSpecProvider;
use reth_rpc_eth_api::{helpers::LoadReceipt, FromEthApiError, RpcReceipt};
use reth_rpc_eth_types::{EthApiError, ReceiptBuilder};
use reth_rpc_eth_types::{receipt::build_receipt, EthApiError};

use crate::{OpEthApi, OpEthApiError};

Expand Down Expand Up @@ -172,9 +172,7 @@ impl OpReceiptFieldsBuilder {
#[derive(Debug)]
pub struct OpReceiptBuilder {
/// Core receipt, has all the fields of an L1 receipt and is the basis for the OP receipt.
pub core_receipt: TransactionReceipt<AnyReceiptEnvelope<Log>>,
/// Transaction type.
pub tx_type: TxType,
pub core_receipt: TransactionReceipt<OpReceiptEnvelope<Log>>,
/// Additional OP receipt fields.
pub op_receipt_fields: OpTransactionReceiptFields,
}
Expand All @@ -189,81 +187,45 @@ impl OpReceiptBuilder {
all_receipts: &[Receipt],
l1_block_info: revm::L1BlockInfo,
) -> Result<Self, OpEthApiError> {
let ReceiptBuilder { base: core_receipt, .. } =
ReceiptBuilder::new(transaction, meta, receipt, all_receipts)
.map_err(OpEthApiError::Eth)?;

let tx_type = transaction.tx_type();
let core_receipt =
build_receipt(transaction, meta, receipt, all_receipts, |receipt_with_bloom| {
match receipt.tx_type {
TxType::Legacy => OpReceiptEnvelope::<Log>::Legacy(receipt_with_bloom),
TxType::Eip2930 => OpReceiptEnvelope::<Log>::Eip2930(receipt_with_bloom),
TxType::Eip1559 => OpReceiptEnvelope::<Log>::Eip1559(receipt_with_bloom),
TxType::Eip4844 => {
// TODO: unreachable
OpReceiptEnvelope::<Log>::Eip1559(receipt_with_bloom)
}
TxType::Eip7702 => OpReceiptEnvelope::<Log>::Eip7702(receipt_with_bloom),
TxType::Deposit => {
OpReceiptEnvelope::<Log>::Deposit(OpDepositReceiptWithBloom::<Log> {
receipt: OpDepositReceipt::<Log> {
inner: receipt_with_bloom.receipt,
deposit_nonce: receipt.deposit_nonce,
deposit_receipt_version: receipt.deposit_receipt_version,
},
logs_bloom: receipt_with_bloom.logs_bloom,
})
}
}
})?;

let op_receipt_fields = OpReceiptFieldsBuilder::default()
.l1_block_info(chain_spec, transaction, l1_block_info)?
.deposit_nonce(receipt.deposit_nonce)
.deposit_version(receipt.deposit_receipt_version)
.build();

Ok(Self { core_receipt, tx_type, op_receipt_fields })
Ok(Self { core_receipt, op_receipt_fields })
}

/// Builds [`OpTransactionReceipt`] by combing core (l1) receipt fields and additional OP
/// receipt fields.
pub fn build(self) -> OpTransactionReceipt {
let Self { core_receipt, tx_type, op_receipt_fields } = self;

let OpTransactionReceiptFields { l1_block_info, deposit_nonce, deposit_receipt_version } =
op_receipt_fields;

let TransactionReceipt {
inner: AnyReceiptEnvelope { inner: receipt_with_bloom, .. },
transaction_hash,
transaction_index,
block_hash,
block_number,
gas_used,
effective_gas_price,
blob_gas_used,
blob_gas_price,
from,
to,
contract_address,
authorization_list,
} = core_receipt;

let inner = match tx_type {
TxType::Legacy => OpReceiptEnvelope::<Log>::Legacy(receipt_with_bloom),
TxType::Eip2930 => OpReceiptEnvelope::<Log>::Eip2930(receipt_with_bloom),
TxType::Eip1559 => OpReceiptEnvelope::<Log>::Eip1559(receipt_with_bloom),
TxType::Eip4844 => {
// TODO: unreachable
OpReceiptEnvelope::<Log>::Eip1559(receipt_with_bloom)
}
TxType::Eip7702 => OpReceiptEnvelope::<Log>::Eip7702(receipt_with_bloom),
TxType::Deposit => {
OpReceiptEnvelope::<Log>::Deposit(OpDepositReceiptWithBloom::<Log> {
receipt: OpDepositReceipt::<Log> {
inner: receipt_with_bloom.receipt,
deposit_nonce,
deposit_receipt_version,
},
logs_bloom: receipt_with_bloom.logs_bloom,
})
}
};
let Self { core_receipt: inner, op_receipt_fields } = self;

let inner = TransactionReceipt::<OpReceiptEnvelope<Log>> {
inner,
transaction_hash,
transaction_index,
block_hash,
block_number,
gas_used,
effective_gas_price,
blob_gas_used,
blob_gas_price,
from,
to,
contract_address,
authorization_list,
};
let OpTransactionReceiptFields { l1_block_info, .. } = op_receipt_fields;

OpTransactionReceipt { inner, l1_block_info }
}
Expand Down
2 changes: 1 addition & 1 deletion crates/optimism/rpc/src/eth/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ where
let signed_tx = tx.clone().into_signed();
let hash = tx.hash;

let mut inner = EthTxBuilder.fill(tx, tx_info).inner;
let mut inner = EthTxBuilder.fill(tx, tx_info);

if signed_tx.is_deposit() {
inner.gas_price = Some(signed_tx.max_fee_per_gas())
Expand Down
5 changes: 0 additions & 5 deletions crates/rpc/rpc-builder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ reth-evm.workspace = true
reth-engine-primitives.workspace = true
reth-primitives.workspace = true

# ethereum
alloy-network.workspace = true
alloy-rpc-types.workspace = true
alloy-serde.workspace = true

# rpc/net
jsonrpsee = { workspace = true, features = ["server"] }
tower-http = { workspace = true, features = ["full"] }
Expand Down
9 changes: 1 addition & 8 deletions crates/rpc/rpc-builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1094,14 +1094,7 @@ where
/// If called outside of the tokio runtime. See also [`Self::eth_api`]
pub fn register_ots(&mut self) -> &mut Self
where
EthApi: TraceExt
+ EthTransactions<
NetworkTypes: alloy_network::Network<
TransactionResponse = alloy_serde::WithOtherFields<
alloy_rpc_types::Transaction,
>,
>,
>,
EthApi: TraceExt + EthTransactions,
{
let otterscan_api = self.otterscan_api();
self.modules.insert(RethRpcModule::Ots, otterscan_api.into_rpc().into());
Expand Down
7 changes: 3 additions & 4 deletions crates/rpc/rpc-builder/tests/it/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@

use crate::utils::{launch_http, launch_http_ws, launch_ws};
use alloy_primitives::{hex_literal::hex, Address, Bytes, TxHash, B256, B64, U256, U64};
use alloy_rpc_types::{
Block, FeeHistory, Filter, Index, Log, PendingTransactionFilterKind, SyncStatus, Transaction,
TransactionReceipt,
use alloy_rpc_types_eth::{
transaction::TransactionRequest, Block, FeeHistory, Filter, Index, Log,
PendingTransactionFilterKind, SyncStatus, Transaction, TransactionReceipt,
};
use alloy_rpc_types_eth::transaction::TransactionRequest;
use alloy_rpc_types_trace::filter::TraceFilter;
use jsonrpsee::{
core::{
Expand Down
2 changes: 1 addition & 1 deletion crates/rpc/rpc-builder/tests/it/middleware.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::utils::{test_address, test_rpc_builder};
use alloy_rpc_types::{Block, Receipt, Transaction};
use alloy_rpc_types_eth::{Block, Receipt, Transaction};
use jsonrpsee::{
server::{middleware::rpc::RpcServiceT, RpcServiceBuilder},
types::Request,
Expand Down
15 changes: 2 additions & 13 deletions crates/rpc/rpc-eth-api/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@

use std::{error::Error, fmt};

use alloy_network::{AnyNetwork, Network};
use alloy_network::Network;
use alloy_rpc_types::Block;
use reth_rpc_eth_types::EthApiError;
use reth_rpc_types_compat::TransactionCompat;

use crate::{AsEthApiError, FromEthApiError, FromEvmError};

/// Network specific `eth` API types.
pub trait EthApiTypes: Send + Sync + Clone {
/// Extension of [`EthApiError`], with network specific errors.
/// Extension of [`FromEthApiError`], with network specific errors.
type Error: Into<jsonrpsee_types::error::ErrorObject<'static>>
+ FromEthApiError
+ AsEthApiError
Expand All @@ -28,16 +27,6 @@ pub trait EthApiTypes: Send + Sync + Clone {
fn tx_resp_builder(&self) -> &Self::TransactionCompat;
}

impl EthApiTypes for () {
type Error = EthApiError;
type NetworkTypes = AnyNetwork;
type TransactionCompat = ();

fn tx_resp_builder(&self) -> &Self::TransactionCompat {
self
}
}

/// Adapter for network specific transaction type.
pub type RpcTransaction<T> = <T as Network>::TransactionResponse;

Expand Down
1 change: 0 additions & 1 deletion crates/rpc/rpc-eth-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ revm.workspace = true
revm-inspectors.workspace = true
revm-primitives = { workspace = true, features = ["dev"] }
alloy-rpc-types.workspace = true
alloy-serde.workspace = true
alloy-eips.workspace = true

# rpc
Expand Down
2 changes: 1 addition & 1 deletion crates/rpc/rpc-eth-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@ pub use gas_oracle::{
};
pub use id_provider::EthSubscriptionIdProvider;
pub use pending_block::{PendingBlock, PendingBlockEnv, PendingBlockEnvOrigin};
pub use receipt::ReceiptBuilder;
pub use receipt::EthReceiptBuilder;
pub use transaction::TransactionSource;
Loading
Loading