mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat(rpc): remove total difficulty (#13303)
Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
@ -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: <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(),
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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<T, B>(
|
||||
senders: Vec<Address>,
|
||||
results: Vec<ExecutionResult>,
|
||||
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 })
|
||||
}
|
||||
|
||||
@ -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,
|
||||
@ -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),
|
||||
}
|
||||
}
|
||||
|
||||
@ -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
|
||||
@ -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<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>
|
||||
@ -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<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
|
||||
@ -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)),
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user