mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
perf(rpc): add optional block argument to trace_block_until_with_inspector (#11631)
This commit is contained in:
@ -1,12 +1,14 @@
|
||||
//! Loads a pending block from database. Helper trait for `eth_` call and trace RPC methods.
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::FromEvmError;
|
||||
use alloy_primitives::B256;
|
||||
use alloy_rpc_types::{BlockId, TransactionInfo};
|
||||
use futures::Future;
|
||||
use reth_chainspec::ChainSpecProvider;
|
||||
use reth_evm::{system_calls::SystemCaller, ConfigureEvm, ConfigureEvmEnv};
|
||||
use reth_primitives::Header;
|
||||
use reth_primitives::{Header, SealedBlockWithSenders};
|
||||
use reth_revm::database::StateProviderDatabase;
|
||||
use reth_rpc_eth_types::{
|
||||
cache::db::{StateCacheDb, StateCacheDbRefMutWrapper, StateProviderTraitObjWrapper},
|
||||
@ -247,6 +249,7 @@ pub trait Trace: LoadState {
|
||||
fn trace_block_until<F, R>(
|
||||
&self,
|
||||
block_id: BlockId,
|
||||
block: Option<Arc<SealedBlockWithSenders>>,
|
||||
highest_index: Option<u64>,
|
||||
config: TracingInspectorConfig,
|
||||
f: F,
|
||||
@ -266,6 +269,7 @@ pub trait Trace: LoadState {
|
||||
{
|
||||
self.trace_block_until_with_inspector(
|
||||
block_id,
|
||||
block,
|
||||
highest_index,
|
||||
move || TracingInspector::new(config),
|
||||
f,
|
||||
@ -285,6 +289,7 @@ pub trait Trace: LoadState {
|
||||
fn trace_block_until_with_inspector<Setup, Insp, F, R>(
|
||||
&self,
|
||||
block_id: BlockId,
|
||||
block: Option<Arc<SealedBlockWithSenders>>,
|
||||
highest_index: Option<u64>,
|
||||
mut inspector_setup: Setup,
|
||||
f: F,
|
||||
@ -305,8 +310,15 @@ pub trait Trace: LoadState {
|
||||
R: Send + 'static,
|
||||
{
|
||||
async move {
|
||||
let block = async {
|
||||
if block.is_some() {
|
||||
return Ok(block)
|
||||
}
|
||||
self.block_with_senders(block_id).await
|
||||
};
|
||||
|
||||
let ((cfg, block_env, _), block) =
|
||||
futures::try_join!(self.evm_env_at(block_id), self.block_with_senders(block_id))?;
|
||||
futures::try_join!(self.evm_env_at(block_id), block)?;
|
||||
|
||||
let Some(block) = block else { return Ok(None) };
|
||||
|
||||
@ -409,6 +421,7 @@ pub trait Trace: LoadState {
|
||||
fn trace_block_with<F, R>(
|
||||
&self,
|
||||
block_id: BlockId,
|
||||
block: Option<Arc<SealedBlockWithSenders>>,
|
||||
config: TracingInspectorConfig,
|
||||
f: F,
|
||||
) -> impl Future<Output = Result<Option<Vec<R>>, Self::Error>> + Send
|
||||
@ -427,7 +440,7 @@ pub trait Trace: LoadState {
|
||||
+ 'static,
|
||||
R: Send + 'static,
|
||||
{
|
||||
self.trace_block_until(block_id, None, config, f)
|
||||
self.trace_block_until(block_id, block, None, config, f)
|
||||
}
|
||||
|
||||
/// Executes all transactions of a block and returns a list of callback results invoked for each
|
||||
@ -447,6 +460,7 @@ pub trait Trace: LoadState {
|
||||
fn trace_block_inspector<Setup, Insp, F, R>(
|
||||
&self,
|
||||
block_id: BlockId,
|
||||
block: Option<Arc<SealedBlockWithSenders>>,
|
||||
insp_setup: Setup,
|
||||
f: F,
|
||||
) -> impl Future<Output = Result<Option<Vec<R>>, Self::Error>> + Send
|
||||
@ -467,6 +481,6 @@ pub trait Trace: LoadState {
|
||||
Insp: for<'a, 'b> Inspector<StateCacheDbRefMutWrapper<'a, 'b>> + Send + 'static,
|
||||
R: Send + 'static,
|
||||
{
|
||||
self.trace_block_until_with_inspector(block_id, None, insp_setup, f)
|
||||
self.trace_block_until_with_inspector(block_id, block, None, insp_setup, f)
|
||||
}
|
||||
}
|
||||
|
||||
@ -334,6 +334,7 @@ where
|
||||
.eth
|
||||
.trace_block_with(
|
||||
num.into(),
|
||||
None,
|
||||
TracingInspectorConfig::default_parity(),
|
||||
|tx_info, inspector, _, _, _| {
|
||||
Ok(inspector.into_parity_builder().into_localized_transaction_traces(tx_info))
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use alloy_primitives::{map::HashSet, Bytes, B256, U256};
|
||||
use alloy_rpc_types::{
|
||||
state::{EvmOverrides, StateOverride},
|
||||
@ -37,6 +35,7 @@ use revm_inspectors::{
|
||||
opcode::OpcodeGasInspector,
|
||||
tracing::{parity::populate_state_diff, TracingInspector, TracingInspectorConfig},
|
||||
};
|
||||
use std::sync::Arc;
|
||||
use tokio::sync::{AcquireError, OwnedSemaphorePermit};
|
||||
|
||||
/// `trace` API implementation.
|
||||
@ -278,14 +277,21 @@ where
|
||||
}
|
||||
|
||||
// fetch all blocks in that range
|
||||
let blocks = self.provider().block_range(start..=end).map_err(Eth::Error::from_eth_err)?;
|
||||
let blocks = self
|
||||
.provider()
|
||||
.sealed_block_with_senders_range(start..=end)
|
||||
.map_err(Eth::Error::from_eth_err)?
|
||||
.into_iter()
|
||||
.map(Arc::new)
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
// trace all blocks
|
||||
let mut block_traces = Vec::with_capacity(blocks.len());
|
||||
for block in &blocks {
|
||||
let matcher = matcher.clone();
|
||||
let traces = self.eth_api().trace_block_until(
|
||||
block.number.into(),
|
||||
block.hash().into(),
|
||||
Some(block.clone()),
|
||||
None,
|
||||
TracingInspectorConfig::default_parity(),
|
||||
move |tx_info, inspector, _, _, _| {
|
||||
@ -369,6 +375,7 @@ where
|
||||
) -> Result<Option<Vec<LocalizedTransactionTrace>>, Eth::Error> {
|
||||
let traces = self.eth_api().trace_block_with(
|
||||
block_id,
|
||||
None,
|
||||
TracingInspectorConfig::default_parity(),
|
||||
|tx_info, inspector, _, _, _| {
|
||||
let traces =
|
||||
@ -405,6 +412,7 @@ where
|
||||
self.eth_api()
|
||||
.trace_block_with(
|
||||
block_id,
|
||||
None,
|
||||
TracingInspectorConfig::from_parity_config(&trace_types),
|
||||
move |tx_info, inspector, res, state, db| {
|
||||
let mut full_trace =
|
||||
@ -460,6 +468,7 @@ where
|
||||
.eth_api()
|
||||
.trace_block_inspector(
|
||||
block_id,
|
||||
None,
|
||||
OpcodeGasInspector::default,
|
||||
move |tx_info, inspector, _res, _, _| {
|
||||
let trace = TransactionOpcodeGas {
|
||||
|
||||
Reference in New Issue
Block a user