Skip to content

Commit

Permalink
chore(rpc): remove redundant EthTransactions::provider (#12121)
Browse files Browse the repository at this point in the history
  • Loading branch information
emhane authored Oct 28, 2024
1 parent a21919c commit 7c9e3f5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 31 deletions.
10 changes: 3 additions & 7 deletions crates/optimism/rpc/src/eth/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,9 @@ use crate::{OpEthApi, SequencerClient};

impl<N> EthTransactions for OpEthApi<N>
where
Self: LoadTransaction,
N: FullNodeComponents,
Self: LoadTransaction<Provider: BlockReaderIdExt>,
N: RpcNodeCore,
{
fn provider(&self) -> impl BlockReaderIdExt {
self.inner.provider()
}

fn signers(&self) -> &parking_lot::RwLock<Vec<Box<dyn EthSigner>>> {
self.inner.signers()
}
Expand Down Expand Up @@ -71,7 +67,7 @@ where

impl<N> OpEthApi<N>
where
N: FullNodeComponents,
N: RpcNodeCore,
{
/// Returns the [`SequencerClient`] if one is set.
pub fn raw_tx_forwarder(&self) -> Option<SequencerClient> {
Expand Down
27 changes: 11 additions & 16 deletions crates/rpc/rpc-eth-api/src/helpers/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,7 @@ use super::{
/// See also <https://github.com/paradigmxyz/reth/issues/6240>
///
/// This implementation follows the behaviour of Geth and disables the basefee check for tracing.
pub trait EthTransactions: LoadTransaction {
/// Returns a handle for reading data from disk.
///
/// Data access in default (L1) trait method implementations.
fn provider(&self) -> impl BlockReaderIdExt;

pub trait EthTransactions: LoadTransaction<Provider: BlockReaderIdExt> {
/// Returns a handle for signing data.
///
/// Singer access in default (L1) trait method implementations.
Expand Down Expand Up @@ -111,7 +106,8 @@ pub trait EthTransactions: LoadTransaction {
}

self.spawn_blocking_io(move |ref this| {
Ok(RpcNodeCore::provider(this)
Ok(this
.provider()
.transaction_by_hash(hash)
.map_err(Self::Error::from_eth_err)?
.map(|tx| tx.encoded_2718().into()))
Expand Down Expand Up @@ -166,21 +162,20 @@ pub trait EthTransactions: LoadTransaction {
{
let this = self.clone();
self.spawn_blocking_io(move |_| {
let (tx, meta) = match RpcNodeCore::provider(&this)
let (tx, meta) = match this
.provider()
.transaction_by_hash_with_meta(hash)
.map_err(Self::Error::from_eth_err)?
{
Some((tx, meta)) => (tx, meta),
None => return Ok(None),
};

let receipt = match EthTransactions::provider(&this)
.receipt_by_hash(hash)
.map_err(Self::Error::from_eth_err)?
{
Some(recpt) => recpt,
None => return Ok(None),
};
let receipt =
match this.provider().receipt_by_hash(hash).map_err(Self::Error::from_eth_err)? {
Some(recpt) => recpt,
None => return Ok(None),
};

Ok(Some((tx, meta, receipt)))
})
Expand Down Expand Up @@ -257,7 +252,7 @@ pub trait EthTransactions: LoadTransaction {
return Ok(None);
}

let Ok(high) = RpcNodeCore::provider(self).best_block_number() else {
let Ok(high) = self.provider().best_block_number() else {
return Err(EthApiError::HeaderNotFound(BlockNumberOrTag::Latest.into()).into());
};

Expand Down
9 changes: 1 addition & 8 deletions crates/rpc/rpc/src/eth/helpers/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,8 @@ use crate::EthApi;
impl<Provider, Pool, Network, EvmConfig> EthTransactions
for EthApi<Provider, Pool, Network, EvmConfig>
where
Self: LoadTransaction,
Pool: TransactionPool + 'static,
Provider: BlockReaderIdExt,
Self: LoadTransaction<Provider: BlockReaderIdExt>,
{
#[inline]
fn provider(&self) -> impl BlockReaderIdExt {
self.inner.provider()
}

#[inline]
fn signers(&self) -> &parking_lot::RwLock<Vec<Box<dyn EthSigner>>> {
self.inner.signers()
Expand Down

0 comments on commit 7c9e3f5

Please sign in to comment.