mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-15 19:02: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:
@@ -415,7 +415,7 @@ impl<TSpec: EthSpec> PeerManager<TSpec> {
|
||||
/// Reports if a peer is banned or not.
|
||||
///
|
||||
/// This is used to determine if we should accept incoming connections.
|
||||
pub fn ban_status(&self, peer_id: &PeerId) -> BanResult {
|
||||
pub fn ban_status(&self, peer_id: &PeerId) -> Option<BanResult> {
|
||||
self.network_globals.peers.read().ban_status(peer_id)
|
||||
}
|
||||
|
||||
@@ -803,7 +803,7 @@ impl<TSpec: EthSpec> PeerManager<TSpec> {
|
||||
) -> bool {
|
||||
{
|
||||
let mut peerdb = self.network_globals.peers.write();
|
||||
if !matches!(peerdb.ban_status(peer_id), BanResult::NotBanned) {
|
||||
if peerdb.ban_status(peer_id).is_some() {
|
||||
// don't connect if the peer is banned
|
||||
error!(self.log, "Connection has been allowed to a banned peer"; "peer_id" => %peer_id);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user