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

Commit

Permalink
Get polkadot to compile via wasm!
Browse files Browse the repository at this point in the history
  • Loading branch information
expenses committed Dec 1, 2019
1 parent 04ffe72 commit 408288b
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 25 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ build = "build.rs"
edition = "2018"

[dependencies]
cli = { package = "polkadot-cli", path = "cli" }
cli = { package = "polkadot-cli", path = "cli", default-features = false }
futures = "0.3.1"
ctrlc = { version = "3.1.3", features = ["termination"] }
service = { package = "polkadot-service", path = "service" }
ctrlc = { version = "3.1.3", features = ["termination"], optional = true }
service = { package = "polkadot-service", path = "service", default-features = false }

[build-dependencies]
vergen = "3.0.4"
Expand Down Expand Up @@ -47,3 +47,7 @@ maintenance = { status = "actively-developed" }
[profile.release]
# Polkadot runtime requires unwinding.
panic = "unwind"

[features]
default = ["rocksdb", "ctrlc"]
rocksdb = ["cli/rocksdb", "service/rocksdb"]
5 changes: 3 additions & 2 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ futures = { version = "0.3.1", features = ["compat"] }
futures01 = { package = "futures", version = "0.1.29" }
structopt = "0.3.4"
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]
default = [ "wasmtime" ]
default = [ "wasmtime", "rocksdb" ]
wasmtime = [ "cli/wasmtime" ]
rocksdb = [ "service/rocksdb" ]
25 changes: 8 additions & 17 deletions cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ mod chain_spec;

use chain_spec::ChainSpec;
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 log::{info, error};
use structopt::StructOpt;
Expand All @@ -37,8 +37,6 @@ pub use cli::{VersionInfo, IntoExit, NoCustom};
pub use cli::{display_role, error};

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> {
Ok(match ChainSpec::from(id) {
Expand All @@ -62,7 +60,7 @@ pub trait Worker: IntoExit {
fn configuration(&self) -> service::CustomConfiguration { Default::default() }

/// 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,
Backend = B, SelectChain = SC,
NetworkSpecialization = service::PolkadotProtocol, CallExecutor = CE>,
Expand Down Expand Up @@ -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|
Ok(service::new_chain_ops(config)?), load_spec),
cli::ParseAndPrepare::CustomCommand(PolkadotSubCommands::ValidationWorker(args)) => {
#[cfg(not(target_os = "unknown"))]
service::run_validation_worker(&args.mem_id)?;
Ok(())
}
Expand All @@ -168,32 +167,24 @@ fn run_until_exit<T, SC, B, CE, W>(
{
let (exit_send, exit) = oneshot::channel();

let executor = runtime.executor();
let informant = cli::informant::build(&service);
let future = select(exit, informant)
.map(|_| Ok(()))
.compat();
let future = select(exit, informant);

executor.spawn(future);
let informant_handle = runtime.spawn(future);

// 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
let _telemetry = service.telemetry();

let work = worker.work(&service, Arc::new(executor));
let work = worker.work(&service, &runtime);
let service = service
.map_err(|err| error!("Error while running Service: {}", err))
.compat();
let future = select(service, work)
.map(|_| Ok::<_, ()>(()))
.compat();
let future = select(service, work);;
let _ = runtime.block_on(future);
let _ = exit_send.send(());

use futures01::Future;

// TODO [andre]: timeout this future substrate/#1318
let _ = runtime.shutdown_on_idle().wait();
let _ = runtime.block_on(informant_handle);

Ok(())
}
5 changes: 3 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#![warn(missing_docs)]

use cli::{AbstractService, VersionInfo, TaskExecutor};
use cli::{AbstractService, VersionInfo, Runtime};
use futures::channel::oneshot;
use futures::{future, FutureExt};

Expand All @@ -33,6 +33,7 @@ impl cli::IntoExit for Worker {
let (exit_send, exit) = oneshot::channel();

let exit_send_cell = RefCell::new(Some(exit_send));
#[cfg(not(target_os = "unknown"))]
ctrlc::set_handler(move || {
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");
Expand All @@ -45,7 +46,7 @@ impl cli::IntoExit for Worker {

impl cli::Worker for Worker {
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,
Backend = B, SelectChain = SC,
NetworkSpecialization = service::PolkadotProtocol, CallExecutor = CE>,
Expand Down

0 comments on commit 408288b

Please sign in to comment.