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

perf(rpc): Use block_with_senders in tracing #5630

Merged
merged 5 commits into from
Dec 1, 2023
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
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 @@ -18,8 +18,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 @@ -87,10 +86,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 @@ -112,11 +113,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 @@ -1037,19 +1037,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
Loading