Skip to content

Conversation

@GheisMohammadi
Copy link
Collaborator

@GheisMohammadi GheisMohammadi commented Oct 30, 2025

This PR refines how trusted peers are sourced and maintained by the P2P host. If the configuration does not provide enough concrete trusted nodes, the host now expands DNS-based sources (dnsaddr) and randomly selects only as many peers as needed to meet the staged stream sync minimum. This avoids over-connecting while ensuring the stream manager has sufficient stable peers to begin and sustain syncing.

Trusted node initialization is centralized to ensure correctness and observability. Concrete multiaddrs are parsed and connected directly, while dnsaddr sources are resolved into peer candidates and sampled to fill the gap up to the configured minimum. The host marks these peers as trusted, seeds the peerstore, and attempts connections so that the stream manager can proactively establish and preserve streams with them.

The update also fixes issues where trusted nodes were added without being marked trusted or without connection attempts, and it introduces detailed logs covering the full lifecycle—from identifying trusted sources and fallback decisions, through DNS resolution, selection, and connection results. This should make diagnosing trusted-node bootstrap problems straightforward in testing and production.

Configuration Changes

  • TrustedNodes has been moved from Network settings to Sync settings for better organization
  • A new DNSStaticNodes configuration option has been added under Sync settings to support dnsaddr-based trusted peer sources (e.g., ["/dnsaddr/_dnsaddr.trusted.s0.ps.hmny.io"])

New Metrics

The PR introduces Prometheus metrics to observe trusted-node behavior over time:

P2P Host Level Metrics (hmy_p2p_*)

  • hmy_p2p_trusted_peers (Gauge) - Current number of trusted peers configured at the P2P host level (libp2p peer connections)
  • hmy_p2p_trusted_peers_added_total (Counter) - Total number of trusted peers successfully added and connected at the P2P host level
  • hmy_p2p_trusted_dns_resolved_total (Counter) - Total number of trusted peer candidates resolved from DNS-based multiaddr sources (dnsaddr)
  • hmy_p2p_trusted_peer_connect_failures_total (Counter) - Total number of failed attempts to establish P2P host-level connections with trusted peers

Stream Manager Level Metrics (hmy_stream_*)

  • hmy_stream_num_trusted_peer_streams (GaugeVec, label: topic) - Current number of active trusted peer streams (streams established with trusted peers and added to main list)
  • hmy_stream_num_reserved_trusted_peer_streams (GaugeVec, label: topic) - Current number of reserved trusted peer streams (streams established with trusted peers and added to reserved list)
  • hmy_stream_trusted_peer_streams_added_total (CounterVec, label: topic) - Total number of trusted peer streams successfully added to the stream manager
  • hmy_stream_trusted_peer_streams_setup_attempts_total (CounterVec, label: topic) - Total number of attempts to setup streams with trusted peers (includes both successful and failed attempts)
  • hmy_stream_trusted_peer_streams_connect_failures_total (CounterVec, label: topic) - Total number of failed attempts to establish streams with trusted peers

@GheisMohammadi GheisMohammadi self-assigned this Oct 30, 2025
@GheisMohammadi GheisMohammadi added the libp2p Peer to Peer networking label Oct 30, 2025
@GheisMohammadi GheisMohammadi marked this pull request as draft October 30, 2025 13:31
@GheisMohammadi GheisMohammadi force-pushed the fix/trusted_nodes branch 2 times, most recently from 52d9bfe to ab03adc Compare October 31, 2025 18:09
@GheisMohammadi GheisMohammadi marked this pull request as ready for review November 3, 2025 23:55
@mur-me
Copy link
Collaborator

mur-me commented Nov 4, 2025

Hey @GheisMohammadi, please take a look on tests 🙏

@GheisMohammadi
Copy link
Collaborator Author

Hey @GheisMohammadi, please take a look on tests 🙏

Fixed

@GheisMohammadi GheisMohammadi requested a review from mur-me November 6, 2025 15:14
@GheisMohammadi GheisMohammadi merged commit 922ec9f into dev Nov 18, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

libp2p Peer to Peer networking

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants