Collator for the "adder" (formerly basic-add) parachain and various small fixes (#438)

* update basic_add wasm

* wasm feature and collator feature

* move test parachains around a little

* fix wasm build for basic_add

* move basic_add to adder, introduce README

* minimal basic_add collator

* ensure collator messages are sent in the right order

* more logging

* route consensus statements to all peers

* minor bugfixes for parachains

* genesis builder accounts for parachain heads

* fix parachains tests

* targets for txpool

* tweak runtime + collator

* fix version in adder-collator

* consistency for overflowing

* adjust comment

* fix stable test run

* remove dummy registration test

* final grumbles
This commit is contained in:
Robert Habermeier
2018-08-01 17:04:04 +02:00
committed by GitHub
parent f5aa4f6f79
commit f4cd995558
27 changed files with 569 additions and 333 deletions
+37 -10
View File
@@ -60,6 +60,7 @@ extern crate polkadot_primitives;
extern crate log;
use std::collections::{BTreeSet, BTreeMap, HashSet};
use std::fmt;
use std::sync::Arc;
use std::time::{Duration, Instant};
@@ -68,12 +69,36 @@ use client::BlockchainEvents;
use polkadot_api::PolkadotApi;
use polkadot_primitives::{AccountId, BlockId, SessionKey};
use polkadot_primitives::parachain::{self, BlockData, DutyRoster, HeadData, ConsolidatedIngress, Message, Id as ParaId};
use polkadot_cli::{ServiceComponents, Service, CustomConfiguration, VersionInfo};
use polkadot_cli::{ServiceComponents, Service, CustomConfiguration};
use polkadot_cli::{Worker, IntoExit};
use tokio::timer::Deadline;
pub use polkadot_cli::VersionInfo;
const COLLATION_TIMEOUT: Duration = Duration::from_secs(30);
/// Error to return when the head data was invalid.
#[derive(Clone, Copy, Debug)]
pub struct InvalidHead;
/// Collation errors.
#[derive(Debug)]
pub enum Error<R> {
/// Error on the relay-chain side of things.
Polkadot(R),
/// Error on the collator side of things.
Collator(InvalidHead),
}
impl<R: fmt::Display> fmt::Display for Error<R> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
Error::Polkadot(ref err) => write!(f, "Polkadot node error: {}", err),
Error::Collator(_) => write!(f, "Collator node error: Invalid head data"),
}
}
}
/// Parachain context needed for collation.
///
/// This can be implemented through an externally attached service or a stub.
@@ -84,7 +109,7 @@ pub trait ParachainContext: Clone {
&self,
last_head: HeadData,
ingress: I,
) -> (BlockData, HeadData);
) -> Result<(BlockData, HeadData), InvalidHead>;
}
/// Relay chain context needed to collate.
@@ -154,18 +179,18 @@ pub fn collate<'a, R, P>(
para_context: P,
key: Arc<ed25519::Pair>,
)
-> impl Future<Item=parachain::Collation, Error=R::Error> + 'a
-> impl Future<Item=parachain::Collation, Error=Error<R::Error>> + 'a
where
R: RelayChainContext + 'a,
R::Error: 'a,
R::FutureEgress: 'a,
P: ParachainContext + 'a,
{
collate_ingress(relay_context).map(move |ingress| {
collate_ingress(relay_context).map_err(Error::Polkadot).and_then(move |ingress| {
let (block_data, head_data) = para_context.produce_candidate(
last_head,
ingress.0.iter().flat_map(|&(id, ref msgs)| msgs.iter().cloned().map(move |msg| (id, msg)))
);
).map_err(Error::Collator)?;
let block_data_hash = block_data.hash();
let signature = key.sign(&block_data_hash.0[..]).into();
@@ -181,10 +206,10 @@ pub fn collate<'a, R, P>(
block_data_hash,
};
parachain::Collation {
Ok(parachain::Collation {
receipt,
block_data,
}
})
})
}
@@ -248,7 +273,7 @@ impl<P, E> Worker for CollationNode<P, E> where
($e:expr) => {
match $e {
Ok(x) => x,
Err(e) => return future::Either::A(future::err(e)),
Err(e) => return future::Either::A(future::err(Error::Polkadot(e))),
}
}
}
@@ -323,17 +348,19 @@ fn compute_targets(para_id: ParaId, session_keys: &[SessionKey], roster: DutyRos
///
/// Provide a future which resolves when the node should exit.
/// This function blocks until done.
pub fn run_collator<P, E>(
pub fn run_collator<P, E, I, ArgT>(
parachain_context: P,
para_id: ParaId,
exit: E,
key: Arc<ed25519::Pair>,
args: Vec<::std::ffi::OsString>,
args: I,
version: VersionInfo,
) -> polkadot_cli::error::Result<()> where
P: ParachainContext + Send + 'static,
E: IntoFuture<Item=(),Error=()>,
E::Future: Send + Clone + 'static,
I: IntoIterator<Item=ArgT>,
ArgT: Into<std::ffi::OsString> + Clone,
{
let node_logic = CollationNode { parachain_context, exit: exit.into_future(), para_id, key };
polkadot_cli::run(args, node_logic, version)