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:
yjh
2023-04-10 07:48:40 +08:00
committed by GitHub
parent f4d079a723
commit d5e460b3bf
29 changed files with 212 additions and 209 deletions
@@ -45,6 +45,7 @@ use sp_trie::{LayoutV0, TrieConfiguration};
use std::{collections::HashSet, sync::Arc};
use substrate_test_runtime::TestAPI;
use substrate_test_runtime_client::{
new_native_or_wasm_executor,
prelude::*,
runtime::{
genesismap::{insert_genesis_block, GenesisConfig},
@@ -58,29 +59,6 @@ mod db;
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(
backend: &InMemoryBackend<BlakeTwo256>,
number: BlockNumber,
@@ -108,7 +86,7 @@ fn construct_block(
StateMachine::new(
backend,
&mut overlay,
&executor(),
&new_native_or_wasm_executor(),
"Core_initialize_block",
&header.encode(),
Default::default(),
@@ -122,7 +100,7 @@ fn construct_block(
StateMachine::new(
backend,
&mut overlay,
&executor(),
&new_native_or_wasm_executor(),
"BlockBuilder_apply_extrinsic",
&tx.encode(),
Default::default(),
@@ -136,7 +114,7 @@ fn construct_block(
let ret_data = StateMachine::new(
backend,
&mut overlay,
&executor(),
&new_native_or_wasm_executor(),
"BlockBuilder_finalize_block",
&[],
Default::default(),
@@ -208,7 +186,7 @@ fn construct_genesis_should_work_with_native() {
let _ = StateMachine::new(
&backend,
&mut overlay,
&executor(),
&new_native_or_wasm_executor(),
"Core_execute_block",
&b1data,
Default::default(),
@@ -241,7 +219,7 @@ fn construct_genesis_should_work_with_wasm() {
let _ = StateMachine::new(
&backend,
&mut overlay,
&executor(),
&new_native_or_wasm_executor(),
"Core_execute_block",
&b1data,
Default::default(),
@@ -274,7 +252,7 @@ fn construct_genesis_with_bad_transaction_should_panic() {
let r = StateMachine::new(
&backend,
&mut overlay,
&executor(),
&new_native_or_wasm_executor(),
"Core_execute_block",
&b1data,
Default::default(),
@@ -1910,7 +1888,7 @@ fn cleans_up_closed_notification_sinks_on_block_import() {
use substrate_test_runtime_client::GenesisInit;
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 genesis_block_builder = sc_service::GenesisBlockBuilder::new(