From bc25549c5fbce3131edc034a8abb53b13f21664d Mon Sep 17 00:00:00 2001 From: KaffinPX Date: Wed, 5 Aug 2026 23:58:53 +0300 Subject: [PATCH 1/5] feat(node): Avoid multi-hop spam --- node/src/application/network/actor.rs | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/node/src/application/network/actor.rs b/node/src/application/network/actor.rs index 79f6c63..4004c46 100644 --- a/node/src/application/network/actor.rs +++ b/node/src/application/network/actor.rs @@ -21,6 +21,7 @@ use rand::Rng; use tokio::sync::mpsc; use tokio::task::JoinHandle; use tokio::time::Instant; +use tracing::warn; use crate::application::loops::peer_loop::channel::MainToPeerTask; use crate::application::loops::peer_loop::channel::PeerTaskToMain; @@ -1031,25 +1032,6 @@ impl NetworkActor { }; tracing::debug!("{direction} connection established with {peer_id} at {address}."); - // If this address belongs to one of our sticky peers (`--peer` - // CLI arguments) then make sure we record the `PeerId`. - if self.sticky_peers.contains_key(&address) { - self.sticky_peers.entry(address.clone()).and_modify(|p| { - match p { - StickyPeer::None | StickyPeer::Dialing(_) => { - tracing::debug!(%peer_id, "Found peer id of sticky peer {address}."); - *p = StickyPeer::Connected(peer_id); - }, - StickyPeer::Connected(pid) => { - if *pid != peer_id { - tracing::debug!(%peer_id, "Found *new* peer id of sticky peer {address}."); - *pid = peer_id; - } - }, - } - }); - } - // Store the new connection. self.active_connections .entry(peer_id) @@ -2030,6 +2012,10 @@ impl NetworkActor { /// instance if there are not enough active connections without on-going /// relay commitments. fn request_peer_relays(&mut self, num_relays: usize) { + if num_relays == 0 { + return; + } + let current_relays = self.relays.keys().collect::>(); let mut available_peers = self .active_connections From 3b416493fe03305879b5238c63e10280ff7491f0 Mon Sep 17 00:00:00 2001 From: KaffinPX Date: Thu, 6 Aug 2026 00:35:37 +0300 Subject: [PATCH 2/5] feat(node): Decrease level of spammy log --- node/src/application/network/actor.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node/src/application/network/actor.rs b/node/src/application/network/actor.rs index 4004c46..621192d 100644 --- a/node/src/application/network/actor.rs +++ b/node/src/application/network/actor.rs @@ -735,7 +735,7 @@ impl NetworkActor { .count() > 1; if is_multihop { - tracing::warn!( + tracing::debug!( "Rejecting multi-hop listen address {address} because multi-hop." ); return Ok(()); From 934f871ba6f7051708046af05b9f5f1f7b31e4ca Mon Sep 17 00:00:00 2001 From: KaffinPX Date: Thu, 6 Aug 2026 03:50:05 +0300 Subject: [PATCH 3/5] feat(node): Change P2P ports and remove unused argument --- node/src/application/config/cli_args.rs | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/node/src/application/config/cli_args.rs b/node/src/application/config/cli_args.rs index cae32c7..d7463bb 100644 --- a/node/src/application/config/cli_args.rs +++ b/node/src/application/config/cli_args.rs @@ -12,13 +12,13 @@ use clap::Parser; use libp2p::multiaddr::Protocol; use libp2p::Multiaddr; use nyks_consensus::transaction::transaction_proof::TransactionProofQuality; +use nyks_consensus::network::Network; +use nyks_consensus::type_scripts::native_currency_amount::NativeCurrencyAmount; +use nyks_rpc_core::api::ops::Namespace; use tracing::error; use crate::application::config::parser::multiaddr::parse_to_multiaddr; use crate::state::mining::block_proposal::BlockProposalRejectError; -use nyks_consensus::network::Network; -use nyks_consensus::type_scripts::native_currency_amount::NativeCurrencyAmount; -use nyks_rpc_core::api::ops::Namespace; const MAX_NUM_INPUTS_FOR_PC_BACKED_TXS: u64 = 200; @@ -98,15 +98,6 @@ pub struct Args { )] pub(crate) max_num_peers: usize, - /// Maximum number of peers to accept from each IP address. - /// - /// Multiple nodes can run on the same IP address which would either mean - /// that multiple nodes run on the same machine, or multiple machines are - /// on the same network that uses Network Address Translation and has one - /// public IP. - #[clap(long)] - pub(crate) max_connections_per_ip: Option, - /// Handshake timeout in seconds. /// /// The timeout used for all messages received and sent during the handshake @@ -170,11 +161,11 @@ pub struct Args { pub(crate) max_mempool_size: ByteSize, /// Port on which to listen for libp2p QUIC peer connections. - #[clap(long, default_value = "9800", value_name = "PORT")] + #[clap(long, default_value = "27828", value_name = "PORT")] pub quic_port: u16, /// Port on which to listen for libp2p TCP peer connections. - #[clap(long, default_value = "9801", value_name = "PORT")] + #[clap(long, default_value = "27829", value_name = "PORT")] pub tcp_port: u16, /// IP on which to listen for peer connections. Will default to all network From 45424c899dd62e6e203a6fb860019791b1ddfb9a Mon Sep 17 00:00:00 2001 From: KaffinPX Date: Thu, 6 Aug 2026 03:58:12 +0300 Subject: [PATCH 4/5] feat(consensus): Fix off-by one that crash nodes over P2P --- consensus/src/mutator_set/mutator_set_accumulator.rs | 3 ++- node/src/application/network/actor.rs | 7 +++---- node/src/application/network/address_book.rs | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/consensus/src/mutator_set/mutator_set_accumulator.rs b/consensus/src/mutator_set/mutator_set_accumulator.rs index e0f0859..1b1f3d0 100644 --- a/consensus/src/mutator_set/mutator_set_accumulator.rs +++ b/consensus/src/mutator_set/mutator_set_accumulator.rs @@ -102,6 +102,7 @@ impl MutatorSetAccumulator { /// Return the lowest and the highest chunk index that are represented in /// the active window, inclusive. + /// /// The returned limits are inclusive, i.e. they point to the chunk with /// the lowest chunk index and the chunk with the highest chunk index that /// are still contained in the active window. @@ -109,7 +110,7 @@ impl MutatorSetAccumulator { let batch_index = self.get_batch_index(); ( batch_index, - batch_index + u64::from(WINDOW_SIZE / CHUNK_SIZE), + batch_index + u64::from(WINDOW_SIZE / CHUNK_SIZE) - 1, ) } diff --git a/node/src/application/network/actor.rs b/node/src/application/network/actor.rs index 621192d..61a3bce 100644 --- a/node/src/application/network/actor.rs +++ b/node/src/application/network/actor.rs @@ -21,7 +21,6 @@ use rand::Rng; use tokio::sync::mpsc; use tokio::task::JoinHandle; use tokio::time::Instant; -use tracing::warn; use crate::application::loops::peer_loop::channel::MainToPeerTask; use crate::application::loops::peer_loop::channel::PeerTaskToMain; @@ -86,12 +85,12 @@ impl RelayStatus { } } -/// The libp2p adapter for the Neptune network stack. +/// The libp2p adapter for the Nyks network stack. /// /// The [`NetworkActor`] serves as a specialized interface between the libp2p /// network stack and the application's main loop. Unlike typical actor models, /// this struct does not own the primary event loop; instead, it facilitates the -/// transition of libp2p-negotiated connections into the standard Neptune +/// transition of libp2p-negotiated connections into the standard Nyks /// protocol ecosystem. Specifically, it mediates establishment of a libp2p /// stream which it then hijacks and passes to a freshly spawned peer loop. /// @@ -105,7 +104,7 @@ impl RelayStatus { /// the validated [`Stream`](libp2p::Stream) and passes it into a concrete /// protocol handler. /// 3. **Protocol Unified Logic**: It spawns the same peer loop used by the -/// legacy network stack. Consequently Neptune message handling remains +/// legacy network stack. Consequently Nyks message handling remains /// unified regardless of the transport layer. /// /// ### Integration: diff --git a/node/src/application/network/address_book.rs b/node/src/application/network/address_book.rs index 9d075a4..666d599 100644 --- a/node/src/application/network/address_book.rs +++ b/node/src/application/network/address_book.rs @@ -30,11 +30,11 @@ pub(crate) struct Peer { /// Unlike the active connection, these are persistent locations. pub(crate) listen_addresses: Vec, - /// The software version of the node (e.g., "neptune-cash/0.6.0"). + /// The software version of the node (e.g., "nyks-node/0.6.0"). /// Useful for telemetry and identifying "heavy" or "light" nodes. pub(crate) agent_version: String, - /// The protocol version (e.g., "/neptune/-main"). + /// The protocol version (e.g., "/nyks/-main"). /// Essential for ensuring you don't sync with incompatible forks. pub(crate) protocol_version: String, From 7611254ce3aee69c69b9bb2f6a9cf43a38f7d6c4 Mon Sep 17 00:00:00 2001 From: KaffinPX Date: Thu, 6 Aug 2026 03:59:16 +0300 Subject: [PATCH 5/5] feat(node): Terminate sync loop on block validation error --- node/src/application/loops/sync_loop.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/node/src/application/loops/sync_loop.rs b/node/src/application/loops/sync_loop.rs index b28374d..68ed164 100644 --- a/node/src/application/loops/sync_loop.rs +++ b/node/src/application/loops/sync_loop.rs @@ -181,6 +181,7 @@ impl SyncLoop { } SuccessorsToSync::BlockValidationError => { tracing::error!("Block validation error occurred during syncing. Possible cause: a reorg happened while syncing. Terminating sync loop."); + break; } }