Skip to content

Commit

Permalink
feat: add header to stage command (paradigmxyz#10127)
Browse files Browse the repository at this point in the history
  • Loading branch information
greged93 authored Aug 6, 2024
1 parent d29c5a8 commit b01ccc2
Showing 1 changed file with 58 additions and 7 deletions.
65 changes: 58 additions & 7 deletions crates/cli/commands/src/stage/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,24 @@
//!
//! Stage debugging tool
use std::{any::Any, net::SocketAddr, sync::Arc, time::Instant};

use crate::common::{AccessRights, Environment, EnvironmentArgs};
use clap::Parser;
use reth_beacon_consensus::EthBeaconConsensus;
use reth_chainspec::ChainSpec;
use reth_cli_runner::CliContext;
use reth_cli_util::get_secret_key;
use reth_config::config::{HashingConfig, SenderRecoveryConfig, TransactionLookupConfig};
use reth_downloaders::bodies::bodies::BodiesDownloaderBuilder;
use reth_downloaders::{
bodies::bodies::BodiesDownloaderBuilder,
headers::reverse_headers::ReverseHeadersDownloaderBuilder,
};
use reth_evm::execute::BlockExecutorProvider;
use reth_exex::ExExManagerHandle;
use reth_network::BlockDownloaderProvider;
use reth_network_p2p::HeadersClient;
use reth_node_core::{
args::{NetworkArgs, StageEnum},
primitives::BlockHashOrNumber,
version::{
BUILD_PROFILE_NAME, CARGO_PKG_VERSION, VERGEN_BUILD_TIMESTAMP, VERGEN_CARGO_FEATURES,
VERGEN_CARGO_TARGET_TRIPLE, VERGEN_GIT_SHA,
Expand All @@ -32,16 +36,17 @@ use reth_provider::{
};
use reth_stages::{
stages::{
AccountHashingStage, BodyStage, ExecutionStage, IndexAccountHistoryStage,
AccountHashingStage, BodyStage, ExecutionStage, HeaderStage, IndexAccountHistoryStage,
IndexStorageHistoryStage, MerkleStage, SenderRecoveryStage, StorageHashingStage,
TransactionLookupStage,
},
ExecInput, ExecOutput, ExecutionStageThresholds, Stage, StageExt, UnwindInput, UnwindOutput,
ExecInput, ExecOutput, ExecutionStageThresholds, Stage, StageError, StageExt, UnwindInput,
UnwindOutput,
};
use std::{any::Any, net::SocketAddr, sync::Arc, time::Instant};
use tokio::sync::watch;
use tracing::*;

use crate::common::{AccessRights, Environment, EnvironmentArgs};

/// `reth stage` command
#[derive(Debug, Parser)]
pub struct Command {
Expand Down Expand Up @@ -138,6 +143,52 @@ impl Command {

let (mut exec_stage, mut unwind_stage): (Box<dyn Stage<_>>, Option<Box<dyn Stage<_>>>) =
match self.stage {
StageEnum::Headers => {
let consensus =
Arc::new(EthBeaconConsensus::new(provider_factory.chain_spec()));

let network_secret_path = self
.network
.p2p_secret_key
.clone()
.unwrap_or_else(|| data_dir.p2p_secret());
let p2p_secret_key = get_secret_key(&network_secret_path)?;

let default_peers_path = data_dir.known_peers();

let network = self
.network
.network_config(
&config,
provider_factory.chain_spec(),
p2p_secret_key,
default_peers_path,
)
.build(provider_factory.clone())
.start_network()
.await?;
let fetch_client = Arc::new(network.fetch_client().await?);

// Use `to` as the tip for the stage
let tip = fetch_client
.get_header(BlockHashOrNumber::Number(self.to))
.await?
.into_data()
.ok_or(StageError::MissingSyncGap)?;
let (_, rx) = watch::channel(tip.hash_slow());

(
Box::new(HeaderStage::new(
provider_factory.clone(),
ReverseHeadersDownloaderBuilder::new(config.stages.headers)
.build(fetch_client, consensus.clone()),
rx,
consensus,
etl_config,
)),
None,
)
}
StageEnum::Bodies => {
let consensus =
Arc::new(EthBeaconConsensus::new(provider_factory.chain_spec()));
Expand Down

0 comments on commit b01ccc2

Please sign in to comment.