Skip to content

Commit

Permalink
Parachain validation moved to external process (paritytech#325)
Browse files Browse the repository at this point in the history
* Improved execution & tests

* Style

* Made CLI arg const

* Moved Upwards message

* CLI subcommand for validation worker

* Build halting parachain

* Build halting parachain

* Made stuff private

* Reorganized parachain tests

* Comment

* Whitespace

* Apply suggestions from code review

Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com>

* Fixed call data size check and introduced an enum

* Apply suggestions from code review

Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com>
  • Loading branch information
arkpar and bkchr committed Jul 23, 2019
1 parent 79d8c40 commit c5836f3
Show file tree
Hide file tree
Showing 19 changed files with 1,076 additions and 417 deletions.
818 changes: 466 additions & 352 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ log = "0.4.6"
tokio = "0.1.7"
futures = "0.1.17"
exit-future = "0.1"
structopt = "0.2"
cli = { package = "substrate-cli", git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
service = { package = "polkadot-service", path = "../service" }
43 changes: 29 additions & 14 deletions cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use tokio::runtime::Runtime;
use service::Service as BareService;
use std::sync::Arc;
use log::info;
use structopt::StructOpt;

pub use service::{
Components as ServiceComponents, PolkadotService, CustomConfiguration, ServiceFactory, Factory,
Expand Down Expand Up @@ -65,21 +66,28 @@ pub trait Worker: IntoExit {
fn work<S: PolkadotService>(self, service: &S, executor: TaskExecutor) -> Self::Work;
}

/// Parse command line arguments into service configuration.
///
/// IANA unassigned port ranges that we could use:
/// 6717-6766 Unassigned
/// 8504-8553 Unassigned
/// 9556-9591 Unassigned
/// 9803-9874 Unassigned
/// 9926-9949 Unassigned
pub fn run<I, T, W>(args: I, worker: W, version: cli::VersionInfo) -> error::Result<()> where
I: IntoIterator<Item = T>,
T: Into<std::ffi::OsString> + Clone,
#[derive(Debug, StructOpt, Clone)]
enum PolkadotSubCommands {
#[structopt(name = "validation-worker", raw(setting = "structopt::clap::AppSettings::Hidden"))]
ValidationWorker(ValidationWokerCommand),
}

impl cli::GetLogFilter for PolkadotSubCommands {
fn get_log_filter(&self) -> Option<String> { None }
}

#[derive(Debug, StructOpt, Clone)]
struct ValidationWokerCommand {
#[structopt()]
pub mem_id: String,
}

/// Parses polkadot specific CLI arguments and run the service.
pub fn run<W>(worker: W, version: cli::VersionInfo) -> error::Result<()> where
W: Worker,
{
cli::parse_and_execute::<service::Factory, NoCustom, NoCustom, _, _, _, _, _>(
load_spec, &version, "parity-polkadot", args, worker,
let command = cli::parse_and_execute::<service::Factory, PolkadotSubCommands, NoCustom, _, _, _, _, _>(
load_spec, &version, "parity-polkadot", std::env::args(), worker,
|worker, _cli_args, _custom_args, mut config| {
info!("{}", version.name);
info!(" version {}", config.full_version());
Expand All @@ -103,7 +111,14 @@ pub fn run<I, T, W>(args: I, worker: W, version: cli::VersionInfo) -> error::Res
),
}.map_err(|e| format!("{:?}", e))
}
).map_err(Into::into).map(|_| ())
)?;

match command {
Some(PolkadotSubCommands::ValidationWorker(args)) => {
service::run_validation_worker(&args.mem_id).map_err(Into::into)
}
_ => Ok(())
}
}

fn run_until_exit<T, C, W>(
Expand Down
7 changes: 2 additions & 5 deletions collator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,24 +429,21 @@ 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, I, ArgT>(
pub fn run_collator<P, E>(
build_parachain_context: P,
para_id: ParaId,
exit: E,
key: Arc<ed25519::Pair>,
args: I,
version: VersionInfo,
) -> polkadot_cli::error::Result<()> where
P: BuildParachainContext + Send + 'static,
P::ParachainContext: Send + 'static,
<<P::ParachainContext as ParachainContext>::ProduceCandidate as IntoFuture>::Future: Send + 'static,
E: IntoFuture<Item=(), Error=()>,
E::Future: Send + Clone + Sync + 'static,
I: IntoIterator<Item=ArgT>,
ArgT: Into<std::ffi::OsString> + Clone,
{
let node_logic = CollationNode { build_parachain_context, exit: exit.into_future(), para_id, key };
polkadot_cli::run(args, node_logic, version)
polkadot_cli::run(node_logic, version)
}

#[cfg(test)]
Expand Down
7 changes: 6 additions & 1 deletion parachain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,17 @@ derive_more = { version = "0.14", optional = true }
serde = { version = "1.0", default-features = false, features = [ "derive" ] }

rstd = { package = "sr-std", git = "https://github.com/paritytech/substrate", branch = "polkadot-master", default-features = false }
shared_memory = { version = "0.8", optional = true }
lazy_static = { version = "1.3.0", optional = true }
parking_lot = { version = "0.7.1", optional = true }
log = { version = "0.4.6", optional = true }

[dev-dependencies]
tiny-keccak = "1.4"
adder = { path = "../test-parachains/adder" }
halt = { path = "../test-parachains/halt" }

[features]
default = ["std"]
wasm-api = []
std = [ "codec/std", "wasmi", "derive_more", "serde/std", "rstd/std" ]
std = [ "codec/std", "wasmi", "derive_more", "serde/std", "rstd/std", "shared_memory", "lazy_static", "parking_lot", "log" ]
10 changes: 10 additions & 0 deletions parachain/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,3 +207,13 @@ pub struct UpwardMessageRef<'a> {
/// Underlying data of the message.
pub data: &'a [u8],
}

/// A message from a parachain to its Relay Chain.
#[derive(Clone, PartialEq, Eq, Encode, Decode)]
#[cfg_attr(feature = "std", derive(Debug))]
pub struct UpwardMessage {
/// The origin for the message to be sent from.
pub origin: ParachainDispatchOrigin,
/// The message data.
pub data: Vec<u8>,
}
Loading

0 comments on commit c5836f3

Please sign in to comment.