Skip to content

Commit

Permalink
make it compile
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse committed Jan 10, 2025
1 parent 4588326 commit 252f6b1
Show file tree
Hide file tree
Showing 17 changed files with 68 additions and 82 deletions.
2 changes: 0 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 6 additions & 11 deletions bin/reth/src/commands/debug_cmd/build_block.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! Command for debugging block building.
use alloy_consensus::TxEip4844;
use alloy_consensus::{BlockHeader, TxEip4844};
use alloy_eips::{
eip2718::Encodable2718,
eip4844::{env_settings::EnvKzgSettings, BlobTransactionSidecar},
Expand All @@ -25,8 +25,7 @@ use reth_fs_util as fs;
use reth_node_api::{BlockTy, EngineApiMessageVersion, PayloadBuilderAttributes};
use reth_node_ethereum::{consensus::EthBeaconConsensus, EthEvmConfig, EthExecutorProvider};
use reth_primitives::{
BlockExt, EthPrimitives, SealedBlockFor, SealedBlockWithSenders, SealedHeader, Transaction,
TransactionSigned,
BlockExt, EthPrimitives, SealedBlockFor, SealedHeader, Transaction, TransactionSigned,
};
use reth_provider::{
providers::{BlockchainProvider, ProviderNodeTypes},
Expand Down Expand Up @@ -238,21 +237,17 @@ impl<C: ChainSpecParser<ChainSpec = ChainSpec>> Command<C> {
debug!(target: "reth::cli", ?block, "Built new payload");

consensus.validate_header_with_total_difficulty(block, U256::MAX)?;
consensus.validate_header(block.sealed_header())?;
consensus.validate_header(&block.clone_sealed_header())?;
consensus.validate_block_pre_execution(block)?;

let senders = block.senders().expect("sender recovery failed");
let block_with_senders =
SealedBlockWithSenders::<BlockTy<N>>::try_new_unhashed(block.clone(), senders)
.unwrap();
let block_with_senders = block.clone().try_recover().unwrap();

let state_provider = blockchain_db.latest()?;
let db = StateProviderDatabase::new(&state_provider);
let executor =
EthExecutorProvider::ethereum(provider_factory.chain_spec()).executor(db);

let block_execution_output =
executor.execute(&block_with_senders.clone().unseal())?;
let block_execution_output = executor.execute(&block_with_senders)?;
let execution_outcome =
ExecutionOutcome::from((block_execution_output, block.number));
debug!(target: "reth::cli", ?execution_outcome, "Executed block");
Expand All @@ -263,7 +258,7 @@ impl<C: ChainSpecParser<ChainSpec = ChainSpec>> Command<C> {
hashed_post_state.clone(),
)?;

if state_root != block_with_senders.state_root {
if state_root != block_with_senders.state_root() {
eyre::bail!(
"state root mismatch. expected: {}. got: {}",
block_with_senders.state_root,
Expand Down
6 changes: 3 additions & 3 deletions bin/reth/src/commands/debug_cmd/execution.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Command for debugging execution.
use crate::{args::NetworkArgs, utils::get_single_header};
use crate::{api::BlockTy, args::NetworkArgs, utils::get_single_header};
use alloy_eips::BlockHashOrNumber;
use alloy_primitives::{BlockNumber, B256};
use clap::Parser;
Expand Down Expand Up @@ -64,7 +64,7 @@ impl<C: ChainSpecParser<ChainSpec = ChainSpec>> Command<C> {
&self,
config: &Config,
client: Client,
consensus: Arc<dyn Consensus<Error = ConsensusError>>,
consensus: Arc<dyn Consensus<BlockTy<N>, Error = ConsensusError>>,
provider_factory: ProviderFactory<N>,
task_executor: &TaskExecutor,
static_file_producer: StaticFileProducer<ProviderFactory<N>>,
Expand Down Expand Up @@ -172,7 +172,7 @@ impl<C: ChainSpecParser<ChainSpec = ChainSpec>> Command<C> {
let Environment { provider_factory, config, data_dir } =
self.env.init::<N>(AccessRights::RW)?;

let consensus: Arc<dyn Consensus<Error = ConsensusError>> =
let consensus: Arc<dyn Consensus<BlockTy<N>, Error = ConsensusError>> =
Arc::new(EthBeaconConsensus::new(provider_factory.chain_spec()));

// Configure and build network
Expand Down
45 changes: 20 additions & 25 deletions bin/reth/src/commands/debug_cmd/in_memory_merkle.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
//! Command for debugging in-memory merkle trie calculation.
use crate::{
api::BlockTy,
args::NetworkArgs,
utils::{get_single_body, get_single_header},
};
use alloy_consensus::BlockHeader;
use alloy_eips::BlockHashOrNumber;
use backon::{ConstantBuilder, Retryable};
use clap::Parser;
Expand All @@ -18,9 +20,9 @@ use reth_evm::execute::{BlockExecutorProvider, Executor};
use reth_execution_types::ExecutionOutcome;
use reth_network::{BlockDownloaderProvider, NetworkHandle};
use reth_network_api::NetworkInfo;
use reth_node_api::{BlockTy, NodePrimitives};
use reth_node_api::NodePrimitives;
use reth_node_ethereum::{consensus::EthBeaconConsensus, EthExecutorProvider};
use reth_primitives::{BlockExt, EthPrimitives};
use reth_primitives::{EthPrimitives, SealedBlock};
use reth_provider::{
providers::ProviderNodeTypes, AccountExtReader, ChainSpecProvider, DatabaseProviderFactory,
HashedPostStateProvider, HashingWriter, LatestStateProviderRef, OriginalValuesKnown,
Expand Down Expand Up @@ -135,33 +137,27 @@ impl<C: ChainSpecParser<ChainSpec = ChainSpec>> Command<C> {
let client = fetch_client.clone();
let chain = provider_factory.chain_spec();
let consensus = Arc::new(EthBeaconConsensus::new(chain.clone()));
let block = (move || get_single_body(client.clone(), header.clone(), consensus.clone()))
.retry(backoff)
.notify(
|err, _| warn!(target: "reth::cli", "Error requesting body: {err}. Retrying..."),
)
.await?;
let block: SealedBlock<BlockTy<N>> = (move || {
get_single_body(client.clone(), header.clone(), consensus.clone())
})
.retry(backoff)
.notify(|err, _| warn!(target: "reth::cli", "Error requesting body: {err}. Retrying..."))
.await?;

let state_provider = LatestStateProviderRef::new(&provider);
let db = StateProviderDatabase::new(&state_provider);

let executor = EthExecutorProvider::ethereum(provider_factory.chain_spec()).executor(db);
let block_execution_output = executor.execute(
&block
.clone()
.into_block::<BlockTy<N>>()
.with_recovered_senders()
.ok_or(BlockValidationError::SenderRecoveryError)?,
)?;
let execution_outcome = ExecutionOutcome::from((block_execution_output, block.number));
let block_execution_output = executor.execute(&block.clone().try_recover()?)?;
let execution_outcome = ExecutionOutcome::from((block_execution_output, block.number()));

// Unpacked `BundleState::state_root_slow` function
let (in_memory_state_root, in_memory_updates) = StateRoot::overlay_root_with_updates(
provider.tx_ref(),
state_provider.hashed_post_state(execution_outcome.state()),
)?;

if in_memory_state_root == block.state_root {
if in_memory_state_root == block.state_root() {
info!(target: "reth::cli", state_root = ?in_memory_state_root, "Computed in-memory state root matches");
return Ok(())
}
Expand All @@ -170,28 +166,27 @@ impl<C: ChainSpecParser<ChainSpec = ChainSpec>> Command<C> {

// Insert block, state and hashes
provider_rw.insert_historical_block(
block
.clone()
.try_with_senders()
.map_err(|_| BlockValidationError::SenderRecoveryError)?,
block.clone().try_recover().map_err(|_| BlockValidationError::SenderRecoveryError)?,
)?;
provider_rw.write_state(
&execution_outcome,
OriginalValuesKnown::No,
StorageLocation::Database,
)?;
let storage_lists = provider_rw.changed_storages_with_range(block.number..=block.number)?;
let storage_lists =
provider_rw.changed_storages_with_range(block.number..=block.number())?;
let storages = provider_rw.plain_state_storages(storage_lists)?;
provider_rw.insert_storage_for_hashing(storages)?;
let account_lists = provider_rw.changed_accounts_with_range(block.number..=block.number)?;
let account_lists =
provider_rw.changed_accounts_with_range(block.number..=block.number())?;
let accounts = provider_rw.basic_accounts(account_lists)?;
provider_rw.insert_account_for_hashing(accounts)?;

let (state_root, incremental_trie_updates) = StateRoot::incremental_root_with_updates(
provider_rw.tx_ref(),
block.number..=block.number,
block.number..=block.number(),
)?;
if state_root != block.state_root {
if state_root != block.state_root() {
eyre::bail!(
"Computed incremental state root mismatch. Expected: {:?}. Got: {:?}",
block.state_root,
Expand Down
12 changes: 6 additions & 6 deletions bin/reth/src/commands/debug_cmd/merkle.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! Command for debugging merkle tree calculation.
use crate::{args::NetworkArgs, utils::get_single_header};
use alloy_consensus::BlockHeader;
use alloy_eips::BlockHashOrNumber;
use backon::{ConstantBuilder, Retryable};
use clap::Parser;
Expand Down Expand Up @@ -128,7 +129,7 @@ impl<C: ChainSpecParser<ChainSpec = ChainSpec>> Command<C> {
info!(target: "reth::cli", target_block_number=self.to, "Finished downloading tip of block range");

// build the full block client
let consensus: Arc<dyn Consensus<Error = ConsensusError>> =
let consensus: Arc<dyn Consensus<BlockTy<N>, Error = ConsensusError>> =
Arc::new(EthBeaconConsensus::new(provider_factory.chain_spec()));
let block_range_client = FullBlockClient::new(fetch_client, consensus);

Expand All @@ -153,18 +154,17 @@ impl<C: ChainSpecParser<ChainSpec = ChainSpec>> Command<C> {

for block in blocks.into_iter().rev() {
let block_number = block.number;
let sealed_block = block
.try_with_senders::<BlockTy<N>>()
.map_err(|block| eyre::eyre!("Error sealing block with senders: {block:?}"))?;
let sealed_block =
block.try_recover().map_err(|_| eyre::eyre!("Error sealing block with senders"))?;
trace!(target: "reth::cli", block_number, "Executing block");

provider_rw.insert_block(sealed_block.clone(), StorageLocation::Database)?;

td += sealed_block.difficulty;
td += sealed_block.difficulty();
let mut executor = executor_provider.batch_executor(StateProviderDatabase::new(
LatestStateProviderRef::new(&provider_rw),
));
executor.execute_and_verify_one(&sealed_block.clone().unseal())?;
executor.execute_and_verify_one(&sealed_block)?;
let execution_outcome = executor.finalize();

provider_rw.write_state(
Expand Down
4 changes: 2 additions & 2 deletions crates/cli/commands/src/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use reth_network_p2p::{
bodies::downloader::BodyDownloader,
headers::downloader::{HeaderDownloader, SyncTarget},
};
use reth_node_api::{BlockTy, BodyTy, HeaderTy};
use reth_node_api::BlockTy;
use reth_node_core::version::SHORT_VERSION;
use reth_node_events::node::NodeEvent;
use reth_provider::{
Expand Down Expand Up @@ -169,7 +169,7 @@ pub fn build_import_pipeline<N, C, E>(
) -> eyre::Result<(Pipeline<N>, impl Stream<Item = NodeEvent<N::Primitives>>)>
where
N: ProviderNodeTypes + CliNodeTypes,
C: Consensus<HeaderTy<N>, BodyTy<N>, Error = ConsensusError> + 'static,
C: Consensus<BlockTy<N>, Error = ConsensusError> + 'static,
E: BlockExecutorProvider<Primitives = N::Primitives>,
{
if !file_client.has_canonical_blocks() {
Expand Down
13 changes: 6 additions & 7 deletions crates/cli/commands/src/init_state/without_evm.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
use alloy_consensus::{BlockHeader, Header};
use alloy_primitives::{BlockNumber, B256, U256};
use alloy_rlp::Decodable;

use alloy_consensus::{BlockHeader, Header};
use reth_codecs::Compact;
use reth_node_builder::NodePrimitives;
use reth_primitives::{SealedBlock, SealedBlockWithSenders, SealedHeader, StaticFileSegment};
use reth_primitives::{SealedBlock, SealedHeader, StaticFileSegment};
use reth_provider::{
providers::StaticFileProvider, BlockWriter, StageCheckpointWriter, StaticFileProviderFactory,
StaticFileWriter, StorageLocation,
};
use reth_stages::{StageCheckpoint, StageId};

use std::{fs::File, io::Read, path::PathBuf};
use tracing::info;

Expand Down Expand Up @@ -69,10 +67,11 @@ where
+ StaticFileProviderFactory<Primitives: NodePrimitives<BlockHeader: Compact>>,
{
provider_rw.insert_block(
SealedBlockWithSenders::try_new_unhashed(
SealedBlock::new(header.clone(), Default::default()),
vec![],
SealedBlock::<<Provider::Primitives as NodePrimitives>::Block>::from_sealed_parts(
header.clone(),
Default::default(),
)
.try_recover()
.expect("no senders or txes"),
StorageLocation::Database,
)?;
Expand Down
4 changes: 2 additions & 2 deletions crates/e2e-test-utils/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use eyre::Ok;
use futures_util::Future;
use reth_chainspec::EthereumHardforks;
use reth_network_api::test_utils::PeersHandleProvider;
use reth_node_api::{Block, BlockTy, EngineTypes, FullNodeComponents};
use reth_node_api::{Block, BlockBody, BlockTy, EngineTypes, FullNodeComponents};
use reth_node_builder::{rpc::RethRpcAddOns, FullNode, NodeTypes, NodeTypesWithEngine};
use reth_node_core::primitives::SignedTransaction;
use reth_payload_primitives::{BuiltPayload, PayloadBuilderAttributes};
Expand Down Expand Up @@ -232,7 +232,7 @@ where
// get head block from notifications stream and verify the tx has been pushed to the
// pool is actually present in the canonical block
let head = self.engine_api.canonical_stream.next().await.unwrap();
let tx = head.tip().transactions().first();
let tx = head.tip().body().transactions().first();
assert_eq!(tx.unwrap().tx_hash().as_slice(), tip_tx_hash.as_slice());

loop {
Expand Down
4 changes: 2 additions & 2 deletions crates/ethereum/node/tests/e2e/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use alloy_genesis::Genesis;
use alloy_primitives::{b256, hex};
use futures::StreamExt;
use reth_chainspec::ChainSpec;
use reth_node_api::{FullNodeComponents, FullNodePrimitives, NodeTypes};
use reth_node_api::{Block, BlockBody, FullNodeComponents, FullNodePrimitives, NodeTypes};
use reth_node_builder::{
rpc::RethRpcAddOns, EngineNodeLauncher, FullNode, NodeBuilder, NodeConfig, NodeHandle,
};
Expand Down Expand Up @@ -65,7 +65,7 @@ where

let head = notifications.next().await.unwrap();

let tx = &head.tip().transactions()[0];
let tx = &head.tip().body().transactions()[0];
assert_eq!(tx.trie_hash(), hash);
println!("mined transaction: {hash}");
}
Expand Down
3 changes: 1 addition & 2 deletions crates/exex/test-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,7 @@ pub async fn test_exex_context_with_chain_spec(
.block_by_hash(genesis_hash)?
.ok_or_else(|| eyre::eyre!("genesis block not found"))?
.seal_slow()
.try_with_senders::<reth_primitives::Block>()
.ok_or_else(|| eyre::eyre!("failed to recover senders"))?;
.try_recover()?;

let head = Head {
number: genesis.number,
Expand Down
7 changes: 6 additions & 1 deletion crates/net/downloaders/src/file_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use reth_network_p2p::{
error::RequestError,
headers::client::{HeadersClient, HeadersDirection, HeadersFut, HeadersRequest},
priority::Priority,
BlockClient,
};
use reth_network_peers::PeerId;
use reth_primitives::SealedHeader;
Expand Down Expand Up @@ -40,7 +41,7 @@ pub const DEFAULT_BYTE_LEN_CHUNK_CHAIN_FILE: u64 = 1_000_000_000;
/// transactions in memory for use in the bodies stage.
///
/// This reads the entire file into memory, so it is not suitable for large files.
#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct FileClient<B: Block = reth_primitives::Block> {
/// The buffered headers retrieved when fetching new bodies.
headers: HashMap<BlockNumber, B::Header>,
Expand Down Expand Up @@ -350,6 +351,10 @@ impl<B: FullBlock> DownloadClient for FileClient<B> {
}
}

impl<B: FullBlock> BlockClient for FileClient<B> {
type Block = B;
}

/// Chunks file into several [`FileClient`]s.
#[derive(Debug)]
pub struct ChunkedFileReader {
Expand Down
5 changes: 2 additions & 3 deletions crates/optimism/node/src/txpool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,10 +400,9 @@ where
self.validate_all(transactions)
}

fn on_new_head_block<H, B>(&self, new_tip_block: &SealedBlock<H, B>)
fn on_new_head_block<B>(&self, new_tip_block: &SealedBlock<B>)
where
H: reth_primitives_traits::BlockHeader,
B: BlockBody,
B: Block,
{
self.inner.on_new_head_block(new_tip_block);
self.update_l1_block_info(
Expand Down
3 changes: 1 addition & 2 deletions crates/optimism/rpc/src/eth/pending_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ where
.provider()
.block_with_senders(block_id, Default::default())
.map_err(Self::Error::from_eth_err)?
.ok_or(EthApiError::HeaderNotFound(block_id.into()))?
.seal_unchecked(latest.hash());
.ok_or(EthApiError::HeaderNotFound(block_id.into()))?;

let receipts = self
.provider()
Expand Down
1 change: 1 addition & 0 deletions crates/optimism/rpc/src/eth/receipt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use reth_optimism_chainspec::OpChainSpec;
use reth_optimism_evm::RethL1BlockInfo;
use reth_optimism_forks::OpHardforks;
use reth_optimism_primitives::{OpReceipt, OpTransactionSigned};
use reth_primitives_traits::Block;
use reth_provider::{ChainSpecProvider, ReceiptProvider, TransactionsProvider};
use reth_rpc_eth_api::{helpers::LoadReceipt, FromEthApiError, RpcReceipt};
use reth_rpc_eth_types::{receipt::build_receipt, EthApiError};
Expand Down
Loading

0 comments on commit 252f6b1

Please sign in to comment.