mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 11:38:01 +00:00
This reverts commit 6ee39261c8.
This commit is contained in:
@@ -110,12 +110,8 @@ pub trait RuntimeInfo {
|
||||
/// Native runtime information.
|
||||
fn native_version(&self) -> &NativeVersion;
|
||||
|
||||
/// Extract [`RuntimeVersion`](sp_version::RuntimeVersion) of the given `runtime_code`.
|
||||
fn runtime_version<E: Externalities>(
|
||||
&self,
|
||||
ext: &mut E,
|
||||
runtime_code: &sp_core::traits::RuntimeCode,
|
||||
) -> error::Result<RuntimeVersion>;
|
||||
/// Extract RuntimeVersion of given :code block
|
||||
fn runtime_version<E: Externalities> (&self, ext: &mut E) -> error::Result<RuntimeVersion>;
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -20,7 +20,7 @@ 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}};
|
||||
use log::trace;
|
||||
use std::{result, cell::RefCell, panic::{UnwindSafe, AssertUnwindSafe}, sync::Arc};
|
||||
use sp_wasm_interface::{HostFunctions, Function};
|
||||
@@ -130,7 +130,6 @@ impl<D: NativeExecutionDispatch> NativeExecutor<D> {
|
||||
fn with_runtime<E, R>(
|
||||
&self,
|
||||
ext: &mut E,
|
||||
runtime_code: &RuntimeCode,
|
||||
f: impl for<'a> FnOnce(
|
||||
AssertUnwindSafe<&'a mut (dyn WasmRuntime + 'static)>,
|
||||
&'a RuntimeVersion,
|
||||
@@ -139,9 +138,8 @@ impl<D: NativeExecutionDispatch> NativeExecutor<D> {
|
||||
) -> Result<R> where E: Externalities {
|
||||
RUNTIMES_CACHE.with(|cache| {
|
||||
let mut cache = cache.borrow_mut();
|
||||
let (runtime, version) = cache.fetch_runtime(
|
||||
let (runtime, version, code_hash) = cache.fetch_runtime(
|
||||
ext,
|
||||
runtime_code,
|
||||
self.fallback_method,
|
||||
self.default_heap_pages,
|
||||
&*self.host_functions,
|
||||
@@ -153,7 +151,7 @@ impl<D: NativeExecutionDispatch> NativeExecutor<D> {
|
||||
match f(runtime, version, ext) {
|
||||
Ok(res) => res,
|
||||
Err(e) => {
|
||||
cache.invalidate_runtime(self.fallback_method, runtime_code.hash.clone());
|
||||
cache.invalidate_runtime(self.fallback_method, code_hash);
|
||||
Err(e)
|
||||
}
|
||||
}
|
||||
@@ -181,9 +179,8 @@ impl<D: NativeExecutionDispatch> RuntimeInfo for NativeExecutor<D> {
|
||||
fn runtime_version<E: Externalities>(
|
||||
&self,
|
||||
ext: &mut E,
|
||||
runtime_code: &RuntimeCode,
|
||||
) -> Result<RuntimeVersion> {
|
||||
self.with_runtime(ext, runtime_code, |_runtime, version, _ext| Ok(Ok(version.clone())))
|
||||
self.with_runtime(ext, |_runtime, version, _ext| Ok(Ok(version.clone())))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -198,14 +195,13 @@ impl<D: NativeExecutionDispatch + 'static> CodeExecutor for NativeExecutor<D> {
|
||||
>(
|
||||
&self,
|
||||
ext: &mut E,
|
||||
runtime_code: &RuntimeCode,
|
||||
method: &str,
|
||||
data: &[u8],
|
||||
use_native: bool,
|
||||
native_call: Option<NC>,
|
||||
) -> (Result<NativeOrEncoded<R>>, bool) {
|
||||
) -> (Result<NativeOrEncoded<R>>, bool){
|
||||
let mut used_native = false;
|
||||
let result = self.with_runtime(ext, runtime_code, |mut runtime, onchain_version, mut ext| {
|
||||
let result = self.with_runtime(ext, |mut runtime, onchain_version, mut ext| {
|
||||
match (
|
||||
use_native,
|
||||
onchain_version.can_call_with(&self.native_version.runtime_version),
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
use crate::error::{Error, WasmError};
|
||||
use log::{trace, warn};
|
||||
use codec::Decode;
|
||||
use sp_core::traits::{Externalities, RuntimeCode};
|
||||
use sp_core::{storage::well_known_keys, traits::Externalities};
|
||||
use sp_version::RuntimeVersion;
|
||||
use std::{collections::hash_map::{Entry, HashMap}, panic::AssertUnwindSafe};
|
||||
use sc_executor_common::wasm_runtime::WasmRuntime;
|
||||
@@ -86,9 +86,8 @@ impl RuntimesCache {
|
||||
///
|
||||
/// # Parameters
|
||||
///
|
||||
/// `ext` - Externalities to use for the getting the runtime's version call.
|
||||
///
|
||||
/// `runtime_code` - The runtime wasm code used setup the runtime.
|
||||
/// `ext` - Externalities to use for the runtime. This is used for setting
|
||||
/// up an initial runtime instance.
|
||||
///
|
||||
/// `default_heap_pages` - Number of 64KB pages to allocate for Wasm execution.
|
||||
///
|
||||
@@ -96,8 +95,8 @@ impl RuntimesCache {
|
||||
///
|
||||
/// # Return value
|
||||
///
|
||||
/// If no error occurred a tuple `(&mut WasmRuntime, RuntimeVerion)` is
|
||||
/// returned.
|
||||
/// If no error occurred a tuple `(&mut WasmRuntime, H256)` is
|
||||
/// returned. `H256` is the hash of the runtime code.
|
||||
///
|
||||
/// In case of failure one of two errors can be returned:
|
||||
///
|
||||
@@ -108,14 +107,20 @@ impl RuntimesCache {
|
||||
pub fn fetch_runtime<E: Externalities>(
|
||||
&mut self,
|
||||
ext: &mut E,
|
||||
runtime_code: &RuntimeCode,
|
||||
wasm_method: WasmExecutionMethod,
|
||||
default_heap_pages: u64,
|
||||
host_functions: &[&'static dyn Function],
|
||||
) -> Result<(&mut (dyn WasmRuntime + 'static), &RuntimeVersion), Error> {
|
||||
let heap_pages = runtime_code.heap_pages.unwrap_or(default_heap_pages);
|
||||
) -> Result<(&mut (dyn WasmRuntime + 'static), &RuntimeVersion, Vec<u8>), Error> {
|
||||
let code_hash = ext
|
||||
.original_storage_hash(well_known_keys::CODE)
|
||||
.ok_or(Error::InvalidCode("`CODE` not found in storage.".into()))?;
|
||||
|
||||
let result = match self.instances.entry((wasm_method, runtime_code.hash.clone())) {
|
||||
let heap_pages = ext
|
||||
.storage(well_known_keys::HEAP_PAGES)
|
||||
.and_then(|pages| u64::decode(&mut &pages[..]).ok())
|
||||
.unwrap_or(default_heap_pages);
|
||||
|
||||
let result = match self.instances.entry((wasm_method, code_hash.clone())) {
|
||||
Entry::Occupied(o) => {
|
||||
let result = o.into_mut();
|
||||
if let Ok(ref mut cached_runtime) = result {
|
||||
@@ -137,7 +142,6 @@ impl RuntimesCache {
|
||||
*result = create_versioned_wasm_runtime(
|
||||
ext,
|
||||
wasm_method,
|
||||
runtime_code,
|
||||
heap_pages,
|
||||
host_functions.into(),
|
||||
);
|
||||
@@ -153,7 +157,6 @@ impl RuntimesCache {
|
||||
let result = create_versioned_wasm_runtime(
|
||||
ext,
|
||||
wasm_method,
|
||||
runtime_code,
|
||||
heap_pages,
|
||||
host_functions.into(),
|
||||
);
|
||||
@@ -165,7 +168,7 @@ impl RuntimesCache {
|
||||
};
|
||||
|
||||
result.as_mut()
|
||||
.map(|entry| (entry.runtime.as_mut(), &entry.version))
|
||||
.map(|entry| (entry.runtime.as_mut(), &entry.version, code_hash))
|
||||
.map_err(|ref e| Error::InvalidCode(format!("{:?}", e)))
|
||||
}
|
||||
|
||||
@@ -206,17 +209,13 @@ pub fn create_wasm_runtime_with_code(
|
||||
fn create_versioned_wasm_runtime<E: Externalities>(
|
||||
ext: &mut E,
|
||||
wasm_method: WasmExecutionMethod,
|
||||
runtime_code: &RuntimeCode,
|
||||
heap_pages: u64,
|
||||
host_functions: Vec<&'static dyn Function>,
|
||||
) -> Result<VersionedRuntime, WasmError> {
|
||||
let mut runtime = create_wasm_runtime_with_code(
|
||||
wasm_method,
|
||||
heap_pages,
|
||||
&runtime_code.code,
|
||||
host_functions,
|
||||
false,
|
||||
)?;
|
||||
let code = ext
|
||||
.original_storage(well_known_keys::CODE)
|
||||
.ok_or(WasmError::CodeNotFound)?;
|
||||
let mut runtime = create_wasm_runtime_with_code(wasm_method, heap_pages, &code, host_functions, false)?;
|
||||
|
||||
// Call to determine runtime version.
|
||||
let version_result = {
|
||||
|
||||
Reference in New Issue
Block a user