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

feat(rpc): remove total difficulty #13303

Merged
merged 5 commits into from
Dec 12, 2024
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
14 changes: 1 addition & 13 deletions crates/rpc/rpc-eth-api/src/helpers/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

use std::sync::Arc;

use alloy_consensus::BlockHeader;
use alloy_eips::BlockId;
use alloy_primitives::Sealable;
use alloy_rlp::Encodable;
Expand All @@ -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;
Expand Down Expand Up @@ -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: <https://github.com/paradigmxyz/reth/issues/10941>
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(),
Expand Down
7 changes: 1 addition & 6 deletions crates/rpc/rpc-eth-api/src/helpers/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 2 additions & 3 deletions crates/rpc/rpc-eth-types/src/simulate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -138,7 +138,6 @@ where
pub fn build_simulated_block<T, B>(
senders: Vec<Address>,
results: Vec<ExecutionResult>,
total_difficulty: U256,
full_transactions: bool,
tx_resp_builder: &T,
block: B,
Expand Down Expand Up @@ -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 })
}
14 changes: 3 additions & 11 deletions crates/rpc/rpc-types-compat/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use crate::{transaction::from_recovered_with_block_context, TransactionCompat};
#[expect(clippy::type_complexity)]
pub fn from_block<T, B>(
block: BlockWithSenders<B>,
total_difficulty: U256,
kind: BlockTransactionsKind,
block_hash: Option<B256>,
tx_resp_builder: &T,
Expand All @@ -29,11 +28,9 @@ where
{
match kind {
BlockTransactionsKind::Hashes => {
Ok(from_block_with_tx_hashes::<T::Transaction, B>(block, total_difficulty, block_hash))
}
BlockTransactionsKind::Full => {
from_block_full::<T, B>(block, total_difficulty, block_hash, tx_resp_builder)
Ok(from_block_with_tx_hashes::<T::Transaction, B>(block, block_hash))
}
BlockTransactionsKind::Full => from_block_full::<T, B>(block, block_hash, tx_resp_builder),
}
}

Expand All @@ -44,7 +41,6 @@ where
/// block: [`BlockTransactions::Hashes`]
pub fn from_block_with_tx_hashes<T, B>(
block: BlockWithSenders<B>,
total_difficulty: U256,
block_hash: Option<B256>,
) -> Block<T, Header<B::Header>>
where
Expand All @@ -57,7 +53,6 @@ where
block.length(),
block_hash,
block.block,
total_difficulty,
BlockTransactions::Hashes(transactions),
)
}
Expand All @@ -70,7 +65,6 @@ where
#[expect(clippy::type_complexity)]
pub fn from_block_full<T, B>(
block: BlockWithSenders<B>,
total_difficulty: U256,
block_hash: Option<B256>,
tx_resp_builder: &T,
) -> Result<Block<T::Transaction, Header<B::Header>>, T::Error>
Expand Down Expand Up @@ -112,7 +106,6 @@ where
block_length,
block_hash,
block.block,
total_difficulty,
BlockTransactions::Full(transactions),
))
}
Expand All @@ -122,7 +115,6 @@ fn from_block_with_transactions<T, B: BlockTrait>(
block_length: usize,
block_hash: B256,
block: B,
total_difficulty: U256,
transactions: BlockTransactions<T>,
) -> Block<T, Header<B::Header>> {
let withdrawals = block
Expand All @@ -140,7 +132,7 @@ fn from_block_with_transactions<T, B: BlockTrait>(
let (header, _) = block.split();
let header = Header::from_consensus(
Sealed::new_unchecked(header, block_hash),
Some(total_difficulty),
None,
Some(U256::from(block_length)),
);

Expand Down
Loading