mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 20:27:58 +00:00
Prevent double allocation of the payload when calling sp_io::storage::get (#11523)
* Expose allocation stats in `FreeingBumpHeapAllocator` * Return allocation stats when calling into the runtime * Bump `parity-scale-codec` to 3.1.3 (fork) * Prevent double allocation of the payload when calling `sp_io::storage::get` * Fix tests * Remove unnecessary `mut` * Enable the `bytes` feature for `parity-scale-codec` in `sp-runtime-interface` * Update client/allocator/src/freeing_bump.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Bump `parity-scale-codec` to 3.1.3 * Fix some of the UI tests Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
@@ -37,7 +37,7 @@ use std::{
|
||||
use codec::{Decode, Encode};
|
||||
use sc_executor_common::{
|
||||
runtime_blob::RuntimeBlob,
|
||||
wasm_runtime::{InvokeMethod, WasmInstance, WasmModule},
|
||||
wasm_runtime::{AllocationStats, InvokeMethod, WasmInstance, WasmModule},
|
||||
};
|
||||
use sp_core::{
|
||||
traits::{CodeExecutor, Externalities, RuntimeCode, RuntimeSpawn, RuntimeSpawnExt},
|
||||
@@ -219,6 +219,47 @@ where
|
||||
allow_missing_host_functions: bool,
|
||||
export_name: &str,
|
||||
call_data: &[u8],
|
||||
) -> std::result::Result<Vec<u8>, Error> {
|
||||
self.uncached_call_impl(
|
||||
runtime_blob,
|
||||
ext,
|
||||
allow_missing_host_functions,
|
||||
export_name,
|
||||
call_data,
|
||||
&mut None,
|
||||
)
|
||||
}
|
||||
|
||||
/// Same as `uncached_call`, except it also returns allocation statistics.
|
||||
#[doc(hidden)] // We use this function in tests.
|
||||
pub fn uncached_call_with_allocation_stats(
|
||||
&self,
|
||||
runtime_blob: RuntimeBlob,
|
||||
ext: &mut dyn Externalities,
|
||||
allow_missing_host_functions: bool,
|
||||
export_name: &str,
|
||||
call_data: &[u8],
|
||||
) -> (std::result::Result<Vec<u8>, Error>, Option<AllocationStats>) {
|
||||
let mut allocation_stats = None;
|
||||
let result = self.uncached_call_impl(
|
||||
runtime_blob,
|
||||
ext,
|
||||
allow_missing_host_functions,
|
||||
export_name,
|
||||
call_data,
|
||||
&mut allocation_stats,
|
||||
);
|
||||
(result, allocation_stats)
|
||||
}
|
||||
|
||||
fn uncached_call_impl(
|
||||
&self,
|
||||
runtime_blob: RuntimeBlob,
|
||||
ext: &mut dyn Externalities,
|
||||
allow_missing_host_functions: bool,
|
||||
export_name: &str,
|
||||
call_data: &[u8],
|
||||
allocation_stats_out: &mut Option<AllocationStats>,
|
||||
) -> std::result::Result<Vec<u8>, Error> {
|
||||
let module = crate::wasm_runtime::create_wasm_runtime_with_code::<H>(
|
||||
self.method,
|
||||
@@ -235,10 +276,14 @@ where
|
||||
let mut instance = AssertUnwindSafe(instance);
|
||||
let mut ext = AssertUnwindSafe(ext);
|
||||
let module = AssertUnwindSafe(module);
|
||||
let mut allocation_stats_out = AssertUnwindSafe(allocation_stats_out);
|
||||
|
||||
with_externalities_safe(&mut **ext, move || {
|
||||
preregister_builtin_ext(module.clone());
|
||||
instance.call_export(export_name, call_data)
|
||||
let (result, allocation_stats) =
|
||||
instance.call_with_allocation_stats(export_name.into(), call_data);
|
||||
**allocation_stats_out = allocation_stats;
|
||||
result
|
||||
})
|
||||
.and_then(|r| r)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user