mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 19:09:54 +00:00
chore(rpc): Add super trait RpcNodeCore to LoadPendingBlock (#12098)
This commit is contained in:
@ -9,7 +9,7 @@ use reth_provider::{BlockIdReader, BlockReader, BlockReaderIdExt, HeaderProvider
|
||||
use reth_rpc_eth_types::EthStateCache;
|
||||
use reth_rpc_types_compat::block::{from_block, uncle_block_from_header};
|
||||
|
||||
use crate::{FromEthApiError, FullEthApiTypes, RpcBlock, RpcReceipt};
|
||||
use crate::{FromEthApiError, FullEthApiTypes, RpcBlock, RpcNodeCore, RpcReceipt};
|
||||
|
||||
use super::{LoadPendingBlock, LoadReceipt, SpawnBlocking};
|
||||
|
||||
@ -220,7 +220,7 @@ 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) = LoadPendingBlock::provider(self)
|
||||
if let Some(pending_block) = RpcNodeCore::provider(self)
|
||||
.pending_block_with_senders()
|
||||
.map_err(Self::Error::from_eth_err)?
|
||||
{
|
||||
@ -234,7 +234,7 @@ pub trait LoadBlock: LoadPendingBlock + SpawnBlocking {
|
||||
};
|
||||
}
|
||||
|
||||
let block_hash = match LoadPendingBlock::provider(self)
|
||||
let block_hash = match RpcNodeCore::provider(self)
|
||||
.block_hash_for_id(block_id)
|
||||
.map_err(Self::Error::from_eth_err)?
|
||||
{
|
||||
|
||||
@ -97,7 +97,7 @@ pub trait EthCall: Call + LoadPendingBlock {
|
||||
let base_block =
|
||||
self.block_with_senders(block).await?.ok_or(EthApiError::HeaderNotFound(block))?;
|
||||
let mut parent_hash = base_block.header.hash();
|
||||
let total_difficulty = LoadPendingBlock::provider(self)
|
||||
let total_difficulty = RpcNodeCore::provider(self)
|
||||
.header_td_by_number(block_env.number.to())
|
||||
.map_err(Self::Error::from_eth_err)?
|
||||
.ok_or(EthApiError::HeaderNotFound(block))?;
|
||||
@ -119,7 +119,7 @@ pub trait EthCall: Call + LoadPendingBlock {
|
||||
block_env.timestamp += U256::from(1);
|
||||
|
||||
if validation {
|
||||
let chain_spec = LoadPendingBlock::provider(&this).chain_spec();
|
||||
let chain_spec = RpcNodeCore::provider(&this).chain_spec();
|
||||
let base_fee_params =
|
||||
chain_spec.base_fee_params_at_timestamp(block_env.timestamp.to());
|
||||
let base_fee = if let Some(latest) = blocks.last() {
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
use crate::{EthApiTypes, FromEthApiError, FromEvmError};
|
||||
use crate::{EthApiTypes, FromEthApiError, FromEvmError, RpcNodeCore};
|
||||
|
||||
use alloy_consensus::EMPTY_OMMER_ROOT_HASH;
|
||||
use alloy_eips::{eip7685::EMPTY_REQUESTS_HASH, merge::BEACON_NONCE};
|
||||
@ -43,32 +43,22 @@ use super::SpawnBlocking;
|
||||
/// Loads a pending block from database.
|
||||
///
|
||||
/// Behaviour shared by several `eth_` RPC methods, not exclusive to `eth_` blocks RPC methods.
|
||||
pub trait LoadPendingBlock: EthApiTypes {
|
||||
/// Returns a handle for reading data from disk.
|
||||
///
|
||||
/// Data access in default (L1) trait method implementations.
|
||||
fn provider(
|
||||
&self,
|
||||
) -> impl BlockReaderIdExt
|
||||
+ EvmEnvProvider
|
||||
+ ChainSpecProvider<ChainSpec: EthChainSpec + EthereumHardforks>
|
||||
+ StateProviderFactory;
|
||||
|
||||
/// Returns a handle for reading data from transaction pool.
|
||||
///
|
||||
/// Data access in default (L1) trait method implementations.
|
||||
fn pool(&self) -> impl TransactionPool;
|
||||
|
||||
pub trait LoadPendingBlock:
|
||||
EthApiTypes
|
||||
+ RpcNodeCore<
|
||||
Provider: BlockReaderIdExt
|
||||
+ EvmEnvProvider
|
||||
+ ChainSpecProvider<ChainSpec: EthChainSpec + EthereumHardforks>
|
||||
+ StateProviderFactory,
|
||||
Pool: TransactionPool,
|
||||
Evm: ConfigureEvm<Header = Header>,
|
||||
>
|
||||
{
|
||||
/// Returns a handle to the pending block.
|
||||
///
|
||||
/// Data access in default (L1) trait method implementations.
|
||||
fn pending_block(&self) -> &Mutex<Option<PendingBlock>>;
|
||||
|
||||
/// Returns a handle for reading evm config.
|
||||
///
|
||||
/// Data access in default (L1) trait method implementations.
|
||||
fn evm_config(&self) -> &impl ConfigureEvm<Header = Header>;
|
||||
|
||||
/// Configures the [`CfgEnvWithHandlerCfg`] and [`BlockEnv`] for the pending block
|
||||
///
|
||||
/// If no pending block is available, this will derive it from the `latest` block
|
||||
|
||||
@ -233,7 +233,7 @@ pub trait LoadState:
|
||||
Ok((cfg, block_env, origin.state_block_id()))
|
||||
} else {
|
||||
// Use cached values if there is no pending block
|
||||
let block_hash = LoadPendingBlock::provider(self)
|
||||
let block_hash = RpcNodeCore::provider(self)
|
||||
.block_hash_for_id(at)
|
||||
.map_err(Self::Error::from_eth_err)?
|
||||
.ok_or(EthApiError::HeaderNotFound(at))?;
|
||||
@ -262,7 +262,7 @@ pub trait LoadState:
|
||||
let (cfg, mut block_env, _) = self.evm_env_at(header.parent_hash.into()).await?;
|
||||
|
||||
let after_merge = cfg.handler_cfg.spec_id >= SpecId::MERGE;
|
||||
LoadPendingBlock::evm_config(self).fill_block_env(&mut block_env, header, after_merge);
|
||||
self.evm_config().fill_block_env(&mut block_env, header, after_merge);
|
||||
|
||||
Ok((cfg, block_env))
|
||||
}
|
||||
|
||||
@ -130,12 +130,12 @@ where
|
||||
} else if cfg.handler_cfg.spec_id.is_enabled_in(SpecId::LONDON) {
|
||||
let parent_block = block_env.number.saturating_to::<u64>();
|
||||
// here we need to fetch the _next_ block's basefee based on the parent block <https://github.com/flashbots/mev-geth/blob/fddf97beec5877483f879a77b7dea2e58a58d653/internal/ethapi/api.go#L2130>
|
||||
let parent = LoadPendingBlock::provider(self.eth_api())
|
||||
let parent = RpcNodeCore::provider(self.eth_api())
|
||||
.header_by_number(parent_block)
|
||||
.map_err(Eth::Error::from_eth_err)?
|
||||
.ok_or(EthApiError::HeaderNotFound(parent_block.into()))?;
|
||||
if let Some(base_fee) = parent.next_block_base_fee(
|
||||
LoadPendingBlock::provider(self.eth_api())
|
||||
RpcNodeCore::provider(self.eth_api())
|
||||
.chain_spec()
|
||||
.base_fee_params_at_block(parent_block),
|
||||
) {
|
||||
|
||||
@ -1,10 +1,13 @@
|
||||
//! Support for building a pending block with transactions from local view of mempool.
|
||||
|
||||
use reth_chainspec::EthereumHardforks;
|
||||
use reth_chainspec::{EthChainSpec, EthereumHardforks};
|
||||
use reth_evm::ConfigureEvm;
|
||||
use reth_primitives::Header;
|
||||
use reth_provider::{BlockReaderIdExt, ChainSpecProvider, EvmEnvProvider, StateProviderFactory};
|
||||
use reth_rpc_eth_api::helpers::{LoadPendingBlock, SpawnBlocking};
|
||||
use reth_rpc_eth_api::{
|
||||
helpers::{LoadPendingBlock, SpawnBlocking},
|
||||
RpcNodeCore,
|
||||
};
|
||||
use reth_rpc_eth_types::PendingBlock;
|
||||
use reth_transaction_pool::TransactionPool;
|
||||
|
||||
@ -13,36 +16,18 @@ use crate::EthApi;
|
||||
impl<Provider, Pool, Network, EvmConfig> LoadPendingBlock
|
||||
for EthApi<Provider, Pool, Network, EvmConfig>
|
||||
where
|
||||
Self: SpawnBlocking,
|
||||
Provider: BlockReaderIdExt
|
||||
+ EvmEnvProvider
|
||||
+ ChainSpecProvider<ChainSpec: EthereumHardforks>
|
||||
+ StateProviderFactory,
|
||||
Pool: TransactionPool,
|
||||
EvmConfig: ConfigureEvm<Header = Header>,
|
||||
Self: SpawnBlocking
|
||||
+ RpcNodeCore<
|
||||
Provider: BlockReaderIdExt
|
||||
+ EvmEnvProvider
|
||||
+ ChainSpecProvider<ChainSpec: EthChainSpec + EthereumHardforks>
|
||||
+ StateProviderFactory,
|
||||
Pool: TransactionPool,
|
||||
Evm: ConfigureEvm<Header = Header>,
|
||||
>,
|
||||
{
|
||||
#[inline]
|
||||
fn provider(
|
||||
&self,
|
||||
) -> impl BlockReaderIdExt
|
||||
+ EvmEnvProvider
|
||||
+ ChainSpecProvider<ChainSpec: EthereumHardforks>
|
||||
+ StateProviderFactory {
|
||||
self.inner.provider()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn pool(&self) -> impl TransactionPool {
|
||||
self.inner.pool()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn pending_block(&self) -> &tokio::sync::Mutex<Option<PendingBlock>> {
|
||||
self.inner.pending_block()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn evm_config(&self) -> &impl ConfigureEvm<Header = Header> {
|
||||
self.inner.evm_config()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user