From aca4a2db39c966fbc12e90fc2e8cd2b51b37ebe7 Mon Sep 17 00:00:00 2001 From: Miguel Oliveira Date: Thu, 12 Dec 2024 09:52:34 -0300 Subject: [PATCH] feat(rpc): remove total difficulty (#13303) Co-authored-by: Matthias Seitz --- crates/rpc/rpc-eth-api/src/helpers/block.rs | 14 +------------- crates/rpc/rpc-eth-api/src/helpers/call.rs | 7 +------ crates/rpc/rpc-eth-types/src/simulate.rs | 5 ++--- crates/rpc/rpc-types-compat/src/block.rs | 14 +++----------- 4 files changed, 7 insertions(+), 33 deletions(-) diff --git a/crates/rpc/rpc-eth-api/src/helpers/block.rs b/crates/rpc/rpc-eth-api/src/helpers/block.rs index 5f0d9f744ef1..1ae084fbe45f 100644 --- a/crates/rpc/rpc-eth-api/src/helpers/block.rs +++ b/crates/rpc/rpc-eth-api/src/helpers/block.rs @@ -2,7 +2,6 @@ use std::sync::Arc; -use alloy_consensus::BlockHeader; use alloy_eips::BlockId; use alloy_primitives::Sealable; use alloy_rlp::Encodable; @@ -11,7 +10,7 @@ use futures::Future; use reth_node_api::BlockBody; use reth_primitives::{SealedBlockFor, SealedBlockWithSenders}; use reth_provider::{ - BlockIdReader, BlockReader, BlockReaderIdExt, HeaderProvider, ProviderHeader, ProviderReceipt, + BlockIdReader, BlockReader, BlockReaderIdExt, ProviderHeader, ProviderReceipt, }; use reth_rpc_types_compat::block::from_block; use revm_primitives::U256; @@ -64,20 +63,9 @@ pub trait EthBlocks: LoadBlock { async move { let Some(block) = self.block_with_senders(block_id).await? else { return Ok(None) }; let block_hash = block.hash(); - let mut total_difficulty = self - .provider() - .header_td_by_number(block.number()) - .map_err(Self::Error::from_eth_err)?; - if total_difficulty.is_none() { - // if we failed to find td after we successfully loaded the block, try again using - // the hash this only matters if the chain is currently transitioning the merge block and there's a reorg: - total_difficulty = - self.provider().header_td(&block.hash()).map_err(Self::Error::from_eth_err)?; - } let block = from_block( (*block).clone().unseal(), - total_difficulty.unwrap_or_default(), full.into(), Some(block_hash), self.tx_resp_builder(), diff --git a/crates/rpc/rpc-eth-api/src/helpers/call.rs b/crates/rpc/rpc-eth-api/src/helpers/call.rs index e22fccc67261..fde88483c63b 100644 --- a/crates/rpc/rpc-eth-api/src/helpers/call.rs +++ b/crates/rpc/rpc-eth-api/src/helpers/call.rs @@ -20,7 +20,7 @@ use reth_chainspec::EthChainSpec; use reth_evm::{ConfigureEvm, ConfigureEvmEnv}; use reth_node_api::BlockBody; use reth_primitives_traits::SignedTransaction; -use reth_provider::{BlockIdReader, ChainSpecProvider, HeaderProvider, ProviderHeader}; +use reth_provider::{BlockIdReader, ChainSpecProvider, ProviderHeader}; use reth_revm::{ database::StateProviderDatabase, db::CacheDB, @@ -95,10 +95,6 @@ pub trait EthCall: EstimateCall + Call + LoadPendingBlock + LoadBlock + FullEthA 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 = RpcNodeCore::provider(self) - .header_td_by_number(block_env.number.to()) - .map_err(Self::Error::from_eth_err)? - .ok_or(EthApiError::HeaderNotFound(block))?; // Only enforce base fee if validation is enabled cfg.disable_base_fee = !validation; @@ -206,7 +202,6 @@ pub trait EthCall: EstimateCall + Call + LoadPendingBlock + LoadBlock + FullEthA simulate::build_simulated_block( senders, results, - total_difficulty, return_full_transactions, this.tx_resp_builder(), block, diff --git a/crates/rpc/rpc-eth-types/src/simulate.rs b/crates/rpc/rpc-eth-types/src/simulate.rs index f18232b8952e..94bdcd86874c 100644 --- a/crates/rpc/rpc-eth-types/src/simulate.rs +++ b/crates/rpc/rpc-eth-types/src/simulate.rs @@ -12,7 +12,7 @@ use reth_primitives_traits::{block::BlockTx, BlockBody as _, SignedTransaction}; use reth_rpc_server_types::result::rpc_err; use reth_rpc_types_compat::{block::from_block, TransactionCompat}; use revm::Database; -use revm_primitives::{Address, Bytes, ExecutionResult, TxKind, U256}; +use revm_primitives::{Address, Bytes, ExecutionResult, TxKind}; use crate::{ error::{api::FromEthApiError, ToRpcError}, @@ -138,7 +138,6 @@ where pub fn build_simulated_block( senders: Vec
, results: Vec, - total_difficulty: U256, full_transactions: bool, tx_resp_builder: &T, block: B, @@ -209,6 +208,6 @@ where let txs_kind = if full_transactions { BlockTransactionsKind::Full } else { BlockTransactionsKind::Hashes }; - let block = from_block(block, total_difficulty, txs_kind, None, tx_resp_builder)?; + let block = from_block(block, txs_kind, None, tx_resp_builder)?; Ok(SimulatedBlock { inner: block, calls }) } diff --git a/crates/rpc/rpc-types-compat/src/block.rs b/crates/rpc/rpc-types-compat/src/block.rs index d3238757fc57..7d8c1480033a 100644 --- a/crates/rpc/rpc-types-compat/src/block.rs +++ b/crates/rpc/rpc-types-compat/src/block.rs @@ -18,7 +18,6 @@ use crate::{transaction::from_recovered_with_block_context, TransactionCompat}; #[expect(clippy::type_complexity)] pub fn from_block( block: BlockWithSenders, - total_difficulty: U256, kind: BlockTransactionsKind, block_hash: Option, tx_resp_builder: &T, @@ -29,11 +28,9 @@ where { match kind { BlockTransactionsKind::Hashes => { - Ok(from_block_with_tx_hashes::(block, total_difficulty, block_hash)) - } - BlockTransactionsKind::Full => { - from_block_full::(block, total_difficulty, block_hash, tx_resp_builder) + Ok(from_block_with_tx_hashes::(block, block_hash)) } + BlockTransactionsKind::Full => from_block_full::(block, block_hash, tx_resp_builder), } } @@ -44,7 +41,6 @@ where /// block: [`BlockTransactions::Hashes`] pub fn from_block_with_tx_hashes( block: BlockWithSenders, - total_difficulty: U256, block_hash: Option, ) -> Block> where @@ -57,7 +53,6 @@ where block.length(), block_hash, block.block, - total_difficulty, BlockTransactions::Hashes(transactions), ) } @@ -70,7 +65,6 @@ where #[expect(clippy::type_complexity)] pub fn from_block_full( block: BlockWithSenders, - total_difficulty: U256, block_hash: Option, tx_resp_builder: &T, ) -> Result>, T::Error> @@ -112,7 +106,6 @@ where block_length, block_hash, block.block, - total_difficulty, BlockTransactions::Full(transactions), )) } @@ -122,7 +115,6 @@ fn from_block_with_transactions( block_length: usize, block_hash: B256, block: B, - total_difficulty: U256, transactions: BlockTransactions, ) -> Block> { let withdrawals = block @@ -140,7 +132,7 @@ fn from_block_with_transactions( let (header, _) = block.split(); let header = Header::from_consensus( Sealed::new_unchecked(header, block_hash), - Some(total_difficulty), + None, Some(U256::from(block_length)), );