Skip to content

Commit

Permalink
perf(rpc): Use block_with_senders in tracing (#5630)
Browse files Browse the repository at this point in the history
Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
  • Loading branch information
yash-atreya and mattsse authored Dec 1, 2023
1 parent 4a0497d commit 1067bb3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 18 deletions.
16 changes: 7 additions & 9 deletions crates/rpc/rpc/src/eth/api/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ use reth_provider::{
};
use reth_revm::{access_list::AccessListInspector, database::StateProviderDatabase};
use reth_rpc_types::{
state::StateOverride, AccessListWithGasUsed, BlockError, Bundle, CallRequest, EthCallResponse,
StateContext,
state::StateOverride, AccessListWithGasUsed, Bundle, CallRequest, EthCallResponse, StateContext,
};
use reth_transaction_pool::TransactionPool;
use revm::{
Expand Down Expand Up @@ -93,10 +92,12 @@ where

let target_block = block_number.unwrap_or(BlockId::Number(BlockNumberOrTag::Latest));

let ((cfg, block_env, _), block) =
futures::try_join!(self.evm_env_at(target_block), self.block_by_id(target_block))?;
let ((cfg, block_env, _), block) = futures::try_join!(
self.evm_env_at(target_block),
self.block_with_senders(target_block)
)?;

let block = block.ok_or_else(|| EthApiError::UnknownBlockNumber)?;
let Some(block) = block else { return Err(EthApiError::UnknownBlockNumber) };
let gas_limit = self.inner.gas_cap;

// we're essentially replaying the transactions in the block here, hence we need the state
Expand All @@ -118,11 +119,8 @@ where
if replay_block_txs {
// only need to replay the transactions in the block if not all transactions are
// to be replayed
let transactions = block.body.into_iter().take(num_txs);

// Execute all transactions until index
let transactions = block.into_transactions_ecrecovered().take(num_txs);
for tx in transactions {
let tx = tx.into_ecrecovered().ok_or(BlockError::InvalidSignature)?;
let tx = tx_env_with_recovered(&tx);
let env = Env { cfg: cfg.clone(), block: block_env.clone(), tx };
let (res, _) = transact(&mut db, env)?;
Expand Down
15 changes: 6 additions & 9 deletions crates/rpc/rpc/src/eth/api/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1038,19 +1038,16 @@ where
block_id: impl Into<BlockId>,
index: Index,
) -> EthResult<Option<Transaction>> {
let block_id = block_id.into();

if let Some(block) = self.block(block_id).await? {
if let Some(block) = self.block_with_senders(block_id.into()).await? {
let block_hash = block.hash;
let block = block.unseal();
if let Some(tx_signed) = block.body.into_iter().nth(index.into()) {
let tx =
tx_signed.into_ecrecovered().ok_or(EthApiError::InvalidTransactionSignature)?;
let block_number = block.number;
let base_fee_per_gas = block.base_fee_per_gas;
if let Some(tx) = block.into_transactions_ecrecovered().nth(index.into()) {
return Ok(Some(from_recovered_with_block_context(
tx,
block_hash,
block.header.number,
block.header.base_fee_per_gas,
block_number,
base_fee_per_gas,
index.into(),
)))
}
Expand Down

0 comments on commit 1067bb3

Please sign in to comment.