mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 01:41:09 +00:00
Evict inactive peers from the collator protocol peer-set (#2680)
* malicious reputation cost is fatal * make ReportBad a malicious cost * futures control-flow for cleaning up inactive collator peers * guide: network bridge updates * add `PeerDisconnected` message * guide: update * reverse order * remember to match * implement disconnect peer in network bridge * implement disconnect_inactive_peers * test * remove println * don't hardcore policy * add fuse outside of loop * use default eviction policy
This commit is contained in:
committed by
GitHub
parent
0f8b6f2f6e
commit
b8867d71bc
@@ -57,6 +57,9 @@ pub(crate) enum Action {
|
||||
/// Report a peer to the network implementation (decreasing/increasing its reputation).
|
||||
ReportPeer(PeerId, UnifiedReputationChange),
|
||||
|
||||
/// Disconnect a peer from the given peer-set without affecting their reputation.
|
||||
DisconnectPeer(PeerId, PeerSet),
|
||||
|
||||
/// A subsystem updates us on the relay chain leaves we consider active.
|
||||
///
|
||||
/// Implementation will send `WireMessage::ViewUpdate` message to peers as appropriate to the
|
||||
@@ -119,6 +122,9 @@ impl From<polkadot_subsystem::SubsystemResult<FromOverseer<NetworkBridgeMessage>
|
||||
}
|
||||
Ok(FromOverseer::Communication { msg }) => match msg {
|
||||
NetworkBridgeMessage::ReportPeer(peer, rep) => Action::ReportPeer(peer, rep),
|
||||
NetworkBridgeMessage::DisconnectPeer(peer, peer_set) => {
|
||||
Action::DisconnectPeer(peer, peer_set)
|
||||
}
|
||||
NetworkBridgeMessage::SendValidationMessage(peers, msg) => {
|
||||
Action::SendValidationMessages(vec![(peers, msg)])
|
||||
}
|
||||
|
||||
@@ -297,6 +297,16 @@ where
|
||||
bridge.network_service.report_peer(peer, rep).await?
|
||||
}
|
||||
|
||||
Action::DisconnectPeer(peer, peer_set) => {
|
||||
tracing::debug!(
|
||||
target: LOG_TARGET,
|
||||
action = "DisconnectPeer",
|
||||
?peer,
|
||||
peer_set = ?peer_set,
|
||||
);
|
||||
bridge.network_service.disconnect_peer(peer, peer_set);
|
||||
}
|
||||
|
||||
Action::ActiveLeaves(ActiveLeavesUpdate { activated, deactivated }) => {
|
||||
tracing::debug!(
|
||||
target: LOG_TARGET,
|
||||
|
||||
@@ -90,6 +90,8 @@ where
|
||||
pub enum NetworkAction {
|
||||
/// Note a change in reputation for a peer.
|
||||
ReputationChange(PeerId, Rep),
|
||||
/// Disconnect a peer from the given peer-set.
|
||||
DisconnectPeer(PeerId, PeerSet),
|
||||
/// Write a notification to a given peer on the given peer-set.
|
||||
WriteNotification(PeerId, PeerSet, Vec<u8>),
|
||||
}
|
||||
@@ -130,6 +132,20 @@ pub trait Network: Send + 'static {
|
||||
.boxed()
|
||||
}
|
||||
|
||||
/// Disconnect a given peer from the peer set specified without harming reputation.
|
||||
fn disconnect_peer(
|
||||
&mut self,
|
||||
who: PeerId,
|
||||
peer_set: PeerSet,
|
||||
) -> BoxFuture<SubsystemResult<()>> {
|
||||
async move {
|
||||
self.action_sink()
|
||||
.send(NetworkAction::DisconnectPeer(who, peer_set))
|
||||
.await
|
||||
}
|
||||
.boxed()
|
||||
}
|
||||
|
||||
/// Write a notification to a peer on the given peer-set's protocol.
|
||||
fn write_notification(
|
||||
&mut self,
|
||||
@@ -179,6 +195,9 @@ impl Network for Arc<NetworkService<Block, Hash>> {
|
||||
);
|
||||
self.0.report_peer(peer, cost_benefit.into_base_rep())
|
||||
}
|
||||
NetworkAction::DisconnectPeer(peer, peer_set) => self
|
||||
.0
|
||||
.disconnect_peer(peer, peer_set.into_protocol_name()),
|
||||
NetworkAction::WriteNotification(peer, peer_set, message) => self
|
||||
.0
|
||||
.write_notification(peer, peer_set.into_protocol_name(), message),
|
||||
|
||||
Reference in New Issue
Block a user