Admin add/remove peer (#7198)

N/A


  Adds endpoints to add and remove trusted peers from the http api. The added peers are trusted peers so they won't be disconnected for bad scores. We try to maintain a connection to the peer in case they disconnect from us by trying to dial it every heartbeat.
This commit is contained in:
Pawan Dhananjay
2025-03-28 05:59:09 -07:00
committed by GitHub
parent a5ea05ce2a
commit 54aef2d043
10 changed files with 217 additions and 7 deletions

View File

@@ -14,6 +14,7 @@ use futures::StreamExt;
use lighthouse_network::rpc::{RequestId, RequestType};
use lighthouse_network::service::Network;
use lighthouse_network::types::GossipKind;
use lighthouse_network::Enr;
use lighthouse_network::{prometheus_client::registry::Registry, MessageAcceptance};
use lighthouse_network::{
rpc::{GoodbyeReason, RpcErrorResponse},
@@ -101,6 +102,10 @@ pub enum NetworkMessage<E: EthSpec> {
reason: GoodbyeReason,
source: ReportSource,
},
/// Connect to a trusted peer and try to maintain the connection.
ConnectTrustedPeer(Enr),
/// Disconnect from a trusted peer and remove it from the `trusted_peers` mapping.
DisconnectTrustedPeer(Enr),
}
/// Messages triggered by validators that may trigger a subscription to a subnet.
@@ -688,6 +693,12 @@ impl<T: BeaconChainTypes> NetworkService<T> {
reason,
source,
} => self.libp2p.goodbye_peer(&peer_id, reason, source),
NetworkMessage::ConnectTrustedPeer(enr) => {
self.libp2p.dial_trusted_peer(enr);
}
NetworkMessage::DisconnectTrustedPeer(enr) => {
self.libp2p.remove_trusted_peer(enr);
}
NetworkMessage::SubscribeCoreTopics => {
if self.subscribed_core_topics() {
return;