mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-11 01:07:21 +00:00
Collators get incoming parachain messages (#149)
* refactor out a consensus data fetcher from table router * move statement checking logic into router * refuse to start authority if collator * support building the table router asynchronously * instantiate_consensus does not overwrite old * update key in new consensus if there was none before * collator collects ingress from network * test produced egress roots * fix adder-collator compilation * address first grumbles * integrate new gossip with collator network launch * address review
This commit is contained in:
committed by
GitHub
parent
67275abe30
commit
454ddf8921
@@ -17,11 +17,10 @@
|
||||
//! Tests for polkadot and validation network.
|
||||
|
||||
use super::{PolkadotProtocol, Status, Message, FullStatus};
|
||||
use validation::{ValidationSession, Knowledge};
|
||||
use validation::SessionParams;
|
||||
|
||||
use parking_lot::Mutex;
|
||||
use polkadot_validation::GenericStatement;
|
||||
use polkadot_primitives::{Block, SessionKey};
|
||||
use polkadot_primitives::{Block, Hash, SessionKey};
|
||||
use polkadot_primitives::parachain::{CandidateReceipt, HeadData, BlockData, CollatorId, ValidatorId};
|
||||
use substrate_primitives::crypto::UncheckedInto;
|
||||
use codec::Encode;
|
||||
@@ -31,7 +30,6 @@ use substrate_network::{
|
||||
generic_message::Message as GenericMessage
|
||||
};
|
||||
|
||||
use std::sync::Arc;
|
||||
use futures::Future;
|
||||
|
||||
mod validation;
|
||||
@@ -88,11 +86,12 @@ fn make_status(status: &Status, roles: Roles) -> FullStatus {
|
||||
}
|
||||
}
|
||||
|
||||
fn make_validation_session(local_key: SessionKey) -> (ValidationSession, Arc<Mutex<Knowledge>>) {
|
||||
let knowledge = Arc::new(Mutex::new(Knowledge::new()));
|
||||
let c = ValidationSession::new(knowledge.clone(), local_key);
|
||||
|
||||
(c, knowledge)
|
||||
fn make_validation_session(parent_hash: Hash, local_key: SessionKey) -> SessionParams {
|
||||
SessionParams {
|
||||
local_session_key: Some(local_key),
|
||||
parent_hash,
|
||||
authorities: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
fn on_message(protocol: &mut PolkadotProtocol, ctx: &mut TestContext, from: NodeIndex, message: Message) {
|
||||
@@ -120,8 +119,8 @@ fn sends_session_key() {
|
||||
|
||||
{
|
||||
let mut ctx = TestContext::default();
|
||||
let (session, _knowledge) = make_validation_session(local_key.clone());
|
||||
protocol.new_validation_session(&mut ctx, parent_hash, session);
|
||||
let params = make_validation_session(parent_hash, local_key.clone());
|
||||
protocol.new_validation_session(&mut ctx, params);
|
||||
assert!(ctx.has_message(peer_a, Message::SessionKey(local_key.clone())));
|
||||
}
|
||||
|
||||
@@ -160,8 +159,9 @@ fn fetches_from_those_with_knowledge() {
|
||||
|
||||
let status = Status { collating_for: None };
|
||||
|
||||
let (session, knowledge) = make_validation_session(local_key.clone());
|
||||
protocol.new_validation_session(&mut TestContext::default(), parent_hash, session);
|
||||
let params = make_validation_session(parent_hash, local_key.clone());
|
||||
let session = protocol.new_validation_session(&mut TestContext::default(), params);
|
||||
let knowledge = session.knowledge();
|
||||
|
||||
knowledge.lock().note_statement(a_key.clone(), &GenericStatement::Valid(candidate_hash));
|
||||
let recv = protocol.fetch_block_data(&mut TestContext::default(), &candidate_receipt, parent_hash);
|
||||
@@ -290,11 +290,11 @@ fn many_session_keys() {
|
||||
let local_key_a: ValidatorId = [3; 32].unchecked_into();
|
||||
let local_key_b: ValidatorId = [4; 32].unchecked_into();
|
||||
|
||||
let (session_a, _knowledge_a) = make_validation_session(local_key_a.clone());
|
||||
let (session_b, _knowledge_b) = make_validation_session(local_key_b.clone());
|
||||
let params_a = make_validation_session(parent_a, local_key_a.clone());
|
||||
let params_b = make_validation_session(parent_b, local_key_b.clone());
|
||||
|
||||
protocol.new_validation_session(&mut TestContext::default(), parent_a, session_a);
|
||||
protocol.new_validation_session(&mut TestContext::default(), parent_b, session_b);
|
||||
protocol.new_validation_session(&mut TestContext::default(), params_a);
|
||||
protocol.new_validation_session(&mut TestContext::default(), params_b);
|
||||
|
||||
assert_eq!(protocol.live_validation_sessions.recent_keys(), &[local_key_a.clone(), local_key_b.clone()]);
|
||||
|
||||
@@ -313,7 +313,7 @@ fn many_session_keys() {
|
||||
|
||||
let peer_b = 2;
|
||||
|
||||
protocol.remove_validation_session(&parent_a);
|
||||
assert!(protocol.remove_validation_session(parent_a));
|
||||
|
||||
{
|
||||
let mut ctx = TestContext::default();
|
||||
|
||||
@@ -471,9 +471,12 @@ fn ingress_fetch_works() {
|
||||
};
|
||||
|
||||
// make sure everyone can get ingress for their own parachain.
|
||||
let fetch_a = router_a.fetch_incoming(id_a).map_err(|_| format!("Could not fetch ingress_a"));
|
||||
let fetch_b = router_b.fetch_incoming(id_b).map_err(|_| format!("Could not fetch ingress_b"));
|
||||
let fetch_c = router_c.fetch_incoming(id_c).map_err(|_| format!("Could not fetch ingress_c"));
|
||||
let fetch_a = router_a.then(move |r| r.unwrap()
|
||||
.fetch_incoming(id_a).map_err(|_| format!("Could not fetch ingress_a")));
|
||||
let fetch_b = router_b.then(move |r| r.unwrap()
|
||||
.fetch_incoming(id_b).map_err(|_| format!("Could not fetch ingress_b")));
|
||||
let fetch_c = router_c.then(move |r| r.unwrap()
|
||||
.fetch_incoming(id_c).map_err(|_| format!("Could not fetch ingress_c")));
|
||||
|
||||
let work = fetch_a.join3(fetch_b, fetch_c);
|
||||
runtime.spawn(built.gossip.then(|_| Ok(()))); // in background.
|
||||
|
||||
Reference in New Issue
Block a user