mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 03:27:58 +00:00
refactor/reputation: unify the values used (#2462)
* refactor/reputation: unify the values used * chore/rep: rename Annoy* to Cost*, make duplicate message Cost*Repeated * fix/reputation: lost and found, convert at the boundary to substrate * refactor/rep: move conversion to base reputation one level down, left conversions * fix/rep: order of magnitude adjustments Thanks pierre! * remove spaces * chore/rep: give rationale for order of magnitude * refactor/rep: move UnifiedReputationChange to separate file * fix/rep: order of magnitudes correction
This commit is contained in:
committed by
GitHub
parent
62c5896592
commit
1e2161258b
@@ -19,7 +19,7 @@ use futures::channel::mpsc;
|
||||
|
||||
use parity_scale_codec::Decode;
|
||||
use polkadot_node_network_protocol::{
|
||||
peer_set::PeerSet, v1 as protocol_v1, PeerId, ReputationChange,
|
||||
peer_set::PeerSet, v1 as protocol_v1, PeerId, UnifiedReputationChange,
|
||||
};
|
||||
use polkadot_primitives::v1::{AuthorityDiscoveryId, BlockNumber};
|
||||
use polkadot_subsystem::messages::{AllMessages, NetworkBridgeMessage};
|
||||
@@ -55,7 +55,7 @@ pub(crate) enum Action {
|
||||
},
|
||||
|
||||
/// Report a peer to the network implementation (decreasing/increasing its reputation).
|
||||
ReportPeer(PeerId, ReputationChange),
|
||||
ReportPeer(PeerId, UnifiedReputationChange),
|
||||
|
||||
/// A subsystem updates us on the relay chain leaves we consider active.
|
||||
///
|
||||
|
||||
@@ -34,7 +34,7 @@ use polkadot_subsystem::messages::{
|
||||
};
|
||||
use polkadot_primitives::v1::{Hash, BlockNumber};
|
||||
use polkadot_node_network_protocol::{
|
||||
ReputationChange, PeerId, peer_set::PeerSet, View, v1 as protocol_v1, OurView,
|
||||
PeerId, peer_set::PeerSet, View, v1 as protocol_v1, OurView, UnifiedReputationChange as Rep,
|
||||
};
|
||||
|
||||
/// Peer set infos for network initialization.
|
||||
@@ -72,10 +72,10 @@ pub use multiplexer::RequestMultiplexer;
|
||||
const MAX_VIEW_HEADS: usize = 5;
|
||||
|
||||
|
||||
const MALFORMED_MESSAGE_COST: ReputationChange = ReputationChange::new(-500, "Malformed Network-bridge message");
|
||||
const UNCONNECTED_PEERSET_COST: ReputationChange = ReputationChange::new(-50, "Message sent to un-connected peer-set");
|
||||
const MALFORMED_VIEW_COST: ReputationChange = ReputationChange::new(-500, "Malformed view");
|
||||
const EMPTY_VIEW_COST: ReputationChange = ReputationChange::new(-500, "Peer sent us an empty view");
|
||||
const MALFORMED_MESSAGE_COST: Rep = Rep::CostMajor("Malformed Network-bridge message");
|
||||
const UNCONNECTED_PEERSET_COST: Rep = Rep::CostMinor("Message sent to un-connected peer-set");
|
||||
const MALFORMED_VIEW_COST: Rep = Rep::CostMajor("Malformed view");
|
||||
const EMPTY_VIEW_COST: Rep = Rep::CostMajor("Peer sent us an empty view");
|
||||
|
||||
// network bridge log target
|
||||
const LOG_TARGET: &'static str = "network_bridge";
|
||||
|
||||
@@ -29,7 +29,7 @@ use sc_network::{NetworkService, IfDisconnected};
|
||||
use polkadot_node_network_protocol::{
|
||||
peer_set::PeerSet,
|
||||
request_response::{OutgoingRequest, Requests},
|
||||
PeerId, ReputationChange,
|
||||
PeerId, UnifiedReputationChange as Rep,
|
||||
};
|
||||
use polkadot_primitives::v1::{Block, Hash};
|
||||
use polkadot_subsystem::{SubsystemError, SubsystemResult};
|
||||
@@ -86,7 +86,7 @@ where
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum NetworkAction {
|
||||
/// Note a change in reputation for a peer.
|
||||
ReputationChange(PeerId, ReputationChange),
|
||||
ReputationChange(PeerId, Rep),
|
||||
/// Write a notification to a given peer on the given peer-set.
|
||||
WriteNotification(PeerId, PeerSet, Vec<u8>),
|
||||
}
|
||||
@@ -111,7 +111,7 @@ pub trait Network: Send + 'static {
|
||||
fn report_peer(
|
||||
&mut self,
|
||||
who: PeerId,
|
||||
cost_benefit: ReputationChange,
|
||||
cost_benefit: Rep,
|
||||
) -> BoxFuture<SubsystemResult<()>> {
|
||||
async move {
|
||||
self.action_sink()
|
||||
@@ -167,7 +167,7 @@ impl Network for Arc<NetworkService<Block, Hash>> {
|
||||
cost_benefit,
|
||||
peer
|
||||
);
|
||||
self.0.report_peer(peer, cost_benefit)
|
||||
self.0.report_peer(peer, cost_benefit.into_base_rep())
|
||||
}
|
||||
NetworkAction::WriteNotification(peer, peer_set, message) => self
|
||||
.0
|
||||
|
||||
Reference in New Issue
Block a user