Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
0edd825
refactor: use builder api for all executors
yjhmelody Mar 28, 2023
9750b54
improve a lot
yjhmelody Mar 28, 2023
de50bf8
remove unused args
yjhmelody Mar 28, 2023
fb0539d
cleanup deps
yjhmelody Mar 28, 2023
b60bbd8
fix inconsistency about heap alloc
yjhmelody Mar 28, 2023
4eb0dc2
add `heap_pages` back to try-runtime
yjhmelody Mar 28, 2023
f449134
fix
yjhmelody Mar 28, 2023
c4175b2
chore: reduce duplicated code for sc-service-test
yjhmelody Mar 28, 2023
86172e6
cleanup code
yjhmelody Mar 28, 2023
f2c2e54
fmt
yjhmelody Mar 28, 2023
ce6dfb6
improve test executor
yjhmelody Mar 28, 2023
95dca94
improve
yjhmelody Mar 29, 2023
cd3bacb
Merge branch 'master' into refactor-use-executor-builder
yjhmelody Mar 29, 2023
c22e1bf
Merge branch 'master' into refactor-use-executor-builder
yjhmelody Mar 29, 2023
7147033
use #[deprecated]
yjhmelody Mar 29, 2023
157646e
set runtime_cache_size: 4
yjhmelody Mar 29, 2023
3f43381
wip
yjhmelody Mar 30, 2023
2dfbe0e
fix and improve
yjhmelody Mar 30, 2023
48161e5
Merge branch 'refactor-use-executor-builder' into refactor-remove-wasmi
yjhmelody Mar 30, 2023
3659412
remove sc-executor-wasmi deps
yjhmelody Mar 30, 2023
9e068da
clean up bench and tests
yjhmelody Mar 30, 2023
16d2e5a
delete "client/executor/wasmi"
yjhmelody Mar 30, 2023
18bbf96
cleanup
yjhmelody Mar 30, 2023
31ac181
refactor builder
yjhmelody Mar 30, 2023
d4cacc0
fix
yjhmelody Mar 30, 2023
7054f42
fix bench
yjhmelody Mar 30, 2023
fd173f6
fix tests
yjhmelody Mar 30, 2023
c523c6e
fix warnings
yjhmelody Mar 30, 2023
68661c0
fix warnings
yjhmelody Mar 30, 2023
00bc047
fix
yjhmelody Mar 30, 2023
35701eb
fix
yjhmelody Mar 30, 2023
3ab11e4
Merge branch 'master' into refactor-use-executor-builder
yjhmelody Mar 31, 2023
149939d
Merge branch 'refactor-use-executor-builder' into refactor-remove-wasmi
yjhmelody Apr 2, 2023
075cf2b
Merge branch 'master' into refactor-remove-wasmi
yjhmelody Apr 2, 2023
3571d48
remove wasmi and fix tests
yjhmelody Apr 2, 2023
a41f6e7
Merge branch 'master' into refactor-remove-wasmi
yjhmelody Apr 10, 2023
51b6bc3
unused imports
yjhmelody Apr 11, 2023
e2d1812
Merge branch 'master' into refactor-remove-wasmi
yjhmelody Apr 23, 2023
5dfe57d
erge branch 'master' into refactor-remove-wasmi
yjhmelody Apr 26, 2023
dfe0e80
improve by suggestions
yjhmelody May 13, 2023
0ee08dc
Merge branch 'master' into refactor-remove-wasmi
yjhmelody May 13, 2023
1b7375a
Update client/cli/src/arg_enums.rs
bkchr May 15, 2023
e24a1e3
Merge remote-tracking branch 'origin/master' into refactor-remove-wasmi
May 21, 2023
d4ccbcd
Merge branch 'master' into refactor-remove-wasmi
yjhmelody May 23, 2023
bbad9f1
Merge remote-tracking branch 'my/refactor-remove-wasmi' into refactor…
yjhmelody May 23, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions bin/node/cli/benches/transaction_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use sc_executor::WasmtimeInstantiationStrategy;
use sc_service::{
config::{
BlocksPruning, DatabaseSource, KeystoreConfig, NetworkConfiguration, OffchainWorkerConfig,
PruningMode, TransactionPoolOptions, WasmExecutionMethod,
PruningMode, TransactionPoolOptions,
},
BasePath, Configuration, Role,
};
Expand Down Expand Up @@ -70,9 +70,7 @@ fn new_node(tokio_handle: Handle) -> node_cli::service::NewFullBase {
state_pruning: Some(PruningMode::ArchiveAll),
blocks_pruning: BlocksPruning::KeepAll,
chain_spec: spec,
wasm_method: WasmExecutionMethod::Compiled {
instantiation_strategy: WasmtimeInstantiationStrategy::PoolingCopyOnWrite,
},
wasm_method: Default::default(),
// NOTE: we enforce the use of the native runtime to make the errors more debuggable
execution_strategies: ExecutionStrategies {
syncing: sc_client_api::ExecutionStrategy::NativeWhenPossible,
Expand Down
7 changes: 3 additions & 4 deletions bin/node/executor/benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ fn bench_execute_block(c: &mut Criterion) {
let mut group = c.benchmark_group("execute blocks");
let execution_methods = vec![
ExecutionMethod::Native,
ExecutionMethod::Wasm(WasmExecutionMethod::Interpreted),
ExecutionMethod::Wasm(WasmExecutionMethod::Compiled {
instantiation_strategy: WasmtimeInstantiationStrategy::PoolingCopyOnWrite,
}),
Expand All @@ -191,9 +190,9 @@ fn bench_execute_block(c: &mut Criterion) {
for strategy in execution_methods {
group.bench_function(format!("{:?}", strategy), |b| {
let genesis_config = node_testing::genesis::config(Some(compact_code_unwrap()));
let (use_native, wasm_method) = match strategy {
ExecutionMethod::Native => (true, WasmExecutionMethod::Interpreted),
ExecutionMethod::Wasm(wasm_method) => (false, wasm_method),
let use_native = match strategy {
ExecutionMethod::Native => true,
ExecutionMethod::Wasm(..) => false,
};

let executor =
Expand Down
2 changes: 1 addition & 1 deletion bin/node/executor/tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use codec::{Decode, Encode};
use frame_support::Hashable;
use frame_system::offchain::AppCrypto;
use sc_executor::{error::Result, NativeElseWasmExecutor, WasmExecutionMethod, WasmExecutor};
use sc_executor::{error::Result, NativeElseWasmExecutor, WasmExecutor};
use sp_consensus_babe::{
digests::{PreDigest, SecondaryPlainPreDigest},
Slot, BABE_ENGINE_ID,
Expand Down
9 changes: 5 additions & 4 deletions bin/node/testing/src/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,10 +393,11 @@ impl BenchDb {

let backend = sc_service::new_db_backend(db_config).expect("Should not fail");
let executor = NativeElseWasmExecutor::new_with_wasm_executor(
sc_executor::WasmExecutor::builder(WasmExecutionMethod::Compiled {
instantiation_strategy: WasmtimeInstantiationStrategy::PoolingCopyOnWrite,
})
.build(),
sc_executor::WasmExecutor::builder()
.with_execution_method(WasmExecutionMethod::Compiled {
instantiation_strategy: WasmtimeInstantiationStrategy::PoolingCopyOnWrite,
})
.build(),
);

let client_config = sc_service::ClientConfig::default();
Expand Down
1 change: 0 additions & 1 deletion client/executor/benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ fn bench_call_instance(c: &mut Criterion) {
precompile: true,
},
),
("interpreted", Method::Interpreted),
];

let runtimes = [("kusama_runtime", kusama_runtime()), ("test_runtime", test_runtime())];
Expand Down
21 changes: 11 additions & 10 deletions client/executor/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,7 @@ impl<H> WasmExecutorBuilder<H> {
}
}

/// The wasm execution method that should be used by the executor.
///
/// Default to
/// 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
Expand Down Expand Up @@ -569,13 +567,16 @@ impl<D: NativeExecutionDispatch> NativeElseWasmExecutor<D> {
max_runtime_instances: usize,
runtime_cache_size: u8,
) -> Self {
let wasm = WasmExecutor::new(
fallback_method,
default_heap_pages,
max_runtime_instances,
None,
runtime_cache_size,
);
let heap_pages = default_heap_pages.map_or(DEFAULT_HEAP_ALLOC_STRATEGY, |h| {
HeapAllocStrategy::Static { extra_pages: h as _ }
});
let wasm = WasmExecutor::builder()
.with_execution_method(fallback_method)
.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 }
}
Expand Down
21 changes: 1 addition & 20 deletions client/executor/src/integration_tests/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,10 @@ mod smaps;
use super::mk_test_runtime;
use crate::WasmExecutionMethod;
use codec::Encode as _;
use sc_executor_common::wasm_runtime::{HeapAllocStrategy, DEFAULT_HEAP_ALLOC_STRATEGY};
use sc_executor_common::wasm_runtime::DEFAULT_HEAP_ALLOC_STRATEGY;

use self::smaps::Smaps;

#[test]
fn memory_consumption_interpreted() {
let _ = sp_tracing::try_init_simple();

if std::env::var("RUN_TEST").is_ok() {
memory_consumption(WasmExecutionMethod::Interpreted);
} else {
// We need to run the test in isolation, to not getting interfered by the other tests.
let executable = std::env::current_exe().unwrap();
let output = std::process::Command::new(executable)
.env("RUN_TEST", "1")
.args(&["--nocapture", "memory_consumption_interpreted"])
.output()
.unwrap();

assert!(output.status.success());
}
}

#[test]
fn memory_consumption_compiled() {
let _ = sp_tracing::try_init_simple();
Expand Down
4 changes: 1 addition & 3 deletions client/executor/wasmtime/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ use codec::{Decode as _, Encode as _};
use sc_executor_common::{
error::Error,
runtime_blob::RuntimeBlob,
wasm_runtime::{
HeapAllocStrategy, WasmModule, DEFAULT_HEAP_ALLOC_PAGES, DEFAULT_HEAP_ALLOC_STRATEGY,
},
wasm_runtime::{HeapAllocStrategy, WasmModule, DEFAULT_HEAP_ALLOC_STRATEGY},
};
use sc_runtime_test::wasm_binary_unwrap;

Expand Down
8 changes: 4 additions & 4 deletions client/service/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ use sc_client_db::{Backend, DatabaseSettings};
use sc_consensus::import_queue::ImportQueue;
use sc_executor::{
sp_wasm_interface::HostFunctions, HeapAllocStrategy, NativeElseWasmExecutor,
NativeExecutionDispatch, RuntimeVersionOf, WasmExecutor, DEFAULT_HEAP_ALLOC_PAGES,
NativeExecutionDispatch, RuntimeVersionOf, WasmExecutor, DEFAULT_HEAP_ALLOC_STRATEGY,
};
use sc_keystore::LocalKeystore;
use sc_network::{config::SyncMode, NetworkService, NetworkStateInfo, NetworkStatusProvider};
Expand Down Expand Up @@ -239,9 +239,9 @@ pub fn new_native_executor<D: NativeExecutionDispatch>(

/// Creates a [`WasmExecutor`] according to [`Configuration`].
pub fn new_wasm_executor<H: HostFunctions>(config: &Configuration) -> WasmExecutor<H> {
let extra_pages =
config.default_heap_pages.map(|p| p as u32).unwrap_or(DEFAULT_HEAP_ALLOC_PAGES);
let strategy = HeapAllocStrategy::Static { extra_pages };
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)
Expand Down
4 changes: 1 addition & 3 deletions client/service/src/client/wasm_override.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,7 @@ pub fn dummy_overrides() -> WasmOverride {
#[cfg(test)]
mod tests {
use super::*;
use sc_executor::{
HeapAllocStrategy, NativeElseWasmExecutor, WasmExecutor,
};
use sc_executor::{HeapAllocStrategy, NativeElseWasmExecutor, WasmExecutor};
use std::fs::{self, File};
use substrate_test_runtime_client::LocalExecutorDispatch;

Expand Down
2 changes: 1 addition & 1 deletion primitives/runtime-interface/test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ fn call_wasm_method_with_result<HF: HostFunctionsT>(

let executor = sc_executor::WasmExecutor::<
ExtendedHostFunctions<sp_io::SubstrateHostFunctions, HF>,
>::builder(sc_executor::WasmExecutionMethod::Interpreted)
>::builder()
.build();

let (result, allocation_stats) = executor.uncached_call_with_allocation_stats(
Expand Down
2 changes: 1 addition & 1 deletion test-utils/runtime/src/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ mod tests {
use super::*;

use crate::{wasm_binary_unwrap, Header, Transfer};
use sc_executor::{NativeElseWasmExecutor, WasmExecutionMethod, WasmExecutor};
use sc_executor::{NativeElseWasmExecutor, WasmExecutor};
use sp_core::{
map,
traits::{CallContext, CodeExecutor, RuntimeCode},
Expand Down
25 changes: 13 additions & 12 deletions utils/frame/try-runtime/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ use sc_cli::{
DEFAULT_WASM_EXECUTION_METHOD,
};
use sc_executor::{
sp_wasm_interface::HostFunctions, HeapAllocStrategy, WasmExecutor, DEFAULT_HEAP_ALLOC_PAGES,
sp_wasm_interface::HostFunctions, HeapAllocStrategy, WasmExecutor, DEFAULT_HEAP_ALLOC_STRATEGY,
};
use sp_api::HashT;
use sp_core::{
Expand Down Expand Up @@ -829,17 +829,18 @@ pub(crate) fn full_extensions() -> Extensions {

/// Build wasm executor by default config.
pub(crate) fn build_executor<H: HostFunctions>(shared: &SharedParams) -> WasmExecutor<H> {
let heap_pages = HeapAllocStrategy::Static {
extra_pages: shared.heap_pages.map(|p| p as u32).unwrap_or(DEFAULT_HEAP_ALLOC_PAGES),
};

WasmExecutor::builder(execution_method_from_cli(
shared.wasm_method,
shared.wasmtime_instantiation_strategy,
))
.with_onchain_heap_alloc_strategy(heap_pages)
.with_offchain_heap_alloc_strategy(heap_pages)
.build()
let heap_pages = shared
.heap_pages
.map_or(DEFAULT_HEAP_ALLOC_STRATEGY, |p| HeapAllocStrategy::Static { extra_pages: p as _ });

WasmExecutor::builder()
.with_execution_method(execution_method_from_cli(
shared.wasm_method,
shared.wasmtime_instantiation_strategy,
))
.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`
Expand Down