Collator-side of collator protocol (#351)

* 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

* extract session-key tracking from consensus

* add local_collations.rs

* finish polish of local_collations

* integrate local_collations into network layer

* introduce API for adding local collations

* mostly finish collator implementation pending service fix

* Specialized network()

* push collations to the network

* grumbles

* substrate-service has custom configuration

* initialize network in collator mode as necessary
This commit is contained in:
Robert Habermeier
2018-07-18 15:04:26 +02:00
committed by GitHub
parent c28dd30461
commit 5a09802e57
9 changed files with 476 additions and 150 deletions
-4
View File
@@ -29,10 +29,6 @@ args:
value_name: KEY
help: Specify node secret key (64-character hex string)
takes_value: true
- collator:
long: collator
help: Enable collator mode
takes_value: false
- validator:
long: validator
help: Enable validator mode
+13 -11
View File
@@ -71,7 +71,7 @@ pub use client::error::Error as ClientError;
pub use client::backend::Backend as ClientBackend;
pub use state_machine::Backend as StateMachineBackend;
pub use polkadot_primitives::Block as PolkadotBlock;
pub use service::{Components as ServiceComponents, Service};
pub use service::{Components as ServiceComponents, Service, CustomConfiguration};
use std::io::{self, Write, Read, stdin, stdout};
use std::fs::File;
@@ -134,11 +134,16 @@ fn base_path(matches: &clap::ArgMatches) -> PathBuf {
pub trait Worker {
/// A future that resolves when the work is done or the node should exit.
/// This will be run on a tokio runtime.
type Work: Future<Item=(),Error=()>;
type Work: Future<Item=(),Error=()> + Send + 'static;
/// An exit scheduled for the future.
type Exit: Future<Item=(),Error=()> + Send + 'static;
/// Return configuration for the polkadot node.
// TODO: make this the full configuration, so embedded nodes don't need
// string CLI args
fn configuration(&self) -> CustomConfiguration { Default::default() }
/// Don't work, but schedule an exit.
fn exit_only(self) -> Self::Exit;
@@ -217,13 +222,7 @@ pub fn run<I, T, W>(args: I, worker: W) -> error::Result<()> where
};
let role =
if matches.is_present("collator") {
info!("Starting collator");
// TODO [rob]: collation node implementation
// This isn't a thing. Different parachains will have their own collator executables and
// maybe link to libpolkadot to get a light-client.
service::Roles::LIGHT
} else if matches.is_present("light") {
if matches.is_present("light") {
info!("Starting (light)");
config.execution_strategy = service::ExecutionStrategy::NativeWhenPossible;
service::Roles::LIGHT
@@ -262,9 +261,10 @@ pub fn run<I, T, W>(args: I, worker: W) -> error::Result<()> where
config.network.net_config_path = config.network.config_path.clone();
let port = match matches.value_of("port") {
Some(port) => port.parse().expect("Invalid p2p port value specified."),
Some(port) => port.parse().map_err(|_| "Invalid p2p port value specified.")?,
None => 30333,
};
config.network.listen_address = Some(SocketAddr::new("0.0.0.0".parse().unwrap(), port));
config.network.public_address = None;
config.network.client_version = format!("parity-polkadot/{}", crate_version!());
@@ -275,6 +275,8 @@ pub fn run<I, T, W>(args: I, worker: W) -> error::Result<()> where
};
}
config.custom = worker.configuration();
config.keys = matches.values_of("key").unwrap_or_default().map(str::to_owned).collect();
if matches.is_present("dev") {
config.keys.push("Alice".into());
@@ -494,7 +496,7 @@ fn run_until_exit<C, W>(
)
};
let _ = worker.work(&service).wait();
let _ = runtime.block_on(worker.work(&service));
exit_send.fire();
Ok(())
}