mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-08 15:58:02 +00:00
client: use appropriate ExecutionContext for initial sync / regular import (#6180)
* client: use appropriate ExecutionContext for sync/import * client: remove dead code * client: ExecutionContext: distinguish between own and foreign imports * client: fix cli parameter doc * Revert "client: ExecutionContext: distinguish between own and foreign imports" This reverts commit 0fac11520704c364a82432c5b927e987ba043cdb. * primitives: add docs for ExecutionContext * cli: execution strategy docs * cli: use different execution context for importing block on validator * cli: remove defaults from execution context flags
This commit is contained in:
@@ -178,6 +178,8 @@ arg_enum! {
|
||||
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-import-block` parameter when the node is a validator.
|
||||
pub const DEFAULT_EXECUTION_IMPORT_BLOCK_VALIDATOR: ExecutionStrategy = ExecutionStrategy::Wasm;
|
||||
/// 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.
|
||||
|
||||
@@ -278,10 +278,10 @@ macro_rules! substrate_cli_subcommands {
|
||||
}
|
||||
}
|
||||
|
||||
fn execution_strategies(&self, is_dev: bool)
|
||||
fn execution_strategies(&self, is_dev: bool, is_validator: bool)
|
||||
-> $crate::Result<::sc_client_api::execution_extensions::ExecutionStrategies> {
|
||||
match self {
|
||||
$($enum::$variant(cmd) => cmd.execution_strategies(is_dev)),*
|
||||
$($enum::$variant(cmd) => cmd.execution_strategies(is_dev, is_validator)),*
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -246,9 +246,14 @@ pub trait CliConfiguration: Sized {
|
||||
///
|
||||
/// By default this is retrieved from `ImportParams` if it is available. Otherwise its
|
||||
/// `ExecutionStrategies::default()`.
|
||||
fn execution_strategies(&self, is_dev: bool) -> Result<ExecutionStrategies> {
|
||||
Ok(self.import_params()
|
||||
.map(|x| x.execution_strategies(is_dev))
|
||||
fn execution_strategies(
|
||||
&self,
|
||||
is_dev: bool,
|
||||
is_validator: bool,
|
||||
) -> Result<ExecutionStrategies> {
|
||||
Ok(self
|
||||
.import_params()
|
||||
.map(|x| x.execution_strategies(is_dev, is_validator))
|
||||
.unwrap_or(Default::default()))
|
||||
}
|
||||
|
||||
@@ -417,6 +422,7 @@ pub trait CliConfiguration: Sized {
|
||||
let node_key = self.node_key(&net_config_dir)?;
|
||||
let role = self.role(is_dev)?;
|
||||
let max_runtime_instances = self.max_runtime_instances()?.unwrap_or(8);
|
||||
let is_validator = role.is_network_authority();
|
||||
|
||||
let unsafe_pruning = self
|
||||
.import_params()
|
||||
@@ -442,7 +448,7 @@ pub trait CliConfiguration: Sized {
|
||||
state_cache_child_ratio: self.state_cache_child_ratio()?,
|
||||
pruning: self.pruning(unsafe_pruning, &role)?,
|
||||
wasm_method: self.wasm_method()?,
|
||||
execution_strategies: self.execution_strategies(is_dev)?,
|
||||
execution_strategies: self.execution_strategies(is_dev, is_validator)?,
|
||||
rpc_http: self.rpc_http()?,
|
||||
rpc_ws: self.rpc_ws()?,
|
||||
rpc_methods: self.rpc_methods()?,
|
||||
|
||||
@@ -17,8 +17,8 @@
|
||||
// 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,
|
||||
ExecutionStrategy, TracingReceiver, WasmExecutionMethod, DEFAULT_EXECUTION_BLOCK_CONSTRUCTION,
|
||||
DEFAULT_EXECUTION_IMPORT_BLOCK, DEFAULT_EXECUTION_IMPORT_BLOCK_VALIDATOR,
|
||||
DEFAULT_EXECUTION_OFFCHAIN_WORKER, DEFAULT_EXECUTION_OTHER, DEFAULT_EXECUTION_SYNCING,
|
||||
};
|
||||
use crate::params::DatabaseParams;
|
||||
@@ -104,22 +104,27 @@ impl ImportParams {
|
||||
}
|
||||
|
||||
/// Get execution strategies for the parameters
|
||||
pub fn execution_strategies(
|
||||
&self,
|
||||
is_dev: bool,
|
||||
) -> ExecutionStrategies {
|
||||
pub fn execution_strategies(&self, is_dev: bool, is_validator: bool) -> ExecutionStrategies {
|
||||
let exec = &self.execution_strategies;
|
||||
let exec_all_or = |strat: ExecutionStrategy, default: ExecutionStrategy| {
|
||||
exec.execution.unwrap_or(if strat == default && is_dev {
|
||||
let exec_all_or = |strat: Option<ExecutionStrategy>, default: ExecutionStrategy| {
|
||||
let default = if is_dev {
|
||||
ExecutionStrategy::Native
|
||||
} else {
|
||||
strat
|
||||
}).into()
|
||||
default
|
||||
};
|
||||
|
||||
exec.execution.unwrap_or(strat.unwrap_or(default)).into()
|
||||
};
|
||||
|
||||
let default_execution_import_block = if is_validator {
|
||||
DEFAULT_EXECUTION_IMPORT_BLOCK_VALIDATOR
|
||||
} else {
|
||||
DEFAULT_EXECUTION_IMPORT_BLOCK
|
||||
};
|
||||
|
||||
ExecutionStrategies {
|
||||
syncing: exec_all_or(exec.execution_syncing, DEFAULT_EXECUTION_SYNCING),
|
||||
importing: exec_all_or(exec.execution_import_block, DEFAULT_EXECUTION_IMPORT_BLOCK),
|
||||
importing: exec_all_or(exec.execution_import_block, default_execution_import_block),
|
||||
block_construction:
|
||||
exec_all_or(exec.execution_block_construction, DEFAULT_EXECUTION_BLOCK_CONSTRUCTION),
|
||||
offchain_worker:
|
||||
@@ -132,25 +137,25 @@ impl ImportParams {
|
||||
/// Execution strategies parameters.
|
||||
#[derive(Debug, StructOpt)]
|
||||
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 for importing blocks as
|
||||
/// part of an initial sync.
|
||||
#[structopt(
|
||||
long = "execution-syncing",
|
||||
value_name = "STRATEGY",
|
||||
possible_values = &ExecutionStrategy::variants(),
|
||||
case_insensitive = true,
|
||||
default_value = DEFAULT_EXECUTION_SYNCING.as_str(),
|
||||
)]
|
||||
pub execution_syncing: ExecutionStrategy,
|
||||
pub execution_syncing: Option<ExecutionStrategy>,
|
||||
|
||||
/// The means of execution used when calling into the runtime while importing blocks.
|
||||
/// The means of execution used when calling into the runtime for general block import
|
||||
/// (including locally authored blocks).
|
||||
#[structopt(
|
||||
long = "execution-import-block",
|
||||
value_name = "STRATEGY",
|
||||
possible_values = &ExecutionStrategy::variants(),
|
||||
case_insensitive = true,
|
||||
default_value = DEFAULT_EXECUTION_IMPORT_BLOCK.as_str(),
|
||||
)]
|
||||
pub execution_import_block: ExecutionStrategy,
|
||||
pub execution_import_block: Option<ExecutionStrategy>,
|
||||
|
||||
/// The means of execution used when calling into the runtime while constructing blocks.
|
||||
#[structopt(
|
||||
@@ -158,9 +163,8 @@ pub struct ExecutionStrategiesParams {
|
||||
value_name = "STRATEGY",
|
||||
possible_values = &ExecutionStrategy::variants(),
|
||||
case_insensitive = true,
|
||||
default_value = DEFAULT_EXECUTION_BLOCK_CONSTRUCTION.as_str(),
|
||||
)]
|
||||
pub execution_block_construction: ExecutionStrategy,
|
||||
pub execution_block_construction: Option<ExecutionStrategy>,
|
||||
|
||||
/// The means of execution used when calling into the runtime while using an off-chain worker.
|
||||
#[structopt(
|
||||
@@ -168,9 +172,8 @@ pub struct ExecutionStrategiesParams {
|
||||
value_name = "STRATEGY",
|
||||
possible_values = &ExecutionStrategy::variants(),
|
||||
case_insensitive = true,
|
||||
default_value = DEFAULT_EXECUTION_OFFCHAIN_WORKER.as_str(),
|
||||
)]
|
||||
pub execution_offchain_worker: ExecutionStrategy,
|
||||
pub execution_offchain_worker: Option<ExecutionStrategy>,
|
||||
|
||||
/// The means of execution used when calling into the runtime while not syncing, importing or constructing blocks.
|
||||
#[structopt(
|
||||
@@ -178,9 +181,8 @@ pub struct ExecutionStrategiesParams {
|
||||
value_name = "STRATEGY",
|
||||
possible_values = &ExecutionStrategy::variants(),
|
||||
case_insensitive = true,
|
||||
default_value = DEFAULT_EXECUTION_OTHER.as_str(),
|
||||
)]
|
||||
pub execution_other: ExecutionStrategy,
|
||||
pub execution_other: Option<ExecutionStrategy>,
|
||||
|
||||
/// The execution strategy that should be used by all execution contexts.
|
||||
#[structopt(
|
||||
|
||||
Reference in New Issue
Block a user