mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-14 18:32:42 +00:00
PeerManager: move the check for banned peers from connection_established (#4569)
## Issue Addressed https://github.com/sigp/lighthouse/issues/4543 ## Proposed Changes - Removes `NotBanned` from `BanResult`, implements `Display` and `std::error::Error` for `BanResult` and changes `ban_result` return type to `Option<BanResult>` which helps returning `BanResult` on `handle_established_inbound_connection` - moves the check from for banned peers from `on_connection_established` to `handle_established_inbound_connection` to start addressing #4543. - Removes `allow_block_list` as it's now redundant? Not sure about this one but if `PeerManager` keeps track of the banned peers, no need to send a `Swarm` event for `alow_block_list` to also keep that list right? ## Questions - #4543 refers: > More specifically, implement the connection limit behaviour inside the peer manager. @AgeManning do you mean copying `libp2p::connection_limits::Behaviour`'s code into `PeerManager`/ having it as an inner `NetworkBehaviour` of `PeerManager`/other? If it's the first two, I think it probably makes more sense to have it as it is as it's less code to maintain. > Also implement the banning of peers inside the behaviour, rather than passing messages back up to the swarm. I tried to achieve this, but we still need to pass the `PeerManagerEvent::Banned` swarm event as `DiscV5` handles it's node and ip management internally and I did not find a method to query if a peer is banned. Is there anything else we can do from here?3397612160/beacon_node/lighthouse_network/src/discovery/mod.rs (L931-L940)Same as the question above, I did not find a way to check if `DiscV5` has the peer banned, so that we could check here and avoid sending `Swarm` events3397612160/beacon_node/lighthouse_network/src/peer_manager/network_behaviour.rs (L168-L178)Is there a chance we try to dial a peer that has been banned previously? Thanks!
This commit is contained in:
@@ -20,8 +20,6 @@ where
|
||||
AppReqId: ReqId,
|
||||
TSpec: EthSpec,
|
||||
{
|
||||
/// Peers banned.
|
||||
pub banned_peers: libp2p::allow_block_list::Behaviour<libp2p::allow_block_list::BlockedPeers>,
|
||||
/// Keep track of active and pending connections to enforce hard limits.
|
||||
pub connection_limits: libp2p::connection_limits::Behaviour,
|
||||
/// The routing pub-sub mechanism for eth2.
|
||||
|
||||
@@ -337,11 +337,8 @@ impl<AppReqId: ReqId, TSpec: EthSpec> Network<AppReqId, TSpec> {
|
||||
libp2p::connection_limits::Behaviour::new(limits)
|
||||
};
|
||||
|
||||
let banned_peers = libp2p::allow_block_list::Behaviour::default();
|
||||
|
||||
let behaviour = {
|
||||
Behaviour {
|
||||
banned_peers,
|
||||
gossipsub,
|
||||
eth2_rpc,
|
||||
discovery,
|
||||
@@ -1402,15 +1399,10 @@ impl<AppReqId: ReqId, TSpec: EthSpec> Network<AppReqId, TSpec> {
|
||||
Some(NetworkEvent::PeerDisconnected(peer_id))
|
||||
}
|
||||
PeerManagerEvent::Banned(peer_id, associated_ips) => {
|
||||
self.swarm.behaviour_mut().banned_peers.block_peer(peer_id);
|
||||
self.discovery_mut().ban_peer(&peer_id, associated_ips);
|
||||
None
|
||||
}
|
||||
PeerManagerEvent::UnBanned(peer_id, associated_ips) => {
|
||||
self.swarm
|
||||
.behaviour_mut()
|
||||
.banned_peers
|
||||
.unblock_peer(peer_id);
|
||||
self.discovery_mut().unban_peer(&peer_id, associated_ips);
|
||||
None
|
||||
}
|
||||
@@ -1459,7 +1451,6 @@ impl<AppReqId: ReqId, TSpec: EthSpec> Network<AppReqId, TSpec> {
|
||||
let maybe_event = match swarm_event {
|
||||
SwarmEvent::Behaviour(behaviour_event) => match behaviour_event {
|
||||
// Handle sub-behaviour events.
|
||||
BehaviourEvent::BannedPeers(void) => void::unreachable(void),
|
||||
BehaviourEvent::Gossipsub(ge) => self.inject_gs_event(ge),
|
||||
BehaviourEvent::Eth2Rpc(re) => self.inject_rpc_event(re),
|
||||
// Inform the peer manager about discovered peers.
|
||||
|
||||
Reference in New Issue
Block a user