Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Update to latest Substrate #407

Merged
merged 2 commits into from
Aug 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
236 changes: 135 additions & 101 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ edition = "2018"
cli = { package = "polkadot-cli", path = "cli" }
futures = "0.1"
ctrlc = { version = "3.0", features = ["termination"] }
service = { package = "polkadot-service", path = "service" }

[build-dependencies]
vergen = "3"
Expand Down
39 changes: 23 additions & 16 deletions cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,15 @@

mod chain_spec;

use std::ops::Deref;
use chain_spec::ChainSpec;
use futures::Future;
use tokio::runtime::Runtime;
use service::{Service as BareService, Error as ServiceError};
use std::sync::Arc;
use log::{info, error};
use structopt::StructOpt;

pub use service::{
Components as ServiceComponents, PolkadotService, CustomConfiguration, ServiceFactory, Factory,
AbstractService, CustomConfiguration,
ProvideRuntimeApi, CoreApi, ParachainHost,
};

Expand Down Expand Up @@ -63,7 +61,13 @@ pub trait Worker: IntoExit {
fn configuration(&self) -> service::CustomConfiguration { Default::default() }

/// Do work and schedule exit.
fn work<S: PolkadotService>(self, service: &S, executor: TaskExecutor) -> Self::Work;
fn work<S, SC, B, CE>(self, service: &S, executor: TaskExecutor) -> Self::Work
where S: AbstractService<Block = service::Block, RuntimeApi = service::RuntimeApi,
Backend = B, SelectChain = SC,
NetworkSpecialization = service::PolkadotProtocol, CallExecutor = CE>,
SC: service::SelectChain<service::Block> + 'static,
B: service::Backend<service::Block, service::Blake2Hasher> + 'static,
CE: service::CallExecutor<service::Block, service::Blake2Hasher> + Clone + Send + Sync + 'static;
}

#[derive(Debug, StructOpt, Clone)]
Expand Down Expand Up @@ -101,39 +105,42 @@ pub fn run<W>(worker: W, version: cli::VersionInfo) -> error::Result<()> where
service::Roles::LIGHT =>
run_until_exit(
runtime,
Factory::new_light(config).map_err(|e| format!("{:?}", e))?,
service::new_light(config).map_err(|e| format!("{:?}", e))?,
worker
),
_ => run_until_exit(
runtime,
Factory::new_full(config).map_err(|e| format!("{:?}", e))?,
service::new_full(config).map_err(|e| format!("{:?}", e))?,
worker
),
}.map_err(|e| format!("{:?}", e))
}),
cli::ParseAndPrepare::BuildSpec(cmd) => cmd.run(load_spec),
cli::ParseAndPrepare::ExportBlocks(cmd) =>
cmd.run::<service::Factory, _, _>(load_spec, worker),
cli::ParseAndPrepare::ImportBlocks(cmd) =>
cmd.run::<service::Factory, _, _>(load_spec, worker),
cli::ParseAndPrepare::ExportBlocks(cmd) => cmd.run_with_builder::<(), _, _, _, _, _>(|config|
Ok(service::new_chain_ops(config)?), load_spec, worker),
cli::ParseAndPrepare::ImportBlocks(cmd) => cmd.run_with_builder::<(), _, _, _, _, _>(|config|
Ok(service::new_chain_ops(config)?), load_spec, worker),
cli::ParseAndPrepare::PurgeChain(cmd) => cmd.run(load_spec),
cli::ParseAndPrepare::RevertChain(cmd) => cmd.run::<service::Factory, _>(load_spec),
cli::ParseAndPrepare::RevertChain(cmd) => cmd.run_with_builder::<(), _, _, _, _>(|config|
Ok(service::new_chain_ops(config)?), load_spec),
cli::ParseAndPrepare::CustomCommand(PolkadotSubCommands::ValidationWorker(args)) => {
service::run_validation_worker(&args.mem_id)?;
Ok(())
}
}
}

fn run_until_exit<T, C, W>(
fn run_until_exit<T, SC, B, CE, W>(
mut runtime: Runtime,
service: T,
worker: W,
) -> error::Result<()>
where
T: Deref<Target=BareService<C>> + Future<Item = (), Error = ServiceError> + Send + 'static,
C: service::Components,
BareService<C>: PolkadotService,
T: AbstractService<Block = service::Block, RuntimeApi = service::RuntimeApi,
SelectChain = SC, Backend = B, NetworkSpecialization = service::PolkadotProtocol, CallExecutor = CE>,
SC: service::SelectChain<service::Block> + 'static,
B: service::Backend<service::Block, service::Blake2Hasher> + 'static,
CE: service::CallExecutor<service::Block, service::Blake2Hasher> + Clone + Send + Sync + 'static,
W: Worker,
{
let (exit_send, exit) = exit_future::signal();
Expand All @@ -146,7 +153,7 @@ fn run_until_exit<T, C, W>(
// but we need to keep holding a reference to the global telemetry guard
let _telemetry = service.telemetry();

let work = worker.work(&*service, Arc::new(executor));
let work = worker.work(&service, Arc::new(executor));
let service = service.map_err(|err| error!("Error while running Service: {}", err));
let _ = runtime.block_on(service.select(work));
exit_send.fire();
Expand Down
1 change: 1 addition & 0 deletions collator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ polkadot-primitives = { path = "../primitives" }
polkadot-cli = { path = "../cli" }
polkadot-network = { path = "../network" }
polkadot-validation = { path = "../validation" }
polkadot-service = { path = "../service" }
log = "0.4"
tokio = "0.1.7"

Expand Down
14 changes: 8 additions & 6 deletions collator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,12 @@ use polkadot_primitives::{
}
};
use polkadot_cli::{
Worker, IntoExit, ProvideRuntimeApi, TaskExecutor, PolkadotService, CustomConfiguration,
ParachainHost,
Worker, IntoExit, ProvideRuntimeApi, TaskExecutor, AbstractService,
CustomConfiguration, ParachainHost,
};
use polkadot_network::validation::{SessionParams, ValidationNetwork};
use polkadot_network::NetworkService;
use polkadot_network::{NetworkService, PolkadotProtocol};
use tokio::timer::Timeout;
use consensus_common::SelectChain;

pub use polkadot_cli::VersionInfo;
pub use polkadot_network::validation::Incoming;
Expand Down Expand Up @@ -287,8 +286,11 @@ impl<P, E> Worker for CollationNode<P, E> where
config
}

fn work<S>(self, service: &S, task_executor: TaskExecutor) -> Self::Work where
S: PolkadotService,
fn work<S, SC, B, CE>(self, service: &S, task_executor: TaskExecutor) -> Self::Work
where S: AbstractService<Block = polkadot_service::Block, RuntimeApi = polkadot_service::RuntimeApi, Backend = B, SelectChain = SC, NetworkSpecialization = PolkadotProtocol, CallExecutor = CE>,
SC: polkadot_service::SelectChain<polkadot_service::Block> + 'static,
B: polkadot_service::Backend<polkadot_service::Block, polkadot_service::Blake2Hasher> + 'static,
CE: polkadot_service::CallExecutor<polkadot_service::Block, polkadot_service::Blake2Hasher> + Clone + Send + Sync + 'static
{
let CollationNode { build_parachain_context, exit, para_id, key } = self;
let client = service.client();
Expand Down
3 changes: 3 additions & 0 deletions service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ sr-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-ma
sr-primitives = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
primitives = { package = "substrate-primitives", git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
client = { package = "substrate-client", git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
client-db = { package = "substrate-client-db", git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
substrate-executor = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
substrate-network = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
consensus_common = { package = "substrate-consensus-common", git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
grandpa = { package = "substrate-finality-grandpa", git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
grandpa_primitives = { package = "substrate-finality-grandpa-primitives", git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
Expand Down
Loading