mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat: Pseudo peer and staged sync
For simplicity, we use with_pow() + pseudo peer that connects to reth itself, so that it can support 1. StateFetcher via NetworkState 2. Block announcement (which requires with_pow()). For block announcement, another way was using ImportService like before, or calling engine_api. But for simplicitiy, for now we just publish from pseudo peer like pre-PoS, hence with_pow().
This commit is contained in:
@ -3,8 +3,9 @@ use crate::{
|
||||
node::{
|
||||
consensus::HlConsensus, evm::config::HlEvmConfig, network::HlNetworkPrimitives, HlNode,
|
||||
},
|
||||
pseudo_peer::BlockSourceArgs,
|
||||
};
|
||||
use clap::Parser;
|
||||
use clap::{Args, Parser};
|
||||
use reth::{
|
||||
args::LogArgs,
|
||||
builder::{NodeBuilder, WithLaunchContext},
|
||||
@ -15,7 +16,7 @@ use reth::{
|
||||
};
|
||||
use reth_chainspec::EthChainSpec;
|
||||
use reth_cli::chainspec::ChainSpecParser;
|
||||
use reth_cli_commands::{launcher::FnLauncher, node::NoArgs};
|
||||
use reth_cli_commands::launcher::FnLauncher;
|
||||
use reth_db::DatabaseEnv;
|
||||
use reth_tracing::FileWorkerGuard;
|
||||
use std::{
|
||||
@ -25,12 +26,20 @@ use std::{
|
||||
};
|
||||
use tracing::info;
|
||||
|
||||
#[derive(Debug, Clone, Args)]
|
||||
#[non_exhaustive]
|
||||
pub struct HlNodeArgs {
|
||||
#[command(flatten)]
|
||||
pub block_source_args: BlockSourceArgs,
|
||||
}
|
||||
|
||||
/// The main reth_hl cli interface.
|
||||
///
|
||||
/// This is the entrypoint to the executable.
|
||||
#[derive(Debug, Parser)]
|
||||
#[command(author, version = SHORT_VERSION, long_version = LONG_VERSION, about = "Reth", long_about = None)]
|
||||
pub struct Cli<Spec: ChainSpecParser = HlChainSpecParser, Ext: clap::Args + fmt::Debug = NoArgs> {
|
||||
pub struct Cli<Spec: ChainSpecParser = HlChainSpecParser, Ext: clap::Args + fmt::Debug = HlNodeArgs>
|
||||
{
|
||||
/// The command to run
|
||||
#[command(subcommand)]
|
||||
pub command: Commands<Spec, Ext>,
|
||||
|
||||
@ -12,6 +12,7 @@ use crate::{
|
||||
},
|
||||
storage::HlStorage,
|
||||
},
|
||||
pseudo_peer::BlockSourceConfig,
|
||||
};
|
||||
use consensus::HlConsensusBuilder;
|
||||
use engine::HlPayloadServiceBuilder;
|
||||
@ -49,12 +50,15 @@ pub type HlNodeAddOns<N> =
|
||||
pub struct HlNode {
|
||||
engine_handle_rx:
|
||||
Arc<Mutex<Option<oneshot::Receiver<BeaconConsensusEngineHandle<HlPayloadTypes>>>>>,
|
||||
block_source_config: BlockSourceConfig,
|
||||
}
|
||||
|
||||
impl HlNode {
|
||||
pub fn new() -> (Self, oneshot::Sender<BeaconConsensusEngineHandle<HlPayloadTypes>>) {
|
||||
pub fn new(
|
||||
block_source_config: BlockSourceConfig,
|
||||
) -> (Self, oneshot::Sender<BeaconConsensusEngineHandle<HlPayloadTypes>>) {
|
||||
let (tx, rx) = oneshot::channel();
|
||||
(Self { engine_handle_rx: Arc::new(Mutex::new(Some(rx))) }, tx)
|
||||
(Self { engine_handle_rx: Arc::new(Mutex::new(Some(rx))), block_source_config }, tx)
|
||||
}
|
||||
}
|
||||
|
||||
@ -79,7 +83,10 @@ impl HlNode {
|
||||
.pool(HlPoolBuilder)
|
||||
.executor(HlExecutorBuilder::default())
|
||||
.payload(HlPayloadServiceBuilder::default())
|
||||
.network(HlNetworkBuilder { engine_handle_rx: self.engine_handle_rx.clone() })
|
||||
.network(HlNetworkBuilder {
|
||||
engine_handle_rx: self.engine_handle_rx.clone(),
|
||||
block_source_config: self.block_source_config.clone(),
|
||||
})
|
||||
.consensus(HlConsensusBuilder::default())
|
||||
}
|
||||
}
|
||||
|
||||
@ -8,6 +8,7 @@ use crate::{
|
||||
types::ReadPrecompileCalls,
|
||||
HlNode,
|
||||
},
|
||||
pseudo_peer::{start_pseudo_peer, BlockSourceConfig},
|
||||
HlBlock,
|
||||
};
|
||||
use alloy_rlp::{Decodable, Encodable};
|
||||
@ -149,6 +150,8 @@ pub type HlNetworkPrimitives =
|
||||
pub struct HlNetworkBuilder {
|
||||
pub(crate) engine_handle_rx:
|
||||
Arc<Mutex<Option<oneshot::Receiver<BeaconConsensusEngineHandle<HlPayloadTypes>>>>>,
|
||||
|
||||
pub(crate) block_source_config: BlockSourceConfig,
|
||||
}
|
||||
|
||||
impl HlNetworkBuilder {
|
||||
@ -162,7 +165,7 @@ impl HlNetworkBuilder {
|
||||
where
|
||||
Node: FullNodeTypes<Types = HlNode>,
|
||||
{
|
||||
let Self { engine_handle_rx } = self;
|
||||
let Self { engine_handle_rx, .. } = self;
|
||||
|
||||
let network_builder = ctx.network_config_builder()?;
|
||||
|
||||
@ -185,6 +188,8 @@ impl HlNetworkBuilder {
|
||||
});
|
||||
|
||||
let network_builder = network_builder
|
||||
.disable_dns_discovery()
|
||||
.disable_nat()
|
||||
.boot_nodes(boot_nodes())
|
||||
.set_head(ctx.head())
|
||||
.with_pow()
|
||||
@ -216,10 +221,17 @@ where
|
||||
ctx: &BuilderContext<Node>,
|
||||
pool: Pool,
|
||||
) -> eyre::Result<Self::Network> {
|
||||
let block_source_config = self.block_source_config.clone();
|
||||
let network_config = self.network_config(ctx)?;
|
||||
let network = NetworkManager::builder(network_config).await?;
|
||||
let handle = ctx.start_network(network, pool);
|
||||
info!(target: "reth::cli", enode=%handle.local_node_record(), "P2P networking initialized");
|
||||
let local_node_record = handle.local_node_record();
|
||||
info!(target: "reth::cli", enode=%local_node_record, "P2P networking initialized");
|
||||
|
||||
ctx.task_executor().spawn_critical("pseudo peer", async move {
|
||||
let block_source = block_source_config.create_cached_block_source().await;
|
||||
start_pseudo_peer(local_node_record.to_string(), block_source).await.unwrap();
|
||||
});
|
||||
|
||||
Ok(handle)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user