mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 18:41:03 +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
@@ -27,7 +27,7 @@ use polkadot_consensus::{Network, SharedTable, Collators};
|
||||
use polkadot_primitives::{AccountId, Block, Hash, SessionKey};
|
||||
use polkadot_primitives::parachain::{Id as ParaId, Collation};
|
||||
|
||||
use futures::{future, prelude::*};
|
||||
use futures::prelude::*;
|
||||
use futures::sync::mpsc;
|
||||
|
||||
use std::sync::Arc;
|
||||
@@ -304,13 +304,38 @@ impl<P: LocalPolkadotApi + Send + Sync + 'static> Network for ConsensusNetwork<P
|
||||
}
|
||||
}
|
||||
|
||||
impl<P: LocalPolkadotApi + Send + Sync + 'static> Collators for ConsensusNetwork<P> {
|
||||
type Error = ();
|
||||
type Collation = future::Empty<Collation, ()>;
|
||||
/// Error when the network appears to be down.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub struct NetworkDown;
|
||||
|
||||
fn collate(&self, _parachain: ParaId, _relay_parent: Hash) -> Self::Collation {
|
||||
future::empty()
|
||||
/// A future that resolves when a collation is received.
|
||||
pub struct AwaitingCollation(Option<::futures::sync::oneshot::Receiver<Collation>>);
|
||||
|
||||
impl Future for AwaitingCollation {
|
||||
type Item = Collation;
|
||||
type Error = NetworkDown;
|
||||
|
||||
fn poll(&mut self) -> Poll<Collation, NetworkDown> {
|
||||
match self.0.poll().map_err(|_| NetworkDown)? {
|
||||
Async::Ready(None) => Err(NetworkDown),
|
||||
Async::Ready(Some(x)) => Ok(Async::Ready(x)),
|
||||
Async::NotReady => Ok(Async::NotReady),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
impl<P: LocalPolkadotApi + Send + Sync + 'static> Collators for ConsensusNetwork<P> {
|
||||
type Error = NetworkDown;
|
||||
type Collation = AwaitingCollation;
|
||||
|
||||
fn collate(&self, parachain: ParaId, relay_parent: Hash) -> Self::Collation {
|
||||
AwaitingCollation(
|
||||
self.network.with_spec(|spec, _| spec.await_collation(relay_parent, parachain))
|
||||
)
|
||||
}
|
||||
|
||||
fn note_bad_collator(&self, _collator: AccountId) { }
|
||||
fn note_bad_collator(&self, collator: AccountId) {
|
||||
self.network.with_spec(|spec, ctx| spec.disconnect_bad_collator(ctx, collator));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user