polkadot_node_network_protocol/
reputation.rs1pub use sc_network::ReputationChange;
18
19#[derive(Debug, Clone, Copy, PartialEq, Eq)]
21#[allow(missing_docs)]
22pub enum UnifiedReputationChange {
23 CostMajor(&'static str),
24 CostMinor(&'static str),
25 CostMajorRepeated(&'static str),
26 CostMinorRepeated(&'static str),
27 Malicious(&'static str),
28 BenefitMinorFirst(&'static str),
29 BenefitMinor(&'static str),
30 BenefitMajorFirst(&'static str),
31 BenefitMajor(&'static str),
32}
33
34impl UnifiedReputationChange {
35 pub const fn cost_or_benefit(&self) -> i32 {
46 match self {
47 Self::CostMinor(_) => -100_000,
48 Self::CostMajor(_) => -300_000,
49 Self::CostMinorRepeated(_) => -200_000,
50 Self::CostMajorRepeated(_) => -600_000,
51 Self::Malicious(_) => i32::MIN,
52 Self::BenefitMajorFirst(_) => 300_000,
53 Self::BenefitMajor(_) => 200_000,
54 Self::BenefitMinorFirst(_) => 15_000,
55 Self::BenefitMinor(_) => 10_000,
56 }
57 }
58
59 pub const fn description(&self) -> &'static str {
61 match self {
62 Self::CostMinor(description) => description,
63 Self::CostMajor(description) => description,
64 Self::CostMinorRepeated(description) => description,
65 Self::CostMajorRepeated(description) => description,
66 Self::Malicious(description) => description,
67 Self::BenefitMajorFirst(description) => description,
68 Self::BenefitMajor(description) => description,
69 Self::BenefitMinorFirst(description) => description,
70 Self::BenefitMinor(description) => description,
71 }
72 }
73
74 pub const fn is_benefit(&self) -> bool {
76 match self {
77 Self::BenefitMajorFirst(_) |
78 Self::BenefitMajor(_) |
79 Self::BenefitMinorFirst(_) |
80 Self::BenefitMinor(_) => true,
81 _ => false,
82 }
83 }
84}
85
86impl From<UnifiedReputationChange> for ReputationChange {
87 fn from(value: UnifiedReputationChange) -> Self {
88 ReputationChange::new(value.cost_or_benefit(), value.description())
89 }
90}