mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-09 08:17:24 +00:00
positive updates to reputations when good things happen (#258)
* positive updates to reputations when good things happen * address review * branch on good or bad pov blocks * add a new constant for bad pov blocks
This commit is contained in:
committed by
Gavin Wood
parent
e8fcb43fcf
commit
c6aa447a50
@@ -16,6 +16,7 @@
|
||||
|
||||
//! Tests for polkadot and validation network.
|
||||
|
||||
use std::collections::HashMap;
|
||||
use super::{PolkadotProtocol, Status, Message, FullStatus};
|
||||
use validation::SessionParams;
|
||||
|
||||
@@ -41,6 +42,7 @@ mod validation;
|
||||
struct TestContext {
|
||||
disabled: Vec<PeerId>,
|
||||
disconnected: Vec<PeerId>,
|
||||
reputations: HashMap<PeerId, i32>,
|
||||
messages: Vec<(PeerId, Vec<u8>)>,
|
||||
}
|
||||
|
||||
@@ -50,6 +52,9 @@ impl Context<Block> for TestContext {
|
||||
}
|
||||
|
||||
fn report_peer(&mut self, peer: PeerId, reputation: i32) {
|
||||
let reputation = self.reputations.get(&peer).map_or(reputation, |v| v + reputation);
|
||||
self.reputations.insert(peer.clone(), reputation);
|
||||
|
||||
match reputation {
|
||||
i if i < -100 => self.disabled.push(peer),
|
||||
i if i < 0 => self.disconnected.push(peer),
|
||||
@@ -306,6 +311,22 @@ fn remove_bad_collator() {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn kick_collator() {
|
||||
let mut protocol = PolkadotProtocol::new(None);
|
||||
|
||||
let who = PeerId::random();
|
||||
let collator_id: CollatorId = [2; 32].unchecked_into();
|
||||
|
||||
let mut ctx = TestContext::default();
|
||||
let status = Status { collating_for: Some((collator_id.clone(), 5.into())) };
|
||||
protocol.on_connect(&mut ctx, who.clone(), make_status(&status, Roles::NONE));
|
||||
assert!(!ctx.disconnected.contains(&who));
|
||||
|
||||
protocol.on_connect(&mut ctx, who.clone(), make_status(&status, Roles::NONE));
|
||||
assert!(ctx.disconnected.contains(&who));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn many_session_keys() {
|
||||
let mut protocol = PolkadotProtocol::new(None);
|
||||
|
||||
Reference in New Issue
Block a user