mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 22:11:02 +00:00
Validator side of the collation protocol. (#295)
* skeleton of collators object * awaiting and handling collations. rename `collators` to CollationPool * add some tests * add tests * implement Collators trait for ConsensusNetwork * plug collators into main polkadot-network * ignore collator role message * add a couple more tests * garbage collection for collations * ensure disconnected backup collator is removed from pool * address other grumbles
This commit is contained in:
committed by
Gav Wood
parent
907eeef9dd
commit
88c40c8fb4
@@ -110,11 +110,12 @@ fn sends_session_key() {
|
||||
let parent_hash = [0; 32].into();
|
||||
let local_key = [1; 32].into();
|
||||
|
||||
let status = Status { collating_for: None };
|
||||
let validator_status = Status { collating_for: None };
|
||||
let collator_status = Status { collating_for: Some(([2; 32].into(), 5.into())) };
|
||||
|
||||
{
|
||||
let mut ctx = TestContext::default();
|
||||
protocol.on_connect(&mut ctx, peer_a, make_status(&status, vec![Role::Authority]));
|
||||
protocol.on_connect(&mut ctx, peer_a, make_status(&validator_status, vec![Role::Authority]));
|
||||
assert!(ctx.messages.is_empty());
|
||||
}
|
||||
|
||||
@@ -128,7 +129,7 @@ fn sends_session_key() {
|
||||
|
||||
{
|
||||
let mut ctx = TestContext::default();
|
||||
protocol.on_connect(&mut ctx, peer_b, make_status(&status, vec![Role::Authority]));
|
||||
protocol.on_connect(&mut ctx, peer_b, make_status(&collator_status, vec![]));
|
||||
assert!(ctx.has_message(peer_b, Message::SessionKey(parent_hash, local_key)));
|
||||
}
|
||||
}
|
||||
@@ -207,3 +208,24 @@ fn fetches_from_those_with_knowledge() {
|
||||
assert_eq!(recv.wait().unwrap(), block_data);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn remove_bad_collator() {
|
||||
let mut protocol = PolkadotProtocol::new();
|
||||
|
||||
let peer_id = 1;
|
||||
let account_id = [2; 32].into();
|
||||
|
||||
let status = Status { collating_for: Some((account_id, 5.into())) };
|
||||
|
||||
{
|
||||
let mut ctx = TestContext::default();
|
||||
protocol.on_connect(&mut ctx, peer_id, make_status(&status, vec![]));
|
||||
}
|
||||
|
||||
{
|
||||
let mut ctx = TestContext::default();
|
||||
protocol.disconnect_bad_collator(&mut ctx, account_id);
|
||||
assert!(ctx.disabled.contains(&peer_id));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user