diff --git a/cumulus/parachains/runtimes/contracts/contracts-rococo/src/contracts.rs b/cumulus/parachains/runtimes/contracts/contracts-rococo/src/contracts.rs index fcd786711bbe..e8cc9d02fb0e 100644 --- a/cumulus/parachains/runtimes/contracts/contracts-rococo/src/contracts.rs +++ b/cumulus/parachains/runtimes/contracts/contracts-rococo/src/contracts.rs @@ -65,6 +65,7 @@ impl Config for Runtime { type AddressGenerator = DefaultAddressGenerator; type MaxCodeLen = ConstU32<{ 123 * 1024 }>; type MaxStorageKeyLen = ConstU32<128>; + type MaxTransientStorageSize = ConstU32<{ 1 * 1024 * 1024 }>; type UnsafeUnstableInterface = ConstBool; type UploadOrigin = EnsureSigned; type InstantiateOrigin = EnsureSigned; diff --git a/prdoc/pr_4566.prdoc b/prdoc/pr_4566.prdoc new file mode 100644 index 000000000000..ea2979bb363a --- /dev/null +++ b/prdoc/pr_4566.prdoc @@ -0,0 +1,23 @@ +# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0 +# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json + +title: "[pallet_contracts] Add support for transient storage in contracts host functions" + +doc: + - audience: Runtime User + description: | + This PR implements transient storage, which behaves identically to regular storage + but is kept only in memory and discarded after every transaction. + This functionality is similar to the `TSTORE` and `TLOAD` operations used in Ethereum. + The following new host functions have been introduced: `get_transient_storage`, + `set_transient_storage`, `take_transient_storage`, `clear_transient_storage` and + `contains_transient_storage`. + These functions are declared as unstable and thus are not activated. + +crates: + - name: pallet-contracts + bump: major + - name: pallet-contracts-uapi + bump: major + - name: contracts-rococo-runtime + bump: minor diff --git a/substrate/bin/node/runtime/src/lib.rs b/substrate/bin/node/runtime/src/lib.rs index 2d1f52066f8f..a1896325ee93 100644 --- a/substrate/bin/node/runtime/src/lib.rs +++ b/substrate/bin/node/runtime/src/lib.rs @@ -1373,6 +1373,7 @@ impl pallet_contracts::Config for Runtime { type UploadOrigin = EnsureSigned; type InstantiateOrigin = EnsureSigned; type MaxDebugBufferLen = ConstU32<{ 2 * 1024 * 1024 }>; + type MaxTransientStorageSize = ConstU32<{ 1 * 1024 * 1024 }>; type RuntimeHoldReason = RuntimeHoldReason; #[cfg(not(feature = "runtime-benchmarks"))] type Migrations = (); diff --git a/substrate/frame/contracts/fixtures/contracts/create_transient_storage_and_call.rs b/substrate/frame/contracts/fixtures/contracts/create_transient_storage_and_call.rs new file mode 100644 index 000000000000..6bafee555771 --- /dev/null +++ b/substrate/frame/contracts/fixtures/contracts/create_transient_storage_and_call.rs @@ -0,0 +1,56 @@ +// This file is part of Substrate. + +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//! This calls another contract as passed as its account id. It also creates some transient storage. +#![no_std] +#![no_main] + +use common::input; +use uapi::{HostFn, HostFnImpl as api}; + +#[no_mangle] +#[polkavm_derive::polkavm_export] +pub extern "C" fn deploy() {} + +#[no_mangle] +#[polkavm_derive::polkavm_export] +pub extern "C" fn call() { + input!( + buffer, + len: u32, + input: [u8; 4], + callee: [u8; 32], + ); + + let data = [0u8; 16 * 1024]; + let value = &data[..len as usize]; + #[allow(deprecated)] + api::set_transient_storage(buffer, value); + + // Call the callee + api::call_v2( + uapi::CallFlags::empty(), + callee, + 0u64, // How much ref_time weight to devote for the execution. 0 = all. + 0u64, // How much proof_size weight to devote for the execution. 0 = all. + None, + &0u64.to_le_bytes(), // Value transferred to the contract. + input, + None, + ) + .unwrap(); +} diff --git a/substrate/frame/contracts/fixtures/contracts/set_transient_storage.rs b/substrate/frame/contracts/fixtures/contracts/set_transient_storage.rs new file mode 100644 index 000000000000..e4fde08314ce --- /dev/null +++ b/substrate/frame/contracts/fixtures/contracts/set_transient_storage.rs @@ -0,0 +1,42 @@ +// This file is part of Substrate. + +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#![no_std] +#![no_main] + +use common::input; +use uapi::{HostFn, HostFnImpl as api}; + +#[no_mangle] +#[polkavm_derive::polkavm_export] +pub extern "C" fn deploy() {} + +#[no_mangle] +#[polkavm_derive::polkavm_export] +pub extern "C" fn call() { + input!(len: u32, ); + + let buffer = [0u8; 16 * 1024]; + let data = &buffer[..len as usize]; + + // Place a garbage value in the transient storage, with the size specified by the call input. + let mut key = [0u8; 32]; + key[0] = 1; + + #[allow(deprecated)] + api::set_transient_storage(&key, data); +} diff --git a/substrate/frame/contracts/fixtures/contracts/transient_storage.rs b/substrate/frame/contracts/fixtures/contracts/transient_storage.rs new file mode 100644 index 000000000000..c797e17887bc --- /dev/null +++ b/substrate/frame/contracts/fixtures/contracts/transient_storage.rs @@ -0,0 +1,58 @@ +// This file is part of Substrate. + +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//! This contract tests the transient storage APIs. +#![no_std] +#![no_main] + +use common::unwrap_output; +use uapi::{HostFn, HostFnImpl as api}; + +#[no_mangle] +#[polkavm_derive::polkavm_export] +pub extern "C" fn deploy() {} + +#[no_mangle] +#[polkavm_derive::polkavm_export] +pub extern "C" fn call() { + const KEY: [u8; 32] = [1u8; 32]; + const VALUE_1: [u8; 4] = [1u8; 4]; + const VALUE_2: [u8; 4] = [2u8; 4]; + const VALUE_3: [u8; 4] = [3u8; 4]; + + #[allow(deprecated)] + { + let existing = api::set_transient_storage(&KEY, &VALUE_1); + assert_eq!(existing, None); + assert_eq!(api::contains_transient_storage(&KEY), Some(VALUE_1.len() as _)); + unwrap_output!(val, [0u8; 4], api::get_transient_storage, &KEY); + assert_eq!(**val, VALUE_1); + + let existing = api::set_transient_storage(&KEY, &VALUE_2); + assert_eq!(existing, Some(VALUE_1.len() as _)); + unwrap_output!(val, [0u8; 4], api::get_transient_storage, &KEY); + assert_eq!(**val, VALUE_2); + + api::clear_transient_storage(&KEY); + assert_eq!(api::contains_transient_storage(&KEY), None); + + let existing = api::set_transient_storage(&KEY, &VALUE_3); + assert_eq!(existing, None); + unwrap_output!(val, [0u8; 32], api::take_transient_storage, &KEY); + assert_eq!(**val, VALUE_3); + } +} diff --git a/substrate/frame/contracts/src/benchmarking/call_builder.rs b/substrate/frame/contracts/src/benchmarking/call_builder.rs index d87eaba73437..5833639d7ce2 100644 --- a/substrate/frame/contracts/src/benchmarking/call_builder.rs +++ b/substrate/frame/contracts/src/benchmarking/call_builder.rs @@ -17,11 +17,12 @@ use crate::{ benchmarking::{Contract, WasmModule}, - exec::Stack, + exec::{Ext, Key, Stack}, storage::meter::Meter, + transient_storage::MeterEntry, wasm::Runtime, - BalanceOf, Config, DebugBufferVec, Determinism, ExecReturnValue, GasMeter, Origin, Schedule, - TypeInfo, WasmBlob, Weight, + BalanceOf, Config, DebugBufferVec, Determinism, Error, ExecReturnValue, GasMeter, Origin, + Schedule, TypeInfo, WasmBlob, Weight, }; use alloc::{vec, vec::Vec}; use codec::{Encode, HasCompact}; @@ -56,6 +57,7 @@ pub struct CallSetup { debug_message: Option>, determinism: Determinism, data: Vec, + transient_storage_size: u32, } impl Default for CallSetup @@ -103,6 +105,7 @@ where debug_message: None, determinism: Determinism::Enforced, data: vec![], + transient_storage_size: 0, } } @@ -126,6 +129,11 @@ where self.data = value; } + /// Set the transient storage size. + pub fn set_transient_storage_size(&mut self, size: u32) { + self.transient_storage_size = size; + } + /// Set the debug message. pub fn enable_debug_message(&mut self) { self.debug_message = Some(Default::default()); @@ -148,7 +156,7 @@ where /// Build the call stack. pub fn ext(&mut self) -> (StackExt<'_, T>, WasmBlob) { - StackExt::bench_new_call( + let mut ext = StackExt::bench_new_call( self.dest.clone(), self.origin.clone(), &mut self.gas_meter, @@ -157,7 +165,11 @@ where self.value, self.debug_message.as_mut(), self.determinism, - ) + ); + if self.transient_storage_size > 0 { + Self::with_transient_storage(&mut ext.0, self.transient_storage_size).unwrap(); + } + ext } /// Prepare a call to the module. @@ -169,6 +181,30 @@ where let (func, store) = module.bench_prepare_call(ext, input); PreparedCall { func, store } } + + /// Add transient_storage + fn with_transient_storage(ext: &mut StackExt, size: u32) -> Result<(), &'static str> { + let &MeterEntry { amount, limit } = ext.transient_storage().meter().current(); + ext.transient_storage().meter().current_mut().limit = size; + for i in 1u32.. { + let mut key_data = i.to_le_bytes().to_vec(); + while key_data.last() == Some(&0) { + key_data.pop(); + } + let key = Key::::try_from_var(key_data).unwrap(); + if let Err(e) = ext.set_transient_storage(&key, Some(Vec::new()), false) { + // Restore previous settings. + ext.transient_storage().meter().current_mut().limit = limit; + ext.transient_storage().meter().current_mut().amount = amount; + if e == Error::::OutOfTransientStorage.into() { + break; + } else { + return Err("Initialization of the transient storage failed"); + } + } + } + Ok(()) + } } #[macro_export] diff --git a/substrate/frame/contracts/src/benchmarking/mod.rs b/substrate/frame/contracts/src/benchmarking/mod.rs index 612f929e8b19..620e6544b08f 100644 --- a/substrate/frame/contracts/src/benchmarking/mod.rs +++ b/substrate/frame/contracts/src/benchmarking/mod.rs @@ -31,6 +31,7 @@ use crate::{ migration::{ codegen::LATEST_MIGRATION_VERSION, v09, v10, v11, v12, v13, v14, v15, v16, MigrationStep, }, + storage::WriteOutcome, wasm::BenchEnv, Pallet as Contracts, *, }; @@ -1162,6 +1163,296 @@ mod benchmarks { Ok(()) } + // We use both full and empty benchmarks here instead of benchmarking transient_storage + // (BTreeMap) directly. This approach is necessary because benchmarking this BTreeMap is very + // slow. Additionally, we use linear regression for our benchmarks, and the BTreeMap's log(n) + // complexity can introduce approximation errors. + #[benchmark(pov_mode = Ignored)] + fn set_transient_storage_empty() -> Result<(), BenchmarkError> { + let max_value_len = T::Schedule::get().limits.payload_len; + let max_key_len = T::MaxStorageKeyLen::get(); + let key = Key::::try_from_var(vec![0u8; max_key_len as usize]) + .map_err(|_| "Key has wrong length")?; + let value = Some(vec![42u8; max_value_len as _]); + let mut setup = CallSetup::::default(); + let (mut ext, _) = setup.ext(); + let mut runtime = crate::wasm::Runtime::new(&mut ext, vec![]); + runtime.ext().transient_storage().meter().current_mut().limit = u32::MAX; + let result; + #[block] + { + result = runtime.ext().set_transient_storage(&key, value, false); + } + + assert_eq!(result, Ok(WriteOutcome::New)); + assert_eq!(runtime.ext().get_transient_storage(&key), Some(vec![42u8; max_value_len as _])); + Ok(()) + } + + #[benchmark(pov_mode = Ignored)] + fn set_transient_storage_full() -> Result<(), BenchmarkError> { + let max_value_len = T::Schedule::get().limits.payload_len; + let max_key_len = T::MaxStorageKeyLen::get(); + let key = Key::::try_from_var(vec![0u8; max_key_len as usize]) + .map_err(|_| "Key has wrong length")?; + let value = Some(vec![42u8; max_value_len as _]); + let mut setup = CallSetup::::default(); + setup.set_transient_storage_size(T::MaxTransientStorageSize::get()); + let (mut ext, _) = setup.ext(); + let mut runtime = crate::wasm::Runtime::new(&mut ext, vec![]); + runtime.ext().transient_storage().meter().current_mut().limit = u32::MAX; + let result; + #[block] + { + result = runtime.ext().set_transient_storage(&key, value, false); + } + + assert_eq!(result, Ok(WriteOutcome::New)); + assert_eq!(runtime.ext().get_transient_storage(&key), Some(vec![42u8; max_value_len as _])); + Ok(()) + } + + #[benchmark(pov_mode = Ignored)] + fn get_transient_storage_empty() -> Result<(), BenchmarkError> { + let max_value_len = T::Schedule::get().limits.payload_len; + let max_key_len = T::MaxStorageKeyLen::get(); + let key = Key::::try_from_var(vec![0u8; max_key_len as usize]) + .map_err(|_| "Key has wrong length")?; + + let mut setup = CallSetup::::default(); + let (mut ext, _) = setup.ext(); + let mut runtime = crate::wasm::Runtime::new(&mut ext, vec![]); + runtime.ext().transient_storage().meter().current_mut().limit = u32::MAX; + runtime + .ext() + .set_transient_storage(&key, Some(vec![42u8; max_value_len as _]), false) + .map_err(|_| "Failed to write to transient storage during setup.")?; + let result; + #[block] + { + result = runtime.ext().get_transient_storage(&key); + } + + assert_eq!(result, Some(vec![42u8; max_value_len as _])); + Ok(()) + } + + #[benchmark(pov_mode = Ignored)] + fn get_transient_storage_full() -> Result<(), BenchmarkError> { + let max_value_len = T::Schedule::get().limits.payload_len; + let max_key_len = T::MaxStorageKeyLen::get(); + let key = Key::::try_from_var(vec![0u8; max_key_len as usize]) + .map_err(|_| "Key has wrong length")?; + + let mut setup = CallSetup::::default(); + setup.set_transient_storage_size(T::MaxTransientStorageSize::get()); + let (mut ext, _) = setup.ext(); + let mut runtime = crate::wasm::Runtime::new(&mut ext, vec![]); + runtime.ext().transient_storage().meter().current_mut().limit = u32::MAX; + runtime + .ext() + .set_transient_storage(&key, Some(vec![42u8; max_value_len as _]), false) + .map_err(|_| "Failed to write to transient storage during setup.")?; + let result; + #[block] + { + result = runtime.ext().get_transient_storage(&key); + } + + assert_eq!(result, Some(vec![42u8; max_value_len as _])); + Ok(()) + } + + // The weight of journal rollbacks should be taken into account when setting storage. + #[benchmark(pov_mode = Ignored)] + fn rollback_transient_storage() -> Result<(), BenchmarkError> { + let max_value_len = T::Schedule::get().limits.payload_len; + let max_key_len = T::MaxStorageKeyLen::get(); + let key = Key::::try_from_var(vec![0u8; max_key_len as usize]) + .map_err(|_| "Key has wrong length")?; + + let mut setup = CallSetup::::default(); + setup.set_transient_storage_size(T::MaxTransientStorageSize::get()); + let (mut ext, _) = setup.ext(); + let mut runtime = crate::wasm::Runtime::new(&mut ext, vec![]); + runtime.ext().transient_storage().meter().current_mut().limit = u32::MAX; + runtime.ext().transient_storage().start_transaction(); + runtime + .ext() + .set_transient_storage(&key, Some(vec![42u8; max_value_len as _]), false) + .map_err(|_| "Failed to write to transient storage during setup.")?; + #[block] + { + runtime.ext().transient_storage().rollback_transaction(); + } + + assert_eq!(runtime.ext().get_transient_storage(&key), None); + Ok(()) + } + + // n: new byte size + // o: old byte size + #[benchmark(pov_mode = Measured)] + fn seal_set_transient_storage( + n: Linear<0, { T::Schedule::get().limits.payload_len }>, + o: Linear<0, { T::Schedule::get().limits.payload_len }>, + ) -> Result<(), BenchmarkError> { + let max_key_len = T::MaxStorageKeyLen::get(); + let key = Key::::try_from_var(vec![0u8; max_key_len as usize]) + .map_err(|_| "Key has wrong length")?; + let value = vec![1u8; n as usize]; + build_runtime!(runtime, memory: [ key.to_vec(), value.clone(), ]); + runtime.ext().transient_storage().meter().current_mut().limit = u32::MAX; + runtime + .ext() + .set_transient_storage(&key, Some(vec![42u8; o as usize]), false) + .map_err(|_| "Failed to write to transient storage during setup.")?; + + let result; + #[block] + { + result = BenchEnv::seal0_set_transient_storage( + &mut runtime, + &mut memory, + 0, // key_ptr + max_key_len, // key_len + max_key_len, // value_ptr + n, // value_len + ); + } + + assert_ok!(result); + assert_eq!(runtime.ext().get_transient_storage(&key).unwrap(), value); + Ok(()) + } + + #[benchmark(pov_mode = Measured)] + fn seal_clear_transient_storage( + n: Linear<0, { T::Schedule::get().limits.payload_len }>, + ) -> Result<(), BenchmarkError> { + let max_key_len = T::MaxStorageKeyLen::get(); + let key = Key::::try_from_var(vec![0u8; max_key_len as usize]) + .map_err(|_| "Key has wrong length")?; + build_runtime!(runtime, memory: [ key.to_vec(), ]); + runtime.ext().transient_storage().meter().current_mut().limit = u32::MAX; + runtime + .ext() + .set_transient_storage(&key, Some(vec![42u8; n as usize]), false) + .map_err(|_| "Failed to write to transient storage during setup.")?; + + let result; + #[block] + { + result = + BenchEnv::seal0_clear_transient_storage(&mut runtime, &mut memory, 0, max_key_len); + } + + assert_ok!(result); + assert!(runtime.ext().get_transient_storage(&key).is_none()); + Ok(()) + } + + #[benchmark(pov_mode = Measured)] + fn seal_get_transient_storage( + n: Linear<0, { T::Schedule::get().limits.payload_len }>, + ) -> Result<(), BenchmarkError> { + let max_key_len = T::MaxStorageKeyLen::get(); + let key = Key::::try_from_var(vec![0u8; max_key_len as usize]) + .map_err(|_| "Key has wrong length")?; + build_runtime!(runtime, memory: [ key.to_vec(), n.to_le_bytes(), vec![0u8; n as _], ]); + runtime.ext().transient_storage().meter().current_mut().limit = u32::MAX; + runtime + .ext() + .set_transient_storage(&key, Some(vec![42u8; n as usize]), false) + .map_err(|_| "Failed to write to transient storage during setup.")?; + + let out_ptr = max_key_len + 4; + let result; + #[block] + { + result = BenchEnv::seal0_get_transient_storage( + &mut runtime, + &mut memory, + 0, // key_ptr + max_key_len, // key_len + out_ptr, // out_ptr + max_key_len, // out_len_ptr + ); + } + + assert_ok!(result); + assert_eq!( + &runtime.ext().get_transient_storage(&key).unwrap(), + &memory[out_ptr as usize..] + ); + Ok(()) + } + + #[benchmark(pov_mode = Measured)] + fn seal_contains_transient_storage( + n: Linear<0, { T::Schedule::get().limits.payload_len }>, + ) -> Result<(), BenchmarkError> { + let max_key_len = T::MaxStorageKeyLen::get(); + let key = Key::::try_from_var(vec![0u8; max_key_len as usize]) + .map_err(|_| "Key has wrong length")?; + build_runtime!(runtime, memory: [ key.to_vec(), ]); + runtime.ext().transient_storage().meter().current_mut().limit = u32::MAX; + runtime + .ext() + .set_transient_storage(&key, Some(vec![42u8; n as usize]), false) + .map_err(|_| "Failed to write to transient storage during setup.")?; + + let result; + #[block] + { + result = BenchEnv::seal0_contains_transient_storage( + &mut runtime, + &mut memory, + 0, + max_key_len, + ); + } + + assert_eq!(result.unwrap(), n); + Ok(()) + } + + #[benchmark(pov_mode = Measured)] + fn seal_take_transient_storage( + n: Linear<0, { T::Schedule::get().limits.payload_len }>, + ) -> Result<(), BenchmarkError> { + let n = T::Schedule::get().limits.payload_len; + let max_key_len = T::MaxStorageKeyLen::get(); + let key = Key::::try_from_var(vec![0u8; max_key_len as usize]) + .map_err(|_| "Key has wrong length")?; + build_runtime!(runtime, memory: [ key.to_vec(), n.to_le_bytes(), vec![0u8; n as _], ]); + runtime.ext().transient_storage().meter().current_mut().limit = u32::MAX; + let value = vec![42u8; n as usize]; + runtime + .ext() + .set_transient_storage(&key, Some(value.clone()), false) + .map_err(|_| "Failed to write to transient storage during setup.")?; + + let out_ptr = max_key_len + 4; + let result; + #[block] + { + result = BenchEnv::seal0_take_transient_storage( + &mut runtime, + &mut memory, + 0, // key_ptr + max_key_len, // key_len + out_ptr, // out_ptr + max_key_len, // out_len_ptr + ); + } + + assert_ok!(result); + assert!(&runtime.ext().get_transient_storage(&key).is_none()); + assert_eq!(&value, &memory[out_ptr as usize..]); + Ok(()) + } + // We transfer to unique accounts. #[benchmark(pov_mode = Measured)] fn seal_transfer() { diff --git a/substrate/frame/contracts/src/exec.rs b/substrate/frame/contracts/src/exec.rs index 0cc4844166f3..31e0bf50b73e 100644 --- a/substrate/frame/contracts/src/exec.rs +++ b/substrate/frame/contracts/src/exec.rs @@ -20,6 +20,7 @@ use crate::{ gas::GasMeter, primitives::{ExecReturnValue, StorageDeposit}, storage::{self, meter::Diff, WriteOutcome}, + transient_storage::TransientStorage, BalanceOf, CodeHash, CodeInfo, CodeInfoOf, Config, ContractInfo, ContractInfoOf, DebugBufferVec, Determinism, Error, Event, Nonce, Origin, Pallet as Contracts, Schedule, LOG_TARGET, @@ -210,6 +211,27 @@ pub trait Ext: sealing::Sealed { take_old: bool, ) -> Result; + /// Returns the transient storage entry of the executing account for the given `key`. + /// + /// Returns `None` if the `key` wasn't previously set by `set_transient_storage` or + /// was deleted. + fn get_transient_storage(&self, key: &Key) -> Option>; + + /// Returns `Some(len)` (in bytes) if a transient storage item exists at `key`. + /// + /// Returns `None` if the `key` wasn't previously set by `set_transient_storage` or + /// was deleted. + fn get_transient_storage_size(&self, key: &Key) -> Option; + + /// Sets the transient storage entry for the given key to the specified value. If `value` is + /// `None` then the storage entry is deleted. + fn set_transient_storage( + &mut self, + key: &Key, + value: Option>, + take_old: bool, + ) -> Result; + /// Returns the caller. fn caller(&self) -> Origin; @@ -308,6 +330,12 @@ pub trait Ext: sealing::Sealed { #[cfg(any(test, feature = "runtime-benchmarks"))] fn contract_info(&mut self) -> &mut ContractInfo; + /// Get a mutable reference to the transient storage. + /// Useful in benchmarks when it is sometimes necessary to modify and inspect the transient + /// storage directly. + #[cfg(feature = "runtime-benchmarks")] + fn transient_storage(&mut self) -> &mut TransientStorage; + /// Sets new code hash for existing contract. fn set_code_hash(&mut self, hash: CodeHash) -> DispatchResult; @@ -474,6 +502,8 @@ pub struct Stack<'a, T: Config, E> { debug_message: Option<&'a mut DebugBufferVec>, /// The determinism requirement of this call stack. determinism: Determinism, + /// Transient storage used to store data, which is kept for the duration of a transaction. + transient_storage: TransientStorage, /// No executable is held by the struct but influences its behaviour. _phantom: PhantomData, } @@ -797,6 +827,7 @@ where frames: Default::default(), debug_message, determinism, + transient_storage: TransientStorage::new(T::MaxTransientStorageSize::get()), _phantom: Default::default(), }; @@ -927,6 +958,9 @@ where let entry_point = frame.entry_point; let delegated_code_hash = if frame.delegate_caller.is_some() { Some(*executable.code_hash()) } else { None }; + + self.transient_storage.start_transaction(); + let do_transaction = || { // We need to charge the storage deposit before the initial transfer so that // it can create the account in case the initial transfer is < ed. @@ -1047,6 +1081,12 @@ where Err(error) => (false, Err(error.into())), }; + if success { + self.transient_storage.commit_transaction(); + } else { + self.transient_storage.rollback_transaction(); + } + self.pop_frame(success); output } @@ -1375,6 +1415,24 @@ where ) } + fn get_transient_storage(&self, key: &Key) -> Option> { + self.transient_storage.read(self.address(), key) + } + + fn get_transient_storage_size(&self, key: &Key) -> Option { + self.transient_storage.read(self.address(), key).map(|value| value.len() as _) + } + + fn set_transient_storage( + &mut self, + key: &Key, + value: Option>, + take_old: bool, + ) -> Result { + let account_id = self.address().clone(); + self.transient_storage.write(&account_id, key, value, take_old) + } + fn address(&self) -> &T::AccountId { &self.top_frame().account_id } @@ -1519,6 +1577,11 @@ where self.top_frame_mut().contract_info() } + #[cfg(feature = "runtime-benchmarks")] + fn transient_storage(&mut self) -> &mut TransientStorage { + &mut self.transient_storage + } + fn set_code_hash(&mut self, hash: CodeHash) -> DispatchResult { let frame = top_frame_mut!(self); if !E::from_storage(hash, &mut frame.nested_gas)?.is_deterministic() { @@ -3827,6 +3890,262 @@ mod tests { }); } + #[test] + fn set_transient_storage_works() { + let code_hash = MockLoader::insert(Call, |ctx, _| { + // Write + assert_eq!( + ctx.ext.set_transient_storage(&Key::Fix([1; 32]), Some(vec![1, 2, 3]), false), + Ok(WriteOutcome::New) + ); + assert_eq!( + ctx.ext.set_transient_storage(&Key::Fix([2; 32]), Some(vec![4, 5, 6]), true), + Ok(WriteOutcome::New) + ); + assert_eq!( + ctx.ext.set_transient_storage(&Key::Fix([3; 32]), None, false), + Ok(WriteOutcome::New) + ); + assert_eq!( + ctx.ext.set_transient_storage(&Key::Fix([4; 32]), None, true), + Ok(WriteOutcome::New) + ); + assert_eq!( + ctx.ext.set_transient_storage(&Key::Fix([5; 32]), Some(vec![]), false), + Ok(WriteOutcome::New) + ); + assert_eq!( + ctx.ext.set_transient_storage(&Key::Fix([6; 32]), Some(vec![]), true), + Ok(WriteOutcome::New) + ); + + // Overwrite + assert_eq!( + ctx.ext.set_transient_storage(&Key::Fix([1; 32]), Some(vec![42]), false), + Ok(WriteOutcome::Overwritten(3)) + ); + assert_eq!( + ctx.ext.set_transient_storage(&Key::Fix([2; 32]), Some(vec![48]), true), + Ok(WriteOutcome::Taken(vec![4, 5, 6])) + ); + assert_eq!( + ctx.ext.set_transient_storage(&Key::Fix([3; 32]), None, false), + Ok(WriteOutcome::New) + ); + assert_eq!( + ctx.ext.set_transient_storage(&Key::Fix([4; 32]), None, true), + Ok(WriteOutcome::New) + ); + assert_eq!( + ctx.ext.set_transient_storage(&Key::Fix([5; 32]), Some(vec![]), false), + Ok(WriteOutcome::Overwritten(0)) + ); + assert_eq!( + ctx.ext.set_transient_storage(&Key::Fix([6; 32]), Some(vec![]), true), + Ok(WriteOutcome::Taken(vec![])) + ); + + exec_success() + }); + + ExtBuilder::default().build().execute_with(|| { + let schedule = ::Schedule::get(); + place_contract(&BOB, code_hash); + let contract_origin = Origin::from_account_id(ALICE); + let mut storage_meter = storage::meter::Meter::new(&contract_origin, None, 0).unwrap(); + assert_ok!(MockStack::run_call( + contract_origin, + BOB, + &mut GasMeter::::new(GAS_LIMIT), + &mut storage_meter, + &schedule, + 0, + vec![], + None, + Determinism::Enforced + )); + }); + } + + #[test] + fn get_transient_storage_works() { + // Call stack: BOB -> CHARLIE(success) -> BOB' (success) + let storage_key_1 = &Key::Fix([1; 32]); + let storage_key_2 = &Key::Fix([2; 32]); + let storage_key_3 = &Key::Fix([3; 32]); + let code_bob = MockLoader::insert(Call, |ctx, _| { + if ctx.input_data[0] == 0 { + assert_eq!( + ctx.ext.set_transient_storage(storage_key_1, Some(vec![1, 2]), false), + Ok(WriteOutcome::New) + ); + assert_eq!( + ctx.ext.call( + Weight::zero(), + BalanceOf::::zero(), + CHARLIE, + 0, + vec![], + true, + false, + ), + exec_success() + ); + assert_eq!(ctx.ext.get_transient_storage(storage_key_1), Some(vec![3])); + assert_eq!(ctx.ext.get_transient_storage(storage_key_2), Some(vec![])); + assert_eq!(ctx.ext.get_transient_storage(storage_key_3), None); + } else { + assert_eq!( + ctx.ext.set_transient_storage(storage_key_1, Some(vec![3]), true), + Ok(WriteOutcome::Taken(vec![1, 2])) + ); + assert_eq!( + ctx.ext.set_transient_storage(storage_key_2, Some(vec![]), false), + Ok(WriteOutcome::New) + ); + } + exec_success() + }); + let code_charlie = MockLoader::insert(Call, |ctx, _| { + assert!(ctx + .ext + .call(Weight::zero(), BalanceOf::::zero(), BOB, 0, vec![99], true, false) + .is_ok()); + // CHARLIE can not read BOB`s storage. + assert_eq!(ctx.ext.get_transient_storage(storage_key_1), None); + exec_success() + }); + + // This one tests passing the input data into a contract via call. + ExtBuilder::default().build().execute_with(|| { + let schedule = ::Schedule::get(); + place_contract(&BOB, code_bob); + place_contract(&CHARLIE, code_charlie); + let contract_origin = Origin::from_account_id(ALICE); + let mut storage_meter = + storage::meter::Meter::new(&contract_origin, Some(0), 0).unwrap(); + + let result = MockStack::run_call( + contract_origin, + BOB, + &mut GasMeter::::new(GAS_LIMIT), + &mut storage_meter, + &schedule, + 0, + vec![0], + None, + Determinism::Enforced, + ); + assert_matches!(result, Ok(_)); + }); + } + + #[test] + fn get_transient_storage_size_works() { + let storage_key_1 = &Key::Fix([1; 32]); + let storage_key_2 = &Key::Fix([2; 32]); + let storage_key_3 = &Key::Fix([3; 32]); + let code_hash = MockLoader::insert(Call, |ctx, _| { + assert_eq!( + ctx.ext.set_transient_storage(storage_key_1, Some(vec![1, 2, 3]), false), + Ok(WriteOutcome::New) + ); + assert_eq!( + ctx.ext.set_transient_storage(storage_key_2, Some(vec![]), false), + Ok(WriteOutcome::New) + ); + assert_eq!(ctx.ext.get_transient_storage_size(storage_key_1), Some(3)); + assert_eq!(ctx.ext.get_transient_storage_size(storage_key_2), Some(0)); + assert_eq!(ctx.ext.get_transient_storage_size(storage_key_3), None); + + exec_success() + }); + + ExtBuilder::default().build().execute_with(|| { + let schedule = ::Schedule::get(); + place_contract(&BOB, code_hash); + let contract_origin = Origin::from_account_id(ALICE); + let mut storage_meter = + storage::meter::Meter::new(&contract_origin, Some(0), 0).unwrap(); + assert_ok!(MockStack::run_call( + contract_origin, + BOB, + &mut GasMeter::::new(GAS_LIMIT), + &mut storage_meter, + &schedule, + 0, + vec![], + None, + Determinism::Enforced + )); + }); + } + + #[test] + fn rollback_transient_storage_works() { + // Call stack: BOB -> CHARLIE (trap) -> BOB' (success) + let storage_key = &Key::Fix([1; 32]); + let code_bob = MockLoader::insert(Call, |ctx, _| { + if ctx.input_data[0] == 0 { + assert_eq!( + ctx.ext.set_transient_storage(storage_key, Some(vec![1, 2]), false), + Ok(WriteOutcome::New) + ); + assert_eq!( + ctx.ext.call( + Weight::zero(), + BalanceOf::::zero(), + CHARLIE, + 0, + vec![], + true, + false + ), + exec_trapped() + ); + assert_eq!(ctx.ext.get_transient_storage(storage_key), Some(vec![1, 2])); + } else { + let overwritten_length = ctx.ext.get_transient_storage_size(storage_key).unwrap(); + assert_eq!( + ctx.ext.set_transient_storage(storage_key, Some(vec![3]), false), + Ok(WriteOutcome::Overwritten(overwritten_length)) + ); + assert_eq!(ctx.ext.get_transient_storage(storage_key), Some(vec![3])); + } + exec_success() + }); + let code_charlie = MockLoader::insert(Call, |ctx, _| { + assert!(ctx + .ext + .call(Weight::zero(), BalanceOf::::zero(), BOB, 0, vec![99], true, false) + .is_ok()); + exec_trapped() + }); + + // This one tests passing the input data into a contract via call. + ExtBuilder::default().build().execute_with(|| { + let schedule = ::Schedule::get(); + place_contract(&BOB, code_bob); + place_contract(&CHARLIE, code_charlie); + let contract_origin = Origin::from_account_id(ALICE); + let mut storage_meter = + storage::meter::Meter::new(&contract_origin, Some(0), 0).unwrap(); + + let result = MockStack::run_call( + contract_origin, + BOB, + &mut GasMeter::::new(GAS_LIMIT), + &mut storage_meter, + &schedule, + 0, + vec![0], + None, + Determinism::Enforced, + ); + assert_matches!(result, Ok(_)); + }); + } + #[test] fn ecdsa_to_eth_address_returns_proper_value() { let bob_ch = MockLoader::insert(Call, |ctx, _| { diff --git a/substrate/frame/contracts/src/lib.rs b/substrate/frame/contracts/src/lib.rs index ed00fdca62ff..093adc07ab48 100644 --- a/substrate/frame/contracts/src/lib.rs +++ b/substrate/frame/contracts/src/lib.rs @@ -97,6 +97,7 @@ pub use primitives::*; mod schedule; mod storage; +mod transient_storage; mod wasm; pub mod chain_extension; @@ -388,6 +389,11 @@ pub mod pallet { #[pallet::constant] type MaxStorageKeyLen: Get; + /// The maximum size of the transient storage in bytes. + /// This includes keys, values, and previous entries used for storage rollback. + #[pallet::constant] + type MaxTransientStorageSize: Get; + /// The maximum number of delegate_dependencies that a contract can lock with /// [`chain_extension::Ext::lock_delegate_dependency`]. #[pallet::constant] @@ -554,6 +560,7 @@ pub mod pallet { type MaxDebugBufferLen = ConstU32<{ 2 * 1024 * 1024 }>; type MaxDelegateDependencies = MaxDelegateDependencies; type MaxStorageKeyLen = ConstU32<128>; + type MaxTransientStorageSize = ConstU32<{ 1 * 1024 * 1024 }>; type Migrations = (); type Time = Self; type Randomness = Self; @@ -605,7 +612,11 @@ pub mod pallet { // Max call depth is CallStack::size() + 1 let max_call_depth = u32::try_from(T::CallStack::size().saturating_add(1)) .expect("CallStack size is too big"); - + // Transient storage uses a BTreeMap, which has overhead compared to the raw size of + // key-value data. To ensure safety, a margin of 2x the raw key-value size is used. + let max_transient_storage_size = T::MaxTransientStorageSize::get() + .checked_mul(2) + .expect("MaxTransientStorageSize is too large"); // Check that given configured `MaxCodeLen`, runtime heap memory limit can't be broken. // // In worst case, the decoded Wasm contract code would be `x16` times larger than the @@ -615,7 +626,7 @@ pub mod pallet { // Next, the pallet keeps the Wasm blob for each // contract, hence we add up `MaxCodeLen` to the safety margin. // - // Finally, the inefficiencies of the freeing-bump allocator + // The inefficiencies of the freeing-bump allocator // being used in the client for the runtime memory allocations, could lead to possible // memory allocations for contract code grow up to `x4` times in some extreme cases, // which gives us total multiplier of `17*4` for `MaxCodeLen`. @@ -624,17 +635,20 @@ pub mod pallet { // memory should be available. Note that maximum allowed heap memory and stack size per // each contract (stack frame) should also be counted. // + // The pallet holds transient storage with a size up to `max_transient_storage_size`. + // // Finally, we allow 50% of the runtime memory to be utilized by the contracts call // stack, keeping the rest for other facilities, such as PoV, etc. // // This gives us the following formula: // - // `(MaxCodeLen * 17 * 4 + MAX_STACK_SIZE + max_heap_size) * max_call_depth < - // max_runtime_mem/2` + // `(MaxCodeLen * 17 * 4 + MAX_STACK_SIZE + max_heap_size) * max_call_depth + + // max_transient_storage_size < max_runtime_mem/2` // // Hence the upper limit for the `MaxCodeLen` can be defined as follows: let code_len_limit = max_runtime_mem .saturating_div(2) + .saturating_sub(max_transient_storage_size) .saturating_div(max_call_depth) .saturating_sub(max_heap_size) .saturating_sub(MAX_STACK_SIZE) @@ -1235,6 +1249,8 @@ pub mod pallet { DelegateDependencyAlreadyExists, /// Can not add a delegate dependency to the code hash of the contract itself. CannotAddSelfAsDelegateDependency, + /// Can not add more data to transient storage. + OutOfTransientStorage, } /// A reason for the pallet contracts placing a hold on funds. diff --git a/substrate/frame/contracts/src/storage.rs b/substrate/frame/contracts/src/storage.rs index 23b5a2514eb1..65e7129cdf84 100644 --- a/substrate/frame/contracts/src/storage.rs +++ b/substrate/frame/contracts/src/storage.rs @@ -335,7 +335,7 @@ impl ContractInfo { } /// Information about what happened to the pre-existing value when calling [`ContractInfo::write`]. -#[cfg_attr(test, derive(Debug, PartialEq))] +#[cfg_attr(any(test, feature = "runtime-benchmarks"), derive(Debug, PartialEq))] pub enum WriteOutcome { /// No value existed at the specified key. New, diff --git a/substrate/frame/contracts/src/tests.rs b/substrate/frame/contracts/src/tests.rs index 3f608d90bea7..cc2a69b5c419 100644 --- a/substrate/frame/contracts/src/tests.rs +++ b/substrate/frame/contracts/src/tests.rs @@ -411,6 +411,7 @@ parameter_types! { pub static DepositPerByte: BalanceOf = 1; pub const DepositPerItem: BalanceOf = 2; pub static MaxDelegateDependencies: u32 = 32; + pub static MaxTransientStorageSize: u32 = 4 * 1024; pub static CodeHashLockupDepositPercent: Perbill = Perbill::from_percent(0); // We need this one set high enough for running benchmarks. @@ -504,6 +505,7 @@ impl Config for Test { type Migrations = crate::migration::codegen::BenchMigrations; type CodeHashLockupDepositPercent = CodeHashLockupDepositPercent; type MaxDelegateDependencies = MaxDelegateDependencies; + type MaxTransientStorageSize = MaxTransientStorageSize; type Debug = TestDebug; } @@ -962,6 +964,68 @@ fn storage_max_value_limit() { }); } +#[test] +fn transient_storage_work() { + let (code, _code_hash) = compile_module::("transient_storage").unwrap(); + + ExtBuilder::default().build().execute_with(|| { + let _ = ::Currency::set_balance(&ALICE, 1_000_000); + let min_balance = Contracts::min_balance(); + let addr = builder::bare_instantiate(Code::Upload(code)) + .value(min_balance * 100) + .build_and_unwrap_account_id(); + + builder::bare_call(addr).build_and_unwrap_result(); + }); +} + +#[test] +fn transient_storage_limit_in_call() { + let (wasm_caller, _code_hash_caller) = + compile_module::("create_transient_storage_and_call").unwrap(); + let (wasm_callee, _code_hash_callee) = compile_module::("set_transient_storage").unwrap(); + ExtBuilder::default().build().execute_with(|| { + let _ = ::Currency::set_balance(&ALICE, 1_000_000); + let min_balance = Contracts::min_balance(); + + // Create both contracts: Constructors do nothing. + let addr_caller = builder::bare_instantiate(Code::Upload(wasm_caller)) + .value(min_balance * 100) + .build_and_unwrap_account_id(); + let addr_callee = builder::bare_instantiate(Code::Upload(wasm_callee)) + .value(min_balance * 100) + .build_and_unwrap_account_id(); + + let storage_value_size = 1000; + MaxTransientStorageSize::set(4 * 1024); + // Call contracts with storage values within the limit. + // Caller and Callee contracts each set a transient storage value of size 1000. + assert_ok!(builder::call(addr_caller.clone()) + .data((storage_value_size, storage_value_size, &addr_callee).encode()) + .build(),); + + MaxTransientStorageSize::set(512); + // Call a contract with a storage value that is too large. + // Limit exceeded in the caller contract. + assert_err_ignore_postinfo!( + builder::call(addr_caller.clone()) + .data((storage_value_size, storage_value_size, &addr_callee).encode()) + .build(), + >::OutOfTransientStorage, + ); + + MaxTransientStorageSize::set(1536); + // Call a contract with a storage value that is too large. + // Limit exceeded in the callee contract. + assert_err_ignore_postinfo!( + builder::call(addr_caller) + .data((storage_value_size, storage_value_size, &addr_callee).encode()) + .build(), + >::ContractTrapped + ); + }); +} + #[test] fn deploy_and_call_other_contract() { let (caller_wasm, _caller_code_hash) = compile_module::("caller_contract").unwrap(); diff --git a/substrate/frame/contracts/src/transient_storage.rs b/substrate/frame/contracts/src/transient_storage.rs new file mode 100644 index 000000000000..c795a966385a --- /dev/null +++ b/substrate/frame/contracts/src/transient_storage.rs @@ -0,0 +1,698 @@ +// This file is part of Substrate. + +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//! This module contains routines for accessing and altering a contract transient storage. + +use crate::{ + exec::{AccountIdOf, Key}, + storage::WriteOutcome, + Config, Error, +}; +use codec::Encode; +use core::marker::PhantomData; +use frame_support::DefaultNoBound; +use sp_runtime::{DispatchError, DispatchResult, Saturating}; +use sp_std::{collections::btree_map::BTreeMap, mem, vec::Vec}; + +/// Meter entry tracks transaction allocations. +#[derive(Default, Debug)] +pub struct MeterEntry { + /// Allocations made in the current transaction. + pub amount: u32, + /// Allocations limit in the current transaction. + pub limit: u32, +} + +impl MeterEntry { + /// Create a new entry. + fn new(limit: u32) -> Self { + Self { limit, amount: Default::default() } + } + + /// Check if the allocated amount exceeds the limit. + fn exceeds_limit(&self, amount: u32) -> bool { + self.amount.saturating_add(amount) > self.limit + } + + /// Absorb the allocation amount of the nested entry into the current entry. + fn absorb(&mut self, rhs: Self) { + self.amount.saturating_accrue(rhs.amount) + } +} + +// The storage meter enforces a limit for each transaction, +// which is calculated as free_storage * (1 - 1/16) for each subsequent frame. +#[derive(DefaultNoBound)] +pub struct StorageMeter { + nested_meters: Vec, + root_meter: MeterEntry, + _phantom: PhantomData, +} + +impl StorageMeter { + const STORAGE_FRACTION_DENOMINATOR: u32 = 16; + /// Create a new storage allocation meter. + fn new(memory_limit: u32) -> Self { + Self { root_meter: MeterEntry::new(memory_limit), ..Default::default() } + } + + /// Charge the allocated amount of transaction storage from the meter. + fn charge(&mut self, amount: u32) -> DispatchResult { + let meter = self.current_mut(); + if meter.exceeds_limit(amount) { + return Err(Error::::OutOfTransientStorage.into()); + } + meter.amount.saturating_accrue(amount); + Ok(()) + } + + /// Revert a transaction meter. + fn revert(&mut self) { + self.nested_meters.pop().expect( + "A call to revert a meter must be preceded by a corresponding call to start a meter; + the code within this crate makes sure that this is always the case; qed", + ); + } + + /// Start a transaction meter. + fn start(&mut self) { + let meter = self.current(); + let mut transaction_limit = meter.limit.saturating_sub(meter.amount); + if !self.nested_meters.is_empty() { + // Allow use of (1 - 1/STORAGE_FRACTION_DENOMINATOR) of free storage for subsequent + // calls. + transaction_limit.saturating_reduce( + transaction_limit.saturating_div(Self::STORAGE_FRACTION_DENOMINATOR), + ); + } + + self.nested_meters.push(MeterEntry::new(transaction_limit)); + } + + /// Commit a transaction meter. + fn commit(&mut self) { + let transaction_meter = self.nested_meters.pop().expect( + "A call to commit a meter must be preceded by a corresponding call to start a meter; + the code within this crate makes sure that this is always the case; qed", + ); + self.current_mut().absorb(transaction_meter) + } + + /// The total allocated amount of memory. + #[cfg(test)] + fn total_amount(&self) -> u32 { + self.nested_meters + .iter() + .fold(self.root_meter.amount, |acc, e| acc.saturating_add(e.amount)) + } + + /// A mutable reference to the current meter entry. + pub fn current_mut(&mut self) -> &mut MeterEntry { + self.nested_meters.last_mut().unwrap_or(&mut self.root_meter) + } + + /// A reference to the current meter entry. + pub fn current(&self) -> &MeterEntry { + self.nested_meters.last().unwrap_or(&self.root_meter) + } +} + +/// An entry representing a journal change. +struct JournalEntry { + key: Vec, + prev_value: Option>, +} + +impl JournalEntry { + /// Create a new change. + fn new(key: Vec, prev_value: Option>) -> Self { + Self { key, prev_value } + } + + /// Revert the change. + fn revert(self, storage: &mut Storage) { + storage.write(&self.key, self.prev_value); + } +} + +/// A journal containing transient storage modifications. +struct Journal(Vec); + +impl Journal { + /// Create a new journal. + fn new() -> Self { + Self(Default::default()) + } + + /// Add a change to the journal. + fn push(&mut self, entry: JournalEntry) { + self.0.push(entry); + } + + /// Length of the journal. + fn len(&self) -> usize { + self.0.len() + } + + /// Roll back all journal changes until the chackpoint + fn rollback(&mut self, storage: &mut Storage, checkpoint: usize) { + self.0.drain(checkpoint..).rev().for_each(|entry| entry.revert(storage)); + } +} + +/// Storage for maintaining the current transaction state. +#[derive(Default)] +struct Storage(BTreeMap, Vec>); + +impl Storage { + /// Read the storage entry. + fn read(&self, key: &Vec) -> Option> { + self.0.get(key).cloned() + } + + /// Write the storage entry. + fn write(&mut self, key: &Vec, value: Option>) -> Option> { + if let Some(value) = value { + // Insert storage entry. + self.0.insert(key.clone(), value) + } else { + // Remove storage entry. + self.0.remove(key) + } + } +} + +/// Transient storage behaves almost identically to regular storage but is discarded after each +/// transaction. It consists of a `BTreeMap` for the current state, a journal of all changes, and a +/// list of checkpoints. On entry to the `start_transaction` function, a marker (checkpoint) is +/// added to the list. New values are written to the current state, and the previous value is +/// recorded in the journal (`write`). When the `commit_transaction` function is called, the marker +/// to the journal index (checkpoint) of when that call was entered is discarded. +/// On `rollback_transaction`, all entries are reverted up to the last checkpoint. +pub struct TransientStorage { + // The storage and journal size is limited by the storage meter. + storage: Storage, + journal: Journal, + // The size of the StorageMeter is limited by the stack depth. + meter: StorageMeter, + // The size of the checkpoints is limited by the stack depth. + checkpoints: Vec, +} + +impl TransientStorage { + /// Create new transient storage with the supplied memory limit. + pub fn new(memory_limit: u32) -> Self { + TransientStorage { + storage: Default::default(), + journal: Journal::new(), + checkpoints: Default::default(), + meter: StorageMeter::new(memory_limit), + } + } + + /// Read the storage value. If the entry does not exist, `None` is returned. + pub fn read(&self, account: &AccountIdOf, key: &Key) -> Option> { + self.storage.read(&Self::storage_key(&account.encode(), &key.hash())) + } + + /// Write a value to storage. + /// + /// If the `value` is `None`, then the entry is removed. If `take` is true, + /// a [`WriteOutcome::Taken`] is returned instead of a [`WriteOutcome::Overwritten`]. + /// If the entry did not exist, [`WriteOutcome::New`] is returned. + pub fn write( + &mut self, + account: &AccountIdOf, + key: &Key, + value: Option>, + take: bool, + ) -> Result { + let key = Self::storage_key(&account.encode(), &key.hash()); + let prev_value = self.storage.read(&key); + // Skip if the same value is being set. + if prev_value != value { + // Calculate the allocation size. + if let Some(value) = &value { + // Charge the key, value and journal entry. + // If a new value is written, a new journal entry is created. The previous value is + // moved to the journal along with its key, and the new value is written to + // storage. + let key_len = key.capacity(); + let mut amount = value + .capacity() + .saturating_add(key_len) + .saturating_add(mem::size_of::()); + if prev_value.is_none() { + // Charge a new storage entry. + // If there was no previous value, a new entry is added to storage (BTreeMap) + // containing a Vec for the key and a Vec for the value. The value was already + // included in the amount. + amount.saturating_accrue(key_len.saturating_add(mem::size_of::>())); + } + self.meter.charge(amount as _)?; + } + self.storage.write(&key, value); + // Update the journal. + self.journal.push(JournalEntry::new(key, prev_value.clone())); + } + + Ok(match (take, prev_value) { + (_, None) => WriteOutcome::New, + (false, Some(prev_value)) => WriteOutcome::Overwritten(prev_value.len() as _), + (true, Some(prev_value)) => WriteOutcome::Taken(prev_value), + }) + } + + /// Start a new nested transaction. + /// + /// This allows to either commit or roll back all changes that are made after this call. + /// For every transaction there must be a matching call to either `rollback_transaction` + /// or `commit_transaction`. + pub fn start_transaction(&mut self) { + self.meter.start(); + self.checkpoints.push(self.journal.len()); + } + + /// Rollback the last transaction started by `start_transaction`. + /// + /// Any changes made during that transaction are discarded. + /// + /// # Panics + /// + /// Will panic if there is no open transaction. + pub fn rollback_transaction(&mut self) { + let checkpoint = self + .checkpoints + .pop() + .expect( + "A call to rollback_transaction must be preceded by a corresponding call to start_transaction; + the code within this crate makes sure that this is always the case; qed" + ); + self.meter.revert(); + self.journal.rollback(&mut self.storage, checkpoint); + } + + /// Commit the last transaction started by `start_transaction`. + /// + /// Any changes made during that transaction are committed. + /// + /// # Panics + /// + /// Will panic if there is no open transaction. + pub fn commit_transaction(&mut self) { + self.checkpoints + .pop() + .expect( + "A call to commit_transaction must be preceded by a corresponding call to start_transaction; + the code within this crate makes sure that this is always the case; qed" + ); + self.meter.commit(); + } + + /// The storage allocation meter used for transaction metering. + #[cfg(any(test, feature = "runtime-benchmarks"))] + pub fn meter(&mut self) -> &mut StorageMeter { + return &mut self.meter + } + + fn storage_key(account: &[u8], key: &[u8]) -> Vec { + let mut storage_key = Vec::with_capacity(account.len() + key.len()); + storage_key.extend_from_slice(&account); + storage_key.extend_from_slice(&key); + storage_key + } +} + +#[cfg(test)] +mod tests { + use super::*; + use crate::{ + tests::{Test, ALICE, BOB, CHARLIE}, + Error, + }; + use core::u32::MAX; + + // Calculate the allocation size for the given entry. + fn allocation_size( + account: &AccountIdOf, + key: &Key, + value: Option>, + ) -> u32 { + let mut storage: TransientStorage = TransientStorage::::new(MAX); + storage + .write(account, key, value, false) + .expect("Could not write to transient storage."); + storage.meter().current().amount + } + + #[test] + fn read_write_works() { + let mut storage: TransientStorage = TransientStorage::::new(2048); + assert_eq!( + storage.write(&ALICE, &Key::Fix([1; 32]), Some(vec![1]), false), + Ok(WriteOutcome::New) + ); + assert_eq!( + storage.write(&ALICE, &Key::Fix([2; 32]), Some(vec![2]), true), + Ok(WriteOutcome::New) + ); + assert_eq!( + storage.write(&BOB, &Key::Fix([3; 32]), Some(vec![3]), false), + Ok(WriteOutcome::New) + ); + assert_eq!(storage.read(&ALICE, &Key::Fix([1; 32])), Some(vec![1])); + assert_eq!(storage.read(&ALICE, &Key::Fix([2; 32])), Some(vec![2])); + assert_eq!(storage.read(&BOB, &Key::Fix([3; 32])), Some(vec![3])); + // Overwrite values. + assert_eq!( + storage.write(&ALICE, &Key::Fix([2; 32]), Some(vec![4, 5]), false), + Ok(WriteOutcome::Overwritten(1)) + ); + assert_eq!( + storage.write(&BOB, &Key::Fix([3; 32]), Some(vec![6, 7]), true), + Ok(WriteOutcome::Taken(vec![3])) + ); + assert_eq!(storage.read(&ALICE, &Key::Fix([1; 32])), Some(vec![1])); + assert_eq!(storage.read(&ALICE, &Key::Fix([2; 32])), Some(vec![4, 5])); + assert_eq!(storage.read(&BOB, &Key::Fix([3; 32])), Some(vec![6, 7])); + + // Check for an empty value. + assert_eq!( + storage.write(&BOB, &Key::Fix([3; 32]), Some(vec![]), true), + Ok(WriteOutcome::Taken(vec![6, 7])) + ); + assert_eq!(storage.read(&BOB, &Key::Fix([3; 32])), Some(vec![])); + + assert_eq!( + storage.write(&BOB, &Key::Fix([3; 32]), None, true), + Ok(WriteOutcome::Taken(vec![])) + ); + assert_eq!(storage.read(&BOB, &Key::Fix([3; 32])), None); + } + + #[test] + fn read_write_with_var_sized_keys_works() { + let mut storage = TransientStorage::::new(2048); + assert_eq!( + storage.write( + &ALICE, + &Key::::try_from_var([1; 64].to_vec()).unwrap(), + Some(vec![1]), + false + ), + Ok(WriteOutcome::New) + ); + assert_eq!( + storage.write( + &BOB, + &Key::::try_from_var([2; 64].to_vec()).unwrap(), + Some(vec![2, 3]), + false + ), + Ok(WriteOutcome::New) + ); + assert_eq!( + storage.read(&ALICE, &Key::::try_from_var([1; 64].to_vec()).unwrap()), + Some(vec![1]) + ); + assert_eq!( + storage.read(&BOB, &Key::::try_from_var([2; 64].to_vec()).unwrap()), + Some(vec![2, 3]) + ); + // Overwrite values. + assert_eq!( + storage.write( + &ALICE, + &Key::::try_from_var([1; 64].to_vec()).unwrap(), + Some(vec![4, 5]), + false + ), + Ok(WriteOutcome::Overwritten(1)) + ); + assert_eq!( + storage.read(&ALICE, &Key::::try_from_var([1; 64].to_vec()).unwrap()), + Some(vec![4, 5]) + ); + } + + #[test] + fn rollback_transaction_works() { + let mut storage = TransientStorage::::new(1024); + + storage.start_transaction(); + assert_eq!( + storage.write(&ALICE, &Key::Fix([1; 32]), Some(vec![1]), false), + Ok(WriteOutcome::New) + ); + storage.rollback_transaction(); + assert_eq!(storage.read(&ALICE, &Key::Fix([1; 32])), None) + } + + #[test] + fn commit_transaction_works() { + let mut storage = TransientStorage::::new(1024); + + storage.start_transaction(); + assert_eq!( + storage.write(&ALICE, &Key::Fix([1; 32]), Some(vec![1]), false), + Ok(WriteOutcome::New) + ); + storage.commit_transaction(); + assert_eq!(storage.read(&ALICE, &Key::Fix([1; 32])), Some(vec![1])) + } + + #[test] + fn overwrite_and_commmit_transaction_works() { + let mut storage = TransientStorage::::new(1024); + storage.start_transaction(); + assert_eq!( + storage.write(&ALICE, &Key::Fix([1; 32]), Some(vec![1]), false), + Ok(WriteOutcome::New) + ); + assert_eq!( + storage.write(&ALICE, &Key::Fix([1; 32]), Some(vec![1, 2]), false), + Ok(WriteOutcome::Overwritten(1)) + ); + storage.commit_transaction(); + assert_eq!(storage.read(&ALICE, &Key::Fix([1; 32])), Some(vec![1, 2])) + } + + #[test] + fn rollback_in_nested_transaction_works() { + let mut storage = TransientStorage::::new(1024); + storage.start_transaction(); + assert_eq!( + storage.write(&ALICE, &Key::Fix([1; 32]), Some(vec![1]), false), + Ok(WriteOutcome::New) + ); + storage.start_transaction(); + assert_eq!( + storage.write(&BOB, &Key::Fix([1; 32]), Some(vec![1]), false), + Ok(WriteOutcome::New) + ); + storage.rollback_transaction(); + storage.commit_transaction(); + assert_eq!(storage.read(&ALICE, &Key::Fix([1; 32])), Some(vec![1])); + assert_eq!(storage.read(&BOB, &Key::Fix([1; 32])), None) + } + + #[test] + fn commit_in_nested_transaction_works() { + let mut storage = TransientStorage::::new(1024); + storage.start_transaction(); + assert_eq!( + storage.write(&ALICE, &Key::Fix([1; 32]), Some(vec![1]), false), + Ok(WriteOutcome::New) + ); + storage.start_transaction(); + assert_eq!( + storage.write(&BOB, &Key::Fix([1; 32]), Some(vec![2]), false), + Ok(WriteOutcome::New) + ); + storage.start_transaction(); + assert_eq!( + storage.write(&CHARLIE, &Key::Fix([1; 32]), Some(vec![3]), false), + Ok(WriteOutcome::New) + ); + storage.commit_transaction(); + storage.commit_transaction(); + storage.commit_transaction(); + assert_eq!(storage.read(&ALICE, &Key::Fix([1; 32])), Some(vec![1])); + assert_eq!(storage.read(&BOB, &Key::Fix([1; 32])), Some(vec![2])); + assert_eq!(storage.read(&CHARLIE, &Key::Fix([1; 32])), Some(vec![3])); + } + + #[test] + fn rollback_all_transactions_works() { + let mut storage = TransientStorage::::new(1024); + storage.start_transaction(); + assert_eq!( + storage.write(&ALICE, &Key::Fix([1; 32]), Some(vec![1]), false), + Ok(WriteOutcome::New) + ); + storage.start_transaction(); + assert_eq!( + storage.write(&BOB, &Key::Fix([1; 32]), Some(vec![2]), false), + Ok(WriteOutcome::New) + ); + storage.start_transaction(); + assert_eq!( + storage.write(&CHARLIE, &Key::Fix([1; 32]), Some(vec![3]), false), + Ok(WriteOutcome::New) + ); + storage.commit_transaction(); + storage.commit_transaction(); + storage.rollback_transaction(); + assert_eq!(storage.read(&ALICE, &Key::Fix([1; 32])), None); + assert_eq!(storage.read(&BOB, &Key::Fix([1; 32])), None); + assert_eq!(storage.read(&CHARLIE, &Key::Fix([1; 32])), None); + } + + #[test] + fn metering_transactions_works() { + let size = allocation_size(&ALICE, &Key::Fix([1; 32]), Some(vec![1u8; 4096])); + let mut storage = TransientStorage::::new(size * 2); + storage.start_transaction(); + assert_eq!( + storage.write(&ALICE, &Key::Fix([1; 32]), Some(vec![1u8; 4096]), false), + Ok(WriteOutcome::New) + ); + let limit = storage.meter().current().limit; + storage.commit_transaction(); + + storage.start_transaction(); + assert_eq!(storage.meter().current().limit, limit - size); + assert_eq!(storage.meter().current().limit - storage.meter().current().amount, size); + assert_eq!( + storage.write(&ALICE, &Key::Fix([2; 32]), Some(vec![1u8; 4096]), false), + Ok(WriteOutcome::New) + ); + assert_eq!(storage.meter().current().amount, size); + storage.commit_transaction(); + assert_eq!(storage.meter().total_amount(), size * 2); + } + + #[test] + fn metering_nested_transactions_works() { + let size = allocation_size(&ALICE, &Key::Fix([1; 32]), Some(vec![1u8; 4096])); + let mut storage = TransientStorage::::new(size * 3); + + storage.start_transaction(); + let limit = storage.meter().current().limit; + assert_eq!( + storage.write(&ALICE, &Key::Fix([1; 32]), Some(vec![1u8; 4096]), false), + Ok(WriteOutcome::New) + ); + storage.start_transaction(); + assert_eq!(storage.meter().total_amount(), size); + assert!(storage.meter().current().limit < limit - size); + assert_eq!( + storage.write(&ALICE, &Key::Fix([2; 32]), Some(vec![1u8; 4096]), false), + Ok(WriteOutcome::New) + ); + storage.commit_transaction(); + assert_eq!(storage.meter().current().limit, limit); + assert_eq!(storage.meter().total_amount(), storage.meter().current().amount); + storage.commit_transaction(); + } + + #[test] + fn metering_transaction_fails() { + let size = allocation_size(&ALICE, &Key::Fix([1; 32]), Some(vec![1u8; 4096])); + let mut storage = TransientStorage::::new(size - 1); + storage.start_transaction(); + assert_eq!( + storage.write(&ALICE, &Key::Fix([1; 32]), Some(vec![1u8; 4096]), false), + Err(Error::::OutOfTransientStorage.into()) + ); + assert_eq!(storage.meter.current().amount, 0); + storage.commit_transaction(); + assert_eq!(storage.meter.total_amount(), 0); + } + + #[test] + fn metering_nested_transactions_fails() { + let size = allocation_size(&ALICE, &Key::Fix([1; 32]), Some(vec![1u8; 4096])); + let mut storage = TransientStorage::::new(size * 2); + + storage.start_transaction(); + assert_eq!( + storage.write(&ALICE, &Key::Fix([1; 32]), Some(vec![1u8; 4096]), false), + Ok(WriteOutcome::New) + ); + storage.start_transaction(); + assert_eq!( + storage.write(&ALICE, &Key::Fix([2; 32]), Some(vec![1u8; 4096]), false), + Err(Error::::OutOfTransientStorage.into()) + ); + storage.commit_transaction(); + storage.commit_transaction(); + assert_eq!(storage.meter.total_amount(), size); + } + + #[test] + fn metering_nested_transaction_with_rollback_works() { + let size = allocation_size(&ALICE, &Key::Fix([1; 32]), Some(vec![1u8; 4096])); + let mut storage = TransientStorage::::new(size * 2); + + storage.start_transaction(); + let limit = storage.meter.current().limit; + storage.start_transaction(); + assert_eq!( + storage.write(&ALICE, &Key::Fix([2; 32]), Some(vec![1u8; 4096]), false), + Ok(WriteOutcome::New) + ); + storage.rollback_transaction(); + + assert_eq!(storage.meter.total_amount(), 0); + assert_eq!(storage.meter.current().limit, limit); + assert_eq!( + storage.write(&ALICE, &Key::Fix([1; 32]), Some(vec![1u8; 4096]), false), + Ok(WriteOutcome::New) + ); + let amount = storage.meter().current().amount; + assert_eq!(storage.meter().total_amount(), amount); + storage.commit_transaction(); + } + + #[test] + fn metering_with_rollback_works() { + let size = allocation_size(&ALICE, &Key::Fix([1; 32]), Some(vec![1u8; 4096])); + let mut storage = TransientStorage::::new(size * 5); + + storage.start_transaction(); + assert_eq!( + storage.write(&ALICE, &Key::Fix([1; 32]), Some(vec![1u8; 4096]), false), + Ok(WriteOutcome::New) + ); + let amount = storage.meter.total_amount(); + storage.start_transaction(); + assert_eq!( + storage.write(&ALICE, &Key::Fix([2; 32]), Some(vec![1u8; 4096]), false), + Ok(WriteOutcome::New) + ); + storage.start_transaction(); + assert_eq!( + storage.write(&BOB, &Key::Fix([1; 32]), Some(vec![1u8; 4096]), false), + Ok(WriteOutcome::New) + ); + storage.commit_transaction(); + storage.rollback_transaction(); + assert_eq!(storage.meter.total_amount(), amount); + storage.commit_transaction(); + } +} diff --git a/substrate/frame/contracts/src/wasm/mod.rs b/substrate/frame/contracts/src/wasm/mod.rs index 2fef07f8b7a4..f4ee76459c4e 100644 --- a/substrate/frame/contracts/src/wasm/mod.rs +++ b/substrate/frame/contracts/src/wasm/mod.rs @@ -506,6 +506,7 @@ mod tests { primitives::ExecReturnValue, storage::WriteOutcome, tests::{RuntimeCall, Test, ALICE, BOB}, + transient_storage::TransientStorage, BalanceOf, CodeHash, Error, Origin, Pallet as Contracts, }; use assert_matches::assert_matches; @@ -563,6 +564,7 @@ mod tests { pub struct MockExt { storage: HashMap, Vec>, + transient_storage: TransientStorage, instantiates: Vec, terminations: Vec, calls: Vec, @@ -591,6 +593,7 @@ mod tests { Self { code_hashes: Default::default(), storage: Default::default(), + transient_storage: TransientStorage::new(1024 * 1024), instantiates: Default::default(), terminations: Default::default(), calls: Default::default(), @@ -691,6 +694,21 @@ mod tests { } Ok(result) } + fn get_transient_storage(&self, key: &Key) -> Option> { + self.transient_storage.read(self.address(), key) + } + fn get_transient_storage_size(&self, key: &Key) -> Option { + self.transient_storage.read(self.address(), key).map(|value| value.len() as _) + } + fn set_transient_storage( + &mut self, + key: &Key, + value: Option>, + take_old: bool, + ) -> Result { + let account_id = self.address().clone(); + self.transient_storage.write(&account_id, key, value, take_old) + } fn caller(&self) -> Origin { self.caller.clone() } @@ -784,6 +802,10 @@ mod tests { fn contract_info(&mut self) -> &mut crate::ContractInfo { unimplemented!() } + #[cfg(feature = "runtime-benchmarks")] + fn transient_storage(&mut self) -> &mut TransientStorage { + unimplemented!() + } fn ecdsa_to_eth_address(&self, _pk: &[u8; 33]) -> Result<[u8; 20], ()> { Ok([2u8; 20]) } @@ -3046,6 +3068,337 @@ mod tests { assert_eq!(&result.data[4..], &[0u8; 0]); } + #[test] + fn set_transient_storage_works() { + const CODE: &str = r#" +(module + (import "seal0" "seal_input" (func $seal_input (param i32 i32))) + (import "seal0" "seal_return" (func $seal_return (param i32 i32 i32))) + (import "seal0" "set_transient_storage" (func $set_transient_storage (param i32 i32 i32 i32) (result i32))) + (import "env" "memory" (memory 1 1)) + + ;; [0, 4) size of input buffer + ;; 4k in little endian + (data (i32.const 0) "\00\10") + + ;; [4, 4100) input buffer + + (func (export "call") + ;; Receive (key ++ value_to_write) + (call $seal_input + (i32.const 4) ;; Pointer to the input buffer + (i32.const 0) ;; Size of the input buffer + ) + ;; Store the passed value to the passed key and store result to memory + (i32.store (i32.const 168) + (call $set_transient_storage + (i32.const 8) ;; key_ptr + (i32.load (i32.const 4)) ;; key_len + (i32.add ;; value_ptr = 8 + key_len + (i32.const 8) + (i32.load (i32.const 4))) + (i32.sub ;; value_len (input_size - (key_len + key_len_len)) + (i32.load (i32.const 0)) + (i32.add + (i32.load (i32.const 4)) + (i32.const 4) + ) + ) + ) + ) + (call $seal_return + (i32.const 0) ;; flags + (i32.const 168) ;; ptr to returned value + (i32.const 4) ;; length of returned value + ) + ) + + (func (export "deploy")) +) +"#; + + let mut ext = MockExt::default(); + + // value did not exist before -> sentinel returned + let input = (32, [1u8; 32], [42u8, 48]).encode(); + let result = execute(CODE, input, &mut ext).unwrap(); + assert_eq!(u32::from_le_bytes(result.data.try_into().unwrap()), crate::SENTINEL); + assert_eq!( + ext.get_transient_storage(&Key::::try_from_var([1u8; 32].to_vec()).unwrap()), + Some(vec![42, 48]) + ); + + // value do exist -> length of old value returned + let input = (32, [1u8; 32], [0u8; 0]).encode(); + let result = execute(CODE, input, &mut ext).unwrap(); + assert_eq!(u32::from_le_bytes(result.data.try_into().unwrap()), 2); + assert_eq!( + ext.get_transient_storage(&Key::::try_from_var([1u8; 32].to_vec()).unwrap()), + Some(vec![]) + ); + + // value do exist -> length of old value returned (test for zero sized val) + let input = (32, [1u8; 32], [99u8]).encode(); + let result = execute(CODE, input, &mut ext).unwrap(); + assert_eq!(u32::from_le_bytes(result.data.try_into().unwrap()), 0); + assert_eq!( + ext.get_transient_storage(&Key::::try_from_var([1u8; 32].to_vec()).unwrap()), + Some(vec![99]) + ); + } + + #[test] + fn get_transient_storage_works() { + const CODE: &str = r#" +(module + (import "seal0" "seal_input" (func $seal_input (param i32 i32))) + (import "seal0" "seal_return" (func $seal_return (param i32 i32 i32))) + (import "seal0" "get_transient_storage" (func $get_transient_storage (param i32 i32 i32 i32) (result i32))) + (import "env" "memory" (memory 1 1)) + + ;; [0, 4) size of input buffer (160 bytes as we copy the key+len here) + (data (i32.const 0) "\A0") + + ;; [4, 8) size of output buffer + ;; 4k in little endian + (data (i32.const 4) "\00\10") + + ;; [8, 168) input buffer + ;; [168, 4264) output buffer + + (func (export "call") + ;; Receive (key ++ value_to_write) + (call $seal_input + (i32.const 8) ;; Pointer to the input buffer + (i32.const 0) ;; Size of the input buffer + ) + ;; Load a storage value and result of this call into the output buffer + (i32.store (i32.const 168) + (call $get_transient_storage + (i32.const 12) ;; key_ptr + (i32.load (i32.const 8)) ;; key_len + (i32.const 172) ;; Pointer to the output buffer + (i32.const 4) ;; Pointer to the size of the buffer + ) + ) + (call $seal_return + (i32.const 0) ;; flags + (i32.const 168) ;; output buffer ptr + (i32.add ;; length: output size + 4 (retval) + (i32.load (i32.const 4)) + (i32.const 4) + ) + ) + ) + + (func (export "deploy")) +) +"#; + + let mut ext = MockExt::default(); + + assert_ok!(ext.set_transient_storage( + &Key::::try_from_var([1u8; 64].to_vec()).unwrap(), + Some(vec![42u8]), + false + )); + assert_ok!(ext.set_transient_storage( + &Key::::try_from_var([2u8; 19].to_vec()).unwrap(), + Some(vec![]), + false + )); + + // value does not exist + let input = (63, [1u8; 64]).encode(); + let result = execute(CODE, input, &mut ext).unwrap(); + assert_eq!( + u32::from_le_bytes(result.data[0..4].try_into().unwrap()), + ReturnErrorCode::KeyNotFound as u32 + ); + + // value exists + let input = (64, [1u8; 64]).encode(); + let result = execute(CODE, input, &mut ext).unwrap(); + assert_eq!( + u32::from_le_bytes(result.data[0..4].try_into().unwrap()), + ReturnErrorCode::Success as u32 + ); + assert_eq!(&result.data[4..], &[42u8]); + + // value exists (test for 0 sized) + let input = (19, [2u8; 19]).encode(); + let result = execute(CODE, input, &mut ext).unwrap(); + assert_eq!( + u32::from_le_bytes(result.data[0..4].try_into().unwrap()), + ReturnErrorCode::Success as u32 + ); + assert_eq!(&result.data[4..], &([] as [u8; 0])); + } + + #[test] + fn clear_transient_storage_works() { + const CODE: &str = r#" +(module + (import "seal0" "seal_input" (func $seal_input (param i32 i32))) + (import "seal0" "seal_return" (func $seal_return (param i32 i32 i32))) + (import "seal0" "clear_transient_storage" (func $clear_transient_storage (param i32 i32) (result i32))) + (import "env" "memory" (memory 1 1)) + + ;; size of input buffer + ;; [0, 4) size of input buffer (128+32 = 160 bytes = 0xA0) + (data (i32.const 0) "\A0") + + ;; [4, 164) input buffer + + (func (export "call") + ;; Receive key + (call $seal_input + (i32.const 4) ;; Where we take input and store it + (i32.const 0) ;; Where we take and store the length of thedata + ) + ;; Call seal_clear_storage and save what it returns at 0 + (i32.store (i32.const 0) + (call $clear_transient_storage + (i32.const 8) ;; key_ptr + (i32.load (i32.const 4)) ;; key_len + ) + ) + (call $seal_return + (i32.const 0) ;; flags + (i32.const 0) ;; returned value + (i32.const 4) ;; length of returned value + ) + ) + + (func (export "deploy")) +) +"#; + + let mut ext = MockExt::default(); + + assert_ok!(ext.set_transient_storage( + &Key::::try_from_var([1u8; 64].to_vec()).unwrap(), + Some(vec![42u8]), + false + )); + + // value did not exist + let input = (32, [3u8; 32]).encode(); + let result = execute(CODE, input, &mut ext).unwrap(); + // sentinel returned + assert_eq!(u32::from_le_bytes(result.data.try_into().unwrap()), crate::SENTINEL); + + // value did exist + let input = (64, [1u8; 64]).encode(); + let result = execute(CODE, input, &mut ext).unwrap(); + // length returned + assert_eq!(u32::from_le_bytes(result.data.try_into().unwrap()), 1); + // value cleared + assert_eq!( + ext.get_transient_storage(&Key::::try_from_var([1u8; 64].to_vec()).unwrap()), + None + ); + } + + #[test] + fn take_transient_storage_works() { + const CODE: &str = r#" +(module + (import "seal0" "seal_return" (func $seal_return (param i32 i32 i32))) + (import "seal0" "seal_input" (func $seal_input (param i32 i32))) + (import "seal0" "take_transient_storage" (func $take_transient_storage (param i32 i32 i32 i32) (result i32))) + (import "env" "memory" (memory 1 1)) + + ;; [0, 4) size of input buffer (160 bytes as we copy the key+len here) + (data (i32.const 0) "\A0") + + ;; [4, 8) size of output buffer + ;; 4k in little endian + (data (i32.const 4) "\00\10") + + ;; [8, 168) input buffer + ;; [168, 4264) output buffer + + (func (export "call") + ;; Receive key + (call $seal_input + (i32.const 8) ;; Pointer to the input buffer + (i32.const 0) ;; Size of the length buffer + ) + + ;; Load a storage value and result of this call into the output buffer + (i32.store (i32.const 168) + (call $take_transient_storage + (i32.const 12) ;; key_ptr + (i32.load (i32.const 8)) ;; key_len + (i32.const 172) ;; Pointer to the output buffer + (i32.const 4) ;; Pointer to the size of the buffer + ) + ) + + ;; Return the contents of the buffer + (call $seal_return + (i32.const 0) ;; flags + (i32.const 168) ;; output buffer ptr + (i32.add ;; length: storage size + 4 (retval) + (i32.load (i32.const 4)) + (i32.const 4) + ) + ) + ) + + (func (export "deploy")) +) +"#; + + let mut ext = MockExt::default(); + + assert_ok!(ext.set_transient_storage( + &Key::::try_from_var([1u8; 64].to_vec()).unwrap(), + Some(vec![42u8]), + false + )); + assert_ok!(ext.set_transient_storage( + &Key::::try_from_var([2u8; 19].to_vec()).unwrap(), + Some(vec![]), + false + )); + + // value does not exist -> error returned + let input = (63, [1u8; 64]).encode(); + let result = execute(CODE, input, &mut ext).unwrap(); + assert_eq!( + u32::from_le_bytes(result.data[0..4].try_into().unwrap()), + ReturnErrorCode::KeyNotFound as u32 + ); + + // value did exist -> value returned + let input = (64, [1u8; 64]).encode(); + let result = execute(CODE, input, &mut ext).unwrap(); + assert_eq!( + u32::from_le_bytes(result.data[0..4].try_into().unwrap()), + ReturnErrorCode::Success as u32 + ); + assert_eq!( + ext.get_transient_storage(&Key::::try_from_var([1u8; 64].to_vec()).unwrap()), + None + ); + assert_eq!(&result.data[4..], &[42u8]); + + // value did exist -> length returned (test for 0 sized) + let input = (19, [2u8; 19]).encode(); + let result = execute(CODE, input, &mut ext).unwrap(); + assert_eq!( + u32::from_le_bytes(result.data[0..4].try_into().unwrap()), + ReturnErrorCode::Success as u32 + ); + assert_eq!( + ext.get_transient_storage(&Key::::try_from_var([2u8; 19].to_vec()).unwrap()), + None + ); + assert_eq!(&result.data[4..], &[0u8; 0]); + } + #[test] fn is_contract_works() { const CODE_IS_CONTRACT: &str = r#" diff --git a/substrate/frame/contracts/src/wasm/runtime.rs b/substrate/frame/contracts/src/wasm/runtime.rs index 50b06de080ca..982d28540ec1 100644 --- a/substrate/frame/contracts/src/wasm/runtime.rs +++ b/substrate/frame/contracts/src/wasm/runtime.rs @@ -199,6 +199,16 @@ pub enum RuntimeCosts { GetStorage(u32), /// Weight of calling `seal_take_storage` for the given size. TakeStorage(u32), + /// Weight of calling `seal_set_transient_storage` for the given storage item sizes. + SetTransientStorage { old_bytes: u32, new_bytes: u32 }, + /// Weight of calling `seal_clear_transient_storage` per cleared byte. + ClearTransientStorage(u32), + /// Weight of calling `seal_contains_transient_storage` per byte of the checked item. + ContainsTransientStorage(u32), + /// Weight of calling `seal_get_transient_storage` with the specified size in storage. + GetTransientStorage(u32), + /// Weight of calling `seal_take_transient_storage` for the given size. + TakeTransientStorage(u32), /// Weight of calling `seal_transfer`. Transfer, /// Base weight of calling `seal_call`. @@ -245,6 +255,34 @@ pub enum RuntimeCosts { UnlockDelegateDependency, } +// For the function that modifies the storage, the benchmarks are done with one item in the +// transient_storage (BTreeMap). To consider the worst-case scenario, the weight of the overhead of +// writing to a full BTreeMap should be included. On top of that, the rollback weight is added, +// which is the worst scenario. +macro_rules! cost_write { + // cost_write!(name, a, b, c) -> T::WeightInfo::name(a, b, c).saturating_add(T::WeightInfo::rollback_transient_storage()) + // .saturating_add(T::WeightInfo::set_transient_storage_full().saturating_sub(T::WeightInfo::set_transient_storage_empty()) + ($name:ident $(, $arg:expr )*) => { + (T::WeightInfo::$name($( $arg ),*).saturating_add(T::WeightInfo::rollback_transient_storage()).saturating_add(cost_write!(@cost_storage))) + }; + + (@cost_storage) => { + T::WeightInfo::set_transient_storage_full().saturating_sub(T::WeightInfo::set_transient_storage_empty()) + }; +} + +macro_rules! cost_read { + // cost_read!(name, a, b, c) -> T::WeightInfo::name(a, b, c).saturating_add(T::WeightInfo::get_transient_storage_full() + // .saturating_sub(T::WeightInfo::get_transient_storage_empty()) + ($name:ident $(, $arg:expr )*) => { + (T::WeightInfo::$name($( $arg ),*).saturating_add(cost_read!(@cost_storage))) + }; + + (@cost_storage) => { + T::WeightInfo::get_transient_storage_full().saturating_sub(T::WeightInfo::get_transient_storage_empty()) + }; +} + macro_rules! cost_args { // cost_args!(name, a, b, c) -> T::WeightInfo::name(a, b, c).saturating_sub(T::WeightInfo::name(0, 0, 0)) ($name:ident, $( $arg: expr ),+) => { @@ -296,6 +334,12 @@ impl Token for RuntimeCosts { ContainsStorage(len) => T::WeightInfo::seal_contains_storage(len), GetStorage(len) => T::WeightInfo::seal_get_storage(len), TakeStorage(len) => T::WeightInfo::seal_take_storage(len), + SetTransientStorage { new_bytes, old_bytes } => + cost_write!(seal_set_transient_storage, new_bytes, old_bytes), + ClearTransientStorage(len) => cost_write!(seal_clear_transient_storage, len), + ContainsTransientStorage(len) => cost_read!(seal_contains_transient_storage, len), + GetTransientStorage(len) => cost_read!(seal_get_transient_storage, len), + TakeTransientStorage(len) => cost_write!(seal_take_transient_storage, len), Transfer => T::WeightInfo::seal_transfer(), CallBase => T::WeightInfo::seal_call(0, 0), DelegateCallBase => T::WeightInfo::seal_delegate_call(), @@ -792,10 +836,129 @@ impl<'a, E: Ext + 'a> Runtime<'a, E> { let key = self.decode_key(memory, key_type, key_ptr)?; let outcome = self.ext.get_storage_size(&key); - self.adjust_gas(charged, RuntimeCosts::ClearStorage(outcome.unwrap_or(0))); + self.adjust_gas(charged, RuntimeCosts::ContainsStorage(outcome.unwrap_or(0))); Ok(outcome.unwrap_or(SENTINEL)) } + fn set_transient_storage( + &mut self, + memory: &[u8], + key_type: KeyType, + key_ptr: u32, + value_ptr: u32, + value_len: u32, + ) -> Result { + let max_size = self.ext.max_value_size(); + let charged = self.charge_gas(RuntimeCosts::SetTransientStorage { + new_bytes: value_len, + old_bytes: max_size, + })?; + if value_len > max_size { + return Err(Error::::ValueTooLarge.into()) + } + let key = self.decode_key(memory, key_type, key_ptr)?; + let value = Some(self.read_sandbox_memory(memory, value_ptr, value_len)?); + let write_outcome = self.ext.set_transient_storage(&key, value, false)?; + self.adjust_gas( + charged, + RuntimeCosts::SetTransientStorage { + new_bytes: value_len, + old_bytes: write_outcome.old_len(), + }, + ); + Ok(write_outcome.old_len_with_sentinel()) + } + + fn clear_transient_storage( + &mut self, + memory: &[u8], + key_type: KeyType, + key_ptr: u32, + ) -> Result { + let charged = + self.charge_gas(RuntimeCosts::ClearTransientStorage(self.ext.max_value_size()))?; + let key = self.decode_key(memory, key_type, key_ptr)?; + let outcome = self.ext.set_transient_storage(&key, None, false)?; + + self.adjust_gas(charged, RuntimeCosts::ClearTransientStorage(outcome.old_len())); + Ok(outcome.old_len_with_sentinel()) + } + + fn get_transient_storage( + &mut self, + memory: &mut [u8], + key_type: KeyType, + key_ptr: u32, + out_ptr: u32, + out_len_ptr: u32, + ) -> Result { + let charged = + self.charge_gas(RuntimeCosts::GetTransientStorage(self.ext.max_value_size()))?; + let key = self.decode_key(memory, key_type, key_ptr)?; + let outcome = self.ext.get_transient_storage(&key); + + if let Some(value) = outcome { + self.adjust_gas(charged, RuntimeCosts::GetTransientStorage(value.len() as u32)); + self.write_sandbox_output( + memory, + out_ptr, + out_len_ptr, + &value, + false, + already_charged, + )?; + Ok(ReturnErrorCode::Success) + } else { + self.adjust_gas(charged, RuntimeCosts::GetTransientStorage(0)); + Ok(ReturnErrorCode::KeyNotFound) + } + } + + fn contains_transient_storage( + &mut self, + memory: &[u8], + key_type: KeyType, + key_ptr: u32, + ) -> Result { + let charged = + self.charge_gas(RuntimeCosts::ContainsTransientStorage(self.ext.max_value_size()))?; + let key = self.decode_key(memory, key_type, key_ptr)?; + let outcome = self.ext.get_transient_storage_size(&key); + + self.adjust_gas(charged, RuntimeCosts::ContainsTransientStorage(outcome.unwrap_or(0))); + Ok(outcome.unwrap_or(SENTINEL)) + } + + fn take_transient_storage( + &mut self, + memory: &mut [u8], + key_type: KeyType, + key_ptr: u32, + out_ptr: u32, + out_len_ptr: u32, + ) -> Result { + let charged = + self.charge_gas(RuntimeCosts::TakeTransientStorage(self.ext.max_value_size()))?; + let key = self.decode_key(memory, key_type, key_ptr)?; + if let crate::storage::WriteOutcome::Taken(value) = + self.ext.set_transient_storage(&key, None, true)? + { + self.adjust_gas(charged, RuntimeCosts::TakeTransientStorage(value.len() as u32)); + self.write_sandbox_output( + memory, + out_ptr, + out_len_ptr, + &value, + false, + already_charged, + )?; + Ok(ReturnErrorCode::Success) + } else { + self.adjust_gas(charged, RuntimeCosts::TakeTransientStorage(0)); + Ok(ReturnErrorCode::KeyNotFound) + } + } + fn call( &mut self, memory: &mut [u8], @@ -1099,6 +1262,67 @@ pub mod env { } } + /// Set the value at the given key in the contract transient storage. + #[unstable] + fn set_transient_storage( + ctx: _, + memory: _, + key_ptr: u32, + key_len: u32, + value_ptr: u32, + value_len: u32, + ) -> Result { + ctx.set_transient_storage(memory, KeyType::Var(key_len), key_ptr, value_ptr, value_len) + } + + /// Clear the value at the given key in the contract storage. + #[unstable] + fn clear_transient_storage( + ctx: _, + memory: _, + key_ptr: u32, + key_len: u32, + ) -> Result { + ctx.clear_transient_storage(memory, KeyType::Var(key_len), key_ptr) + } + + /// Retrieve the value under the given key from transient storage. + #[unstable] + fn get_transient_storage( + ctx: _, + memory: _, + key_ptr: u32, + key_len: u32, + out_ptr: u32, + out_len_ptr: u32, + ) -> Result { + ctx.get_transient_storage(memory, KeyType::Var(key_len), key_ptr, out_ptr, out_len_ptr) + } + + /// Checks whether there is a value stored under the given key in transient storage. + #[unstable] + fn contains_transient_storage( + ctx: _, + memory: _, + key_ptr: u32, + key_len: u32, + ) -> Result { + ctx.contains_transient_storage(memory, KeyType::Var(key_len), key_ptr) + } + + /// Retrieve and remove the value under the given key from transient storage. + #[unstable] + fn take_transient_storage( + ctx: _, + memory: _, + key_ptr: u32, + key_len: u32, + out_ptr: u32, + out_len_ptr: u32, + ) -> Result { + ctx.take_transient_storage(memory, KeyType::Var(key_len), key_ptr, out_ptr, out_len_ptr) + } + /// Transfer some value to another account. /// See [`pallet_contracts_uapi::HostFn::transfer`]. #[prefixed_alias] diff --git a/substrate/frame/contracts/src/weights.rs b/substrate/frame/contracts/src/weights.rs index 0404a9d3d8e5..dc10a8aee773 100644 --- a/substrate/frame/contracts/src/weights.rs +++ b/substrate/frame/contracts/src/weights.rs @@ -18,9 +18,9 @@ //! Autogenerated weights for `pallet_contracts` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 -//! DATE: 2024-06-07, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2024-07-09, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `runner-1pho9goo-project-674-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz` +//! HOSTNAME: `runner-yaoqqom-project-674-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz` //! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: `1024` // Executed Command: @@ -98,6 +98,16 @@ pub trait WeightInfo { fn seal_get_storage(n: u32, ) -> Weight; fn seal_contains_storage(n: u32, ) -> Weight; fn seal_take_storage(n: u32, ) -> Weight; + fn set_transient_storage_empty() -> Weight; + fn set_transient_storage_full() -> Weight; + fn get_transient_storage_empty() -> Weight; + fn get_transient_storage_full() -> Weight; + fn rollback_transient_storage() -> Weight; + fn seal_set_transient_storage(n: u32, o: u32, ) -> Weight; + fn seal_clear_transient_storage(n: u32, ) -> Weight; + fn seal_get_transient_storage(n: u32, ) -> Weight; + fn seal_contains_transient_storage(n: u32, ) -> Weight; + fn seal_take_transient_storage(n: u32, ) -> Weight; fn seal_transfer() -> Weight; fn seal_call(t: u32, i: u32, ) -> Weight; fn seal_delegate_call() -> Weight; @@ -127,8 +137,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `142` // Estimated: `1627` - // Minimum execution time: 1_896_000 picoseconds. - Weight::from_parts(1_990_000, 1627) + // Minimum execution time: 1_921_000 picoseconds. + Weight::from_parts(2_003_000, 1627) .saturating_add(T::DbWeight::get().reads(1_u64)) } /// Storage: `Skipped::Metadata` (r:0 w:0) @@ -138,10 +148,10 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `452 + k * (69 ±0)` // Estimated: `442 + k * (70 ±0)` - // Minimum execution time: 11_142_000 picoseconds. - Weight::from_parts(11_578_000, 442) - // Standard Error: 1_557 - .saturating_add(Weight::from_parts(1_165_198, 0).saturating_mul(k.into())) + // Minimum execution time: 11_364_000 picoseconds. + Weight::from_parts(11_463_000, 442) + // Standard Error: 2_141 + .saturating_add(Weight::from_parts(1_149_944, 0).saturating_mul(k.into())) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(k.into()))) .saturating_add(T::DbWeight::get().writes(2_u64)) @@ -155,10 +165,10 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `211 + c * (1 ±0)` // Estimated: `6149 + c * (1 ±0)` - // Minimum execution time: 7_649_000 picoseconds. - Weight::from_parts(4_827_445, 6149) + // Minimum execution time: 7_565_000 picoseconds. + Weight::from_parts(5_041_009, 6149) // Standard Error: 5 - .saturating_add(Weight::from_parts(1_630, 0).saturating_mul(c.into())) + .saturating_add(Weight::from_parts(1_640, 0).saturating_mul(c.into())) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) .saturating_add(Weight::from_parts(0, 1).saturating_mul(c.into())) @@ -171,8 +181,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `510` // Estimated: `6450` - // Minimum execution time: 16_096_000 picoseconds. - Weight::from_parts(16_937_000, 6450) + // Minimum execution time: 15_894_000 picoseconds. + Weight::from_parts(16_618_000, 6450) .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -185,10 +195,10 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `171 + k * (1 ±0)` // Estimated: `3635 + k * (1 ±0)` - // Minimum execution time: 3_131_000 picoseconds. - Weight::from_parts(3_209_000, 3635) - // Standard Error: 481 - .saturating_add(Weight::from_parts(1_087_506, 0).saturating_mul(k.into())) + // Minimum execution time: 3_077_000 picoseconds. + Weight::from_parts(3_144_000, 3635) + // Standard Error: 650 + .saturating_add(Weight::from_parts(1_095_835, 0).saturating_mul(k.into())) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(k.into()))) @@ -207,10 +217,10 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `325 + c * (1 ±0)` // Estimated: `6263 + c * (1 ±0)` - // Minimum execution time: 15_289_000 picoseconds. - Weight::from_parts(16_157_168, 6263) + // Minimum execution time: 14_960_000 picoseconds. + Weight::from_parts(15_778_951, 6263) // Standard Error: 1 - .saturating_add(Weight::from_parts(395, 0).saturating_mul(c.into())) + .saturating_add(Weight::from_parts(443, 0).saturating_mul(c.into())) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) .saturating_add(Weight::from_parts(0, 1).saturating_mul(c.into())) @@ -221,8 +231,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `440` // Estimated: `6380` - // Minimum execution time: 12_312_000 picoseconds. - Weight::from_parts(12_650_000, 6380) + // Minimum execution time: 11_849_000 picoseconds. + Weight::from_parts(12_273_000, 6380) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -236,8 +246,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `352` // Estimated: `6292` - // Minimum execution time: 47_239_000 picoseconds. - Weight::from_parts(48_617_000, 6292) + // Minimum execution time: 47_862_000 picoseconds. + Weight::from_parts(48_879_000, 6292) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -249,8 +259,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `594` // Estimated: `6534` - // Minimum execution time: 52_084_000 picoseconds. - Weight::from_parts(53_838_000, 6534) + // Minimum execution time: 50_754_000 picoseconds. + Weight::from_parts(52_720_000, 6534) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } @@ -260,8 +270,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `409` // Estimated: `6349` - // Minimum execution time: 11_785_000 picoseconds. - Weight::from_parts(12_284_000, 6349) + // Minimum execution time: 11_459_000 picoseconds. + Weight::from_parts(11_921_000, 6349) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -271,8 +281,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `142` // Estimated: `1627` - // Minimum execution time: 2_136_000 picoseconds. - Weight::from_parts(2_233_000, 1627) + // Minimum execution time: 2_135_000 picoseconds. + Weight::from_parts(2_247_000, 1627) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -284,8 +294,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `166` // Estimated: `3631` - // Minimum execution time: 10_957_000 picoseconds. - Weight::from_parts(11_314_000, 3631) + // Minimum execution time: 10_645_000 picoseconds. + Weight::from_parts(11_107_000, 3631) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } @@ -295,8 +305,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `142` // Estimated: `3607` - // Minimum execution time: 4_354_000 picoseconds. - Weight::from_parts(4_613_000, 3607) + // Minimum execution time: 4_353_000 picoseconds. + Weight::from_parts(4_628_000, 3607) .saturating_add(T::DbWeight::get().reads(1_u64)) } /// Storage: UNKNOWN KEY `0x4342193e496fab7ec59d615ed0dc55304e7b9012096b41c4eb3aaf947f6ea429` (r:1 w:0) @@ -307,8 +317,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `167` // Estimated: `3632` - // Minimum execution time: 5_541_000 picoseconds. - Weight::from_parts(5_790_000, 3632) + // Minimum execution time: 5_432_000 picoseconds. + Weight::from_parts(5_624_000, 3632) .saturating_add(T::DbWeight::get().reads(2_u64)) } /// Storage: UNKNOWN KEY `0x4342193e496fab7ec59d615ed0dc55304e7b9012096b41c4eb3aaf947f6ea429` (r:1 w:0) @@ -319,8 +329,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `142` // Estimated: `3607` - // Minimum execution time: 5_502_000 picoseconds. - Weight::from_parts(5_701_000, 3607) + // Minimum execution time: 5_371_000 picoseconds. + Weight::from_parts(5_794_000, 3607) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -339,12 +349,12 @@ impl WeightInfo for SubstrateWeight { /// The range of component `c` is `[0, 125952]`. fn call_with_code_per_byte(c: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `801 + c * (1 ±0)` - // Estimated: `4264 + c * (1 ±0)` - // Minimum execution time: 247_884_000 picoseconds. - Weight::from_parts(265_795_781, 4264) + // Measured: `800 + c * (1 ±0)` + // Estimated: `4266 + c * (1 ±0)` + // Minimum execution time: 247_157_000 picoseconds. + Weight::from_parts(269_252_698, 4266) // Standard Error: 4 - .saturating_add(Weight::from_parts(724, 0).saturating_mul(c.into())) + .saturating_add(Weight::from_parts(729, 0).saturating_mul(c.into())) .saturating_add(T::DbWeight::get().reads(6_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) .saturating_add(Weight::from_parts(0, 1).saturating_mul(c.into())) @@ -372,14 +382,14 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `323` // Estimated: `6262` - // Minimum execution time: 4_500_184_000 picoseconds. - Weight::from_parts(160_729_258, 6262) - // Standard Error: 143 - .saturating_add(Weight::from_parts(52_809, 0).saturating_mul(c.into())) - // Standard Error: 17 - .saturating_add(Weight::from_parts(2_173, 0).saturating_mul(i.into())) - // Standard Error: 17 - .saturating_add(Weight::from_parts(2_165, 0).saturating_mul(s.into())) + // Minimum execution time: 4_575_784_000 picoseconds. + Weight::from_parts(207_379_459, 6262) + // Standard Error: 124 + .saturating_add(Weight::from_parts(52_392, 0).saturating_mul(c.into())) + // Standard Error: 15 + .saturating_add(Weight::from_parts(2_257, 0).saturating_mul(i.into())) + // Standard Error: 15 + .saturating_add(Weight::from_parts(2_263, 0).saturating_mul(s.into())) .saturating_add(T::DbWeight::get().reads(8_u64)) .saturating_add(T::DbWeight::get().writes(7_u64)) } @@ -404,13 +414,13 @@ impl WeightInfo for SubstrateWeight { fn instantiate(i: u32, s: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `560` - // Estimated: `4029` - // Minimum execution time: 2_219_163_000 picoseconds. - Weight::from_parts(2_236_918_000, 4029) - // Standard Error: 32 - .saturating_add(Weight::from_parts(937, 0).saturating_mul(i.into())) - // Standard Error: 32 - .saturating_add(Weight::from_parts(938, 0).saturating_mul(s.into())) + // Estimated: `4017` + // Minimum execution time: 2_306_770_000 picoseconds. + Weight::from_parts(2_462_908_000, 4017) + // Standard Error: 33 + .saturating_add(Weight::from_parts(898, 0).saturating_mul(i.into())) + // Standard Error: 33 + .saturating_add(Weight::from_parts(859, 0).saturating_mul(s.into())) .saturating_add(T::DbWeight::get().reads(8_u64)) .saturating_add(T::DbWeight::get().writes(5_u64)) } @@ -430,8 +440,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `826` // Estimated: `4291` - // Minimum execution time: 164_801_000 picoseconds. - Weight::from_parts(167_250_000, 4291) + // Minimum execution time: 165_499_000 picoseconds. + Weight::from_parts(169_903_000, 4291) .saturating_add(T::DbWeight::get().reads(6_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } @@ -448,10 +458,10 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `142` // Estimated: `3607` - // Minimum execution time: 225_207_000 picoseconds. - Weight::from_parts(263_665_658, 3607) - // Standard Error: 47 - .saturating_add(Weight::from_parts(50_732, 0).saturating_mul(c.into())) + // Minimum execution time: 227_590_000 picoseconds. + Weight::from_parts(260_045_588, 3607) + // Standard Error: 52 + .saturating_add(Weight::from_parts(51_305, 0).saturating_mul(c.into())) .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -468,10 +478,10 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `142` // Estimated: `3607` - // Minimum execution time: 230_718_000 picoseconds. - Weight::from_parts(258_359_271, 3607) - // Standard Error: 47 - .saturating_add(Weight::from_parts(51_014, 0).saturating_mul(c.into())) + // Minimum execution time: 239_634_000 picoseconds. + Weight::from_parts(262_040_831, 3607) + // Standard Error: 103 + .saturating_add(Weight::from_parts(51_590, 0).saturating_mul(c.into())) .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -487,8 +497,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `315` // Estimated: `3780` - // Minimum execution time: 39_668_000 picoseconds. - Weight::from_parts(41_031_000, 3780) + // Minimum execution time: 39_152_000 picoseconds. + Weight::from_parts(39_970_000, 3780) .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -502,8 +512,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `552` // Estimated: `6492` - // Minimum execution time: 25_890_000 picoseconds. - Weight::from_parts(26_603_000, 6492) + // Minimum execution time: 25_143_000 picoseconds. + Weight::from_parts(26_103_000, 6492) .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -512,17 +522,17 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 8_269_000 picoseconds. - Weight::from_parts(9_227_069, 0) - // Standard Error: 74 - .saturating_add(Weight::from_parts(51_396, 0).saturating_mul(r.into())) + // Minimum execution time: 8_406_000 picoseconds. + Weight::from_parts(9_056_753, 0) + // Standard Error: 98 + .saturating_add(Weight::from_parts(53_110, 0).saturating_mul(r.into())) } fn seal_caller() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 602_000 picoseconds. - Weight::from_parts(664_000, 0) + // Minimum execution time: 659_000 picoseconds. + Weight::from_parts(705_000, 0) } /// Storage: `Contracts::ContractInfoOf` (r:1 w:0) /// Proof: `Contracts::ContractInfoOf` (`max_values`: None, `max_size`: Some(1795), added: 4270, mode: `Measured`) @@ -530,8 +540,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `354` // Estimated: `3819` - // Minimum execution time: 6_131_000 picoseconds. - Weight::from_parts(6_468_000, 3819) + // Minimum execution time: 6_165_000 picoseconds. + Weight::from_parts(6_340_000, 3819) .saturating_add(T::DbWeight::get().reads(1_u64)) } /// Storage: `Contracts::ContractInfoOf` (r:1 w:0) @@ -540,79 +550,79 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `447` // Estimated: `3912` - // Minimum execution time: 7_557_000 picoseconds. - Weight::from_parts(7_704_000, 3912) + // Minimum execution time: 7_398_000 picoseconds. + Weight::from_parts(7_661_000, 3912) .saturating_add(T::DbWeight::get().reads(1_u64)) } fn seal_own_code_hash() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 783_000 picoseconds. - Weight::from_parts(848_000, 0) + // Minimum execution time: 723_000 picoseconds. + Weight::from_parts(793_000, 0) } fn seal_caller_is_origin() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 397_000 picoseconds. - Weight::from_parts(435_000, 0) + // Minimum execution time: 398_000 picoseconds. + Weight::from_parts(428_000, 0) } fn seal_caller_is_root() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 351_000 picoseconds. - Weight::from_parts(372_000, 0) + // Minimum execution time: 329_000 picoseconds. + Weight::from_parts(364_000, 0) } fn seal_address() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 608_000 picoseconds. - Weight::from_parts(645_000, 0) + // Minimum execution time: 592_000 picoseconds. + Weight::from_parts(624_000, 0) } fn seal_gas_left() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 661_000 picoseconds. - Weight::from_parts(729_000, 0) + // Minimum execution time: 665_000 picoseconds. + Weight::from_parts(714_000, 0) } fn seal_balance() -> Weight { // Proof Size summary in bytes: // Measured: `140` // Estimated: `0` - // Minimum execution time: 4_545_000 picoseconds. - Weight::from_parts(4_663_000, 0) + // Minimum execution time: 4_486_000 picoseconds. + Weight::from_parts(4_668_000, 0) } fn seal_value_transferred() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 614_000 picoseconds. - Weight::from_parts(641_000, 0) + // Minimum execution time: 548_000 picoseconds. + Weight::from_parts(590_000, 0) } fn seal_minimum_balance() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 583_000 picoseconds. - Weight::from_parts(618_000, 0) + // Minimum execution time: 536_000 picoseconds. + Weight::from_parts(578_000, 0) } fn seal_block_number() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 583_000 picoseconds. - Weight::from_parts(617_000, 0) + // Minimum execution time: 552_000 picoseconds. + Weight::from_parts(599_000, 0) } fn seal_now() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 607_000 picoseconds. - Weight::from_parts(638_000, 0) + // Minimum execution time: 556_000 picoseconds. + Weight::from_parts(600_000, 0) } /// Storage: `TransactionPayment::NextFeeMultiplier` (r:1 w:0) /// Proof: `TransactionPayment::NextFeeMultiplier` (`max_values`: Some(1), `max_size`: Some(16), added: 511, mode: `Measured`) @@ -620,8 +630,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `67` // Estimated: `1552` - // Minimum execution time: 4_172_000 picoseconds. - Weight::from_parts(4_408_000, 1552) + // Minimum execution time: 4_084_000 picoseconds. + Weight::from_parts(4_321_000, 1552) .saturating_add(T::DbWeight::get().reads(1_u64)) } /// The range of component `n` is `[0, 1048572]`. @@ -629,20 +639,20 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 475_000 picoseconds. - Weight::from_parts(515_000, 0) + // Minimum execution time: 468_000 picoseconds. + Weight::from_parts(492_000, 0) // Standard Error: 3 - .saturating_add(Weight::from_parts(298, 0).saturating_mul(n.into())) + .saturating_add(Weight::from_parts(310, 0).saturating_mul(n.into())) } /// The range of component `n` is `[0, 1048572]`. fn seal_return(n: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 289_000 picoseconds. - Weight::from_parts(357_000, 0) - // Standard Error: 10 - .saturating_add(Weight::from_parts(405, 0).saturating_mul(n.into())) + // Minimum execution time: 377_000 picoseconds. + Weight::from_parts(396_000, 0) + // Standard Error: 9 + .saturating_add(Weight::from_parts(431, 0).saturating_mul(n.into())) } /// Storage: `Contracts::DeletionQueueCounter` (r:1 w:1) /// Proof: `Contracts::DeletionQueueCounter` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `Measured`) @@ -655,10 +665,10 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `319 + n * (78 ±0)` // Estimated: `3784 + n * (2553 ±0)` - // Minimum execution time: 13_316_000 picoseconds. - Weight::from_parts(15_855_821, 3784) - // Standard Error: 7_274 - .saturating_add(Weight::from_parts(3_447_246, 0).saturating_mul(n.into())) + // Minimum execution time: 13_028_000 picoseconds. + Weight::from_parts(15_330_917, 3784) + // Standard Error: 8_260 + .saturating_add(Weight::from_parts(3_594_893, 0).saturating_mul(n.into())) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(n.into()))) .saturating_add(T::DbWeight::get().writes(3_u64)) @@ -671,8 +681,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `76` // Estimated: `1561` - // Minimum execution time: 3_468_000 picoseconds. - Weight::from_parts(3_608_000, 1561) + // Minimum execution time: 3_367_000 picoseconds. + Weight::from_parts(3_555_000, 1561) .saturating_add(T::DbWeight::get().reads(1_u64)) } /// Storage: `System::EventTopics` (r:4 w:4) @@ -683,12 +693,12 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `990 + t * (2475 ±0)` - // Minimum execution time: 3_777_000 picoseconds. - Weight::from_parts(4_028_191, 990) - // Standard Error: 5_907 - .saturating_add(Weight::from_parts(2_183_733, 0).saturating_mul(t.into())) + // Minimum execution time: 3_779_000 picoseconds. + Weight::from_parts(4_003_836, 990) + // Standard Error: 5_409 + .saturating_add(Weight::from_parts(2_082_176, 0).saturating_mul(t.into())) // Standard Error: 1 - .saturating_add(Weight::from_parts(18, 0).saturating_mul(n.into())) + .saturating_add(Weight::from_parts(14, 0).saturating_mul(n.into())) .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(t.into()))) .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(t.into()))) .saturating_add(Weight::from_parts(0, 2475).saturating_mul(t.into())) @@ -698,10 +708,10 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 400_000 picoseconds. - Weight::from_parts(423_000, 0) + // Minimum execution time: 409_000 picoseconds. + Weight::from_parts(447_000, 0) // Standard Error: 10 - .saturating_add(Weight::from_parts(1_209, 0).saturating_mul(i.into())) + .saturating_add(Weight::from_parts(1_219, 0).saturating_mul(i.into())) } /// Storage: `Skipped::Metadata` (r:0 w:0) /// Proof: `Skipped::Metadata` (`max_values`: None, `max_size`: None, mode: `Measured`) @@ -711,12 +721,12 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `250 + o * (1 ±0)` // Estimated: `249 + o * (1 ±0)` - // Minimum execution time: 9_033_000 picoseconds. - Weight::from_parts(8_797_934, 249) + // Minimum execution time: 9_176_000 picoseconds. + Weight::from_parts(9_121_191, 249) // Standard Error: 1 - .saturating_add(Weight::from_parts(257, 0).saturating_mul(n.into())) + .saturating_add(Weight::from_parts(292, 0).saturating_mul(n.into())) // Standard Error: 1 - .saturating_add(Weight::from_parts(51, 0).saturating_mul(o.into())) + .saturating_add(Weight::from_parts(31, 0).saturating_mul(o.into())) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) .saturating_add(Weight::from_parts(0, 1).saturating_mul(o.into())) @@ -728,10 +738,10 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `248 + n * (1 ±0)` // Estimated: `248 + n * (1 ±0)` - // Minimum execution time: 7_167_000 picoseconds. - Weight::from_parts(8_012_194, 248) + // Minimum execution time: 7_294_000 picoseconds. + Weight::from_parts(7_963_151, 248) // Standard Error: 1 - .saturating_add(Weight::from_parts(90, 0).saturating_mul(n.into())) + .saturating_add(Weight::from_parts(92, 0).saturating_mul(n.into())) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) .saturating_add(Weight::from_parts(0, 1).saturating_mul(n.into())) @@ -743,10 +753,10 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `248 + n * (1 ±0)` // Estimated: `248 + n * (1 ±0)` - // Minimum execution time: 6_868_000 picoseconds. - Weight::from_parts(7_801_811, 248) + // Minimum execution time: 6_978_000 picoseconds. + Weight::from_parts(7_741_355, 248) // Standard Error: 1 - .saturating_add(Weight::from_parts(605, 0).saturating_mul(n.into())) + .saturating_add(Weight::from_parts(654, 0).saturating_mul(n.into())) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(Weight::from_parts(0, 1).saturating_mul(n.into())) } @@ -757,10 +767,10 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `248 + n * (1 ±0)` // Estimated: `248 + n * (1 ±0)` - // Minimum execution time: 6_322_000 picoseconds. - Weight::from_parts(7_103_552, 248) + // Minimum execution time: 6_286_000 picoseconds. + Weight::from_parts(7_026_923, 248) // Standard Error: 1 - .saturating_add(Weight::from_parts(79, 0).saturating_mul(n.into())) + .saturating_add(Weight::from_parts(86, 0).saturating_mul(n.into())) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(Weight::from_parts(0, 1).saturating_mul(n.into())) } @@ -771,20 +781,106 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `248 + n * (1 ±0)` // Estimated: `248 + n * (1 ±0)` - // Minimum execution time: 7_702_000 picoseconds. - Weight::from_parts(8_746_305, 248) - // Standard Error: 2 - .saturating_add(Weight::from_parts(604, 0).saturating_mul(n.into())) + // Minimum execution time: 7_597_000 picoseconds. + Weight::from_parts(8_706_785, 248) + // Standard Error: 1 + .saturating_add(Weight::from_parts(653, 0).saturating_mul(n.into())) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) .saturating_add(Weight::from_parts(0, 1).saturating_mul(n.into())) } + fn set_transient_storage_empty() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 1_497_000 picoseconds. + Weight::from_parts(1_564_000, 0) + } + fn set_transient_storage_full() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 2_670_000 picoseconds. + Weight::from_parts(2_807_000, 0) + } + fn get_transient_storage_empty() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 3_836_000 picoseconds. + Weight::from_parts(3_878_000, 0) + } + fn get_transient_storage_full() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 4_537_000 picoseconds. + Weight::from_parts(4_665_000, 0) + } + fn rollback_transient_storage() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 1_592_000 picoseconds. + Weight::from_parts(1_742_000, 0) + } + /// The range of component `n` is `[0, 16384]`. + /// The range of component `o` is `[0, 16384]`. + fn seal_set_transient_storage(n: u32, o: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 6_101_000 picoseconds. + Weight::from_parts(2_481_218, 0) + // Standard Error: 0 + .saturating_add(Weight::from_parts(242, 0).saturating_mul(n.into())) + // Standard Error: 0 + .saturating_add(Weight::from_parts(300, 0).saturating_mul(o.into())) + } + /// The range of component `n` is `[0, 16384]`. + fn seal_clear_transient_storage(n: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 2_059_000 picoseconds. + Weight::from_parts(2_426_609, 0) + // Standard Error: 2 + .saturating_add(Weight::from_parts(307, 0).saturating_mul(n.into())) + } + /// The range of component `n` is `[0, 16384]`. + fn seal_get_transient_storage(n: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 1_918_000 picoseconds. + Weight::from_parts(2_114_837, 0) + // Standard Error: 0 + .saturating_add(Weight::from_parts(302, 0).saturating_mul(n.into())) + } + /// The range of component `n` is `[0, 16384]`. + fn seal_contains_transient_storage(n: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 1_759_000 picoseconds. + Weight::from_parts(1_959_995, 0) + // Standard Error: 0 + .saturating_add(Weight::from_parts(147, 0).saturating_mul(n.into())) + } + /// The range of component `n` is `[0, 16384]`. + fn seal_take_transient_storage(_n: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 9_759_000 picoseconds. + Weight::from_parts(9_952_099, 0) + } fn seal_transfer() -> Weight { // Proof Size summary in bytes: // Measured: `140` // Estimated: `0` - // Minimum execution time: 8_851_000 picoseconds. - Weight::from_parts(9_083_000, 0) + // Minimum execution time: 8_700_000 picoseconds. + Weight::from_parts(8_903_000, 0) } /// Storage: `Contracts::ContractInfoOf` (r:1 w:1) /// Proof: `Contracts::ContractInfoOf` (`max_values`: None, `max_size`: Some(1795), added: 4270, mode: `Measured`) @@ -800,12 +896,12 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `620 + t * (280 ±0)` // Estimated: `4085 + t * (2182 ±0)` - // Minimum execution time: 121_148_000 picoseconds. - Weight::from_parts(119_605_377, 4085) - // Standard Error: 208_337 - .saturating_add(Weight::from_parts(43_153_338, 0).saturating_mul(t.into())) + // Minimum execution time: 123_399_000 picoseconds. + Weight::from_parts(120_909_821, 4085) + // Standard Error: 166_830 + .saturating_add(Weight::from_parts(43_853_642, 0).saturating_mul(t.into())) // Standard Error: 0 - .saturating_add(Weight::from_parts(5, 0).saturating_mul(i.into())) + .saturating_add(Weight::from_parts(6, 0).saturating_mul(i.into())) .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(t.into()))) .saturating_add(T::DbWeight::get().writes(1_u64)) @@ -820,8 +916,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `430` // Estimated: `3895` - // Minimum execution time: 108_159_000 picoseconds. - Weight::from_parts(110_027_000, 3895) + // Minimum execution time: 112_350_000 picoseconds. + Weight::from_parts(116_003_000, 3895) .saturating_add(T::DbWeight::get().reads(2_u64)) } /// Storage: `Contracts::CodeInfoOf` (r:1 w:1) @@ -839,13 +935,13 @@ impl WeightInfo for SubstrateWeight { fn seal_instantiate(i: u32, s: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `676` - // Estimated: `4127` - // Minimum execution time: 1_861_874_000 picoseconds. - Weight::from_parts(1_872_926_000, 4127) - // Standard Error: 23 - .saturating_add(Weight::from_parts(557, 0).saturating_mul(i.into())) - // Standard Error: 23 - .saturating_add(Weight::from_parts(920, 0).saturating_mul(s.into())) + // Estimated: `4132` + // Minimum execution time: 1_972_276_000 picoseconds. + Weight::from_parts(1_977_872_000, 4132) + // Standard Error: 24 + .saturating_add(Weight::from_parts(623, 0).saturating_mul(i.into())) + // Standard Error: 24 + .saturating_add(Weight::from_parts(917, 0).saturating_mul(s.into())) .saturating_add(T::DbWeight::get().reads(5_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } @@ -854,64 +950,64 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 878_000 picoseconds. - Weight::from_parts(10_993_950, 0) + // Minimum execution time: 899_000 picoseconds. + Weight::from_parts(10_963_972, 0) // Standard Error: 0 - .saturating_add(Weight::from_parts(1_325, 0).saturating_mul(n.into())) + .saturating_add(Weight::from_parts(1_355, 0).saturating_mul(n.into())) } /// The range of component `n` is `[0, 1048576]`. fn seal_hash_keccak_256(n: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 1_261_000 picoseconds. - Weight::from_parts(9_759_497, 0) + // Minimum execution time: 1_396_000 picoseconds. + Weight::from_parts(9_404_986, 0) // Standard Error: 0 - .saturating_add(Weight::from_parts(3_594, 0).saturating_mul(n.into())) + .saturating_add(Weight::from_parts(3_627, 0).saturating_mul(n.into())) } /// The range of component `n` is `[0, 1048576]`. fn seal_hash_blake2_256(n: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 726_000 picoseconds. - Weight::from_parts(9_795_728, 0) + // Minimum execution time: 834_000 picoseconds. + Weight::from_parts(9_749_716, 0) // Standard Error: 0 - .saturating_add(Weight::from_parts(1_455, 0).saturating_mul(n.into())) + .saturating_add(Weight::from_parts(1_500, 0).saturating_mul(n.into())) } /// The range of component `n` is `[0, 1048576]`. fn seal_hash_blake2_128(n: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 739_000 picoseconds. - Weight::from_parts(9_701_202, 0) + // Minimum execution time: 756_000 picoseconds. + Weight::from_parts(8_995_036, 0) // Standard Error: 0 - .saturating_add(Weight::from_parts(1_459, 0).saturating_mul(n.into())) + .saturating_add(Weight::from_parts(1_495, 0).saturating_mul(n.into())) } /// The range of component `n` is `[0, 125697]`. fn seal_sr25519_verify(n: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 43_309_000 picoseconds. - Weight::from_parts(41_405_949, 0) + // Minimum execution time: 45_800_000 picoseconds. + Weight::from_parts(44_676_829, 0) // Standard Error: 8 - .saturating_add(Weight::from_parts(5_336, 0).saturating_mul(n.into())) + .saturating_add(Weight::from_parts(5_315, 0).saturating_mul(n.into())) } fn seal_ecdsa_recover() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 47_880_000 picoseconds. - Weight::from_parts(49_025_000, 0) + // Minimum execution time: 47_415_000 picoseconds. + Weight::from_parts(48_743_000, 0) } fn seal_ecdsa_to_eth_address() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 13_462_000 picoseconds. - Weight::from_parts(13_631_000, 0) + // Minimum execution time: 13_437_000 picoseconds. + Weight::from_parts(13_588_000, 0) } /// Storage: `Contracts::CodeInfoOf` (r:1 w:1) /// Proof: `Contracts::CodeInfoOf` (`max_values`: None, `max_size`: Some(93), added: 2568, mode: `Measured`) @@ -921,8 +1017,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `430` // Estimated: `3895` - // Minimum execution time: 17_978_000 picoseconds. - Weight::from_parts(18_578_000, 3895) + // Minimum execution time: 17_775_000 picoseconds. + Weight::from_parts(18_332_000, 3895) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -932,8 +1028,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `355` // Estimated: `3820` - // Minimum execution time: 8_384_000 picoseconds. - Weight::from_parts(8_687_000, 3820) + // Minimum execution time: 8_326_000 picoseconds. + Weight::from_parts(8_656_000, 3820) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -943,8 +1039,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `355` // Estimated: `3558` - // Minimum execution time: 7_547_000 picoseconds. - Weight::from_parts(7_935_000, 3558) + // Minimum execution time: 7_276_000 picoseconds. + Weight::from_parts(7_630_000, 3558) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -952,15 +1048,15 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 331_000 picoseconds. - Weight::from_parts(363_000, 0) + // Minimum execution time: 330_000 picoseconds. + Weight::from_parts(373_000, 0) } fn seal_account_reentrance_count() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 349_000 picoseconds. - Weight::from_parts(365_000, 0) + // Minimum execution time: 381_000 picoseconds. + Weight::from_parts(418_000, 0) } /// Storage: `Contracts::Nonce` (r:1 w:0) /// Proof: `Contracts::Nonce` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `Measured`) @@ -968,8 +1064,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `219` // Estimated: `1704` - // Minimum execution time: 2_814_000 picoseconds. - Weight::from_parts(3_038_000, 1704) + // Minimum execution time: 2_711_000 picoseconds. + Weight::from_parts(2_941_000, 1704) .saturating_add(T::DbWeight::get().reads(1_u64)) } /// The range of component `r` is `[0, 5000]`. @@ -977,10 +1073,10 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 693_000 picoseconds. - Weight::from_parts(665_431, 0) - // Standard Error: 12 - .saturating_add(Weight::from_parts(7_030, 0).saturating_mul(r.into())) + // Minimum execution time: 720_000 picoseconds. + Weight::from_parts(389_111, 0) + // Standard Error: 16 + .saturating_add(Weight::from_parts(7_278, 0).saturating_mul(r.into())) } } @@ -992,8 +1088,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `142` // Estimated: `1627` - // Minimum execution time: 1_896_000 picoseconds. - Weight::from_parts(1_990_000, 1627) + // Minimum execution time: 1_921_000 picoseconds. + Weight::from_parts(2_003_000, 1627) .saturating_add(RocksDbWeight::get().reads(1_u64)) } /// Storage: `Skipped::Metadata` (r:0 w:0) @@ -1003,10 +1099,10 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `452 + k * (69 ±0)` // Estimated: `442 + k * (70 ±0)` - // Minimum execution time: 11_142_000 picoseconds. - Weight::from_parts(11_578_000, 442) - // Standard Error: 1_557 - .saturating_add(Weight::from_parts(1_165_198, 0).saturating_mul(k.into())) + // Minimum execution time: 11_364_000 picoseconds. + Weight::from_parts(11_463_000, 442) + // Standard Error: 2_141 + .saturating_add(Weight::from_parts(1_149_944, 0).saturating_mul(k.into())) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().reads((1_u64).saturating_mul(k.into()))) .saturating_add(RocksDbWeight::get().writes(2_u64)) @@ -1020,10 +1116,10 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `211 + c * (1 ±0)` // Estimated: `6149 + c * (1 ±0)` - // Minimum execution time: 7_649_000 picoseconds. - Weight::from_parts(4_827_445, 6149) + // Minimum execution time: 7_565_000 picoseconds. + Weight::from_parts(5_041_009, 6149) // Standard Error: 5 - .saturating_add(Weight::from_parts(1_630, 0).saturating_mul(c.into())) + .saturating_add(Weight::from_parts(1_640, 0).saturating_mul(c.into())) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) .saturating_add(Weight::from_parts(0, 1).saturating_mul(c.into())) @@ -1036,8 +1132,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `510` // Estimated: `6450` - // Minimum execution time: 16_096_000 picoseconds. - Weight::from_parts(16_937_000, 6450) + // Minimum execution time: 15_894_000 picoseconds. + Weight::from_parts(16_618_000, 6450) .saturating_add(RocksDbWeight::get().reads(3_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -1050,10 +1146,10 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `171 + k * (1 ±0)` // Estimated: `3635 + k * (1 ±0)` - // Minimum execution time: 3_131_000 picoseconds. - Weight::from_parts(3_209_000, 3635) - // Standard Error: 481 - .saturating_add(Weight::from_parts(1_087_506, 0).saturating_mul(k.into())) + // Minimum execution time: 3_077_000 picoseconds. + Weight::from_parts(3_144_000, 3635) + // Standard Error: 650 + .saturating_add(Weight::from_parts(1_095_835, 0).saturating_mul(k.into())) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) .saturating_add(RocksDbWeight::get().writes((1_u64).saturating_mul(k.into()))) @@ -1072,10 +1168,10 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `325 + c * (1 ±0)` // Estimated: `6263 + c * (1 ±0)` - // Minimum execution time: 15_289_000 picoseconds. - Weight::from_parts(16_157_168, 6263) + // Minimum execution time: 14_960_000 picoseconds. + Weight::from_parts(15_778_951, 6263) // Standard Error: 1 - .saturating_add(Weight::from_parts(395, 0).saturating_mul(c.into())) + .saturating_add(Weight::from_parts(443, 0).saturating_mul(c.into())) .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) .saturating_add(Weight::from_parts(0, 1).saturating_mul(c.into())) @@ -1086,8 +1182,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `440` // Estimated: `6380` - // Minimum execution time: 12_312_000 picoseconds. - Weight::from_parts(12_650_000, 6380) + // Minimum execution time: 11_849_000 picoseconds. + Weight::from_parts(12_273_000, 6380) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -1101,8 +1197,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `352` // Estimated: `6292` - // Minimum execution time: 47_239_000 picoseconds. - Weight::from_parts(48_617_000, 6292) + // Minimum execution time: 47_862_000 picoseconds. + Weight::from_parts(48_879_000, 6292) .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -1114,8 +1210,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `594` // Estimated: `6534` - // Minimum execution time: 52_084_000 picoseconds. - Weight::from_parts(53_838_000, 6534) + // Minimum execution time: 50_754_000 picoseconds. + Weight::from_parts(52_720_000, 6534) .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } @@ -1125,8 +1221,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `409` // Estimated: `6349` - // Minimum execution time: 11_785_000 picoseconds. - Weight::from_parts(12_284_000, 6349) + // Minimum execution time: 11_459_000 picoseconds. + Weight::from_parts(11_921_000, 6349) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -1136,8 +1232,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `142` // Estimated: `1627` - // Minimum execution time: 2_136_000 picoseconds. - Weight::from_parts(2_233_000, 1627) + // Minimum execution time: 2_135_000 picoseconds. + Weight::from_parts(2_247_000, 1627) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -1149,8 +1245,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `166` // Estimated: `3631` - // Minimum execution time: 10_957_000 picoseconds. - Weight::from_parts(11_314_000, 3631) + // Minimum execution time: 10_645_000 picoseconds. + Weight::from_parts(11_107_000, 3631) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } @@ -1160,8 +1256,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `142` // Estimated: `3607` - // Minimum execution time: 4_354_000 picoseconds. - Weight::from_parts(4_613_000, 3607) + // Minimum execution time: 4_353_000 picoseconds. + Weight::from_parts(4_628_000, 3607) .saturating_add(RocksDbWeight::get().reads(1_u64)) } /// Storage: UNKNOWN KEY `0x4342193e496fab7ec59d615ed0dc55304e7b9012096b41c4eb3aaf947f6ea429` (r:1 w:0) @@ -1172,8 +1268,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `167` // Estimated: `3632` - // Minimum execution time: 5_541_000 picoseconds. - Weight::from_parts(5_790_000, 3632) + // Minimum execution time: 5_432_000 picoseconds. + Weight::from_parts(5_624_000, 3632) .saturating_add(RocksDbWeight::get().reads(2_u64)) } /// Storage: UNKNOWN KEY `0x4342193e496fab7ec59d615ed0dc55304e7b9012096b41c4eb3aaf947f6ea429` (r:1 w:0) @@ -1184,8 +1280,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `142` // Estimated: `3607` - // Minimum execution time: 5_502_000 picoseconds. - Weight::from_parts(5_701_000, 3607) + // Minimum execution time: 5_371_000 picoseconds. + Weight::from_parts(5_794_000, 3607) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -1204,12 +1300,12 @@ impl WeightInfo for () { /// The range of component `c` is `[0, 125952]`. fn call_with_code_per_byte(c: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `801 + c * (1 ±0)` - // Estimated: `4264 + c * (1 ±0)` - // Minimum execution time: 247_884_000 picoseconds. - Weight::from_parts(265_795_781, 4264) + // Measured: `800 + c * (1 ±0)` + // Estimated: `4266 + c * (1 ±0)` + // Minimum execution time: 247_157_000 picoseconds. + Weight::from_parts(269_252_698, 4266) // Standard Error: 4 - .saturating_add(Weight::from_parts(724, 0).saturating_mul(c.into())) + .saturating_add(Weight::from_parts(729, 0).saturating_mul(c.into())) .saturating_add(RocksDbWeight::get().reads(6_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) .saturating_add(Weight::from_parts(0, 1).saturating_mul(c.into())) @@ -1237,14 +1333,14 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `323` // Estimated: `6262` - // Minimum execution time: 4_500_184_000 picoseconds. - Weight::from_parts(160_729_258, 6262) - // Standard Error: 143 - .saturating_add(Weight::from_parts(52_809, 0).saturating_mul(c.into())) - // Standard Error: 17 - .saturating_add(Weight::from_parts(2_173, 0).saturating_mul(i.into())) - // Standard Error: 17 - .saturating_add(Weight::from_parts(2_165, 0).saturating_mul(s.into())) + // Minimum execution time: 4_575_784_000 picoseconds. + Weight::from_parts(207_379_459, 6262) + // Standard Error: 124 + .saturating_add(Weight::from_parts(52_392, 0).saturating_mul(c.into())) + // Standard Error: 15 + .saturating_add(Weight::from_parts(2_257, 0).saturating_mul(i.into())) + // Standard Error: 15 + .saturating_add(Weight::from_parts(2_263, 0).saturating_mul(s.into())) .saturating_add(RocksDbWeight::get().reads(8_u64)) .saturating_add(RocksDbWeight::get().writes(7_u64)) } @@ -1269,13 +1365,13 @@ impl WeightInfo for () { fn instantiate(i: u32, s: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `560` - // Estimated: `4029` - // Minimum execution time: 2_219_163_000 picoseconds. - Weight::from_parts(2_236_918_000, 4029) - // Standard Error: 32 - .saturating_add(Weight::from_parts(937, 0).saturating_mul(i.into())) - // Standard Error: 32 - .saturating_add(Weight::from_parts(938, 0).saturating_mul(s.into())) + // Estimated: `4017` + // Minimum execution time: 2_306_770_000 picoseconds. + Weight::from_parts(2_462_908_000, 4017) + // Standard Error: 33 + .saturating_add(Weight::from_parts(898, 0).saturating_mul(i.into())) + // Standard Error: 33 + .saturating_add(Weight::from_parts(859, 0).saturating_mul(s.into())) .saturating_add(RocksDbWeight::get().reads(8_u64)) .saturating_add(RocksDbWeight::get().writes(5_u64)) } @@ -1295,8 +1391,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `826` // Estimated: `4291` - // Minimum execution time: 164_801_000 picoseconds. - Weight::from_parts(167_250_000, 4291) + // Minimum execution time: 165_499_000 picoseconds. + Weight::from_parts(169_903_000, 4291) .saturating_add(RocksDbWeight::get().reads(6_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } @@ -1313,10 +1409,10 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `142` // Estimated: `3607` - // Minimum execution time: 225_207_000 picoseconds. - Weight::from_parts(263_665_658, 3607) - // Standard Error: 47 - .saturating_add(Weight::from_parts(50_732, 0).saturating_mul(c.into())) + // Minimum execution time: 227_590_000 picoseconds. + Weight::from_parts(260_045_588, 3607) + // Standard Error: 52 + .saturating_add(Weight::from_parts(51_305, 0).saturating_mul(c.into())) .saturating_add(RocksDbWeight::get().reads(3_u64)) .saturating_add(RocksDbWeight::get().writes(3_u64)) } @@ -1333,10 +1429,10 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `142` // Estimated: `3607` - // Minimum execution time: 230_718_000 picoseconds. - Weight::from_parts(258_359_271, 3607) - // Standard Error: 47 - .saturating_add(Weight::from_parts(51_014, 0).saturating_mul(c.into())) + // Minimum execution time: 239_634_000 picoseconds. + Weight::from_parts(262_040_831, 3607) + // Standard Error: 103 + .saturating_add(Weight::from_parts(51_590, 0).saturating_mul(c.into())) .saturating_add(RocksDbWeight::get().reads(3_u64)) .saturating_add(RocksDbWeight::get().writes(3_u64)) } @@ -1352,8 +1448,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `315` // Estimated: `3780` - // Minimum execution time: 39_668_000 picoseconds. - Weight::from_parts(41_031_000, 3780) + // Minimum execution time: 39_152_000 picoseconds. + Weight::from_parts(39_970_000, 3780) .saturating_add(RocksDbWeight::get().reads(3_u64)) .saturating_add(RocksDbWeight::get().writes(3_u64)) } @@ -1367,8 +1463,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `552` // Estimated: `6492` - // Minimum execution time: 25_890_000 picoseconds. - Weight::from_parts(26_603_000, 6492) + // Minimum execution time: 25_143_000 picoseconds. + Weight::from_parts(26_103_000, 6492) .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(3_u64)) } @@ -1377,17 +1473,17 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 8_269_000 picoseconds. - Weight::from_parts(9_227_069, 0) - // Standard Error: 74 - .saturating_add(Weight::from_parts(51_396, 0).saturating_mul(r.into())) + // Minimum execution time: 8_406_000 picoseconds. + Weight::from_parts(9_056_753, 0) + // Standard Error: 98 + .saturating_add(Weight::from_parts(53_110, 0).saturating_mul(r.into())) } fn seal_caller() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 602_000 picoseconds. - Weight::from_parts(664_000, 0) + // Minimum execution time: 659_000 picoseconds. + Weight::from_parts(705_000, 0) } /// Storage: `Contracts::ContractInfoOf` (r:1 w:0) /// Proof: `Contracts::ContractInfoOf` (`max_values`: None, `max_size`: Some(1795), added: 4270, mode: `Measured`) @@ -1395,8 +1491,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `354` // Estimated: `3819` - // Minimum execution time: 6_131_000 picoseconds. - Weight::from_parts(6_468_000, 3819) + // Minimum execution time: 6_165_000 picoseconds. + Weight::from_parts(6_340_000, 3819) .saturating_add(RocksDbWeight::get().reads(1_u64)) } /// Storage: `Contracts::ContractInfoOf` (r:1 w:0) @@ -1405,79 +1501,79 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `447` // Estimated: `3912` - // Minimum execution time: 7_557_000 picoseconds. - Weight::from_parts(7_704_000, 3912) + // Minimum execution time: 7_398_000 picoseconds. + Weight::from_parts(7_661_000, 3912) .saturating_add(RocksDbWeight::get().reads(1_u64)) } fn seal_own_code_hash() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 783_000 picoseconds. - Weight::from_parts(848_000, 0) + // Minimum execution time: 723_000 picoseconds. + Weight::from_parts(793_000, 0) } fn seal_caller_is_origin() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 397_000 picoseconds. - Weight::from_parts(435_000, 0) + // Minimum execution time: 398_000 picoseconds. + Weight::from_parts(428_000, 0) } fn seal_caller_is_root() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 351_000 picoseconds. - Weight::from_parts(372_000, 0) + // Minimum execution time: 329_000 picoseconds. + Weight::from_parts(364_000, 0) } fn seal_address() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 608_000 picoseconds. - Weight::from_parts(645_000, 0) + // Minimum execution time: 592_000 picoseconds. + Weight::from_parts(624_000, 0) } fn seal_gas_left() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 661_000 picoseconds. - Weight::from_parts(729_000, 0) + // Minimum execution time: 665_000 picoseconds. + Weight::from_parts(714_000, 0) } fn seal_balance() -> Weight { // Proof Size summary in bytes: // Measured: `140` // Estimated: `0` - // Minimum execution time: 4_545_000 picoseconds. - Weight::from_parts(4_663_000, 0) + // Minimum execution time: 4_486_000 picoseconds. + Weight::from_parts(4_668_000, 0) } fn seal_value_transferred() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 614_000 picoseconds. - Weight::from_parts(641_000, 0) + // Minimum execution time: 548_000 picoseconds. + Weight::from_parts(590_000, 0) } fn seal_minimum_balance() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 583_000 picoseconds. - Weight::from_parts(618_000, 0) + // Minimum execution time: 536_000 picoseconds. + Weight::from_parts(578_000, 0) } fn seal_block_number() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 583_000 picoseconds. - Weight::from_parts(617_000, 0) + // Minimum execution time: 552_000 picoseconds. + Weight::from_parts(599_000, 0) } fn seal_now() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 607_000 picoseconds. - Weight::from_parts(638_000, 0) + // Minimum execution time: 556_000 picoseconds. + Weight::from_parts(600_000, 0) } /// Storage: `TransactionPayment::NextFeeMultiplier` (r:1 w:0) /// Proof: `TransactionPayment::NextFeeMultiplier` (`max_values`: Some(1), `max_size`: Some(16), added: 511, mode: `Measured`) @@ -1485,8 +1581,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `67` // Estimated: `1552` - // Minimum execution time: 4_172_000 picoseconds. - Weight::from_parts(4_408_000, 1552) + // Minimum execution time: 4_084_000 picoseconds. + Weight::from_parts(4_321_000, 1552) .saturating_add(RocksDbWeight::get().reads(1_u64)) } /// The range of component `n` is `[0, 1048572]`. @@ -1494,20 +1590,20 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 475_000 picoseconds. - Weight::from_parts(515_000, 0) + // Minimum execution time: 468_000 picoseconds. + Weight::from_parts(492_000, 0) // Standard Error: 3 - .saturating_add(Weight::from_parts(298, 0).saturating_mul(n.into())) + .saturating_add(Weight::from_parts(310, 0).saturating_mul(n.into())) } /// The range of component `n` is `[0, 1048572]`. fn seal_return(n: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 289_000 picoseconds. - Weight::from_parts(357_000, 0) - // Standard Error: 10 - .saturating_add(Weight::from_parts(405, 0).saturating_mul(n.into())) + // Minimum execution time: 377_000 picoseconds. + Weight::from_parts(396_000, 0) + // Standard Error: 9 + .saturating_add(Weight::from_parts(431, 0).saturating_mul(n.into())) } /// Storage: `Contracts::DeletionQueueCounter` (r:1 w:1) /// Proof: `Contracts::DeletionQueueCounter` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `Measured`) @@ -1520,10 +1616,10 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `319 + n * (78 ±0)` // Estimated: `3784 + n * (2553 ±0)` - // Minimum execution time: 13_316_000 picoseconds. - Weight::from_parts(15_855_821, 3784) - // Standard Error: 7_274 - .saturating_add(Weight::from_parts(3_447_246, 0).saturating_mul(n.into())) + // Minimum execution time: 13_028_000 picoseconds. + Weight::from_parts(15_330_917, 3784) + // Standard Error: 8_260 + .saturating_add(Weight::from_parts(3_594_893, 0).saturating_mul(n.into())) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().reads((1_u64).saturating_mul(n.into()))) .saturating_add(RocksDbWeight::get().writes(3_u64)) @@ -1536,8 +1632,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `76` // Estimated: `1561` - // Minimum execution time: 3_468_000 picoseconds. - Weight::from_parts(3_608_000, 1561) + // Minimum execution time: 3_367_000 picoseconds. + Weight::from_parts(3_555_000, 1561) .saturating_add(RocksDbWeight::get().reads(1_u64)) } /// Storage: `System::EventTopics` (r:4 w:4) @@ -1548,12 +1644,12 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `0` // Estimated: `990 + t * (2475 ±0)` - // Minimum execution time: 3_777_000 picoseconds. - Weight::from_parts(4_028_191, 990) - // Standard Error: 5_907 - .saturating_add(Weight::from_parts(2_183_733, 0).saturating_mul(t.into())) + // Minimum execution time: 3_779_000 picoseconds. + Weight::from_parts(4_003_836, 990) + // Standard Error: 5_409 + .saturating_add(Weight::from_parts(2_082_176, 0).saturating_mul(t.into())) // Standard Error: 1 - .saturating_add(Weight::from_parts(18, 0).saturating_mul(n.into())) + .saturating_add(Weight::from_parts(14, 0).saturating_mul(n.into())) .saturating_add(RocksDbWeight::get().reads((1_u64).saturating_mul(t.into()))) .saturating_add(RocksDbWeight::get().writes((1_u64).saturating_mul(t.into()))) .saturating_add(Weight::from_parts(0, 2475).saturating_mul(t.into())) @@ -1563,10 +1659,10 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 400_000 picoseconds. - Weight::from_parts(423_000, 0) + // Minimum execution time: 409_000 picoseconds. + Weight::from_parts(447_000, 0) // Standard Error: 10 - .saturating_add(Weight::from_parts(1_209, 0).saturating_mul(i.into())) + .saturating_add(Weight::from_parts(1_219, 0).saturating_mul(i.into())) } /// Storage: `Skipped::Metadata` (r:0 w:0) /// Proof: `Skipped::Metadata` (`max_values`: None, `max_size`: None, mode: `Measured`) @@ -1576,12 +1672,12 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `250 + o * (1 ±0)` // Estimated: `249 + o * (1 ±0)` - // Minimum execution time: 9_033_000 picoseconds. - Weight::from_parts(8_797_934, 249) + // Minimum execution time: 9_176_000 picoseconds. + Weight::from_parts(9_121_191, 249) // Standard Error: 1 - .saturating_add(Weight::from_parts(257, 0).saturating_mul(n.into())) + .saturating_add(Weight::from_parts(292, 0).saturating_mul(n.into())) // Standard Error: 1 - .saturating_add(Weight::from_parts(51, 0).saturating_mul(o.into())) + .saturating_add(Weight::from_parts(31, 0).saturating_mul(o.into())) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) .saturating_add(Weight::from_parts(0, 1).saturating_mul(o.into())) @@ -1593,10 +1689,10 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `248 + n * (1 ±0)` // Estimated: `248 + n * (1 ±0)` - // Minimum execution time: 7_167_000 picoseconds. - Weight::from_parts(8_012_194, 248) + // Minimum execution time: 7_294_000 picoseconds. + Weight::from_parts(7_963_151, 248) // Standard Error: 1 - .saturating_add(Weight::from_parts(90, 0).saturating_mul(n.into())) + .saturating_add(Weight::from_parts(92, 0).saturating_mul(n.into())) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) .saturating_add(Weight::from_parts(0, 1).saturating_mul(n.into())) @@ -1608,10 +1704,10 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `248 + n * (1 ±0)` // Estimated: `248 + n * (1 ±0)` - // Minimum execution time: 6_868_000 picoseconds. - Weight::from_parts(7_801_811, 248) + // Minimum execution time: 6_978_000 picoseconds. + Weight::from_parts(7_741_355, 248) // Standard Error: 1 - .saturating_add(Weight::from_parts(605, 0).saturating_mul(n.into())) + .saturating_add(Weight::from_parts(654, 0).saturating_mul(n.into())) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(Weight::from_parts(0, 1).saturating_mul(n.into())) } @@ -1622,10 +1718,10 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `248 + n * (1 ±0)` // Estimated: `248 + n * (1 ±0)` - // Minimum execution time: 6_322_000 picoseconds. - Weight::from_parts(7_103_552, 248) + // Minimum execution time: 6_286_000 picoseconds. + Weight::from_parts(7_026_923, 248) // Standard Error: 1 - .saturating_add(Weight::from_parts(79, 0).saturating_mul(n.into())) + .saturating_add(Weight::from_parts(86, 0).saturating_mul(n.into())) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(Weight::from_parts(0, 1).saturating_mul(n.into())) } @@ -1636,20 +1732,106 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `248 + n * (1 ±0)` // Estimated: `248 + n * (1 ±0)` - // Minimum execution time: 7_702_000 picoseconds. - Weight::from_parts(8_746_305, 248) - // Standard Error: 2 - .saturating_add(Weight::from_parts(604, 0).saturating_mul(n.into())) + // Minimum execution time: 7_597_000 picoseconds. + Weight::from_parts(8_706_785, 248) + // Standard Error: 1 + .saturating_add(Weight::from_parts(653, 0).saturating_mul(n.into())) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) .saturating_add(Weight::from_parts(0, 1).saturating_mul(n.into())) } + fn set_transient_storage_empty() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 1_497_000 picoseconds. + Weight::from_parts(1_564_000, 0) + } + fn set_transient_storage_full() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 2_670_000 picoseconds. + Weight::from_parts(2_807_000, 0) + } + fn get_transient_storage_empty() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 3_836_000 picoseconds. + Weight::from_parts(3_878_000, 0) + } + fn get_transient_storage_full() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 4_537_000 picoseconds. + Weight::from_parts(4_665_000, 0) + } + fn rollback_transient_storage() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 1_592_000 picoseconds. + Weight::from_parts(1_742_000, 0) + } + /// The range of component `n` is `[0, 16384]`. + /// The range of component `o` is `[0, 16384]`. + fn seal_set_transient_storage(n: u32, o: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 6_101_000 picoseconds. + Weight::from_parts(2_481_218, 0) + // Standard Error: 0 + .saturating_add(Weight::from_parts(242, 0).saturating_mul(n.into())) + // Standard Error: 0 + .saturating_add(Weight::from_parts(300, 0).saturating_mul(o.into())) + } + /// The range of component `n` is `[0, 16384]`. + fn seal_clear_transient_storage(n: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 2_059_000 picoseconds. + Weight::from_parts(2_426_609, 0) + // Standard Error: 2 + .saturating_add(Weight::from_parts(307, 0).saturating_mul(n.into())) + } + /// The range of component `n` is `[0, 16384]`. + fn seal_get_transient_storage(n: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 1_918_000 picoseconds. + Weight::from_parts(2_114_837, 0) + // Standard Error: 0 + .saturating_add(Weight::from_parts(302, 0).saturating_mul(n.into())) + } + /// The range of component `n` is `[0, 16384]`. + fn seal_contains_transient_storage(n: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 1_759_000 picoseconds. + Weight::from_parts(1_959_995, 0) + // Standard Error: 0 + .saturating_add(Weight::from_parts(147, 0).saturating_mul(n.into())) + } + /// The range of component `n` is `[0, 16384]`. + fn seal_take_transient_storage(_n: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 9_759_000 picoseconds. + Weight::from_parts(9_952_099, 0) + } fn seal_transfer() -> Weight { // Proof Size summary in bytes: // Measured: `140` // Estimated: `0` - // Minimum execution time: 8_851_000 picoseconds. - Weight::from_parts(9_083_000, 0) + // Minimum execution time: 8_700_000 picoseconds. + Weight::from_parts(8_903_000, 0) } /// Storage: `Contracts::ContractInfoOf` (r:1 w:1) /// Proof: `Contracts::ContractInfoOf` (`max_values`: None, `max_size`: Some(1795), added: 4270, mode: `Measured`) @@ -1665,12 +1847,12 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `620 + t * (280 ±0)` // Estimated: `4085 + t * (2182 ±0)` - // Minimum execution time: 121_148_000 picoseconds. - Weight::from_parts(119_605_377, 4085) - // Standard Error: 208_337 - .saturating_add(Weight::from_parts(43_153_338, 0).saturating_mul(t.into())) + // Minimum execution time: 123_399_000 picoseconds. + Weight::from_parts(120_909_821, 4085) + // Standard Error: 166_830 + .saturating_add(Weight::from_parts(43_853_642, 0).saturating_mul(t.into())) // Standard Error: 0 - .saturating_add(Weight::from_parts(5, 0).saturating_mul(i.into())) + .saturating_add(Weight::from_parts(6, 0).saturating_mul(i.into())) .saturating_add(RocksDbWeight::get().reads(3_u64)) .saturating_add(RocksDbWeight::get().reads((1_u64).saturating_mul(t.into()))) .saturating_add(RocksDbWeight::get().writes(1_u64)) @@ -1685,8 +1867,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `430` // Estimated: `3895` - // Minimum execution time: 108_159_000 picoseconds. - Weight::from_parts(110_027_000, 3895) + // Minimum execution time: 112_350_000 picoseconds. + Weight::from_parts(116_003_000, 3895) .saturating_add(RocksDbWeight::get().reads(2_u64)) } /// Storage: `Contracts::CodeInfoOf` (r:1 w:1) @@ -1704,13 +1886,13 @@ impl WeightInfo for () { fn seal_instantiate(i: u32, s: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `676` - // Estimated: `4127` - // Minimum execution time: 1_861_874_000 picoseconds. - Weight::from_parts(1_872_926_000, 4127) - // Standard Error: 23 - .saturating_add(Weight::from_parts(557, 0).saturating_mul(i.into())) - // Standard Error: 23 - .saturating_add(Weight::from_parts(920, 0).saturating_mul(s.into())) + // Estimated: `4132` + // Minimum execution time: 1_972_276_000 picoseconds. + Weight::from_parts(1_977_872_000, 4132) + // Standard Error: 24 + .saturating_add(Weight::from_parts(623, 0).saturating_mul(i.into())) + // Standard Error: 24 + .saturating_add(Weight::from_parts(917, 0).saturating_mul(s.into())) .saturating_add(RocksDbWeight::get().reads(5_u64)) .saturating_add(RocksDbWeight::get().writes(3_u64)) } @@ -1719,64 +1901,64 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 878_000 picoseconds. - Weight::from_parts(10_993_950, 0) + // Minimum execution time: 899_000 picoseconds. + Weight::from_parts(10_963_972, 0) // Standard Error: 0 - .saturating_add(Weight::from_parts(1_325, 0).saturating_mul(n.into())) + .saturating_add(Weight::from_parts(1_355, 0).saturating_mul(n.into())) } /// The range of component `n` is `[0, 1048576]`. fn seal_hash_keccak_256(n: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 1_261_000 picoseconds. - Weight::from_parts(9_759_497, 0) + // Minimum execution time: 1_396_000 picoseconds. + Weight::from_parts(9_404_986, 0) // Standard Error: 0 - .saturating_add(Weight::from_parts(3_594, 0).saturating_mul(n.into())) + .saturating_add(Weight::from_parts(3_627, 0).saturating_mul(n.into())) } /// The range of component `n` is `[0, 1048576]`. fn seal_hash_blake2_256(n: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 726_000 picoseconds. - Weight::from_parts(9_795_728, 0) + // Minimum execution time: 834_000 picoseconds. + Weight::from_parts(9_749_716, 0) // Standard Error: 0 - .saturating_add(Weight::from_parts(1_455, 0).saturating_mul(n.into())) + .saturating_add(Weight::from_parts(1_500, 0).saturating_mul(n.into())) } /// The range of component `n` is `[0, 1048576]`. fn seal_hash_blake2_128(n: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 739_000 picoseconds. - Weight::from_parts(9_701_202, 0) + // Minimum execution time: 756_000 picoseconds. + Weight::from_parts(8_995_036, 0) // Standard Error: 0 - .saturating_add(Weight::from_parts(1_459, 0).saturating_mul(n.into())) + .saturating_add(Weight::from_parts(1_495, 0).saturating_mul(n.into())) } /// The range of component `n` is `[0, 125697]`. fn seal_sr25519_verify(n: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 43_309_000 picoseconds. - Weight::from_parts(41_405_949, 0) + // Minimum execution time: 45_800_000 picoseconds. + Weight::from_parts(44_676_829, 0) // Standard Error: 8 - .saturating_add(Weight::from_parts(5_336, 0).saturating_mul(n.into())) + .saturating_add(Weight::from_parts(5_315, 0).saturating_mul(n.into())) } fn seal_ecdsa_recover() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 47_880_000 picoseconds. - Weight::from_parts(49_025_000, 0) + // Minimum execution time: 47_415_000 picoseconds. + Weight::from_parts(48_743_000, 0) } fn seal_ecdsa_to_eth_address() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 13_462_000 picoseconds. - Weight::from_parts(13_631_000, 0) + // Minimum execution time: 13_437_000 picoseconds. + Weight::from_parts(13_588_000, 0) } /// Storage: `Contracts::CodeInfoOf` (r:1 w:1) /// Proof: `Contracts::CodeInfoOf` (`max_values`: None, `max_size`: Some(93), added: 2568, mode: `Measured`) @@ -1786,8 +1968,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `430` // Estimated: `3895` - // Minimum execution time: 17_978_000 picoseconds. - Weight::from_parts(18_578_000, 3895) + // Minimum execution time: 17_775_000 picoseconds. + Weight::from_parts(18_332_000, 3895) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -1797,8 +1979,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `355` // Estimated: `3820` - // Minimum execution time: 8_384_000 picoseconds. - Weight::from_parts(8_687_000, 3820) + // Minimum execution time: 8_326_000 picoseconds. + Weight::from_parts(8_656_000, 3820) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -1808,8 +1990,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `355` // Estimated: `3558` - // Minimum execution time: 7_547_000 picoseconds. - Weight::from_parts(7_935_000, 3558) + // Minimum execution time: 7_276_000 picoseconds. + Weight::from_parts(7_630_000, 3558) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -1817,15 +1999,15 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 331_000 picoseconds. - Weight::from_parts(363_000, 0) + // Minimum execution time: 330_000 picoseconds. + Weight::from_parts(373_000, 0) } fn seal_account_reentrance_count() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 349_000 picoseconds. - Weight::from_parts(365_000, 0) + // Minimum execution time: 381_000 picoseconds. + Weight::from_parts(418_000, 0) } /// Storage: `Contracts::Nonce` (r:1 w:0) /// Proof: `Contracts::Nonce` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `Measured`) @@ -1833,8 +2015,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `219` // Estimated: `1704` - // Minimum execution time: 2_814_000 picoseconds. - Weight::from_parts(3_038_000, 1704) + // Minimum execution time: 2_711_000 picoseconds. + Weight::from_parts(2_941_000, 1704) .saturating_add(RocksDbWeight::get().reads(1_u64)) } /// The range of component `r` is `[0, 5000]`. @@ -1842,9 +2024,9 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 693_000 picoseconds. - Weight::from_parts(665_431, 0) - // Standard Error: 12 - .saturating_add(Weight::from_parts(7_030, 0).saturating_mul(r.into())) + // Minimum execution time: 720_000 picoseconds. + Weight::from_parts(389_111, 0) + // Standard Error: 16 + .saturating_add(Weight::from_parts(7_278, 0).saturating_mul(r.into())) } } diff --git a/substrate/frame/contracts/uapi/src/host.rs b/substrate/frame/contracts/uapi/src/host.rs index 92065eda5d63..51f0cd7eb2dc 100644 --- a/substrate/frame/contracts/uapi/src/host.rs +++ b/substrate/frame/contracts/uapi/src/host.rs @@ -67,7 +67,7 @@ fn ptr_or_sentinel(data: &Option<&[u8]>) -> *const u8 { pub enum HostFnImpl {} /// Defines all the host apis implemented by both wasm and RISC-V vms. -pub trait HostFn { +pub trait HostFn: private::Sealed { /// Returns the number of times specified contract exists on the call stack. Delegated calls are /// not counted as separate calls. /// @@ -292,6 +292,20 @@ pub trait HostFn { /// Returns the size of the pre-existing value at the specified key if any. fn clear_storage_v1(key: &[u8]) -> Option; + /// Clear the value at the given key in the contract transient storage. + /// + /// # Parameters + /// + /// - `key`: The storage key. + /// + /// # Return + /// + /// Returns the size of the pre-existing value at the specified key if any. + #[deprecated( + note = "Unstable function. Behaviour can change without further notice. Use only for testing." + )] + fn clear_transient_storage(key: &[u8]) -> Option; + /// Retrieve the code hash for a specified contract address. /// /// # Parameters @@ -324,6 +338,21 @@ pub trait HostFn { /// Returns the size of the pre-existing value at the specified key if any. fn contains_storage_v1(key: &[u8]) -> Option; + /// Checks whether there is a value stored under the given key in transient storage. + /// + /// The key length must not exceed the maximum defined by the contracts module parameter. + /// + /// # Parameters + /// - `key`: The storage key. + /// + /// # Return + /// + /// Returns the size of the pre-existing value at the specified key if any. + #[deprecated( + note = "Unstable function. Behaviour can change without further notice. Use only for testing." + )] + fn contains_transient_storage(key: &[u8]) -> Option; + /// Emit a custom debug message. /// /// No newlines are added to the supplied message. @@ -453,6 +482,22 @@ pub trait HostFn { /// [KeyNotFound][`crate::ReturnErrorCode::KeyNotFound] fn get_storage_v1(key: &[u8], output: &mut &mut [u8]) -> Result; + /// Retrieve the value under the given key from transient storage. + /// + /// The key length must not exceed the maximum defined by the contracts module parameter. + /// + /// # Parameters + /// - `key`: The storage key. + /// - `output`: A reference to the output data buffer to write the storage entry. + /// + /// # Errors + /// + /// [KeyNotFound][`crate::ReturnErrorCode::KeyNotFound] + #[deprecated( + note = "Unstable function. Behaviour can change without further notice. Use only for testing." + )] + fn get_transient_storage(key: &[u8], output: &mut &mut [u8]) -> Result; + hash_fn!(sha2_256, 32); hash_fn!(keccak_256, 32); hash_fn!(blake2_256, 32); @@ -673,6 +718,24 @@ pub trait HostFn { /// Returns the size of the pre-existing value at the specified key if any. fn set_storage_v2(key: &[u8], value: &[u8]) -> Option; + /// Set the value at the given key in the contract transient storage. + /// + /// The key and value lengths must not exceed the maximums defined by the contracts module + /// parameters. + /// + /// # Parameters + /// + /// - `key`: The storage key. + /// - `encoded_value`: The storage value. + /// + /// # Return + /// + /// Returns the size of the pre-existing value at the specified key if any. + #[deprecated( + note = "Unstable function. Behaviour can change without further notice. Use only for testing." + )] + fn set_transient_storage(key: &[u8], value: &[u8]) -> Option; + /// Verify a sr25519 signature /// /// # Parameters @@ -696,6 +759,20 @@ pub trait HostFn { /// [KeyNotFound][`crate::ReturnErrorCode::KeyNotFound] fn take_storage(key: &[u8], output: &mut &mut [u8]) -> Result; + /// Retrieve and remove the value under the given key from transient storage. + /// + /// # Parameters + /// - `key`: The storage key. + /// - `output`: A reference to the output data buffer to write the storage entry. + /// + /// # Errors + /// + /// [KeyNotFound][`crate::ReturnErrorCode::KeyNotFound] + #[deprecated( + note = "Unstable function. Behaviour can change without further notice. Use only for testing." + )] + fn take_transient_storage(key: &[u8], output: &mut &mut [u8]) -> Result; + /// Transfer some amount of funds into the specified account. /// /// # Parameters @@ -804,3 +881,8 @@ pub trait HostFn { )] fn xcm_send(dest: &[u8], msg: &[u8], output: &mut [u8; 32]) -> Result; } + +mod private { + pub trait Sealed {} + impl Sealed for super::HostFnImpl {} +} diff --git a/substrate/frame/contracts/uapi/src/host/riscv32.rs b/substrate/frame/contracts/uapi/src/host/riscv32.rs index 561ab28747df..355520233212 100644 --- a/substrate/frame/contracts/uapi/src/host/riscv32.rs +++ b/substrate/frame/contracts/uapi/src/host/riscv32.rs @@ -172,6 +172,10 @@ impl HostFn for HostFnImpl { todo!() } + fn set_transient_storage(key: &[u8], encoded_value: &[u8]) -> Option { + todo!() + } + fn clear_storage(key: &[u8]) { todo!() } @@ -180,13 +184,25 @@ impl HostFn for HostFnImpl { todo!() } + fn clear_transient_storage(key: &[u8]) -> Option { + todo!() + } + impl_get_storage!(get_storage, sys::get_storage); impl_get_storage!(get_storage_v1, sys::v1::get_storage); + fn get_transient_storage(key: &[u8], output: &mut &mut [u8]) -> Result { + todo!() + } + fn take_storage(key: &[u8], output: &mut &mut [u8]) -> Result { todo!() } + fn take_transient_storage(key: &[u8], output: &mut &mut [u8]) -> Result { + todo!() + } + fn contains_storage(key: &[u8]) -> Option { todo!() } @@ -195,6 +211,10 @@ impl HostFn for HostFnImpl { todo!() } + fn contains_transient_storage(key: &[u8]) -> Option { + todo!() + } + fn terminate(beneficiary: &[u8]) -> ! { todo!() } diff --git a/substrate/frame/contracts/uapi/src/host/wasm32.rs b/substrate/frame/contracts/uapi/src/host/wasm32.rs index cb5435bfc014..55600bc3201f 100644 --- a/substrate/frame/contracts/uapi/src/host/wasm32.rs +++ b/substrate/frame/contracts/uapi/src/host/wasm32.rs @@ -61,6 +61,8 @@ mod sys { pub fn clear_storage(key_ptr: *const u8); + pub fn clear_transient_storage(key_ptr: *const u8, key_len: u32) -> ReturnCode; + pub fn code_hash( account_id_ptr: *const u8, output_ptr: *mut u8, @@ -69,6 +71,8 @@ mod sys { pub fn contains_storage(key_ptr: *const u8) -> ReturnCode; + pub fn contains_transient_storage(key_ptr: *const u8, key_len: u32) -> ReturnCode; + pub fn debug_message(str_ptr: *const u8, str_len: u32) -> ReturnCode; pub fn delegate_call( @@ -103,6 +107,13 @@ mod sys { out_len_ptr: *mut u32, ) -> ReturnCode; + pub fn get_transient_storage( + key_ptr: *const u8, + key_len: u32, + out_ptr: *mut u8, + out_len_ptr: *mut u32, + ) -> ReturnCode; + pub fn hash_blake2_128(input_ptr: *const u8, input_len: u32, output_ptr: *mut u8); pub fn hash_blake2_256(input_ptr: *const u8, input_len: u32, output_ptr: *mut u8); @@ -133,6 +144,13 @@ mod sys { pub fn set_storage(key_ptr: *const u8, value_ptr: *const u8, value_len: u32); + pub fn set_transient_storage( + key_ptr: *const u8, + key_len: u32, + value_ptr: *const u8, + value_len: u32, + ) -> ReturnCode; + pub fn sr25519_verify( signature_ptr: *const u8, public_key_ptr: *const u8, @@ -147,6 +165,13 @@ mod sys { out_len_ptr: *mut u32, ) -> ReturnCode; + pub fn take_transient_storage( + key_ptr: *const u8, + key_len: u32, + out_ptr: *mut u8, + out_len_ptr: *mut u32, + ) -> ReturnCode; + pub fn terminate(beneficiary_ptr: *const u8) -> !; pub fn transfer( @@ -598,6 +623,18 @@ impl HostFn for HostFnImpl { ret_code.into() } + fn set_transient_storage(key: &[u8], encoded_value: &[u8]) -> Option { + let ret_code = unsafe { + sys::set_transient_storage( + key.as_ptr(), + key.len() as u32, + encoded_value.as_ptr(), + encoded_value.len() as u32, + ) + }; + ret_code.into() + } + fn clear_storage(key: &[u8]) { unsafe { sys::clear_storage(key.as_ptr()) }; } @@ -607,6 +644,11 @@ impl HostFn for HostFnImpl { ret_code.into() } + fn clear_transient_storage(key: &[u8]) -> Option { + let ret_code = unsafe { sys::clear_transient_storage(key.as_ptr(), key.len() as u32) }; + ret_code.into() + } + #[inline(always)] fn get_storage(key: &[u8], output: &mut &mut [u8]) -> Result { let mut output_len = output.len() as u32; @@ -633,6 +675,23 @@ impl HostFn for HostFnImpl { ret_code.into() } + #[inline(always)] + fn get_transient_storage(key: &[u8], output: &mut &mut [u8]) -> Result { + let mut output_len = output.len() as u32; + let ret_code = { + unsafe { + sys::get_transient_storage( + key.as_ptr(), + key.len() as u32, + output.as_mut_ptr(), + &mut output_len, + ) + } + }; + extract_from_slice(output, output_len as usize); + ret_code.into() + } + #[inline(always)] fn take_storage(key: &[u8], output: &mut &mut [u8]) -> Result { let mut output_len = output.len() as u32; @@ -650,6 +709,23 @@ impl HostFn for HostFnImpl { ret_code.into() } + #[inline(always)] + fn take_transient_storage(key: &[u8], output: &mut &mut [u8]) -> Result { + let mut output_len = output.len() as u32; + let ret_code = { + unsafe { + sys::take_transient_storage( + key.as_ptr(), + key.len() as u32, + output.as_mut_ptr(), + &mut output_len, + ) + } + }; + extract_from_slice(output, output_len as usize); + ret_code.into() + } + fn debug_message(str: &[u8]) -> Result { let ret_code = unsafe { sys::debug_message(str.as_ptr(), str.len() as u32) }; ret_code.into() @@ -665,6 +741,11 @@ impl HostFn for HostFnImpl { ret_code.into() } + fn contains_transient_storage(key: &[u8]) -> Option { + let ret_code = unsafe { sys::contains_transient_storage(key.as_ptr(), key.len() as u32) }; + ret_code.into() + } + fn terminate(beneficiary: &[u8]) -> ! { unsafe { sys::terminate(beneficiary.as_ptr()) } }