mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 19:09:54 +00:00
chore: simplify p2p subcommand (#9265)
This commit is contained in:
@ -12,12 +12,10 @@ use backon::{ConstantBuilder, Retryable};
|
||||
use clap::{Parser, Subcommand};
|
||||
use reth_chainspec::ChainSpec;
|
||||
use reth_config::Config;
|
||||
use reth_db::create_db;
|
||||
use reth_network::NetworkConfigBuilder;
|
||||
use reth_network_p2p::bodies::client::BodiesClient;
|
||||
use reth_node_core::args::DatadirArgs;
|
||||
use reth_primitives::BlockHashOrNumber;
|
||||
use reth_provider::{providers::StaticFileProvider, ProviderFactory};
|
||||
use std::{path::PathBuf, sync::Arc};
|
||||
|
||||
/// `reth p2p` command
|
||||
@ -75,10 +73,6 @@ pub enum Subcommands {
|
||||
impl Command {
|
||||
/// Execute `p2p` command
|
||||
pub async fn execute(&self) -> eyre::Result<()> {
|
||||
let tempdir = tempfile::TempDir::new()?;
|
||||
let noop_db = Arc::new(create_db(tempdir.into_path(), self.db.database_args())?);
|
||||
|
||||
// add network name to data dir
|
||||
let data_dir = self.datadir.clone().resolve_datadir(self.chain.chain);
|
||||
let config_path = self.config.clone().unwrap_or_else(|| data_dir.config());
|
||||
|
||||
@ -101,7 +95,7 @@ impl Command {
|
||||
let rlpx_socket = (self.network.addr, self.network.port).into();
|
||||
let boot_nodes = self.chain.bootnodes().unwrap_or_default();
|
||||
|
||||
let network = NetworkConfigBuilder::new(p2p_secret_key)
|
||||
let net = NetworkConfigBuilder::new(p2p_secret_key)
|
||||
.peer_config(config.peers_config_with_basic_nodes_from_file(None))
|
||||
.external_ip_resolver(self.network.nat)
|
||||
.chain_spec(self.chain.clone())
|
||||
@ -110,13 +104,11 @@ impl Command {
|
||||
.apply(|builder| {
|
||||
self.network.discovery.apply_to_builder(builder, rlpx_socket, boot_nodes)
|
||||
})
|
||||
.build(Arc::new(ProviderFactory::new(
|
||||
noop_db,
|
||||
self.chain.clone(),
|
||||
StaticFileProvider::read_write(data_dir.static_files())?,
|
||||
)))
|
||||
.start_network()
|
||||
.build_with_noop_provider()
|
||||
.manager()
|
||||
.await?;
|
||||
let network = net.handle().clone();
|
||||
tokio::task::spawn(net);
|
||||
|
||||
let fetch_client = network.fetch_client().await?;
|
||||
let retries = self.retries.max(1);
|
||||
@ -14,7 +14,7 @@ use reth_eth_wire::{HelloMessage, HelloMessageWithProtocols, Status};
|
||||
use reth_network_peers::{mainnet_nodes, pk2id, sepolia_nodes, PeerId, TrustedPeer};
|
||||
use reth_network_types::{PeersConfig, SessionsConfig};
|
||||
use reth_primitives::{ForkFilter, Head};
|
||||
use reth_storage_api::{BlockReader, HeaderProvider};
|
||||
use reth_storage_api::{BlockNumReader, BlockReader, HeaderProvider};
|
||||
use reth_tasks::{TaskSpawner, TokioTaskExecutor};
|
||||
use secp256k1::SECP256K1;
|
||||
use std::{collections::HashSet, net::SocketAddr, sync::Arc};
|
||||
@ -119,6 +119,16 @@ impl<C> NetworkConfig<C> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<C> NetworkConfig<C>
|
||||
where
|
||||
C: BlockNumReader,
|
||||
{
|
||||
/// Convenience method for calling [`NetworkManager::new`].
|
||||
pub async fn manager(self) -> Result<NetworkManager<C>, NetworkError> {
|
||||
NetworkManager::new(self).await
|
||||
}
|
||||
}
|
||||
|
||||
impl<C> NetworkConfig<C>
|
||||
where
|
||||
C: BlockReader + HeaderProvider + Clone + Unpin + 'static,
|
||||
|
||||
Reference in New Issue
Block a user