From 1acff8bb45659408c03aca5ad408c9eac20fbc4a Mon Sep 17 00:00:00 2001 From: Dan Cline <6798349+Rjected@users.noreply.github.com> Date: Thu, 13 Apr 2023 05:08:09 -0400 Subject: [PATCH] fix: use chain specific net dir for known peers (#2218) --- bin/reth/src/args/network_args.rs | 12 ++++++++---- bin/reth/src/node/mod.rs | 3 +-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/bin/reth/src/args/network_args.rs b/bin/reth/src/args/network_args.rs index c68c2044be..c4b6108e29 100644 --- a/bin/reth/src/args/network_args.rs +++ b/bin/reth/src/args/network_args.rs @@ -4,7 +4,7 @@ use crate::dirs::{KnownPeersPath, PlatformPath}; use clap::Args; use reth_net_nat::NatResolver; use reth_network::NetworkConfigBuilder; -use reth_primitives::{mainnet_nodes, ChainSpec, NodeRecord}; +use reth_primitives::{mainnet_nodes, Chain, ChainSpec, NodeRecord}; use reth_staged_sync::Config; use secp256k1::SecretKey; use std::{path::PathBuf, sync::Arc}; @@ -63,7 +63,7 @@ impl NetworkArgs { let chain_bootnodes = chain_spec.chain.bootnodes().unwrap_or_else(mainnet_nodes); let network_config_builder = config - .network_config(self.nat, self.persistent_peers_file(), secret_key) + .network_config(self.nat, self.persistent_peers_file(chain_spec.chain), secret_key) .boot_nodes(self.bootnodes.clone().unwrap_or(chain_bootnodes)) .chain_spec(chain_spec); @@ -75,11 +75,15 @@ impl NetworkArgs { impl NetworkArgs { /// If `no_persist_peers` is true then this returns the path to the persistent peers file - pub fn persistent_peers_file(&self) -> Option { + /// + /// Uses the input chain to determine a chain-specific path to the known peers file. + pub fn persistent_peers_file(&self, chain: Chain) -> Option { if self.no_persist_peers { return None } - Some(self.peers_file.clone().into()) + + let peers_file = self.peers_file.clone().with_chain(chain); + Some(peers_file.into()) } } diff --git a/bin/reth/src/node/mod.rs b/bin/reth/src/node/mod.rs index b4f6c11250..3c67166ddf 100644 --- a/bin/reth/src/node/mod.rs +++ b/bin/reth/src/node/mod.rs @@ -177,7 +177,6 @@ impl Command { info!(target: "reth::cli", "Test transaction pool initialized"); info!(target: "reth::cli", "Connecting to P2P network"); - // let secret_key_path = self.p2p_secret_key.join(chain_prefix); let secret_key = get_secret_key(&self.p2p_secret_key)?; let network_config = self.load_network_config( &config, @@ -470,7 +469,7 @@ impl Command { .request_handler(client) .split_with_handle(); - let known_peers_file = self.network.persistent_peers_file(); + let known_peers_file = self.network.persistent_peers_file(self.chain.chain); task_executor.spawn_critical_with_signal("p2p network task", |shutdown| { run_network_until_shutdown(shutdown, network, known_peers_file) });