mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-25 03:35:43 +00:00
refactor(sc-executor): use wasm executor builder instead of old apis (#13740)
* refactor: use builder api for all executors * improve a lot * remove unused args * cleanup deps * fix inconsistency about heap alloc * add `heap_pages` back to try-runtime * fix * chore: reduce duplicated code for sc-service-test * cleanup code * fmt * improve test executor * improve * use #[deprecated] * set runtime_cache_size: 4 * fix and improve * refactor builder * fix * fix bench * fix tests * fix warnings * fix warnings * fix * fix * update by suggestions * update name
This commit is contained in:
@@ -68,12 +68,7 @@ pub fn new_partial(
|
|||||||
})
|
})
|
||||||
.transpose()?;
|
.transpose()?;
|
||||||
|
|
||||||
let executor = NativeElseWasmExecutor::<ExecutorDispatch>::new(
|
let executor = sc_service::new_native_or_wasm_executor(&config);
|
||||||
config.wasm_method,
|
|
||||||
config.default_heap_pages,
|
|
||||||
config.max_runtime_instances,
|
|
||||||
config.runtime_cache_size,
|
|
||||||
);
|
|
||||||
|
|
||||||
let (client, backend, keystore_container, task_manager) =
|
let (client, backend, keystore_container, task_manager) =
|
||||||
sc_service::new_full_parts::<Block, RuntimeApi, _>(
|
sc_service::new_full_parts::<Block, RuntimeApi, _>(
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ use sc_client_api::execution_extensions::ExecutionStrategies;
|
|||||||
use sc_service::{
|
use sc_service::{
|
||||||
config::{
|
config::{
|
||||||
BlocksPruning, DatabaseSource, KeystoreConfig, NetworkConfiguration, OffchainWorkerConfig,
|
BlocksPruning, DatabaseSource, KeystoreConfig, NetworkConfiguration, OffchainWorkerConfig,
|
||||||
PruningMode, TransactionPoolOptions, WasmExecutionMethod,
|
PruningMode, TransactionPoolOptions,
|
||||||
},
|
},
|
||||||
BasePath, Configuration, Role,
|
BasePath, Configuration, Role,
|
||||||
};
|
};
|
||||||
@@ -69,7 +69,7 @@ fn new_node(tokio_handle: Handle) -> node_cli::service::NewFullBase {
|
|||||||
state_pruning: Some(PruningMode::ArchiveAll),
|
state_pruning: Some(PruningMode::ArchiveAll),
|
||||||
blocks_pruning: BlocksPruning::KeepAll,
|
blocks_pruning: BlocksPruning::KeepAll,
|
||||||
chain_spec: spec,
|
chain_spec: spec,
|
||||||
wasm_method: WasmExecutionMethod::Interpreted,
|
wasm_method: Default::default(),
|
||||||
// NOTE: we enforce the use of the native runtime to make the errors more debuggable
|
// NOTE: we enforce the use of the native runtime to make the errors more debuggable
|
||||||
execution_strategies: ExecutionStrategies {
|
execution_strategies: ExecutionStrategies {
|
||||||
syncing: sc_client_api::ExecutionStrategy::NativeWhenPossible,
|
syncing: sc_client_api::ExecutionStrategy::NativeWhenPossible,
|
||||||
|
|||||||
@@ -163,12 +163,7 @@ pub fn new_partial(
|
|||||||
})
|
})
|
||||||
.transpose()?;
|
.transpose()?;
|
||||||
|
|
||||||
let executor = NativeElseWasmExecutor::<ExecutorDispatch>::new(
|
let executor = sc_service::new_native_or_wasm_executor(&config);
|
||||||
config.wasm_method,
|
|
||||||
config.default_heap_pages,
|
|
||||||
config.max_runtime_instances,
|
|
||||||
config.runtime_cache_size,
|
|
||||||
);
|
|
||||||
|
|
||||||
let (client, backend, keystore_container, task_manager) =
|
let (client, backend, keystore_container, task_manager) =
|
||||||
sc_service::new_full_parts::<Block, RuntimeApi, _>(
|
sc_service::new_full_parts::<Block, RuntimeApi, _>(
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ use node_executor::ExecutorDispatch;
|
|||||||
use node_primitives::{BlockNumber, Hash};
|
use node_primitives::{BlockNumber, Hash};
|
||||||
use node_testing::keyring::*;
|
use node_testing::keyring::*;
|
||||||
use sc_executor::{
|
use sc_executor::{
|
||||||
Externalities, NativeElseWasmExecutor, RuntimeVersionOf, WasmExecutionMethod,
|
Externalities, NativeElseWasmExecutor, RuntimeVersionOf, WasmExecutionMethod, WasmExecutor,
|
||||||
WasmtimeInstantiationStrategy,
|
WasmtimeInstantiationStrategy,
|
||||||
};
|
};
|
||||||
use sp_core::{
|
use sp_core::{
|
||||||
@@ -191,12 +191,13 @@ fn bench_execute_block(c: &mut Criterion) {
|
|||||||
for strategy in execution_methods {
|
for strategy in execution_methods {
|
||||||
group.bench_function(format!("{:?}", strategy), |b| {
|
group.bench_function(format!("{:?}", strategy), |b| {
|
||||||
let genesis_config = node_testing::genesis::config(Some(compact_code_unwrap()));
|
let genesis_config = node_testing::genesis::config(Some(compact_code_unwrap()));
|
||||||
let (use_native, wasm_method) = match strategy {
|
let use_native = match strategy {
|
||||||
ExecutionMethod::Native => (true, WasmExecutionMethod::Interpreted),
|
ExecutionMethod::Native => true,
|
||||||
ExecutionMethod::Wasm(wasm_method) => (false, wasm_method),
|
ExecutionMethod::Wasm(..) => false,
|
||||||
};
|
};
|
||||||
|
|
||||||
let executor = NativeElseWasmExecutor::new(wasm_method, None, 8, 2);
|
let executor =
|
||||||
|
NativeElseWasmExecutor::new_with_wasm_executor(WasmExecutor::builder().build());
|
||||||
let runtime_code = RuntimeCode {
|
let runtime_code = RuntimeCode {
|
||||||
code_fetcher: &sp_core::traits::WrappedRuntimeCode(compact_code_unwrap().into()),
|
code_fetcher: &sp_core::traits::WrappedRuntimeCode(compact_code_unwrap().into()),
|
||||||
hash: vec![1, 2, 3],
|
hash: vec![1, 2, 3],
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
use codec::{Decode, Encode};
|
use codec::{Decode, Encode};
|
||||||
use frame_support::Hashable;
|
use frame_support::Hashable;
|
||||||
use frame_system::offchain::AppCrypto;
|
use frame_system::offchain::AppCrypto;
|
||||||
use sc_executor::{error::Result, NativeElseWasmExecutor, WasmExecutionMethod};
|
use sc_executor::{error::Result, NativeElseWasmExecutor, WasmExecutor};
|
||||||
use sp_consensus_babe::{
|
use sp_consensus_babe::{
|
||||||
digests::{PreDigest, SecondaryPlainPreDigest},
|
digests::{PreDigest, SecondaryPlainPreDigest},
|
||||||
Slot, BABE_ENGINE_ID,
|
Slot, BABE_ENGINE_ID,
|
||||||
@@ -98,7 +98,7 @@ pub fn from_block_number(n: u32) -> Header {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn executor() -> NativeElseWasmExecutor<ExecutorDispatch> {
|
pub fn executor() -> NativeElseWasmExecutor<ExecutorDispatch> {
|
||||||
NativeElseWasmExecutor::new(WasmExecutionMethod::Interpreted, None, 8, 2)
|
NativeElseWasmExecutor::new_with_wasm_executor(WasmExecutor::builder().build())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn executor_call(
|
pub fn executor_call(
|
||||||
|
|||||||
@@ -23,41 +23,34 @@ use crate::{
|
|||||||
Inspector,
|
Inspector,
|
||||||
};
|
};
|
||||||
use sc_cli::{CliConfiguration, ImportParams, Result, SharedParams};
|
use sc_cli::{CliConfiguration, ImportParams, Result, SharedParams};
|
||||||
use sc_executor::NativeElseWasmExecutor;
|
use sc_service::{Configuration, NativeExecutionDispatch};
|
||||||
use sc_service::{new_full_client, Configuration, NativeExecutionDispatch};
|
|
||||||
use sp_runtime::traits::Block;
|
use sp_runtime::traits::Block;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
impl InspectCmd {
|
impl InspectCmd {
|
||||||
/// Run the inspect command, passing the inspector.
|
/// Run the inspect command, passing the inspector.
|
||||||
pub fn run<B, RA, EX>(&self, config: Configuration) -> Result<()>
|
pub fn run<B, RA, D>(&self, config: Configuration) -> Result<()>
|
||||||
where
|
where
|
||||||
B: Block,
|
B: Block,
|
||||||
B::Hash: FromStr,
|
B::Hash: FromStr,
|
||||||
RA: Send + Sync + 'static,
|
RA: Send + Sync + 'static,
|
||||||
EX: NativeExecutionDispatch + 'static,
|
D: NativeExecutionDispatch + 'static,
|
||||||
{
|
{
|
||||||
let executor = NativeElseWasmExecutor::<EX>::new(
|
let executor = sc_service::new_native_or_wasm_executor::<D>(&config);
|
||||||
config.wasm_method,
|
let client = sc_service::new_full_client::<B, RA, _>(&config, None, executor)?;
|
||||||
config.default_heap_pages,
|
|
||||||
config.max_runtime_instances,
|
|
||||||
config.runtime_cache_size,
|
|
||||||
);
|
|
||||||
|
|
||||||
let client = new_full_client::<B, RA, _>(&config, None, executor)?;
|
|
||||||
let inspect = Inspector::<B>::new(client);
|
let inspect = Inspector::<B>::new(client);
|
||||||
|
|
||||||
match &self.command {
|
match &self.command {
|
||||||
InspectSubCmd::Block { input } => {
|
InspectSubCmd::Block { input } => {
|
||||||
let input = input.parse()?;
|
let input = input.parse()?;
|
||||||
let res = inspect.block(input).map_err(|e| format!("{}", e))?;
|
let res = inspect.block(input).map_err(|e| e.to_string())?;
|
||||||
println!("{}", res);
|
println!("{res}");
|
||||||
Ok(())
|
Ok(())
|
||||||
},
|
},
|
||||||
InspectSubCmd::Extrinsic { input } => {
|
InspectSubCmd::Extrinsic { input } => {
|
||||||
let input = input.parse()?;
|
let input = input.parse()?;
|
||||||
let res = inspect.extrinsic(input).map_err(|e| format!("{}", e))?;
|
let res = inspect.extrinsic(input).map_err(|e| e.to_string())?;
|
||||||
println!("{}", res);
|
println!("{res}");
|
||||||
Ok(())
|
Ok(())
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -392,14 +392,14 @@ impl BenchDb {
|
|||||||
let task_executor = TaskExecutor::new();
|
let task_executor = TaskExecutor::new();
|
||||||
|
|
||||||
let backend = sc_service::new_db_backend(db_config).expect("Should not fail");
|
let backend = sc_service::new_db_backend(db_config).expect("Should not fail");
|
||||||
let executor = NativeElseWasmExecutor::new(
|
let executor = NativeElseWasmExecutor::new_with_wasm_executor(
|
||||||
WasmExecutionMethod::Compiled {
|
sc_executor::WasmExecutor::builder()
|
||||||
instantiation_strategy: WasmtimeInstantiationStrategy::PoolingCopyOnWrite,
|
.with_execution_method(WasmExecutionMethod::Compiled {
|
||||||
},
|
instantiation_strategy: WasmtimeInstantiationStrategy::PoolingCopyOnWrite,
|
||||||
None,
|
})
|
||||||
8,
|
.build(),
|
||||||
2,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
let client_config = sc_service::ClientConfig::default();
|
let client_config = sc_service::ClientConfig::default();
|
||||||
let genesis_block_builder = sc_service::GenesisBlockBuilder::new(
|
let genesis_block_builder = sc_service::GenesisBlockBuilder::new(
|
||||||
&keyring.generate_genesis(),
|
&keyring.generate_genesis(),
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ use codec::Encode;
|
|||||||
|
|
||||||
use sc_executor_common::{
|
use sc_executor_common::{
|
||||||
runtime_blob::RuntimeBlob,
|
runtime_blob::RuntimeBlob,
|
||||||
wasm_runtime::{HeapAllocStrategy, WasmInstance, WasmModule},
|
wasm_runtime::{HeapAllocStrategy, WasmInstance, WasmModule, DEFAULT_HEAP_ALLOC_STRATEGY},
|
||||||
};
|
};
|
||||||
use sc_executor_wasmtime::InstantiationStrategy;
|
use sc_executor_wasmtime::InstantiationStrategy;
|
||||||
use sc_runtime_test::wasm_binary_unwrap as test_runtime;
|
use sc_runtime_test::wasm_binary_unwrap as test_runtime;
|
||||||
@@ -51,13 +51,12 @@ fn initialize(
|
|||||||
) -> Arc<dyn WasmModule> {
|
) -> Arc<dyn WasmModule> {
|
||||||
let blob = RuntimeBlob::uncompress_if_needed(runtime).unwrap();
|
let blob = RuntimeBlob::uncompress_if_needed(runtime).unwrap();
|
||||||
let host_functions = sp_io::SubstrateHostFunctions::host_functions();
|
let host_functions = sp_io::SubstrateHostFunctions::host_functions();
|
||||||
let extra_pages = 2048;
|
|
||||||
let allow_missing_func_imports = true;
|
let allow_missing_func_imports = true;
|
||||||
|
|
||||||
match method {
|
match method {
|
||||||
Method::Interpreted => sc_executor_wasmi::create_runtime(
|
Method::Interpreted => sc_executor_wasmi::create_runtime(
|
||||||
blob,
|
blob,
|
||||||
HeapAllocStrategy::Static { extra_pages },
|
DEFAULT_HEAP_ALLOC_STRATEGY,
|
||||||
host_functions,
|
host_functions,
|
||||||
allow_missing_func_imports,
|
allow_missing_func_imports,
|
||||||
)
|
)
|
||||||
@@ -67,7 +66,7 @@ fn initialize(
|
|||||||
allow_missing_func_imports,
|
allow_missing_func_imports,
|
||||||
cache_path: None,
|
cache_path: None,
|
||||||
semantics: sc_executor_wasmtime::Semantics {
|
semantics: sc_executor_wasmtime::Semantics {
|
||||||
heap_alloc_strategy: HeapAllocStrategy::Static { extra_pages },
|
heap_alloc_strategy: DEFAULT_HEAP_ALLOC_STRATEGY,
|
||||||
instantiation_strategy,
|
instantiation_strategy,
|
||||||
deterministic_stack_limit: None,
|
deterministic_stack_limit: None,
|
||||||
canonicalize_nans: false,
|
canonicalize_nans: false,
|
||||||
|
|||||||
@@ -23,6 +23,13 @@ use sp_wasm_interface::Value;
|
|||||||
|
|
||||||
pub use sc_allocator::AllocationStats;
|
pub use sc_allocator::AllocationStats;
|
||||||
|
|
||||||
|
/// Default heap allocation strategy.
|
||||||
|
pub const DEFAULT_HEAP_ALLOC_STRATEGY: HeapAllocStrategy =
|
||||||
|
HeapAllocStrategy::Static { extra_pages: DEFAULT_HEAP_ALLOC_PAGES };
|
||||||
|
|
||||||
|
/// Default heap allocation pages.
|
||||||
|
pub const DEFAULT_HEAP_ALLOC_PAGES: u32 = 2048;
|
||||||
|
|
||||||
/// A method to be used to find the entrypoint when calling into the runtime
|
/// A method to be used to find the entrypoint when calling into the runtime
|
||||||
///
|
///
|
||||||
/// Contains variants on how to resolve wasm function that will be invoked.
|
/// Contains variants on how to resolve wasm function that will be invoked.
|
||||||
|
|||||||
+30
-21
@@ -32,16 +32,14 @@ use std::{
|
|||||||
use codec::Encode;
|
use codec::Encode;
|
||||||
use sc_executor_common::{
|
use sc_executor_common::{
|
||||||
runtime_blob::RuntimeBlob,
|
runtime_blob::RuntimeBlob,
|
||||||
wasm_runtime::{AllocationStats, HeapAllocStrategy, WasmInstance, WasmModule},
|
wasm_runtime::{
|
||||||
|
AllocationStats, HeapAllocStrategy, WasmInstance, WasmModule, DEFAULT_HEAP_ALLOC_STRATEGY,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
use sp_core::traits::{CallContext, CodeExecutor, Externalities, RuntimeCode};
|
use sp_core::traits::{CallContext, CodeExecutor, Externalities, RuntimeCode};
|
||||||
use sp_version::{GetNativeVersion, NativeVersion, RuntimeVersion};
|
use sp_version::{GetNativeVersion, NativeVersion, RuntimeVersion};
|
||||||
use sp_wasm_interface::{ExtendedHostFunctions, HostFunctions};
|
use sp_wasm_interface::{ExtendedHostFunctions, HostFunctions};
|
||||||
|
|
||||||
/// Default heap allocation strategy.
|
|
||||||
const DEFAULT_HEAP_ALLOC_STRATEGY: HeapAllocStrategy =
|
|
||||||
HeapAllocStrategy::Static { extra_pages: 2048 };
|
|
||||||
|
|
||||||
/// Set up the externalities and safe calling environment to execute runtime calls.
|
/// Set up the externalities and safe calling environment to execute runtime calls.
|
||||||
///
|
///
|
||||||
/// If the inner closure panics, it will be caught and return an error.
|
/// If the inner closure panics, it will be caught and return an error.
|
||||||
@@ -100,10 +98,10 @@ impl<H> WasmExecutorBuilder<H> {
|
|||||||
/// Create a new instance of `Self`
|
/// Create a new instance of `Self`
|
||||||
///
|
///
|
||||||
/// - `method`: The wasm execution method that should be used by the executor.
|
/// - `method`: The wasm execution method that should be used by the executor.
|
||||||
pub fn new(method: WasmExecutionMethod) -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
_phantom: PhantomData,
|
_phantom: PhantomData,
|
||||||
method,
|
method: WasmExecutionMethod::default(),
|
||||||
onchain_heap_alloc_strategy: None,
|
onchain_heap_alloc_strategy: None,
|
||||||
offchain_heap_alloc_strategy: None,
|
offchain_heap_alloc_strategy: None,
|
||||||
max_runtime_instances: 2,
|
max_runtime_instances: 2,
|
||||||
@@ -113,6 +111,12 @@ impl<H> WasmExecutorBuilder<H> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Create the wasm executor with execution method that should be used by the executor.
|
||||||
|
pub fn with_execution_method(mut self, method: WasmExecutionMethod) -> Self {
|
||||||
|
self.method = method;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
/// Create the wasm executor with the given number of `heap_alloc_strategy` for onchain runtime
|
/// Create the wasm executor with the given number of `heap_alloc_strategy` for onchain runtime
|
||||||
/// calls.
|
/// calls.
|
||||||
pub fn with_onchain_heap_alloc_strategy(
|
pub fn with_onchain_heap_alloc_strategy(
|
||||||
@@ -256,6 +260,7 @@ where
|
|||||||
/// compiled execution method is used.
|
/// compiled execution method is used.
|
||||||
///
|
///
|
||||||
/// `runtime_cache_size` - The capacity of runtime cache.
|
/// `runtime_cache_size` - The capacity of runtime cache.
|
||||||
|
#[deprecated(note = "use `Self::builder` method instead of it")]
|
||||||
pub fn new(
|
pub fn new(
|
||||||
method: WasmExecutionMethod,
|
method: WasmExecutionMethod,
|
||||||
default_heap_pages: Option<u64>,
|
default_heap_pages: Option<u64>,
|
||||||
@@ -283,11 +288,12 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Instantiate a builder for creating an instance of `Self`.
|
/// Instantiate a builder for creating an instance of `Self`.
|
||||||
pub fn builder(method: WasmExecutionMethod) -> WasmExecutorBuilder<H> {
|
pub fn builder() -> WasmExecutorBuilder<H> {
|
||||||
WasmExecutorBuilder::new(method)
|
WasmExecutorBuilder::new()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Ignore missing function imports if set true.
|
/// Ignore missing function imports if set true.
|
||||||
|
#[deprecated(note = "use `Self::builder` method instead of it")]
|
||||||
pub fn allow_missing_host_functions(&mut self, allow_missing_host_functions: bool) {
|
pub fn allow_missing_host_functions(&mut self, allow_missing_host_functions: bool) {
|
||||||
self.allow_missing_host_functions = allow_missing_host_functions
|
self.allow_missing_host_functions = allow_missing_host_functions
|
||||||
}
|
}
|
||||||
@@ -539,6 +545,7 @@ pub struct NativeElseWasmExecutor<D: NativeExecutionDispatch> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<D: NativeExecutionDispatch> NativeElseWasmExecutor<D> {
|
impl<D: NativeExecutionDispatch> NativeElseWasmExecutor<D> {
|
||||||
|
///
|
||||||
/// Create new instance.
|
/// Create new instance.
|
||||||
///
|
///
|
||||||
/// # Parameters
|
/// # Parameters
|
||||||
@@ -553,19 +560,23 @@ impl<D: NativeExecutionDispatch> NativeElseWasmExecutor<D> {
|
|||||||
/// `max_runtime_instances` - The number of runtime instances to keep in memory ready for reuse.
|
/// `max_runtime_instances` - The number of runtime instances to keep in memory ready for reuse.
|
||||||
///
|
///
|
||||||
/// `runtime_cache_size` - The capacity of runtime cache.
|
/// `runtime_cache_size` - The capacity of runtime cache.
|
||||||
|
#[deprecated(note = "use `Self::new_with_wasm_executor` method instead of it")]
|
||||||
pub fn new(
|
pub fn new(
|
||||||
fallback_method: WasmExecutionMethod,
|
fallback_method: WasmExecutionMethod,
|
||||||
default_heap_pages: Option<u64>,
|
default_heap_pages: Option<u64>,
|
||||||
max_runtime_instances: usize,
|
max_runtime_instances: usize,
|
||||||
runtime_cache_size: u8,
|
runtime_cache_size: u8,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let wasm = WasmExecutor::new(
|
let heap_pages = default_heap_pages.map_or(DEFAULT_HEAP_ALLOC_STRATEGY, |h| {
|
||||||
fallback_method,
|
HeapAllocStrategy::Static { extra_pages: h as _ }
|
||||||
default_heap_pages,
|
});
|
||||||
max_runtime_instances,
|
let wasm = WasmExecutor::builder()
|
||||||
None,
|
.with_execution_method(fallback_method)
|
||||||
runtime_cache_size,
|
.with_onchain_heap_alloc_strategy(heap_pages)
|
||||||
);
|
.with_offchain_heap_alloc_strategy(heap_pages)
|
||||||
|
.with_max_runtime_instances(max_runtime_instances)
|
||||||
|
.with_runtime_cache_size(runtime_cache_size)
|
||||||
|
.build();
|
||||||
|
|
||||||
NativeElseWasmExecutor { native_version: D::native_version(), wasm }
|
NativeElseWasmExecutor { native_version: D::native_version(), wasm }
|
||||||
}
|
}
|
||||||
@@ -580,6 +591,7 @@ impl<D: NativeExecutionDispatch> NativeElseWasmExecutor<D> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Ignore missing function imports if set true.
|
/// Ignore missing function imports if set true.
|
||||||
|
#[deprecated(note = "use `Self::new_with_wasm_executor` method instead of it")]
|
||||||
pub fn allow_missing_host_functions(&mut self, allow_missing_host_functions: bool) {
|
pub fn allow_missing_host_functions(&mut self, allow_missing_host_functions: bool) {
|
||||||
self.wasm.allow_missing_host_functions = allow_missing_host_functions
|
self.wasm.allow_missing_host_functions = allow_missing_host_functions
|
||||||
}
|
}
|
||||||
@@ -714,11 +726,8 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn native_executor_registers_custom_interface() {
|
fn native_executor_registers_custom_interface() {
|
||||||
let executor = NativeElseWasmExecutor::<MyExecutorDispatch>::new(
|
let executor = NativeElseWasmExecutor::<MyExecutorDispatch>::new_with_wasm_executor(
|
||||||
WasmExecutionMethod::Interpreted,
|
WasmExecutor::builder().build(),
|
||||||
None,
|
|
||||||
8,
|
|
||||||
2,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
fn extract_host_functions<H>(
|
fn extract_host_functions<H>(
|
||||||
@@ -21,7 +21,7 @@
|
|||||||
use super::mk_test_runtime;
|
use super::mk_test_runtime;
|
||||||
use crate::WasmExecutionMethod;
|
use crate::WasmExecutionMethod;
|
||||||
use codec::Encode as _;
|
use codec::Encode as _;
|
||||||
use sc_executor_common::wasm_runtime::HeapAllocStrategy;
|
use sc_executor_common::wasm_runtime::DEFAULT_HEAP_ALLOC_STRATEGY;
|
||||||
|
|
||||||
mod smaps;
|
mod smaps;
|
||||||
|
|
||||||
@@ -74,7 +74,7 @@ fn memory_consumption(wasm_method: WasmExecutionMethod) {
|
|||||||
// For that we make a series of runtime calls, probing the RSS for the VMA matching the linear
|
// For that we make a series of runtime calls, probing the RSS for the VMA matching the linear
|
||||||
// memory. After the call we expect RSS to be equal to 0.
|
// memory. After the call we expect RSS to be equal to 0.
|
||||||
|
|
||||||
let runtime = mk_test_runtime(wasm_method, HeapAllocStrategy::Static { extra_pages: 1024 });
|
let runtime = mk_test_runtime(wasm_method, DEFAULT_HEAP_ALLOC_STRATEGY);
|
||||||
|
|
||||||
let mut instance = runtime.new_instance().unwrap();
|
let mut instance = runtime.new_instance().unwrap();
|
||||||
let heap_base = instance
|
let heap_base = instance
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ use codec::{Decode, Encode};
|
|||||||
use sc_executor_common::{
|
use sc_executor_common::{
|
||||||
error::Error,
|
error::Error,
|
||||||
runtime_blob::RuntimeBlob,
|
runtime_blob::RuntimeBlob,
|
||||||
wasm_runtime::{HeapAllocStrategy, WasmModule},
|
wasm_runtime::{HeapAllocStrategy, WasmModule, DEFAULT_HEAP_ALLOC_STRATEGY},
|
||||||
};
|
};
|
||||||
use sc_runtime_test::wasm_binary_unwrap;
|
use sc_runtime_test::wasm_binary_unwrap;
|
||||||
use sp_core::{
|
use sp_core::{
|
||||||
@@ -114,8 +114,10 @@ fn call_in_wasm<E: Externalities>(
|
|||||||
execution_method: WasmExecutionMethod,
|
execution_method: WasmExecutionMethod,
|
||||||
ext: &mut E,
|
ext: &mut E,
|
||||||
) -> Result<Vec<u8>, Error> {
|
) -> Result<Vec<u8>, Error> {
|
||||||
let executor =
|
let executor = crate::WasmExecutor::<HostFunctions>::builder()
|
||||||
crate::WasmExecutor::<HostFunctions>::new(execution_method, Some(1024), 8, None, 2);
|
.with_execution_method(execution_method)
|
||||||
|
.build();
|
||||||
|
|
||||||
executor.uncached_call(
|
executor.uncached_call(
|
||||||
RuntimeBlob::uncompress_if_needed(wasm_binary_unwrap()).unwrap(),
|
RuntimeBlob::uncompress_if_needed(wasm_binary_unwrap()).unwrap(),
|
||||||
ext,
|
ext,
|
||||||
@@ -446,13 +448,11 @@ test_wasm_execution!(should_trap_when_heap_exhausted);
|
|||||||
fn should_trap_when_heap_exhausted(wasm_method: WasmExecutionMethod) {
|
fn should_trap_when_heap_exhausted(wasm_method: WasmExecutionMethod) {
|
||||||
let mut ext = TestExternalities::default();
|
let mut ext = TestExternalities::default();
|
||||||
|
|
||||||
let executor = crate::WasmExecutor::<HostFunctions>::new(
|
let executor = crate::WasmExecutor::<HostFunctions>::builder()
|
||||||
wasm_method,
|
.with_execution_method(wasm_method)
|
||||||
Some(17), // `17` is the initial number of pages compiled into the binary.
|
// `17` is the initial number of pages compiled into the binary.
|
||||||
8,
|
.with_onchain_heap_alloc_strategy(HeapAllocStrategy::Static { extra_pages: 17 })
|
||||||
None,
|
.build();
|
||||||
2,
|
|
||||||
);
|
|
||||||
|
|
||||||
let err = executor
|
let err = executor
|
||||||
.uncached_call(
|
.uncached_call(
|
||||||
@@ -560,7 +560,7 @@ fn restoration_of_globals(wasm_method: WasmExecutionMethod) {
|
|||||||
|
|
||||||
test_wasm_execution!(interpreted_only heap_is_reset_between_calls);
|
test_wasm_execution!(interpreted_only heap_is_reset_between_calls);
|
||||||
fn heap_is_reset_between_calls(wasm_method: WasmExecutionMethod) {
|
fn heap_is_reset_between_calls(wasm_method: WasmExecutionMethod) {
|
||||||
let runtime = mk_test_runtime(wasm_method, HeapAllocStrategy::Static { extra_pages: 1024 });
|
let runtime = mk_test_runtime(wasm_method, DEFAULT_HEAP_ALLOC_STRATEGY);
|
||||||
let mut instance = runtime.new_instance().unwrap();
|
let mut instance = runtime.new_instance().unwrap();
|
||||||
|
|
||||||
let heap_base = instance
|
let heap_base = instance
|
||||||
@@ -579,13 +579,11 @@ fn heap_is_reset_between_calls(wasm_method: WasmExecutionMethod) {
|
|||||||
|
|
||||||
test_wasm_execution!(parallel_execution);
|
test_wasm_execution!(parallel_execution);
|
||||||
fn parallel_execution(wasm_method: WasmExecutionMethod) {
|
fn parallel_execution(wasm_method: WasmExecutionMethod) {
|
||||||
let executor = std::sync::Arc::new(crate::WasmExecutor::<HostFunctions>::new(
|
let executor = Arc::new(
|
||||||
wasm_method,
|
crate::WasmExecutor::<HostFunctions>::builder()
|
||||||
Some(1024),
|
.with_execution_method(wasm_method)
|
||||||
8,
|
.build(),
|
||||||
None,
|
);
|
||||||
2,
|
|
||||||
));
|
|
||||||
let threads: Vec<_> = (0..8)
|
let threads: Vec<_> = (0..8)
|
||||||
.map(|_| {
|
.map(|_| {
|
||||||
let executor = executor.clone();
|
let executor = executor.clone();
|
||||||
|
|||||||
@@ -32,24 +32,29 @@
|
|||||||
#![recursion_limit = "128"]
|
#![recursion_limit = "128"]
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
mod native_executor;
|
mod executor;
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod integration_tests;
|
mod integration_tests;
|
||||||
mod wasm_runtime;
|
mod wasm_runtime;
|
||||||
|
|
||||||
pub use codec::Codec;
|
pub use self::{
|
||||||
pub use native_executor::{
|
executor::{
|
||||||
with_externalities_safe, NativeElseWasmExecutor, NativeExecutionDispatch, WasmExecutor,
|
with_externalities_safe, NativeElseWasmExecutor, NativeExecutionDispatch, WasmExecutor,
|
||||||
|
},
|
||||||
|
wasm_runtime::{read_embedded_version, WasmExecutionMethod},
|
||||||
};
|
};
|
||||||
|
pub use codec::Codec;
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub use sp_core::traits::Externalities;
|
pub use sp_core::traits::Externalities;
|
||||||
pub use sp_version::{NativeVersion, RuntimeVersion};
|
pub use sp_version::{NativeVersion, RuntimeVersion};
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub use sp_wasm_interface;
|
pub use sp_wasm_interface;
|
||||||
pub use wasm_runtime::{read_embedded_version, WasmExecutionMethod};
|
|
||||||
pub use wasmi;
|
pub use wasmi;
|
||||||
|
|
||||||
pub use sc_executor_common::error;
|
pub use sc_executor_common::{
|
||||||
|
error,
|
||||||
|
wasm_runtime::{HeapAllocStrategy, DEFAULT_HEAP_ALLOC_PAGES, DEFAULT_HEAP_ALLOC_STRATEGY},
|
||||||
|
};
|
||||||
pub use sc_executor_wasmtime::InstantiationStrategy as WasmtimeInstantiationStrategy;
|
pub use sc_executor_wasmtime::InstantiationStrategy as WasmtimeInstantiationStrategy;
|
||||||
|
|
||||||
/// Extracts the runtime version of a given runtime code.
|
/// Extracts the runtime version of a given runtime code.
|
||||||
@@ -74,13 +79,7 @@ mod tests {
|
|||||||
let mut ext = TestExternalities::default();
|
let mut ext = TestExternalities::default();
|
||||||
let mut ext = ext.ext();
|
let mut ext = ext.ext();
|
||||||
|
|
||||||
let executor = WasmExecutor::<sp_io::SubstrateHostFunctions>::new(
|
let executor = WasmExecutor::<sp_io::SubstrateHostFunctions>::builder().build();
|
||||||
WasmExecutionMethod::Interpreted,
|
|
||||||
Some(8),
|
|
||||||
8,
|
|
||||||
None,
|
|
||||||
2,
|
|
||||||
);
|
|
||||||
let res = executor
|
let res = executor
|
||||||
.uncached_call(
|
.uncached_call(
|
||||||
RuntimeBlob::uncompress_if_needed(wasm_binary_unwrap()).unwrap(),
|
RuntimeBlob::uncompress_if_needed(wasm_binary_unwrap()).unwrap(),
|
||||||
|
|||||||
@@ -434,7 +434,7 @@ where
|
|||||||
// The following unwind safety assertion is OK because if the method call panics, the
|
// The following unwind safety assertion is OK because if the method call panics, the
|
||||||
// runtime will be dropped.
|
// runtime will be dropped.
|
||||||
let runtime = AssertUnwindSafe(runtime.as_ref());
|
let runtime = AssertUnwindSafe(runtime.as_ref());
|
||||||
crate::native_executor::with_externalities_safe(&mut **ext, move || {
|
crate::executor::with_externalities_safe(&mut **ext, move || {
|
||||||
runtime.new_instance()?.call("Core_version".into(), &[])
|
runtime.new_instance()?.call("Core_version".into(), &[])
|
||||||
})
|
})
|
||||||
.map_err(|_| WasmError::Instantiation("panic in call to get runtime version".into()))?
|
.map_err(|_| WasmError::Instantiation("panic in call to get runtime version".into()))?
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ use codec::{Decode as _, Encode as _};
|
|||||||
use sc_executor_common::{
|
use sc_executor_common::{
|
||||||
error::Error,
|
error::Error,
|
||||||
runtime_blob::RuntimeBlob,
|
runtime_blob::RuntimeBlob,
|
||||||
wasm_runtime::{HeapAllocStrategy, WasmModule},
|
wasm_runtime::{HeapAllocStrategy, WasmModule, DEFAULT_HEAP_ALLOC_STRATEGY},
|
||||||
};
|
};
|
||||||
use sc_runtime_test::wasm_binary_unwrap;
|
use sc_runtime_test::wasm_binary_unwrap;
|
||||||
|
|
||||||
@@ -93,7 +93,7 @@ impl RuntimeBuilder {
|
|||||||
instantiation_strategy,
|
instantiation_strategy,
|
||||||
canonicalize_nans: false,
|
canonicalize_nans: false,
|
||||||
deterministic_stack: false,
|
deterministic_stack: false,
|
||||||
heap_pages: HeapAllocStrategy::Static { extra_pages: 1024 },
|
heap_pages: DEFAULT_HEAP_ALLOC_STRATEGY,
|
||||||
precompile_runtime: false,
|
precompile_runtime: false,
|
||||||
tmpdir: None,
|
tmpdir: None,
|
||||||
}
|
}
|
||||||
@@ -477,7 +477,7 @@ fn test_instances_without_reuse_are_not_leaked() {
|
|||||||
deterministic_stack_limit: None,
|
deterministic_stack_limit: None,
|
||||||
canonicalize_nans: false,
|
canonicalize_nans: false,
|
||||||
parallel_compilation: true,
|
parallel_compilation: true,
|
||||||
heap_alloc_strategy: HeapAllocStrategy::Static { extra_pages: 2048 },
|
heap_alloc_strategy: DEFAULT_HEAP_ALLOC_STRATEGY,
|
||||||
wasm_multi_value: false,
|
wasm_multi_value: false,
|
||||||
wasm_bulk_memory: false,
|
wasm_bulk_memory: false,
|
||||||
wasm_reference_types: false,
|
wasm_reference_types: false,
|
||||||
|
|||||||
@@ -36,7 +36,10 @@ use sc_client_api::{
|
|||||||
};
|
};
|
||||||
use sc_client_db::{Backend, DatabaseSettings};
|
use sc_client_db::{Backend, DatabaseSettings};
|
||||||
use sc_consensus::import_queue::ImportQueue;
|
use sc_consensus::import_queue::ImportQueue;
|
||||||
use sc_executor::RuntimeVersionOf;
|
use sc_executor::{
|
||||||
|
sp_wasm_interface::HostFunctions, HeapAllocStrategy, NativeElseWasmExecutor,
|
||||||
|
NativeExecutionDispatch, RuntimeVersionOf, WasmExecutor, DEFAULT_HEAP_ALLOC_STRATEGY,
|
||||||
|
};
|
||||||
use sc_keystore::LocalKeystore;
|
use sc_keystore::LocalKeystore;
|
||||||
use sc_network::{config::SyncMode, NetworkService, NetworkStateInfo, NetworkStatusProvider};
|
use sc_network::{config::SyncMode, NetworkService, NetworkStateInfo, NetworkStatusProvider};
|
||||||
use sc_network_bitswap::BitswapRequestHandler;
|
use sc_network_bitswap::BitswapRequestHandler;
|
||||||
@@ -74,11 +77,10 @@ pub type TFullClient<TBl, TRtApi, TExec> =
|
|||||||
Client<TFullBackend<TBl>, TFullCallExecutor<TBl, TExec>, TBl, TRtApi>;
|
Client<TFullBackend<TBl>, TFullCallExecutor<TBl, TExec>, TBl, TRtApi>;
|
||||||
|
|
||||||
/// Full client backend type.
|
/// Full client backend type.
|
||||||
pub type TFullBackend<TBl> = sc_client_db::Backend<TBl>;
|
pub type TFullBackend<TBl> = Backend<TBl>;
|
||||||
|
|
||||||
/// Full client call executor type.
|
/// Full client call executor type.
|
||||||
pub type TFullCallExecutor<TBl, TExec> =
|
pub type TFullCallExecutor<TBl, TExec> = crate::client::LocalCallExecutor<TBl, Backend<TBl>, TExec>;
|
||||||
crate::client::LocalCallExecutor<TBl, sc_client_db::Backend<TBl>, TExec>;
|
|
||||||
|
|
||||||
type TFullParts<TBl, TRtApi, TExec> =
|
type TFullParts<TBl, TRtApi, TExec> =
|
||||||
(TFullClient<TBl, TRtApi, TExec>, Arc<TFullBackend<TBl>>, KeystoreContainer, TaskManager);
|
(TFullClient<TBl, TRtApi, TExec>, Arc<TFullBackend<TBl>>, KeystoreContainer, TaskManager);
|
||||||
@@ -229,6 +231,27 @@ where
|
|||||||
Ok((client, backend, keystore_container, task_manager))
|
Ok((client, backend, keystore_container, task_manager))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Creates a [`NativeElseWasmExecutor`] according to [`Configuration`].
|
||||||
|
pub fn new_native_or_wasm_executor<D: NativeExecutionDispatch>(
|
||||||
|
config: &Configuration,
|
||||||
|
) -> NativeElseWasmExecutor<D> {
|
||||||
|
NativeElseWasmExecutor::new_with_wasm_executor(new_wasm_executor(config))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Creates a [`WasmExecutor`] according to [`Configuration`].
|
||||||
|
pub fn new_wasm_executor<H: HostFunctions>(config: &Configuration) -> WasmExecutor<H> {
|
||||||
|
let strategy = config
|
||||||
|
.default_heap_pages
|
||||||
|
.map_or(DEFAULT_HEAP_ALLOC_STRATEGY, |p| HeapAllocStrategy::Static { extra_pages: p as _ });
|
||||||
|
WasmExecutor::<H>::builder()
|
||||||
|
.with_execution_method(config.wasm_method)
|
||||||
|
.with_onchain_heap_alloc_strategy(strategy)
|
||||||
|
.with_offchain_heap_alloc_strategy(strategy)
|
||||||
|
.with_max_runtime_instances(config.max_runtime_instances)
|
||||||
|
.with_runtime_cache_size(config.runtime_cache_size)
|
||||||
|
.build()
|
||||||
|
}
|
||||||
|
|
||||||
/// Create an instance of default DB-backend backend.
|
/// Create an instance of default DB-backend backend.
|
||||||
pub fn new_db_backend<Block>(
|
pub fn new_db_backend<Block>(
|
||||||
settings: DatabaseSettings,
|
settings: DatabaseSettings,
|
||||||
@@ -254,7 +277,7 @@ pub fn new_client<E, Block, RA, G>(
|
|||||||
telemetry: Option<TelemetryHandle>,
|
telemetry: Option<TelemetryHandle>,
|
||||||
config: ClientConfig<Block>,
|
config: ClientConfig<Block>,
|
||||||
) -> Result<
|
) -> Result<
|
||||||
crate::client::Client<
|
Client<
|
||||||
Backend<Block>,
|
Backend<Block>,
|
||||||
crate::client::LocalCallExecutor<Block, Backend<Block>, E>,
|
crate::client::LocalCallExecutor<Block, Backend<Block>, E>,
|
||||||
Block,
|
Block,
|
||||||
@@ -277,7 +300,7 @@ where
|
|||||||
execution_extensions,
|
execution_extensions,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
crate::client::Client::new(
|
Client::new(
|
||||||
backend,
|
backend,
|
||||||
executor,
|
executor,
|
||||||
spawn_handle,
|
spawn_handle,
|
||||||
|
|||||||
@@ -360,7 +360,7 @@ mod tests {
|
|||||||
use super::*;
|
use super::*;
|
||||||
use backend::Backend;
|
use backend::Backend;
|
||||||
use sc_client_api::in_mem;
|
use sc_client_api::in_mem;
|
||||||
use sc_executor::{NativeElseWasmExecutor, WasmExecutionMethod};
|
use sc_executor::{NativeElseWasmExecutor, WasmExecutor};
|
||||||
use sp_core::{
|
use sp_core::{
|
||||||
testing::TaskExecutor,
|
testing::TaskExecutor,
|
||||||
traits::{FetchRuntimeCode, WrappedRuntimeCode},
|
traits::{FetchRuntimeCode, WrappedRuntimeCode},
|
||||||
@@ -368,14 +368,18 @@ mod tests {
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use substrate_test_runtime_client::{runtime, GenesisInit, LocalExecutorDispatch};
|
use substrate_test_runtime_client::{runtime, GenesisInit, LocalExecutorDispatch};
|
||||||
|
|
||||||
|
fn executor() -> NativeElseWasmExecutor<LocalExecutorDispatch> {
|
||||||
|
NativeElseWasmExecutor::new_with_wasm_executor(
|
||||||
|
WasmExecutor::builder()
|
||||||
|
.with_max_runtime_instances(1)
|
||||||
|
.with_runtime_cache_size(2)
|
||||||
|
.build(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn should_get_override_if_exists() {
|
fn should_get_override_if_exists() {
|
||||||
let executor = NativeElseWasmExecutor::<LocalExecutorDispatch>::new(
|
let executor = executor();
|
||||||
WasmExecutionMethod::Interpreted,
|
|
||||||
Some(128),
|
|
||||||
1,
|
|
||||||
2,
|
|
||||||
);
|
|
||||||
|
|
||||||
let overrides = crate::client::wasm_override::dummy_overrides();
|
let overrides = crate::client::wasm_override::dummy_overrides();
|
||||||
let onchain_code = WrappedRuntimeCode(substrate_test_runtime::wasm_binary_unwrap().into());
|
let onchain_code = WrappedRuntimeCode(substrate_test_runtime::wasm_binary_unwrap().into());
|
||||||
@@ -443,12 +447,7 @@ mod tests {
|
|||||||
fn returns_runtime_version_from_substitute() {
|
fn returns_runtime_version_from_substitute() {
|
||||||
const SUBSTITUTE_SPEC_NAME: &str = "substitute-spec-name-cool";
|
const SUBSTITUTE_SPEC_NAME: &str = "substitute-spec-name-cool";
|
||||||
|
|
||||||
let executor = NativeElseWasmExecutor::<LocalExecutorDispatch>::new(
|
let executor = executor();
|
||||||
WasmExecutionMethod::Interpreted,
|
|
||||||
Some(128),
|
|
||||||
1,
|
|
||||||
2,
|
|
||||||
);
|
|
||||||
|
|
||||||
let backend = Arc::new(in_mem::Backend::<runtime::Block>::new());
|
let backend = Arc::new(in_mem::Backend::<runtime::Block>::new());
|
||||||
|
|
||||||
|
|||||||
@@ -264,21 +264,26 @@ pub fn dummy_overrides() -> WasmOverride {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use sc_executor::{NativeElseWasmExecutor, WasmExecutionMethod};
|
use sc_executor::{HeapAllocStrategy, NativeElseWasmExecutor, WasmExecutor};
|
||||||
use std::fs::{self, File};
|
use std::fs::{self, File};
|
||||||
use substrate_test_runtime_client::LocalExecutorDispatch;
|
use substrate_test_runtime_client::LocalExecutorDispatch;
|
||||||
|
|
||||||
|
fn executor() -> NativeElseWasmExecutor<substrate_test_runtime_client::LocalExecutorDispatch> {
|
||||||
|
NativeElseWasmExecutor::<substrate_test_runtime_client::LocalExecutorDispatch>::new_with_wasm_executor(
|
||||||
|
WasmExecutor::builder()
|
||||||
|
.with_onchain_heap_alloc_strategy(HeapAllocStrategy::Static {extra_pages: 128})
|
||||||
|
.with_offchain_heap_alloc_strategy(HeapAllocStrategy::Static {extra_pages: 128})
|
||||||
|
.with_max_runtime_instances(1)
|
||||||
|
.with_runtime_cache_size(2)
|
||||||
|
.build()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
fn wasm_test<F>(fun: F)
|
fn wasm_test<F>(fun: F)
|
||||||
where
|
where
|
||||||
F: Fn(&Path, &[u8], &NativeElseWasmExecutor<LocalExecutorDispatch>),
|
F: Fn(&Path, &[u8], &NativeElseWasmExecutor<LocalExecutorDispatch>),
|
||||||
{
|
{
|
||||||
let exec =
|
let exec = executor();
|
||||||
NativeElseWasmExecutor::<substrate_test_runtime_client::LocalExecutorDispatch>::new(
|
|
||||||
WasmExecutionMethod::Interpreted,
|
|
||||||
Some(128),
|
|
||||||
1,
|
|
||||||
2,
|
|
||||||
);
|
|
||||||
let bytes = substrate_test_runtime::wasm_binary_unwrap();
|
let bytes = substrate_test_runtime::wasm_binary_unwrap();
|
||||||
let dir = tempfile::tempdir().expect("Create a temporary directory");
|
let dir = tempfile::tempdir().expect("Create a temporary directory");
|
||||||
fun(dir.path(), bytes, &exec);
|
fun(dir.path(), bytes, &exec);
|
||||||
@@ -287,12 +292,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn should_get_runtime_version() {
|
fn should_get_runtime_version() {
|
||||||
let executor = NativeElseWasmExecutor::<LocalExecutorDispatch>::new(
|
let executor = executor();
|
||||||
WasmExecutionMethod::Interpreted,
|
|
||||||
Some(128),
|
|
||||||
1,
|
|
||||||
2,
|
|
||||||
);
|
|
||||||
|
|
||||||
let version = WasmOverride::runtime_version(
|
let version = WasmOverride::runtime_version(
|
||||||
&executor,
|
&executor,
|
||||||
|
|||||||
@@ -56,9 +56,9 @@ use sp_runtime::{
|
|||||||
pub use self::{
|
pub use self::{
|
||||||
builder::{
|
builder::{
|
||||||
build_network, build_offchain_workers, new_client, new_db_backend, new_full_client,
|
build_network, build_offchain_workers, new_client, new_db_backend, new_full_client,
|
||||||
new_full_parts, new_full_parts_with_genesis_builder, spawn_tasks, BuildNetworkParams,
|
new_full_parts, new_full_parts_with_genesis_builder, new_native_or_wasm_executor,
|
||||||
KeystoreContainer, NetworkStarter, SpawnTasksParams, TFullBackend, TFullCallExecutor,
|
spawn_tasks, BuildNetworkParams, KeystoreContainer, NetworkStarter, SpawnTasksParams,
|
||||||
TFullClient,
|
TFullBackend, TFullCallExecutor, TFullClient,
|
||||||
},
|
},
|
||||||
client::{ClientConfig, LocalCallExecutor},
|
client::{ClientConfig, LocalCallExecutor},
|
||||||
error::Error,
|
error::Error,
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ use sp_trie::{LayoutV0, TrieConfiguration};
|
|||||||
use std::{collections::HashSet, sync::Arc};
|
use std::{collections::HashSet, sync::Arc};
|
||||||
use substrate_test_runtime::TestAPI;
|
use substrate_test_runtime::TestAPI;
|
||||||
use substrate_test_runtime_client::{
|
use substrate_test_runtime_client::{
|
||||||
|
new_native_or_wasm_executor,
|
||||||
prelude::*,
|
prelude::*,
|
||||||
runtime::{
|
runtime::{
|
||||||
genesismap::{insert_genesis_block, GenesisConfig},
|
genesismap::{insert_genesis_block, GenesisConfig},
|
||||||
@@ -58,29 +59,6 @@ mod db;
|
|||||||
|
|
||||||
const TEST_ENGINE_ID: ConsensusEngineId = *b"TEST";
|
const TEST_ENGINE_ID: ConsensusEngineId = *b"TEST";
|
||||||
|
|
||||||
pub struct ExecutorDispatch;
|
|
||||||
|
|
||||||
impl sc_executor::NativeExecutionDispatch for ExecutorDispatch {
|
|
||||||
type ExtendHostFunctions = ();
|
|
||||||
|
|
||||||
fn dispatch(method: &str, data: &[u8]) -> Option<Vec<u8>> {
|
|
||||||
substrate_test_runtime_client::runtime::api::dispatch(method, data)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn native_version() -> sc_executor::NativeVersion {
|
|
||||||
substrate_test_runtime_client::runtime::native_version()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn executor() -> sc_executor::NativeElseWasmExecutor<ExecutorDispatch> {
|
|
||||||
sc_executor::NativeElseWasmExecutor::new(
|
|
||||||
sc_executor::WasmExecutionMethod::Interpreted,
|
|
||||||
None,
|
|
||||||
8,
|
|
||||||
2,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn construct_block(
|
fn construct_block(
|
||||||
backend: &InMemoryBackend<BlakeTwo256>,
|
backend: &InMemoryBackend<BlakeTwo256>,
|
||||||
number: BlockNumber,
|
number: BlockNumber,
|
||||||
@@ -108,7 +86,7 @@ fn construct_block(
|
|||||||
StateMachine::new(
|
StateMachine::new(
|
||||||
backend,
|
backend,
|
||||||
&mut overlay,
|
&mut overlay,
|
||||||
&executor(),
|
&new_native_or_wasm_executor(),
|
||||||
"Core_initialize_block",
|
"Core_initialize_block",
|
||||||
&header.encode(),
|
&header.encode(),
|
||||||
Default::default(),
|
Default::default(),
|
||||||
@@ -122,7 +100,7 @@ fn construct_block(
|
|||||||
StateMachine::new(
|
StateMachine::new(
|
||||||
backend,
|
backend,
|
||||||
&mut overlay,
|
&mut overlay,
|
||||||
&executor(),
|
&new_native_or_wasm_executor(),
|
||||||
"BlockBuilder_apply_extrinsic",
|
"BlockBuilder_apply_extrinsic",
|
||||||
&tx.encode(),
|
&tx.encode(),
|
||||||
Default::default(),
|
Default::default(),
|
||||||
@@ -136,7 +114,7 @@ fn construct_block(
|
|||||||
let ret_data = StateMachine::new(
|
let ret_data = StateMachine::new(
|
||||||
backend,
|
backend,
|
||||||
&mut overlay,
|
&mut overlay,
|
||||||
&executor(),
|
&new_native_or_wasm_executor(),
|
||||||
"BlockBuilder_finalize_block",
|
"BlockBuilder_finalize_block",
|
||||||
&[],
|
&[],
|
||||||
Default::default(),
|
Default::default(),
|
||||||
@@ -208,7 +186,7 @@ fn construct_genesis_should_work_with_native() {
|
|||||||
let _ = StateMachine::new(
|
let _ = StateMachine::new(
|
||||||
&backend,
|
&backend,
|
||||||
&mut overlay,
|
&mut overlay,
|
||||||
&executor(),
|
&new_native_or_wasm_executor(),
|
||||||
"Core_execute_block",
|
"Core_execute_block",
|
||||||
&b1data,
|
&b1data,
|
||||||
Default::default(),
|
Default::default(),
|
||||||
@@ -241,7 +219,7 @@ fn construct_genesis_should_work_with_wasm() {
|
|||||||
let _ = StateMachine::new(
|
let _ = StateMachine::new(
|
||||||
&backend,
|
&backend,
|
||||||
&mut overlay,
|
&mut overlay,
|
||||||
&executor(),
|
&new_native_or_wasm_executor(),
|
||||||
"Core_execute_block",
|
"Core_execute_block",
|
||||||
&b1data,
|
&b1data,
|
||||||
Default::default(),
|
Default::default(),
|
||||||
@@ -274,7 +252,7 @@ fn construct_genesis_with_bad_transaction_should_panic() {
|
|||||||
let r = StateMachine::new(
|
let r = StateMachine::new(
|
||||||
&backend,
|
&backend,
|
||||||
&mut overlay,
|
&mut overlay,
|
||||||
&executor(),
|
&new_native_or_wasm_executor(),
|
||||||
"Core_execute_block",
|
"Core_execute_block",
|
||||||
&b1data,
|
&b1data,
|
||||||
Default::default(),
|
Default::default(),
|
||||||
@@ -1910,7 +1888,7 @@ fn cleans_up_closed_notification_sinks_on_block_import() {
|
|||||||
use substrate_test_runtime_client::GenesisInit;
|
use substrate_test_runtime_client::GenesisInit;
|
||||||
|
|
||||||
let backend = Arc::new(sc_client_api::in_mem::Backend::new());
|
let backend = Arc::new(sc_client_api::in_mem::Backend::new());
|
||||||
let executor = substrate_test_runtime_client::new_native_executor();
|
let executor = new_native_or_wasm_executor();
|
||||||
let client_config = sc_service::ClientConfig::default();
|
let client_config = sc_service::ClientConfig::default();
|
||||||
|
|
||||||
let genesis_block_builder = sc_service::GenesisBlockBuilder::new(
|
let genesis_block_builder = sc_service::GenesisBlockBuilder::new(
|
||||||
|
|||||||
@@ -65,9 +65,7 @@ impl<G, E, F, U> Drop for TestNet<G, E, F, U> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait TestNetNode:
|
pub trait TestNetNode: Clone + Future<Output = Result<(), Error>> + Send + 'static {
|
||||||
Clone + Future<Output = Result<(), sc_service::Error>> + Send + 'static
|
|
||||||
{
|
|
||||||
type Block: BlockT;
|
type Block: BlockT;
|
||||||
type Backend: Backend<Self::Block>;
|
type Backend: Backend<Self::Block>;
|
||||||
type Executor: CallExecutor<Self::Block> + Send + Sync;
|
type Executor: CallExecutor<Self::Block> + Send + Sync;
|
||||||
@@ -128,7 +126,7 @@ impl<TBl: BlockT, TBackend, TExec, TRtApi, TExPool> Clone
|
|||||||
impl<TBl: BlockT, TBackend, TExec, TRtApi, TExPool> Future
|
impl<TBl: BlockT, TBackend, TExec, TRtApi, TExPool> Future
|
||||||
for TestNetComponents<TBl, TBackend, TExec, TRtApi, TExPool>
|
for TestNetComponents<TBl, TBackend, TExec, TRtApi, TExPool>
|
||||||
{
|
{
|
||||||
type Output = Result<(), sc_service::Error>;
|
type Output = Result<(), Error>;
|
||||||
|
|
||||||
fn poll(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Self::Output> {
|
fn poll(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Self::Output> {
|
||||||
Pin::new(&mut self.task_manager.lock().future()).poll(cx)
|
Pin::new(&mut self.task_manager.lock().future()).poll(cx)
|
||||||
@@ -248,7 +246,7 @@ fn node_config<
|
|||||||
state_pruning: Default::default(),
|
state_pruning: Default::default(),
|
||||||
blocks_pruning: BlocksPruning::KeepFinalized,
|
blocks_pruning: BlocksPruning::KeepFinalized,
|
||||||
chain_spec: Box::new((*spec).clone()),
|
chain_spec: Box::new((*spec).clone()),
|
||||||
wasm_method: sc_service::config::WasmExecutionMethod::Interpreted,
|
wasm_method: Default::default(),
|
||||||
wasm_runtime_overrides: Default::default(),
|
wasm_runtime_overrides: Default::default(),
|
||||||
execution_strategies: Default::default(),
|
execution_strategies: Default::default(),
|
||||||
rpc_http: None,
|
rpc_http: None,
|
||||||
|
|||||||
@@ -589,7 +589,7 @@ fn assert_runtime_updated_digest(num: usize) {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn set_code_with_real_wasm_blob() {
|
fn set_code_with_real_wasm_blob() {
|
||||||
let executor = substrate_test_runtime_client::new_native_executor();
|
let executor = substrate_test_runtime_client::new_native_or_wasm_executor();
|
||||||
let mut ext = new_test_ext();
|
let mut ext = new_test_ext();
|
||||||
ext.register_extension(sp_core::traits::ReadRuntimeVersionExt::new(executor));
|
ext.register_extension(sp_core::traits::ReadRuntimeVersionExt::new(executor));
|
||||||
ext.execute_with(|| {
|
ext.execute_with(|| {
|
||||||
@@ -613,7 +613,7 @@ fn set_code_with_real_wasm_blob() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn runtime_upgraded_with_set_storage() {
|
fn runtime_upgraded_with_set_storage() {
|
||||||
let executor = substrate_test_runtime_client::new_native_executor();
|
let executor = substrate_test_runtime_client::new_native_or_wasm_executor();
|
||||||
let mut ext = new_test_ext();
|
let mut ext = new_test_ext();
|
||||||
ext.register_extension(sp_core::traits::ReadRuntimeVersionExt::new(executor));
|
ext.register_extension(sp_core::traits::ReadRuntimeVersionExt::new(executor));
|
||||||
ext.execute_with(|| {
|
ext.execute_with(|| {
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ use substrate_test_runtime_client::{
|
|||||||
use codec::Encode;
|
use codec::Encode;
|
||||||
use sc_block_builder::BlockBuilderProvider;
|
use sc_block_builder::BlockBuilderProvider;
|
||||||
use sp_consensus::SelectChain;
|
use sp_consensus::SelectChain;
|
||||||
|
use substrate_test_runtime_client::sc_executor::WasmExecutor;
|
||||||
|
|
||||||
fn calling_function_with_strat(strat: ExecutionStrategy) {
|
fn calling_function_with_strat(strat: ExecutionStrategy) {
|
||||||
let client = TestClientBuilder::new().set_execution_strategy(strat).build();
|
let client = TestClientBuilder::new().set_execution_strategy(strat).build();
|
||||||
@@ -178,11 +179,8 @@ fn record_proof_works() {
|
|||||||
|
|
||||||
// Use the proof backend to execute `execute_block`.
|
// Use the proof backend to execute `execute_block`.
|
||||||
let mut overlay = Default::default();
|
let mut overlay = Default::default();
|
||||||
let executor = NativeElseWasmExecutor::<LocalExecutorDispatch>::new(
|
let executor = NativeElseWasmExecutor::<LocalExecutorDispatch>::new_with_wasm_executor(
|
||||||
WasmExecutionMethod::Interpreted,
|
WasmExecutor::builder().build(),
|
||||||
None,
|
|
||||||
8,
|
|
||||||
2,
|
|
||||||
);
|
);
|
||||||
execution_proof_check_on_trie_backend(
|
execution_proof_check_on_trie_backend(
|
||||||
&backend,
|
&backend,
|
||||||
|
|||||||
@@ -42,7 +42,8 @@ fn call_wasm_method_with_result<HF: HostFunctionsT>(
|
|||||||
|
|
||||||
let executor = sc_executor::WasmExecutor::<
|
let executor = sc_executor::WasmExecutor::<
|
||||||
ExtendedHostFunctions<sp_io::SubstrateHostFunctions, HF>,
|
ExtendedHostFunctions<sp_io::SubstrateHostFunctions, HF>,
|
||||||
>::new(sc_executor::WasmExecutionMethod::Interpreted, Some(8), 8, None, 2);
|
>::builder()
|
||||||
|
.build();
|
||||||
|
|
||||||
let (result, allocation_stats) = executor.uncached_call_with_allocation_stats(
|
let (result, allocation_stats) = executor.uncached_call_with_allocation_stats(
|
||||||
RuntimeBlob::uncompress_if_needed(binary).expect("Failed to parse binary"),
|
RuntimeBlob::uncompress_if_needed(binary).expect("Failed to parse binary"),
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ pub use sc_client_api::{
|
|||||||
BadBlocks, ForkBlocks,
|
BadBlocks, ForkBlocks,
|
||||||
};
|
};
|
||||||
pub use sc_client_db::{self, Backend, BlocksPruning};
|
pub use sc_client_db::{self, Backend, BlocksPruning};
|
||||||
pub use sc_executor::{self, NativeElseWasmExecutor, WasmExecutionMethod};
|
pub use sc_executor::{self, NativeElseWasmExecutor, WasmExecutionMethod, WasmExecutor};
|
||||||
pub use sc_service::{client, RpcHandlers};
|
pub use sc_service::{client, RpcHandlers};
|
||||||
pub use sp_consensus;
|
pub use sp_consensus;
|
||||||
pub use sp_keyring::{
|
pub use sp_keyring::{
|
||||||
@@ -286,7 +286,7 @@ impl<Block: BlockT, D, Backend, G: GenesisInit>
|
|||||||
Backend: sc_client_api::backend::Backend<Block> + 'static,
|
Backend: sc_client_api::backend::Backend<Block> + 'static,
|
||||||
{
|
{
|
||||||
let executor = executor.into().unwrap_or_else(|| {
|
let executor = executor.into().unwrap_or_else(|| {
|
||||||
NativeElseWasmExecutor::new(WasmExecutionMethod::Interpreted, None, 8, 2)
|
NativeElseWasmExecutor::new_with_wasm_executor(WasmExecutor::builder().build())
|
||||||
});
|
});
|
||||||
let executor = LocalCallExecutor::new(
|
let executor = LocalCallExecutor::new(
|
||||||
self.backend.clone(),
|
self.backend.clone(),
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ use sp_core::{
|
|||||||
Pair,
|
Pair,
|
||||||
};
|
};
|
||||||
use sp_runtime::traits::{Block as BlockT, Hash as HashT, Header as HeaderT};
|
use sp_runtime::traits::{Block as BlockT, Hash as HashT, Header as HeaderT};
|
||||||
|
use substrate_test_client::sc_executor::WasmExecutor;
|
||||||
use substrate_test_runtime::genesismap::{additional_storage_with_genesis, GenesisConfig};
|
use substrate_test_runtime::genesismap::{additional_storage_with_genesis, GenesisConfig};
|
||||||
|
|
||||||
/// A prelude to import in tests.
|
/// A prelude to import in tests.
|
||||||
@@ -171,7 +172,7 @@ pub type Client<B> = client::Client<
|
|||||||
client::LocalCallExecutor<
|
client::LocalCallExecutor<
|
||||||
substrate_test_runtime::Block,
|
substrate_test_runtime::Block,
|
||||||
B,
|
B,
|
||||||
sc_executor::NativeElseWasmExecutor<LocalExecutorDispatch>,
|
NativeElseWasmExecutor<LocalExecutorDispatch>,
|
||||||
>,
|
>,
|
||||||
substrate_test_runtime::Block,
|
substrate_test_runtime::Block,
|
||||||
substrate_test_runtime::RuntimeApi,
|
substrate_test_runtime::RuntimeApi,
|
||||||
@@ -290,6 +291,6 @@ pub fn new() -> Client<Backend> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Create a new native executor.
|
/// Create a new native executor.
|
||||||
pub fn new_native_executor() -> NativeElseWasmExecutor<LocalExecutorDispatch> {
|
pub fn new_native_or_wasm_executor() -> NativeElseWasmExecutor<LocalExecutorDispatch> {
|
||||||
NativeElseWasmExecutor::new(sc_executor::WasmExecutionMethod::Interpreted, None, 8, 2)
|
NativeElseWasmExecutor::new_with_wasm_executor(WasmExecutor::builder().build())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -376,7 +376,7 @@ mod tests {
|
|||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
use crate::{wasm_binary_unwrap, Header, Transfer};
|
use crate::{wasm_binary_unwrap, Header, Transfer};
|
||||||
use sc_executor::{NativeElseWasmExecutor, WasmExecutionMethod};
|
use sc_executor::{NativeElseWasmExecutor, WasmExecutor};
|
||||||
use sp_core::{
|
use sp_core::{
|
||||||
map,
|
map,
|
||||||
traits::{CallContext, CodeExecutor, RuntimeCode},
|
traits::{CallContext, CodeExecutor, RuntimeCode},
|
||||||
@@ -400,7 +400,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn executor() -> NativeElseWasmExecutor<NativeDispatch> {
|
fn executor() -> NativeElseWasmExecutor<NativeDispatch> {
|
||||||
NativeElseWasmExecutor::new(WasmExecutionMethod::Interpreted, None, 8, 2)
|
NativeElseWasmExecutor::new_with_wasm_executor(WasmExecutor::builder().build())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn new_test_ext() -> TestExternalities {
|
fn new_test_ext() -> TestExternalities {
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ use sc_cli::{
|
|||||||
execution_method_from_cli, CliConfiguration, ExecutionStrategy, Result, SharedParams,
|
execution_method_from_cli, CliConfiguration, ExecutionStrategy, Result, SharedParams,
|
||||||
};
|
};
|
||||||
use sc_client_db::BenchmarkingState;
|
use sc_client_db::BenchmarkingState;
|
||||||
use sc_executor::NativeElseWasmExecutor;
|
use sc_executor::{NativeElseWasmExecutor, WasmExecutor};
|
||||||
use sc_service::{Configuration, NativeExecutionDispatch};
|
use sc_service::{Configuration, NativeExecutionDispatch};
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use sp_core::{
|
use sp_core::{
|
||||||
@@ -209,11 +209,16 @@ impl PalletCmd {
|
|||||||
// Do not enable storage tracking
|
// Do not enable storage tracking
|
||||||
false,
|
false,
|
||||||
)?;
|
)?;
|
||||||
let executor = NativeElseWasmExecutor::<ExecDispatch>::new(
|
|
||||||
execution_method_from_cli(self.wasm_method, self.wasmtime_instantiation_strategy),
|
let method =
|
||||||
self.heap_pages,
|
execution_method_from_cli(self.wasm_method, self.wasmtime_instantiation_strategy);
|
||||||
2, // The runtime instances cache size.
|
|
||||||
2, // The runtime cache size
|
let executor = NativeElseWasmExecutor::<ExecDispatch>::new_with_wasm_executor(
|
||||||
|
WasmExecutor::builder()
|
||||||
|
.with_execution_method(method)
|
||||||
|
.with_max_runtime_instances(2)
|
||||||
|
.with_runtime_cache_size(2)
|
||||||
|
.build(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let extensions = || -> Extensions {
|
let extensions = || -> Extensions {
|
||||||
|
|||||||
@@ -368,7 +368,9 @@ use sc_cli::{
|
|||||||
WasmtimeInstantiationStrategy, DEFAULT_WASMTIME_INSTANTIATION_STRATEGY,
|
WasmtimeInstantiationStrategy, DEFAULT_WASMTIME_INSTANTIATION_STRATEGY,
|
||||||
DEFAULT_WASM_EXECUTION_METHOD,
|
DEFAULT_WASM_EXECUTION_METHOD,
|
||||||
};
|
};
|
||||||
use sc_executor::{sp_wasm_interface::HostFunctions, WasmExecutor};
|
use sc_executor::{
|
||||||
|
sp_wasm_interface::HostFunctions, HeapAllocStrategy, WasmExecutor, DEFAULT_HEAP_ALLOC_STRATEGY,
|
||||||
|
};
|
||||||
use sp_api::HashT;
|
use sp_api::HashT;
|
||||||
use sp_core::{
|
use sp_core::{
|
||||||
hexdisplay::HexDisplay,
|
hexdisplay::HexDisplay,
|
||||||
@@ -824,18 +826,20 @@ pub(crate) fn full_extensions<H: HostFunctions>(wasm_executor: WasmExecutor<H>)
|
|||||||
extensions
|
extensions
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Build wasm executor by default config.
|
||||||
pub(crate) fn build_executor<H: HostFunctions>(shared: &SharedParams) -> WasmExecutor<H> {
|
pub(crate) fn build_executor<H: HostFunctions>(shared: &SharedParams) -> WasmExecutor<H> {
|
||||||
let heap_pages = shared.heap_pages.or(Some(2048));
|
let heap_pages = shared
|
||||||
let max_runtime_instances = 8;
|
.heap_pages
|
||||||
let runtime_cache_size = 2;
|
.map_or(DEFAULT_HEAP_ALLOC_STRATEGY, |p| HeapAllocStrategy::Static { extra_pages: p as _ });
|
||||||
|
|
||||||
WasmExecutor::new(
|
WasmExecutor::builder()
|
||||||
execution_method_from_cli(shared.wasm_method, shared.wasmtime_instantiation_strategy),
|
.with_execution_method(execution_method_from_cli(
|
||||||
heap_pages,
|
shared.wasm_method,
|
||||||
max_runtime_instances,
|
shared.wasmtime_instantiation_strategy,
|
||||||
None,
|
))
|
||||||
runtime_cache_size,
|
.with_onchain_heap_alloc_strategy(heap_pages)
|
||||||
)
|
.with_offchain_heap_alloc_strategy(heap_pages)
|
||||||
|
.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Ensure that the given `ext` is compiled with `try-runtime`
|
/// Ensure that the given `ext` is compiled with `try-runtime`
|
||||||
|
|||||||
Reference in New Issue
Block a user