mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 19:09:54 +00:00
chore(rpc): remove redundant trait method LoadBlock::provider (#12100)
This commit is contained in:
@ -7,7 +7,7 @@ use reth_chainspec::ChainSpecProvider;
|
||||
use reth_node_api::{FullNodeComponents, NodeTypes};
|
||||
use reth_optimism_chainspec::OpChainSpec;
|
||||
use reth_primitives::TransactionMeta;
|
||||
use reth_provider::{BlockReaderIdExt, HeaderProvider};
|
||||
use reth_provider::HeaderProvider;
|
||||
use reth_rpc_eth_api::{
|
||||
helpers::{EthBlocks, LoadBlock, LoadPendingBlock, LoadReceipt, SpawnBlocking},
|
||||
RpcReceipt,
|
||||
@ -87,11 +87,6 @@ where
|
||||
Self: LoadPendingBlock + SpawnBlocking,
|
||||
N: FullNodeComponents,
|
||||
{
|
||||
#[inline]
|
||||
fn provider(&self) -> impl BlockReaderIdExt {
|
||||
self.inner.provider()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn cache(&self) -> &EthStateCache {
|
||||
self.inner.cache()
|
||||
|
||||
@ -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};
|
||||
@ -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>
|
||||
|
||||
@ -85,13 +85,13 @@ pub trait EthBlocks: LoadBlock {
|
||||
async move {
|
||||
if block_id.is_pending() {
|
||||
// Pending block can be fetched directly without need for caching
|
||||
return Ok(LoadBlock::provider(self)
|
||||
return Ok(RpcNodeCore::provider(self)
|
||||
.pending_block()
|
||||
.map_err(Self::Error::from_eth_err)?
|
||||
.map(|block| block.body.transactions.len()))
|
||||
}
|
||||
|
||||
let block_hash = match LoadBlock::provider(self)
|
||||
let block_hash = match RpcNodeCore::provider(self)
|
||||
.block_hash_for_id(block_id)
|
||||
.map_err(Self::Error::from_eth_err)?
|
||||
{
|
||||
@ -132,7 +132,7 @@ pub trait EthBlocks: LoadBlock {
|
||||
if block_id.is_pending() {
|
||||
// First, try to get the pending block from the provider, in case we already
|
||||
// received the actual pending block from the CL.
|
||||
if let Some((block, receipts)) = LoadBlock::provider(self)
|
||||
if let Some((block, receipts)) = RpcNodeCore::provider(self)
|
||||
.pending_block_and_receipts()
|
||||
.map_err(Self::Error::from_eth_err)?
|
||||
{
|
||||
@ -145,7 +145,7 @@ pub trait EthBlocks: LoadBlock {
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(block_hash) = LoadBlock::provider(self)
|
||||
if let Some(block_hash) = RpcNodeCore::provider(self)
|
||||
.block_hash_for_id(block_id)
|
||||
.map_err(Self::Error::from_eth_err)?
|
||||
{
|
||||
@ -167,7 +167,7 @@ pub trait EthBlocks: LoadBlock {
|
||||
&self,
|
||||
block_id: BlockId,
|
||||
) -> Result<Option<Vec<reth_primitives::Header>>, Self::Error> {
|
||||
LoadBlock::provider(self).ommers_by_id(block_id).map_err(Self::Error::from_eth_err)
|
||||
RpcNodeCore::provider(self).ommers_by_id(block_id).map_err(Self::Error::from_eth_err)
|
||||
}
|
||||
|
||||
/// Returns uncle block at given index in given block.
|
||||
@ -182,12 +182,12 @@ pub trait EthBlocks: LoadBlock {
|
||||
async move {
|
||||
let uncles = if block_id.is_pending() {
|
||||
// Pending block can be fetched directly without need for caching
|
||||
LoadBlock::provider(self)
|
||||
RpcNodeCore::provider(self)
|
||||
.pending_block()
|
||||
.map_err(Self::Error::from_eth_err)?
|
||||
.map(|block| block.body.ommers)
|
||||
} else {
|
||||
LoadBlock::provider(self)
|
||||
RpcNodeCore::provider(self)
|
||||
.ommers_by_id(block_id)
|
||||
.map_err(Self::Error::from_eth_err)?
|
||||
}
|
||||
@ -202,11 +202,6 @@ pub trait EthBlocks: LoadBlock {
|
||||
///
|
||||
/// Behaviour shared by several `eth_` RPC methods, not exclusive to `eth_` blocks RPC methods.
|
||||
pub trait LoadBlock: LoadPendingBlock + SpawnBlocking {
|
||||
// Returns a handle for reading data from disk.
|
||||
///
|
||||
/// Data access in default (L1) trait method implementations.
|
||||
fn provider(&self) -> impl BlockReaderIdExt;
|
||||
|
||||
/// Returns a handle for reading data from memory.
|
||||
///
|
||||
/// Data access in default (L1) trait method implementations.
|
||||
@ -220,7 +215,8 @@ pub trait LoadBlock: LoadPendingBlock + SpawnBlocking {
|
||||
async move {
|
||||
if block_id.is_pending() {
|
||||
// Pending block can be fetched directly without need for caching
|
||||
if let Some(pending_block) = RpcNodeCore::provider(self)
|
||||
if let Some(pending_block) = self
|
||||
.provider()
|
||||
.pending_block_with_senders()
|
||||
.map_err(Self::Error::from_eth_err)?
|
||||
{
|
||||
@ -234,7 +230,8 @@ pub trait LoadBlock: LoadPendingBlock + SpawnBlocking {
|
||||
};
|
||||
}
|
||||
|
||||
let block_hash = match RpcNodeCore::provider(self)
|
||||
let block_hash = match self
|
||||
.provider()
|
||||
.block_hash_for_id(block_id)
|
||||
.map_err(Self::Error::from_eth_err)?
|
||||
{
|
||||
|
||||
@ -259,7 +259,8 @@ pub trait EthCall: Call + LoadPendingBlock {
|
||||
// if it's not pending, we should always use block_hash over block_number to ensure that
|
||||
// different provider calls query data related to the same block.
|
||||
if !is_block_target_pending {
|
||||
target_block = LoadBlock::provider(self)
|
||||
target_block = self
|
||||
.provider()
|
||||
.block_hash_for_id(target_block)
|
||||
.map_err(|_| EthApiError::HeaderNotFound(target_block))?
|
||||
.ok_or_else(|| EthApiError::HeaderNotFound(target_block))?
|
||||
|
||||
@ -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()))
|
||||
@ -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)?
|
||||
{
|
||||
@ -257,7 +257,7 @@ pub trait EthTransactions: LoadTransaction {
|
||||
return Ok(None);
|
||||
}
|
||||
|
||||
let Ok(high) = LoadBlock::provider(self).best_block_number() else {
|
||||
let Ok(high) = RpcNodeCore::provider(self).best_block_number() else {
|
||||
return Err(EthApiError::HeaderNotFound(BlockNumberOrTag::Latest.into()).into());
|
||||
};
|
||||
|
||||
@ -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)?;
|
||||
@ -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.
|
||||
|
||||
@ -73,11 +73,6 @@ where
|
||||
Self: LoadPendingBlock + SpawnBlocking,
|
||||
Provider: BlockReaderIdExt,
|
||||
{
|
||||
#[inline]
|
||||
fn provider(&self) -> impl BlockReaderIdExt {
|
||||
self.inner.provider()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn cache(&self) -> &EthStateCache {
|
||||
self.inner.cache()
|
||||
|
||||
@ -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;
|
||||
@ -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)]
|
||||
|
||||
Reference in New Issue
Block a user