mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 00:01:09 +00:00
Allow missing functions when checking the new runtime's version (#5741)
This commit is contained in:
@@ -262,6 +262,23 @@ impl std::fmt::Display for CodeNotFound {
|
||||
}
|
||||
}
|
||||
|
||||
/// `Allow` or `Disallow` missing host functions when instantiating a WASM blob.
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub enum MissingHostFunctions {
|
||||
/// Any missing host function will be replaced by a stub that returns an error when
|
||||
/// being called.
|
||||
Allow,
|
||||
/// Any missing host function will result in an error while instantiating the WASM blob,
|
||||
Disallow,
|
||||
}
|
||||
|
||||
impl MissingHostFunctions {
|
||||
/// Are missing host functions allowed?
|
||||
pub fn allowed(self) -> bool {
|
||||
matches!(self, Self::Allow)
|
||||
}
|
||||
}
|
||||
|
||||
/// Something that can call a method in a WASM blob.
|
||||
pub trait CallInWasm: Send + Sync {
|
||||
/// Call the given `method` in the given `wasm_blob` using `call_data` (SCALE encoded arguments)
|
||||
@@ -280,6 +297,7 @@ pub trait CallInWasm: Send + Sync {
|
||||
method: &str,
|
||||
call_data: &[u8],
|
||||
ext: &mut dyn Externalities,
|
||||
missing_host_functions: MissingHostFunctions,
|
||||
) -> Result<Vec<u8>, String>;
|
||||
}
|
||||
|
||||
|
||||
@@ -329,7 +329,18 @@ pub trait Misc {
|
||||
|
||||
self.extension::<CallInWasmExt>()
|
||||
.expect("No `CallInWasmExt` associated for the current context!")
|
||||
.call_in_wasm(wasm, None, "Core_version", &[], &mut ext)
|
||||
.call_in_wasm(
|
||||
wasm,
|
||||
None,
|
||||
"Core_version",
|
||||
&[],
|
||||
&mut ext,
|
||||
// If a runtime upgrade introduces new host functions that are not provided by
|
||||
// the node, we should not fail at instantiation. Otherwise nodes that are
|
||||
// updated could run this successfully and it could lead to a storage root
|
||||
// mismatch when importing this block.
|
||||
sp_core::traits::MissingHostFunctions::Allow,
|
||||
)
|
||||
.ok()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,5 +18,6 @@ sp-runtime-interface-test-wasm = { version = "2.0.0-dev", path = "../test-wasm"
|
||||
sp-runtime-interface-test-wasm-deprecated = { version = "2.0.0-dev", path = "../test-wasm-deprecated" }
|
||||
sp-state-machine = { version = "0.8.0-dev", path = "../../../primitives/state-machine" }
|
||||
sp-runtime = { version = "2.0.0-dev", path = "../../runtime" }
|
||||
sp-core = { version = "2.0.0-dev", path = "../../core" }
|
||||
sp-io = { version = "2.0.0-dev", path = "../../io" }
|
||||
tracing = "0.1.13"
|
||||
|
||||
@@ -41,7 +41,6 @@ fn call_wasm_method<HF: HostFunctionsT>(binary: &[u8], method: &str) -> TestExte
|
||||
sc_executor::WasmExecutionMethod::Interpreted,
|
||||
Some(8),
|
||||
host_functions,
|
||||
false,
|
||||
8,
|
||||
);
|
||||
executor.call_in_wasm(
|
||||
@@ -50,6 +49,7 @@ fn call_wasm_method<HF: HostFunctionsT>(binary: &[u8], method: &str) -> TestExte
|
||||
method,
|
||||
&[],
|
||||
&mut ext_ext,
|
||||
sp_core::traits::MissingHostFunctions::Disallow,
|
||||
).expect(&format!("Executes `{}`", method));
|
||||
|
||||
ext
|
||||
|
||||
@@ -811,6 +811,7 @@ mod tests {
|
||||
_: &str,
|
||||
_: &[u8],
|
||||
_: &mut dyn Externalities,
|
||||
_: sp_core::traits::MissingHostFunctions,
|
||||
) -> std::result::Result<Vec<u8>, String> {
|
||||
unimplemented!("Not required in tests.")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user