Unverified Commit 408288b0 authored by Ashley's avatar Ashley
Browse files

Get polkadot to compile via wasm!

parent 04ffe72e
...@@ -3698,7 +3698,6 @@ dependencies = [ ...@@ -3698,7 +3698,6 @@ dependencies = [
name = "polkadot-service" name = "polkadot-service"
version = "0.7.1" version = "0.7.1"
dependencies = [ dependencies = [
"exit-future 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
"futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)",
"futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"hex-literal 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "hex-literal 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
......
...@@ -10,10 +10,10 @@ build = "build.rs" ...@@ -10,10 +10,10 @@ build = "build.rs"
edition = "2018" edition = "2018"
[dependencies] [dependencies]
cli = { package = "polkadot-cli", path = "cli" } cli = { package = "polkadot-cli", path = "cli", default-features = false }
futures = "0.3.1" futures = "0.3.1"
ctrlc = { version = "3.1.3", features = ["termination"] } ctrlc = { version = "3.1.3", features = ["termination"], optional = true }
service = { package = "polkadot-service", path = "service" } service = { package = "polkadot-service", path = "service", default-features = false }
[build-dependencies] [build-dependencies]
vergen = "3.0.4" vergen = "3.0.4"
...@@ -47,3 +47,7 @@ maintenance = { status = "actively-developed" } ...@@ -47,3 +47,7 @@ maintenance = { status = "actively-developed" }
[profile.release] [profile.release]
# Polkadot runtime requires unwinding. # Polkadot runtime requires unwinding.
panic = "unwind" panic = "unwind"
[features]
default = ["rocksdb", "ctrlc"]
rocksdb = ["cli/rocksdb", "service/rocksdb"]
...@@ -12,8 +12,9 @@ futures = { version = "0.3.1", features = ["compat"] } ...@@ -12,8 +12,9 @@ futures = { version = "0.3.1", features = ["compat"] }
futures01 = { package = "futures", version = "0.1.29" } futures01 = { package = "futures", version = "0.1.29" }
structopt = "0.3.4" structopt = "0.3.4"
cli = { package = "substrate-cli", git = "https://github.com/paritytech/substrate", branch = "ashley-update-exit-future" } cli = { package = "substrate-cli", git = "https://github.com/paritytech/substrate", branch = "ashley-update-exit-future" }
service = { package = "polkadot-service", path = "../service" } service = { package = "polkadot-service", path = "../service", default-features = false }
[features] [features]
default = [ "wasmtime" ] default = [ "wasmtime", "rocksdb" ]
wasmtime = [ "cli/wasmtime" ] wasmtime = [ "cli/wasmtime" ]
rocksdb = [ "service/rocksdb" ]
...@@ -23,7 +23,7 @@ mod chain_spec; ...@@ -23,7 +23,7 @@ mod chain_spec;
use chain_spec::ChainSpec; use chain_spec::ChainSpec;
use futures::{Future, FutureExt, TryFutureExt, future::select, channel::oneshot, compat::Future01CompatExt}; use futures::{Future, FutureExt, TryFutureExt, future::select, channel::oneshot, compat::Future01CompatExt};
use tokio::runtime::Runtime; pub use tokio::runtime::Runtime;
use std::sync::Arc; use std::sync::Arc;
use log::{info, error}; use log::{info, error};
use structopt::StructOpt; use structopt::StructOpt;
...@@ -37,8 +37,6 @@ pub use cli::{VersionInfo, IntoExit, NoCustom}; ...@@ -37,8 +37,6 @@ pub use cli::{VersionInfo, IntoExit, NoCustom};
pub use cli::{display_role, error}; pub use cli::{display_role, error};
type BoxedFuture = Box<dyn futures01::Future<Item = (), Error = ()> + Send>; type BoxedFuture = Box<dyn futures01::Future<Item = (), Error = ()> + Send>;
/// Abstraction over an executor that lets you spawn tasks in the background.
pub type TaskExecutor = Arc<dyn futures01::future::Executor<BoxedFuture> + Send + Sync>;
fn load_spec(id: &str) -> Result<Option<service::ChainSpec>, String> { fn load_spec(id: &str) -> Result<Option<service::ChainSpec>, String> {
Ok(match ChainSpec::from(id) { Ok(match ChainSpec::from(id) {
...@@ -62,7 +60,7 @@ pub trait Worker: IntoExit { ...@@ -62,7 +60,7 @@ pub trait Worker: IntoExit {
fn configuration(&self) -> service::CustomConfiguration { Default::default() } fn configuration(&self) -> service::CustomConfiguration { Default::default() }
/// Do work and schedule exit. /// Do work and schedule exit.
fn work<S, SC, B, CE>(self, service: &S, executor: TaskExecutor) -> Self::Work fn work<S, SC, B, CE>(self, service: &S, executor: &Runtime) -> Self::Work
where S: AbstractService<Block = service::Block, RuntimeApi = service::RuntimeApi, where S: AbstractService<Block = service::Block, RuntimeApi = service::RuntimeApi,
Backend = B, SelectChain = SC, Backend = B, SelectChain = SC,
NetworkSpecialization = service::PolkadotProtocol, CallExecutor = CE>, NetworkSpecialization = service::PolkadotProtocol, CallExecutor = CE>,
...@@ -147,6 +145,7 @@ pub fn run<W>(worker: W, version: cli::VersionInfo) -> error::Result<()> where ...@@ -147,6 +145,7 @@ pub fn run<W>(worker: W, version: cli::VersionInfo) -> error::Result<()> where
cli::ParseAndPrepare::RevertChain(cmd) => cmd.run_with_builder::<(), _, _, _, _, _>(|config| cli::ParseAndPrepare::RevertChain(cmd) => cmd.run_with_builder::<(), _, _, _, _, _>(|config|
Ok(service::new_chain_ops(config)?), load_spec), Ok(service::new_chain_ops(config)?), load_spec),
cli::ParseAndPrepare::CustomCommand(PolkadotSubCommands::ValidationWorker(args)) => { cli::ParseAndPrepare::CustomCommand(PolkadotSubCommands::ValidationWorker(args)) => {
#[cfg(not(target_os = "unknown"))]
service::run_validation_worker(&args.mem_id)?; service::run_validation_worker(&args.mem_id)?;
Ok(()) Ok(())
} }
...@@ -168,32 +167,24 @@ fn run_until_exit<T, SC, B, CE, W>( ...@@ -168,32 +167,24 @@ fn run_until_exit<T, SC, B, CE, W>(
{ {
let (exit_send, exit) = oneshot::channel(); let (exit_send, exit) = oneshot::channel();
let executor = runtime.executor();
let informant = cli::informant::build(&service); let informant = cli::informant::build(&service);
let future = select(exit, informant) let future = select(exit, informant);
.map(|_| Ok(()))
.compat();
executor.spawn(future); let informant_handle = runtime.spawn(future);
// we eagerly drop the service so that the internal exit future is fired, // we eagerly drop the service so that the internal exit future is fired,
// but we need to keep holding a reference to the global telemetry guard // but we need to keep holding a reference to the global telemetry guard
let _telemetry = service.telemetry(); let _telemetry = service.telemetry();
let work = worker.work(&service, Arc::new(executor)); let work = worker.work(&service, &runtime);
let service = service let service = service
.map_err(|err| error!("Error while running Service: {}", err)) .map_err(|err| error!("Error while running Service: {}", err))
.compat(); .compat();
let future = select(service, work) let future = select(service, work);;
.map(|_| Ok::<_, ()>(()))
.compat();
let _ = runtime.block_on(future); let _ = runtime.block_on(future);
let _ = exit_send.send(()); let _ = exit_send.send(());
use futures01::Future; let _ = runtime.block_on(informant_handle);
// TODO [andre]: timeout this future substrate/#1318
let _ = runtime.shutdown_on_idle().wait();
Ok(()) Ok(())
} }
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
#![warn(missing_docs)] #![warn(missing_docs)]
use cli::{AbstractService, VersionInfo, TaskExecutor}; use cli::{AbstractService, VersionInfo, Runtime};
use futures::channel::oneshot; use futures::channel::oneshot;
use futures::{future, FutureExt}; use futures::{future, FutureExt};
...@@ -33,6 +33,7 @@ impl cli::IntoExit for Worker { ...@@ -33,6 +33,7 @@ impl cli::IntoExit for Worker {
let (exit_send, exit) = oneshot::channel(); let (exit_send, exit) = oneshot::channel();
let exit_send_cell = RefCell::new(Some(exit_send)); let exit_send_cell = RefCell::new(Some(exit_send));
#[cfg(not(target_os = "unknown"))]
ctrlc::set_handler(move || { ctrlc::set_handler(move || {
if let Some(exit_send) = exit_send_cell.try_borrow_mut().expect("signal handler not reentrant; qed").take() { if let Some(exit_send) = exit_send_cell.try_borrow_mut().expect("signal handler not reentrant; qed").take() {
exit_send.send(()).expect("Error sending exit notification"); exit_send.send(()).expect("Error sending exit notification");
...@@ -45,7 +46,7 @@ impl cli::IntoExit for Worker { ...@@ -45,7 +46,7 @@ impl cli::IntoExit for Worker {
impl cli::Worker for Worker { impl cli::Worker for Worker {
type Work = <Self as cli::IntoExit>::Exit; type Work = <Self as cli::IntoExit>::Exit;
fn work<S, SC, B, CE>(self, _: &S, _: TaskExecutor) -> Self::Work fn work<S, SC, B, CE>(self, _: &S, _: &Runtime) -> Self::Work
where S: AbstractService<Block = service::Block, RuntimeApi = service::RuntimeApi, where S: AbstractService<Block = service::Block, RuntimeApi = service::RuntimeApi,
Backend = B, SelectChain = SC, Backend = B, SelectChain = SC,
NetworkSpecialization = service::PolkadotProtocol, CallExecutor = CE>, NetworkSpecialization = service::PolkadotProtocol, CallExecutor = CE>,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment