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(rpc): add super trait RpcNodeCore to LoadTransaction #12104

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
15 changes: 3 additions & 12 deletions crates/optimism/rpc/src/eth/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use reth_provider::{BlockReaderIdExt, ReceiptProvider, TransactionsProvider};
use reth_rpc::eth::EthTxBuilder;
use reth_rpc_eth_api::{
helpers::{EthSigner, EthTransactions, LoadTransaction, SpawnBlocking},
FromEthApiError, FullEthApiTypes, TransactionCompat,
FromEthApiError, FullEthApiTypes, RpcNodeCore, TransactionCompat,
};
use reth_rpc_eth_types::{utils::recover_raw_transaction, EthStateCache};
use reth_transaction_pool::{PoolTransaction, TransactionOrigin, TransactionPool};
Expand Down Expand Up @@ -61,21 +61,12 @@ where
impl<N> LoadTransaction for OpEthApi<N>
where
Self: SpawnBlocking + FullEthApiTypes,
N: FullNodeComponents,
N: RpcNodeCore<Provider: TransactionsProvider, Pool: TransactionPool>,
{
type Pool = N::Pool;

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

#[inline]
fn cache(&self) -> &EthStateCache {
self.inner.cache()
}

fn pool(&self) -> &Self::Pool {
self.inner.pool()
}
}

impl<N> OpEthApi<N>
Expand Down
31 changes: 12 additions & 19 deletions crates/rpc/rpc-eth-api/src/helpers/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ pub trait EthTransactions: LoadTransaction {
}

self.spawn_blocking_io(move |ref this| {
Ok(LoadTransaction::provider(this)
Ok(RpcNodeCore::provider(this)
.transaction_by_hash(hash)
.map_err(Self::Error::from_eth_err)?
.map(|tx| tx.encoded_2718().into()))
Expand Down Expand Up @@ -166,7 +166,7 @@ pub trait EthTransactions: LoadTransaction {
{
let this = self.clone();
self.spawn_blocking_io(move |_| {
let (tx, meta) = match LoadTransaction::provider(&this)
let (tx, meta) = match RpcNodeCore::provider(&this)
.transaction_by_hash_with_meta(hash)
.map_err(Self::Error::from_eth_err)?
{
Expand Down Expand Up @@ -383,10 +383,15 @@ pub trait EthTransactions: LoadTransaction {

let transaction = self.sign_request(&from, request).await?.with_signer(from);

let pool_transaction = <<Self as LoadTransaction>::Pool as TransactionPool>::Transaction::try_from_consensus(transaction.into()).map_err(|_| EthApiError::TransactionConversionError)?;
let pool_transaction =
<<Self as RpcNodeCore>::Pool as TransactionPool>::Transaction::try_from_consensus(
transaction.into(),
)
.map_err(|_| EthApiError::TransactionConversionError)?;

// submit the transaction to the pool with a `Local` origin
let hash = LoadTransaction::pool(self)
let hash = self
.pool()
.add_transaction(TransactionOrigin::Local, pool_transaction)
.await
.map_err(Self::Error::from_eth_err)?;
Expand Down Expand Up @@ -460,26 +465,14 @@ pub trait EthTransactions: LoadTransaction {
///
/// Behaviour shared by several `eth_` RPC methods, not exclusive to `eth_` transactions RPC
/// methods.
pub trait LoadTransaction: SpawnBlocking + FullEthApiTypes {
/// Transaction pool with pending transactions. [`TransactionPool::Transaction`] is the
/// supported transaction type.
type Pool: TransactionPool;

/// Returns a handle for reading data from disk.
///
/// Data access in default (L1) trait method implementations.
fn provider(&self) -> impl TransactionsProvider;

pub trait LoadTransaction:
SpawnBlocking + FullEthApiTypes + RpcNodeCore<Provider: TransactionsProvider, Pool: TransactionPool>
{
/// Returns a handle for reading data from memory.
///
/// Data access in default (L1) trait method implementations.
fn cache(&self) -> &EthStateCache;

/// Returns a handle for reading data from pool.
///
/// Data access in default (L1) trait method implementations.
fn pool(&self) -> &Self::Pool;

/// Returns the transaction by hash.
///
/// Checks the pool and state.
Expand Down
20 changes: 4 additions & 16 deletions crates/rpc/rpc/src/eth/helpers/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use reth_provider::{BlockReaderIdExt, TransactionsProvider};
use reth_rpc_eth_api::{
helpers::{EthSigner, EthTransactions, LoadTransaction, SpawnBlocking},
FullEthApiTypes,
FullEthApiTypes, RpcNodeCore,
};
use reth_rpc_eth_types::EthStateCache;
use reth_transaction_pool::TransactionPool;
Expand Down Expand Up @@ -31,26 +31,14 @@ where
impl<Provider, Pool, Network, EvmConfig> LoadTransaction
for EthApi<Provider, Pool, Network, EvmConfig>
where
Self: SpawnBlocking + FullEthApiTypes,
Provider: TransactionsProvider,
Pool: TransactionPool,
Self: SpawnBlocking
+ FullEthApiTypes
+ RpcNodeCore<Provider: TransactionsProvider, Pool: TransactionPool>,
{
type Pool = Pool;

#[inline]
fn provider(&self) -> impl TransactionsProvider {
self.inner.provider()
}

#[inline]
fn cache(&self) -> &EthStateCache {
self.inner.cache()
}

#[inline]
fn pool(&self) -> &Self::Pool {
self.inner.pool()
}
}

#[cfg(test)]
Expand Down
Loading