feat: add --nat flag to reth node (#888)

Co-authored-by: Georgios Konstantopoulos <me@gakonst.com>
This commit is contained in:
Ikechukwu Ahiara Marvellous
2023-01-18 02:53:15 +01:00
committed by GitHub
parent dba3b30a42
commit 37ca7e0b33
4 changed files with 12 additions and 0 deletions

View File

@ -24,6 +24,8 @@ reth-network-api = {path = "../../crates/net/network-api" }
reth-downloaders = {path = "../../crates/net/downloaders" }
reth-cli-utils = { path = "../../crates/cli/utils" }
reth-tracing = { path = "../../crates/tracing" }
reth-net-nat = { path = "../../crates/net/nat" }
reth-discv4 = { path = "../../crates/net/discv4" }
# tracing
tracing = "0.1"

View File

@ -2,6 +2,7 @@
use std::sync::Arc;
use reth_db::database::Database;
use reth_discv4::Discv4Config;
use reth_network::{
config::{mainnet_nodes, rng_secret_key},
NetworkConfig, PeersConfig,
@ -29,6 +30,7 @@ impl Config {
chain_spec: ChainSpec,
disable_discovery: bool,
bootnodes: Option<Vec<NodeRecord>>,
nat_resolution_method: reth_net_nat::NatResolver,
) -> NetworkConfig<ProviderImpl<DB>> {
let peer_config = reth_network::PeersConfig::default()
.with_trusted_nodes(self.peers.trusted_nodes.clone())
@ -36,6 +38,7 @@ impl Config {
NetworkConfig::builder(Arc::new(ProviderImpl::new(db)), rng_secret_key())
.boot_nodes(bootnodes.unwrap_or_else(mainnet_nodes))
.peer_config(peer_config)
.discovery(Discv4Config::builder().external_ip_resolver(Some(nat_resolution_method)))
.chain_spec(chain_spec)
.set_discovery(disable_discovery)
.build()

View File

@ -16,6 +16,7 @@ use reth_cli_utils::init::init_genesis;
use reth_consensus::BeaconConsensus;
use reth_downloaders::{bodies, headers};
use reth_interfaces::consensus::ForkchoiceState;
use reth_net_nat::NatResolver;
use reth_network::NetworkEvent;
use reth_network_api::NetworkInfo;
use reth_primitives::{BlockNumber, ChainSpec, NodeRecord, H256};
@ -83,6 +84,9 @@ pub struct Command {
#[arg(long, value_delimiter = ',')]
bootnodes: Option<Vec<NodeRecord>>,
#[arg(long, default_value = "any")]
nat: NatResolver,
}
impl Command {
@ -126,6 +130,7 @@ impl Command {
self.chain.clone(),
self.network.disable_discovery,
self.bootnodes.clone(),
self.nat,
)
.start_network()
.await?;