mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 11:07:56 +00:00
Allow missing functions when checking the new runtime's version (#5741)
This commit is contained in:
@@ -45,7 +45,6 @@ fn call_in_wasm<E: Externalities>(
|
||||
execution_method,
|
||||
Some(1024),
|
||||
HostFunctions::host_functions(),
|
||||
true,
|
||||
8,
|
||||
);
|
||||
executor.call_in_wasm(
|
||||
@@ -54,6 +53,7 @@ fn call_in_wasm<E: Externalities>(
|
||||
function,
|
||||
call_data,
|
||||
ext,
|
||||
sp_core::traits::MissingHostFunctions::Allow,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -511,7 +511,6 @@ fn should_trap_when_heap_exhausted(wasm_method: WasmExecutionMethod) {
|
||||
wasm_method,
|
||||
Some(17), // `17` is the initial number of pages compiled into the binary.
|
||||
HostFunctions::host_functions(),
|
||||
true,
|
||||
8,
|
||||
);
|
||||
executor.call_in_wasm(
|
||||
@@ -520,6 +519,7 @@ fn should_trap_when_heap_exhausted(wasm_method: WasmExecutionMethod) {
|
||||
"test_exhaust_heap",
|
||||
&[0],
|
||||
&mut ext.ext(),
|
||||
sp_core::traits::MissingHostFunctions::Allow,
|
||||
).unwrap();
|
||||
}
|
||||
|
||||
|
||||
@@ -77,7 +77,6 @@ mod tests {
|
||||
WasmExecutionMethod::Interpreted,
|
||||
Some(8),
|
||||
sp_io::SubstrateHostFunctions::host_functions(),
|
||||
true,
|
||||
8,
|
||||
);
|
||||
let res = executor.call_in_wasm(
|
||||
@@ -86,6 +85,7 @@ mod tests {
|
||||
"test_empty_return",
|
||||
&[],
|
||||
&mut ext,
|
||||
sp_core::traits::MissingHostFunctions::Allow,
|
||||
).unwrap();
|
||||
assert_eq!(res, vec![0u8; 0]);
|
||||
}
|
||||
|
||||
@@ -20,7 +20,9 @@ use crate::{
|
||||
};
|
||||
use sp_version::{NativeVersion, RuntimeVersion};
|
||||
use codec::{Decode, Encode};
|
||||
use sp_core::{NativeOrEncoded, traits::{CodeExecutor, Externalities, RuntimeCode}};
|
||||
use sp_core::{
|
||||
NativeOrEncoded, traits::{CodeExecutor, Externalities, RuntimeCode, MissingHostFunctions},
|
||||
};
|
||||
use log::trace;
|
||||
use std::{result, panic::{UnwindSafe, AssertUnwindSafe}, sync::Arc};
|
||||
use sp_wasm_interface::{HostFunctions, Function};
|
||||
@@ -83,8 +85,6 @@ pub struct WasmExecutor {
|
||||
host_functions: Arc<Vec<&'static dyn Function>>,
|
||||
/// WASM runtime cache.
|
||||
cache: Arc<RuntimeCache>,
|
||||
/// Allow missing function imports.
|
||||
allow_missing_func_imports: bool,
|
||||
/// The size of the instances cache.
|
||||
max_runtime_instances: usize,
|
||||
}
|
||||
@@ -102,7 +102,6 @@ impl WasmExecutor {
|
||||
method: WasmExecutionMethod,
|
||||
default_heap_pages: Option<u64>,
|
||||
host_functions: Vec<&'static dyn Function>,
|
||||
allow_missing_func_imports: bool,
|
||||
max_runtime_instances: usize,
|
||||
) -> Self {
|
||||
WasmExecutor {
|
||||
@@ -110,7 +109,6 @@ impl WasmExecutor {
|
||||
default_heap_pages: default_heap_pages.unwrap_or(DEFAULT_HEAP_PAGES),
|
||||
host_functions: Arc::new(host_functions),
|
||||
cache: Arc::new(RuntimeCache::new(max_runtime_instances)),
|
||||
allow_missing_func_imports,
|
||||
max_runtime_instances,
|
||||
}
|
||||
}
|
||||
@@ -132,6 +130,7 @@ impl WasmExecutor {
|
||||
&self,
|
||||
runtime_code: &RuntimeCode,
|
||||
ext: &mut dyn Externalities,
|
||||
allow_missing_host_functions: bool,
|
||||
f: F,
|
||||
) -> Result<R>
|
||||
where F: FnOnce(
|
||||
@@ -146,7 +145,7 @@ impl WasmExecutor {
|
||||
self.method,
|
||||
self.default_heap_pages,
|
||||
&*self.host_functions,
|
||||
self.allow_missing_func_imports,
|
||||
allow_missing_host_functions,
|
||||
|instance, version, ext| {
|
||||
let instance = AssertUnwindSafe(instance);
|
||||
let ext = AssertUnwindSafe(ext);
|
||||
@@ -167,7 +166,10 @@ impl sp_core::traits::CallInWasm for WasmExecutor {
|
||||
method: &str,
|
||||
call_data: &[u8],
|
||||
ext: &mut dyn Externalities,
|
||||
missing_host_functions: MissingHostFunctions,
|
||||
) -> std::result::Result<Vec<u8>, String> {
|
||||
let allow_missing_host_functions = missing_host_functions.allowed();
|
||||
|
||||
if let Some(hash) = code_hash {
|
||||
let code = RuntimeCode {
|
||||
code_fetcher: &sp_core::traits::WrappedRuntimeCode(wasm_code.into()),
|
||||
@@ -175,7 +177,7 @@ impl sp_core::traits::CallInWasm for WasmExecutor {
|
||||
heap_pages: None,
|
||||
};
|
||||
|
||||
self.with_instance(&code, ext, |instance, _, mut ext| {
|
||||
self.with_instance(&code, ext, allow_missing_host_functions, |instance, _, mut ext| {
|
||||
with_externalities_safe(
|
||||
&mut **ext,
|
||||
move || instance.call(method, call_data),
|
||||
@@ -187,7 +189,7 @@ impl sp_core::traits::CallInWasm for WasmExecutor {
|
||||
self.default_heap_pages,
|
||||
&wasm_code,
|
||||
self.host_functions.to_vec(),
|
||||
self.allow_missing_func_imports,
|
||||
allow_missing_host_functions,
|
||||
)
|
||||
.map_err(|e| format!("Failed to create module: {:?}", e))?;
|
||||
|
||||
@@ -240,7 +242,6 @@ impl<D: NativeExecutionDispatch> NativeExecutor<D> {
|
||||
fallback_method,
|
||||
default_heap_pages,
|
||||
host_functions,
|
||||
false,
|
||||
max_runtime_instances,
|
||||
);
|
||||
|
||||
@@ -265,8 +266,9 @@ impl<D: NativeExecutionDispatch> RuntimeInfo for NativeExecutor<D> {
|
||||
self.wasm.with_instance(
|
||||
runtime_code,
|
||||
ext,
|
||||
false,
|
||||
|_instance, version, _ext|
|
||||
Ok(version.cloned().ok_or_else(|| Error::ApiError("Unknown version".into())))
|
||||
Ok(version.cloned().ok_or_else(|| Error::ApiError("Unknown version".into()))),
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -290,6 +292,7 @@ impl<D: NativeExecutionDispatch + 'static> CodeExecutor for NativeExecutor<D> {
|
||||
let result = self.wasm.with_instance(
|
||||
runtime_code,
|
||||
ext,
|
||||
false,
|
||||
|instance, onchain_version, mut ext| {
|
||||
let onchain_version = onchain_version.ok_or_else(
|
||||
|| Error::ApiError("Unknown version".into())
|
||||
@@ -372,8 +375,9 @@ impl<D: NativeExecutionDispatch> sp_core::traits::CallInWasm for NativeExecutor<
|
||||
method: &str,
|
||||
call_data: &[u8],
|
||||
ext: &mut dyn Externalities,
|
||||
missing_host_functions: MissingHostFunctions,
|
||||
) -> std::result::Result<Vec<u8>, String> {
|
||||
self.wasm.call_in_wasm(wasm_blob, code_hash, method, call_data, ext)
|
||||
self.wasm.call_in_wasm(wasm_blob, code_hash, method, call_data, ext, missing_host_functions)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user