fix: implement periodic peer discovery without connection failure tracking#650
Merged
mergify[bot] merged 13 commits intosigp:release-v1.0.0from Oct 7, 2025
Conversation
Increases max_keep_files for libp2p.log and discv5.log from 1 to 5. This provides better debugging history without excessive disk usage (~500MB max for both logs combined at 100MB each).
- Add clarifying comments for ENR subnet state management - Upgrade log level from debug to info for subnet updates (important state changes) - Document that subnet bitfield is populated dynamically via gossipsub subscriptions
Logs the subnets bitfield when initiating handshakes to help debug subnet-based peering issues.
Adds intelligent failure tracking to prevent repeated connection attempts to persistently failing peers while avoiding memory leaks. Features: - Blacklist peers after 5 consecutive failures - 1-hour expiration for automatic retry - Hard limit of 1000 records (defense-in-depth) - Periodic cleanup in heartbeat - Auto-clear on successful connection Tested over 2 hours: Connection errors reduced 97% (2,358 → ~60)
…d peers Implements custom ENR to multiaddr conversion that only returns TCP and QUIC addresses that libp2p can actually use, avoiding wasted connection attempts. Changes: - Add enr_to_multiaddrs() function for TCP/QUIC extraction - Skip plain UDP addresses (not usable by libp2p) - Skip blacklisted peers in subnet peer selection - Properly handle both IPv4 and IPv6 addresses This reduces unnecessary connection attempts and respects the failure tracking.
Exposes connection state and failure tracking methods needed by the network event loop, and integrates periodic cleanup in the heartbeat. Changes: - Add connected_peers() accessor - Add record_connection_failure() method - Call cleanup_expired_failures() in heartbeat (every 30s) This completes the peer management infrastructure for periodic discovery.
…dling Fixes peer count plateau by triggering discovery every 30s when below target. Previously discovery only ran once at startup, limiting peer growth to 12-14. Changes: - Add periodic discovery check in heartbeat (every 30s) - Log connection errors at debug level (normal P2P behavior) - Record connection failures for blacklist system - Simplify subnet metadata update with match statement - Add structured logging for subnet bitfield changes Tested over 2 hours: 4→30 peers (650% increase), connection errors reduced 97%
Addresses Copilot review feedback - replace inline blacklist check with dedicated method to improve code maintainability and avoid duplication.
Track and log inbound vs outbound peer connections by: - Adding counters for inbound_count and outbound_count - Using endpoint.is_dialer() from ConnectionEstablished/Closed events - Displaying counts in Network status heartbeat logs This provides better visibility into connection patterns without needing to maintain additional HashMaps of peer IDs. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Replace custom enr_to_multiaddrs() with EnrExt trait methods to get only TCP and QUIC addresses (excludes plain UDP).
…cking Implements periodic peer discovery to maintain target peer count without the connection failure blacklist mechanism. Core changes: - Trigger peer discovery every 30s when below target peer count - Track inbound vs outbound connection counts for metrics - Log connection errors at debug level (normal P2P behavior) This approach focuses on proactive peer discovery rather than reactive blacklisting of failing peers.
Changes periodic discovery from generic peer discovery to subnet-aware discovery, preventing connections from being denied due to MissingNeededSubnets. Root cause: - Generic discover_peers() found ANY peers on the network - We dialed peers that didn't offer our needed subnets - Connection was accepted initially but then denied with MissingNeededSubnets - This created a cycle of discovery -> dial -> deny Solution: - Use start_subnet_query() instead to filter by needed subnets - Only discover and dial peers that offer subnets we actually need - Aligns with existing subnet-aware discovery used elsewhere This complements the existing per-subnet discovery (which ensures minimum peers per subnet) by helping reach overall target peer count through subnet-filtered discovery of all needed subnets simultaneously.
petarjuki7
pushed a commit
to petarjuki7/anchor
that referenced
this pull request
Oct 16, 2025
…cking (sigp#650) Fixes peer count plateau and connection denial issues caused by generic discovery attempting to connect to peers without needed subnets. ### Subnet-Aware Periodic Discovery - Trigger discovery every 30s when peer count is below target - **Uses subnet filtering** via `start_subnet_query()` instead of generic `discover_peers()` - Only discovers and dials peers that offer our needed subnets - Prevents `MissingNeededSubnets` connection denials ### Connection Metrics - Track inbound vs outbound connection counts - Provides visibility into connection direction distribution - Helps monitor peer connectivity patterns ### Logging Improvements - Connection errors logged at debug level (normal P2P behavior) - Reduces log noise while maintaining debugging capability - Increased log retention (5 files vs 1) for better historical tracking Co-Authored-By: diego <diego@sigmaprime.io> Co-Authored-By: Age Manning <Age@AgeManning.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue Addressed
Fixes peer count plateau and connection denial issues caused by generic discovery attempting to connect to peers without needed subnets.
Proposed Changes
Subnet-Aware Periodic Discovery
start_subnet_query()instead of genericdiscover_peers()MissingNeededSubnetsconnection denialsConnection Metrics
Logging Improvements
Root Cause Analysis
The original PR #649 added generic
discover_peers()which found ANY peers on the network:MissingNeededSubnetserrorSolution
Use subnet-aware discovery that filters ENRs before dialing:
Additional Info
This PR intentionally excludes the connection failure blacklist mechanism from PR #649 to evaluate a simpler approach.
Two complementary discovery mechanisms:
check_subnet_peers): Ensures minimum 6 peers per subnetComparison with PR #649:
Advantages:
Trade-offs: