From c2f78371f1227a52f98e9fb46b89fddb64c16b42 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Sat, 14 Jul 2018 16:10:20 +0200 Subject: [PATCH] Dual execution (#311) * Initial logic * Remove accidental file * Config * Remove accidental * Apply CLI config * Additional work. Sadly pointless. * Rearrange everything * Loop into CLI param * Implement dual execution * typo * fix tests. * Better docs * Fix bug * Add some tests * Report block information on consensus failure, tests * Fix test --- polkadot/cli/src/cli.yml | 6 +++++- polkadot/cli/src/lib.rs | 16 +++++++++++++++- polkadot/service/src/components.rs | 10 +++++----- polkadot/service/src/config.rs | 4 ++++ polkadot/service/src/lib.rs | 8 ++++---- 5 files changed, 33 insertions(+), 11 deletions(-) diff --git a/polkadot/cli/src/cli.yml b/polkadot/cli/src/cli.yml index bae81c5fd0..bb6f1defbf 100644 --- a/polkadot/cli/src/cli.yml +++ b/polkadot/cli/src/cli.yml @@ -74,7 +74,7 @@ args: - pruning: long: pruning value_name: PRUNING_MODE - help: Specify the pruning mode. (a number of blocks to keep or "archive"). Default is 256. + help: Specify the pruning mode, a number of blocks to keep or "archive". Default is 256. takes_value: true - name: long: name @@ -95,6 +95,10 @@ args: value_name: TELEMETRY_URL help: The URL of the telemetry server. Implies --telemetry takes_value: true + - execution: + long: execution + value_name: STRATEGY + help: The means of execution used when calling into the runtime. Can be either wasm, native or both. subcommands: - build-spec: about: Build a spec.json file, outputing to stdout diff --git a/polkadot/cli/src/lib.rs b/polkadot/cli/src/lib.rs index 6c0f44bd17..d51ee7bed2 100644 --- a/polkadot/cli/src/lib.rs +++ b/polkadot/cli/src/lib.rs @@ -218,18 +218,32 @@ pub fn run(args: I, worker: W) -> error::Result<()> where if matches.is_present("collator") { info!("Starting collator"); // TODO [rob]: collation node implementation - service::Role::FULL + // This isn't a thing. Different parachains will have their own collator executables and + // maybe link to libpolkadot to get a light-client. + service::Role::LIGHT } else if matches.is_present("light") { info!("Starting (light)"); + config.execution_strategy = service::ExecutionStrategy::NativeWhenPossible; service::Role::LIGHT } else if matches.is_present("validator") || matches.is_present("dev") { info!("Starting validator"); + config.execution_strategy = service::ExecutionStrategy::Both; service::Role::AUTHORITY } else { info!("Starting (heavy)"); + config.execution_strategy = service::ExecutionStrategy::NativeWhenPossible; service::Role::FULL }; + if let Some(s) = matches.value_of("execution") { + config.execution_strategy = match s { + "both" => service::ExecutionStrategy::Both, + "native" => service::ExecutionStrategy::NativeWhenPossible, + "wasm" => service::ExecutionStrategy::AlwaysWasm, + _ => return Err(error::ErrorKind::Input("Invalid execution mode specified".to_owned()).into()), + }; + } + config.roles = role; { config.network.boot_nodes.extend(matches diff --git a/polkadot/service/src/components.rs b/polkadot/service/src/components.rs index b7b5c3c96a..44e16e5ff4 100644 --- a/polkadot/service/src/components.rs +++ b/polkadot/service/src/components.rs @@ -30,7 +30,7 @@ use polkadot_api; use polkadot_executor::Executor as LocalDispatch; use polkadot_network::NetworkService; use polkadot_primitives::{Block, BlockId, Hash}; -use state_machine; +use state_machine::{self, ExecutionStrategy}; use substrate_executor::NativeExecutor; use transaction_pool::{self, TransactionPool}; use tokio::runtime::TaskExecutor; @@ -50,7 +50,7 @@ pub trait Components { type Executor: 'static + client::CallExecutor + Send + Sync; /// Create client. - fn build_client(&self, settings: client_db::DatabaseSettings, executor: CodeExecutor, chain_spec: &ChainSpec) + fn build_client(&self, settings: client_db::DatabaseSettings, executor: CodeExecutor, chain_spec: &ChainSpec, execution_strategy: ExecutionStrategy) -> Result<(Arc>, Option>>), error::Error>; /// Create api. @@ -83,9 +83,9 @@ impl Components for FullComponents { type Api = Client; type Executor = client::LocalCallExecutor, NativeExecutor>; - fn build_client(&self, db_settings: client_db::DatabaseSettings, executor: CodeExecutor, chain_spec: &ChainSpec) + fn build_client(&self, db_settings: client_db::DatabaseSettings, executor: CodeExecutor, chain_spec: &ChainSpec, execution_strategy: ExecutionStrategy) -> Result<(Arc>, Option>>), error::Error> { - Ok((Arc::new(client_db::new_client(db_settings, executor, chain_spec)?), None)) + Ok((Arc::new(client_db::new_client(db_settings, executor, chain_spec, execution_strategy)?), None)) } fn build_api(&self, client: Arc>) -> Arc { @@ -142,7 +142,7 @@ impl Components for LightComponents { client::light::blockchain::Blockchain, network::OnDemand>, network::OnDemand>; - fn build_client(&self, db_settings: client_db::DatabaseSettings, executor: CodeExecutor, spec: &ChainSpec) + fn build_client(&self, db_settings: client_db::DatabaseSettings, executor: CodeExecutor, spec: &ChainSpec, _execution_strategy: ExecutionStrategy) -> Result<(Arc>, Option>>), error::Error> { let db_storage = client_db::light::LightStorage::new(db_settings)?; let light_blockchain = client::light::new_light_blockchain(db_storage); diff --git a/polkadot/service/src/config.rs b/polkadot/service/src/config.rs index 5b27331882..c9fdc9ced1 100644 --- a/polkadot/service/src/config.rs +++ b/polkadot/service/src/config.rs @@ -18,6 +18,7 @@ use transaction_pool; use chain_spec::ChainSpec; +pub use state_machine::ExecutionStrategy; pub use network::Role; pub use network::NetworkConfiguration; pub use client_db::PruningMode; @@ -44,6 +45,8 @@ pub struct Configuration { pub telemetry: Option, /// Node name. pub name: String, + /// Execution strategy. + pub execution_strategy: ExecutionStrategy, } impl Configuration { @@ -60,6 +63,7 @@ impl Configuration { keys: Default::default(), telemetry: Default::default(), pruning: PruningMode::ArchiveAll, + execution_strategy: ExecutionStrategy::Both, }; configuration.network.boot_nodes = configuration.chain_spec.boot_nodes().to_vec(); configuration diff --git a/polkadot/service/src/lib.rs b/polkadot/service/src/lib.rs index 7ac4f714f2..787e304c06 100644 --- a/polkadot/service/src/lib.rs +++ b/polkadot/service/src/lib.rs @@ -73,7 +73,7 @@ use tokio::runtime::TaskExecutor; pub use self::error::{ErrorKind, Error}; pub use self::components::{Components, FullComponents, LightComponents}; -pub use config::{Configuration, Role, PruningMode}; +pub use config::{Configuration, Role, PruningMode, ExecutionStrategy}; pub use chain_spec::ChainSpec; /// Polkadot service. @@ -112,7 +112,7 @@ pub fn new_client(config: Configuration) -> Result Service let (signal, exit) = ::exit_future::signal(); // Create client - let executor = polkadot_executor::Executor::new(); + let executor = polkadot_executor::Executor::with_heap_pages(128); let mut keystore = Keystore::open(config.keystore_path.into())?; for seed in &config.keys { @@ -144,7 +144,7 @@ impl Service pruning: config.pruning, }; - let (client, on_demand) = components.build_client(db_settings, executor, &config.chain_spec)?; + let (client, on_demand) = components.build_client(db_settings, executor, &config.chain_spec, config.execution_strategy)?; let api = components.build_api(client.clone()); let best_header = client.best_block_header()?;