Skip to content

Commit

Permalink
client: ExecutionContext: distinguish between own and foreign imports
Browse files Browse the repository at this point in the history
  • Loading branch information
andresilva committed May 28, 2020
1 parent 06315f5 commit 0fac115
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 48 deletions.
10 changes: 5 additions & 5 deletions bin/node/testing/src/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -515,19 +515,19 @@ impl Profile {
fn into_execution_strategies(self) -> ExecutionStrategies {
match self {
Profile::Wasm => ExecutionStrategies {
syncing: ExecutionStrategy::AlwaysWasm,
importing: ExecutionStrategy::AlwaysWasm,
own_block_import: ExecutionStrategy::AlwaysWasm,
foreign_block_import: ExecutionStrategy::AlwaysWasm,
block_construction: ExecutionStrategy::AlwaysWasm,
offchain_worker: ExecutionStrategy::AlwaysWasm,
other: ExecutionStrategy::AlwaysWasm,
},
Profile::Native => ExecutionStrategies {
syncing: ExecutionStrategy::NativeElseWasm,
importing: ExecutionStrategy::NativeElseWasm,
own_block_import: ExecutionStrategy::NativeElseWasm,
foreign_block_import: ExecutionStrategy::NativeElseWasm,
block_construction: ExecutionStrategy::NativeElseWasm,
offchain_worker: ExecutionStrategy::NativeElseWasm,
other: ExecutionStrategy::NativeElseWasm,
}
},
}
}
}
Expand Down
20 changes: 10 additions & 10 deletions client/api/src/execution_extensions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ use parking_lot::RwLock;
/// Execution strategies settings.
#[derive(Debug, Clone)]
pub struct ExecutionStrategies {
/// Execution strategy used when syncing.
pub syncing: ExecutionStrategy,
/// Execution strategy used when importing blocks.
pub importing: ExecutionStrategy,
/// Execution strategy used when importing locally authored blocks.
pub own_block_import: ExecutionStrategy,
/// Execution strategy used when importing foreign blocks.
pub foreign_block_import: ExecutionStrategy,
/// Execution strategy used when constructing blocks.
pub block_construction: ExecutionStrategy,
/// Execution strategy used for offchain workers.
Expand All @@ -53,8 +53,8 @@ pub struct ExecutionStrategies {
impl Default for ExecutionStrategies {
fn default() -> ExecutionStrategies {
ExecutionStrategies {
syncing: ExecutionStrategy::NativeElseWasm,
importing: ExecutionStrategy::NativeElseWasm,
own_block_import: ExecutionStrategy::NativeElseWasm,
foreign_block_import: ExecutionStrategy::NativeElseWasm,
block_construction: ExecutionStrategy::AlwaysWasm,
offchain_worker: ExecutionStrategy::NativeWhenPossible,
other: ExecutionStrategy::NativeElseWasm,
Expand Down Expand Up @@ -145,10 +145,10 @@ impl<Block: traits::Block> ExecutionExtensions<Block> {
let manager = match context {
ExecutionContext::BlockConstruction =>
self.strategies.block_construction.get_manager(),
ExecutionContext::Syncing =>
self.strategies.syncing.get_manager(),
ExecutionContext::Importing =>
self.strategies.importing.get_manager(),
ExecutionContext::OwnBlockImport =>
self.strategies.own_block_import.get_manager(),
ExecutionContext::ForeignBlockImport =>
self.strategies.foreign_block_import.get_manager(),
ExecutionContext::OffchainCall(Some((_, capabilities))) if capabilities.has_all() =>
self.strategies.offchain_worker.get_manager(),
ExecutionContext::OffchainCall(_) =>
Expand Down
9 changes: 5 additions & 4 deletions client/cli/src/arg_enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,11 @@ arg_enum! {
}
}

/// Default value for the `--execution-syncing` parameter.
pub const DEFAULT_EXECUTION_SYNCING: ExecutionStrategy = ExecutionStrategy::NativeElseWasm;
/// Default value for the `--execution-import-block` parameter.
pub const DEFAULT_EXECUTION_IMPORT_BLOCK: ExecutionStrategy = ExecutionStrategy::NativeElseWasm;
/// Default value for the `--execution-own-block-import` parameter.
pub const DEFAULT_EXECUTION_OWN_BLOCK_IMPORT: ExecutionStrategy = ExecutionStrategy::NativeElseWasm;
/// Default value for the `--execution-foreign-block-import` parameter.
pub const DEFAULT_EXECUTION_FOREIGN_BLOCK_IMPORT: ExecutionStrategy =
ExecutionStrategy::NativeElseWasm;
/// Default value for the `--execution-block-construction` parameter.
pub const DEFAULT_EXECUTION_BLOCK_CONSTRUCTION: ExecutionStrategy = ExecutionStrategy::Wasm;
/// Default value for the `--execution-offchain-worker` parameter.
Expand Down
32 changes: 17 additions & 15 deletions client/cli/src/params/import_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use crate::arg_enums::{
ExecutionStrategy, TracingReceiver, WasmExecutionMethod,
DEFAULT_EXECUTION_BLOCK_CONSTRUCTION, DEFAULT_EXECUTION_IMPORT_BLOCK,
DEFAULT_EXECUTION_OFFCHAIN_WORKER, DEFAULT_EXECUTION_OTHER, DEFAULT_EXECUTION_SYNCING,
ExecutionStrategy, TracingReceiver, WasmExecutionMethod, DEFAULT_EXECUTION_BLOCK_CONSTRUCTION,
DEFAULT_EXECUTION_FOREIGN_BLOCK_IMPORT, DEFAULT_EXECUTION_OFFCHAIN_WORKER,
DEFAULT_EXECUTION_OTHER, DEFAULT_EXECUTION_OWN_BLOCK_IMPORT,
};
use crate::params::DatabaseParams;
use crate::params::PruningParams;
Expand Down Expand Up @@ -118,8 +118,10 @@ impl ImportParams {
};

ExecutionStrategies {
syncing: exec_all_or(exec.execution_syncing, DEFAULT_EXECUTION_SYNCING),
importing: exec_all_or(exec.execution_import_block, DEFAULT_EXECUTION_IMPORT_BLOCK),
own_block_import:
exec_all_or(exec.execution_own_block_import, DEFAULT_EXECUTION_OWN_BLOCK_IMPORT),
foreign_block_import:
exec_all_or(exec.execution_foreign_block_import, DEFAULT_EXECUTION_FOREIGN_BLOCK_IMPORT),
block_construction:
exec_all_or(exec.execution_block_construction, DEFAULT_EXECUTION_BLOCK_CONSTRUCTION),
offchain_worker:
Expand All @@ -132,25 +134,25 @@ impl ImportParams {
/// Execution strategies parameters.
#[derive(Debug, StructOpt, Clone)]
pub struct ExecutionStrategiesParams {
/// The means of execution used when calling into the runtime while syncing blocks.
/// The means of execution used when calling into the runtime while import locally authored blocks.
#[structopt(
long = "execution-syncing",
long = "execution-own-block-import",
value_name = "STRATEGY",
possible_values = &ExecutionStrategy::variants(),
case_insensitive = true,
default_value = DEFAULT_EXECUTION_SYNCING.as_str(),
default_value = DEFAULT_EXECUTION_OWN_BLOCK_IMPORT.as_str(),
)]
pub execution_syncing: ExecutionStrategy,
pub execution_own_block_import: ExecutionStrategy,

/// The means of execution used when calling into the runtime while importing blocks.
/// The means of execution used when calling into the runtime while importing foreign blocks.
#[structopt(
long = "execution-import-block",
long = "execution-foreign-block-import",
value_name = "STRATEGY",
possible_values = &ExecutionStrategy::variants(),
case_insensitive = true,
default_value = DEFAULT_EXECUTION_IMPORT_BLOCK.as_str(),
default_value = DEFAULT_EXECUTION_FOREIGN_BLOCK_IMPORT.as_str(),
)]
pub execution_import_block: ExecutionStrategy,
pub execution_foreign_block_import: ExecutionStrategy,

/// The means of execution used when calling into the runtime while constructing blocks.
#[structopt(
Expand Down Expand Up @@ -192,8 +194,8 @@ pub struct ExecutionStrategiesParams {
"execution-other",
"execution-offchain-worker",
"execution-block-construction",
"execution-import-block",
"execution-syncing",
"execution-own-block-import",
"execution-foreign-block-import",
]
)]
pub execution: Option<ExecutionStrategy>,
Expand Down
6 changes: 3 additions & 3 deletions client/service/src/client/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -861,10 +861,10 @@ impl<B, E, Block, RA> Client<B, E, Block, RA> where
// block.
(true, ref mut storage_changes @ None, Some(ref body)) => {
let runtime_api = self.runtime_api();
let execution_context = if import_block.origin == BlockOrigin::NetworkInitialSync {
ExecutionContext::Syncing
let execution_context = if import_block.origin == BlockOrigin::Own {
ExecutionContext::OwnBlockImport
} else {
ExecutionContext::Importing
ExecutionContext::ForeignBlockImport
};

runtime_api.execute_block_with_context(
Expand Down
10 changes: 5 additions & 5 deletions primitives/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ pub use sp_std;

/// Context for executing a call into the runtime.
pub enum ExecutionContext {
/// Context for general importing (including own blocks).
Importing,
/// Context used when syncing the blockchain.
Syncing,
/// Context used for importing locally authored blocks.
OwnBlockImport,
/// Context used for importing foreign blocks.
ForeignBlockImport,
/// Context used for block construction.
BlockConstruction,
/// Context used for offchain calls.
Expand All @@ -111,7 +111,7 @@ impl ExecutionContext {
use ExecutionContext::*;

match self {
Importing | Syncing | BlockConstruction =>
OwnBlockImport | ForeignBlockImport | BlockConstruction =>
offchain::Capabilities::none(),
// Enable keystore and transaction pool by default for offchain calls.
OffchainCall(None) => [
Expand Down
9 changes: 3 additions & 6 deletions test-utils/client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,10 @@ impl<Block: BlockT, Executor, Backend, G: GenesisInit> TestClientBuilder<Block,
}

/// Set the execution strategy that should be used by all contexts.
pub fn set_execution_strategy(
mut self,
execution_strategy: ExecutionStrategy
) -> Self {
pub fn set_execution_strategy(mut self, execution_strategy: ExecutionStrategy) -> Self {
self.execution_strategies = ExecutionStrategies {
syncing: execution_strategy,
importing: execution_strategy,
own_block_import: execution_strategy,
foreign_block_import: execution_strategy,
block_construction: execution_strategy,
offchain_worker: execution_strategy,
other: execution_strategy,
Expand Down

0 comments on commit 0fac115

Please sign in to comment.