Skip to content

Conversation

diegomrsantos
Copy link
Contributor

@diegomrsantos diegomrsantos commented Jul 16, 2025

This commit fully integrates the peer blocking features from the block-peers branch into the new modular peer manager architecture. Key changes:

Blocking Infrastructure:

  • Add BlockingManager wrapping libp2p-allow-block-list for connection denial
  • Integrate blocking checks into all connection handlers (pending/established)
  • Add automatic peer unblocking after RETAIN_SCORE_EPOCH_MULTIPLIER duration

Score-Based Blocking:

  • Implement check_and_block_peers_by_score() to automatically block peers with gossipsub scores below GRAYLIST_THRESHOLD
  • Integrate peer score checking into heartbeat system for periodic execution
  • Automatically disconnect blocked peers immediately

Connection Prevention:

  • Update should_dial_peer() to check blocked peers before dialing
  • Filter blocked peers in discovery and subnet peer selection
  • Ensure all connection paths respect the blocked peer list

Event System Updates:

  • Replace ConnectActions events with PeerManagerHeartbeat events
  • Consolidate peer management actions and score checking into single heartbeat
  • Update Network to handle new event structure with integrated score checking

The implementation ensures that peers with poor gossipsub scores are automatically blocked and prevented from connecting, while maintaining the modular architecture.

This commit fully integrates the peer blocking features from the block-peers branch
into the new modular peer manager architecture. Key changes:

Blocking Infrastructure:
- Add BlockingManager wrapping libp2p-allow-block-list for connection denial
- Integrate blocking checks into all connection handlers (pending/established)
- Add automatic peer unblocking after RETAIN_SCORE_EPOCH_MULTIPLIER duration

Score-Based Blocking:
- Implement check_and_block_peers_by_score() to automatically block peers
  with gossipsub scores below GRAYLIST_THRESHOLD
- Integrate peer score checking into heartbeat system for periodic execution
- Automatically disconnect blocked peers immediately

Connection Prevention:
- Update should_dial_peer() to check blocked peers before dialing
- Filter blocked peers in discovery and subnet peer selection
- Ensure all connection paths respect the blocked peer list

Event System Updates:
- Replace ConnectActions events with PeerManagerHeartbeat events
- Consolidate peer management actions and score checking into single heartbeat
- Update Network to handle new event structure with integrated score checking

API Cleanup:
- Remove unused manual blocking API methods (block_peer, unblock_peer)
- Keep essential methods for score-based blocking and status queries
- Maintain clean separation between manual and automatic blocking

The implementation ensures that peers with poor gossipsub scores are automatically
blocked and prevented from connecting, while maintaining the modular architecture
and ensuring no behavioral changes from the original peer manager.
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR integrates peer blocking functionality into the modular peer manager architecture, implementing automatic blocking of peers with poor gossipsub scores. The changes consolidate peer management actions and score checking into a unified heartbeat system while maintaining the modular design.

Key changes:

  • Introduces BlockingManager for centralized peer blocking with automatic expiration
  • Replaces ConnectActions events with consolidated PeerManagerHeartbeat events that include both connection actions and score checking signals
  • Integrates blocking checks into all connection handlers and peer discovery logic

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
anchor/network/src/peer_manager/types.rs Adds HeartbeatEvent struct and updates Event enum to use PeerManagerHeartbeat
anchor/network/src/peer_manager/mod.rs Integrates BlockingManager into PeerManager with blocking checks in connection handlers
anchor/network/src/peer_manager/heartbeat.rs Updates heartbeat logic to accept blocked_peers parameter
anchor/network/src/peer_manager/discovery.rs Adds blocked peer filtering to peer discovery and connection logic
anchor/network/src/peer_manager/connection.rs Prevents dialing of blocked peers in should_dial_peer method
anchor/network/src/peer_manager/blocking.rs New module implementing BlockingManager with libp2p integration
anchor/network/src/network.rs Updates event handling and adds score-based peer blocking functionality
anchor/network/src/behaviour.rs Passes epoch duration to PeerManager constructor

@diegomrsantos diegomrsantos self-assigned this Jul 16, 2025
- Remove redundant HeartbeatManager::heartbeat() wrapper function
- Consolidate all heartbeat logic directly in PeerManager::heartbeat()
- Simplify HeartbeatManager to only handle timing (poll_tick)
- Clean up unused imports in heartbeat.rs
- Improve code organization with clear separation of concerns:
  - HeartbeatManager: Timer management only
  - PeerManager: All heartbeat logic and orchestration
  - PeerDiscovery: Peer discovery/connection logic

This eliminates an unnecessary layer of indirection and centralizes
heartbeat functionality for better maintainability.
@diegomrsantos diegomrsantos requested a review from dknopik July 17, 2025 12:43
Copy link
Member

@dknopik dknopik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really nice, thanks!

mergify bot added a commit that referenced this pull request Jul 18, 2025
@diegomrsantos diegomrsantos changed the title Integrate peer blocking functionality into modular peer manager feat: integrate peer blocking functionality into modular peer manager Jul 18, 2025
@diegomrsantos diegomrsantos changed the title feat: integrate peer blocking functionality into modular peer manager feat(peer_manager): integrate peer blocking functionality into modular peer manager Jul 18, 2025
@mergify mergify bot merged commit 1488331 into sigp:unstable Jul 18, 2025
16 checks passed
diegomrsantos added a commit to diegomrsantos/anchor that referenced this pull request Sep 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants