mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 04:37:57 +00:00
Pre-Charge max size when contracts access storage (#10691)
* Fix seal_get_storage * Fix seal_take_storage * Add more benchmarks * cargo run --quiet --release --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_contracts --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/contracts/src/weights.rs --template=./.maintain/frame-weight-template.hbs * Fix seal_set_storage * Fix seal_contains_storage and seal_clear_storage * Fix benchmarks * cargo run --quiet --release --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_contracts --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/contracts/src/weights.rs --template=./.maintain/frame-weight-template.hbs * Get rid of mem::size_of in benchmarks * Fix up code loading * Apply suggestions from code review Co-authored-by: Hernando Castano <HCastano@users.noreply.github.com> * Fix test to call same function twice * Replaced u32::MAX by SENTINEL const * Fix seal_contains_storage benchmark * cargo run --quiet --profile=production --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_contracts --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/contracts/src/weights.rs --template=./.maintain/frame-weight-template.hbs Co-authored-by: Parity Bot <admin@parity.io> Co-authored-by: Hernando Castano <HCastano@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
e327b734bc
commit
dc45201a64
@@ -22,7 +22,7 @@ pub mod meter;
|
||||
use crate::{
|
||||
exec::{AccountIdOf, StorageKey},
|
||||
weights::WeightInfo,
|
||||
BalanceOf, CodeHash, Config, ContractInfoOf, DeletionQueue, Error, TrieId,
|
||||
BalanceOf, CodeHash, Config, ContractInfoOf, DeletionQueue, Error, TrieId, SENTINEL,
|
||||
};
|
||||
use codec::{Decode, Encode};
|
||||
use frame_support::{
|
||||
@@ -87,6 +87,33 @@ pub enum WriteOutcome {
|
||||
Taken(Vec<u8>),
|
||||
}
|
||||
|
||||
impl WriteOutcome {
|
||||
/// Extracts the size of the overwritten value or `0` if there
|
||||
/// was no value in storage.
|
||||
pub fn old_len(&self) -> u32 {
|
||||
match self {
|
||||
Self::New => 0,
|
||||
Self::Overwritten(len) => *len,
|
||||
Self::Taken(value) => value.len() as u32,
|
||||
}
|
||||
}
|
||||
|
||||
/// Extracts the size of the overwritten value or `SENTINEL` if there
|
||||
/// was no value in storage.
|
||||
///
|
||||
/// # Note
|
||||
///
|
||||
/// We cannot use `0` as sentinel value because there could be a zero sized
|
||||
/// storage entry which is different from a non existing one.
|
||||
pub fn old_len_with_sentinel(&self) -> u32 {
|
||||
match self {
|
||||
Self::New => SENTINEL,
|
||||
Self::Overwritten(len) => *len,
|
||||
Self::Taken(value) => value.len() as u32,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Storage<T>(PhantomData<T>);
|
||||
|
||||
impl<T> Storage<T>
|
||||
@@ -102,9 +129,12 @@ where
|
||||
child::get_raw(&child_trie_info(trie_id), &blake2_256(key))
|
||||
}
|
||||
|
||||
/// Returns `true` iff the `key` exists in storage.
|
||||
pub fn contains(trie_id: &TrieId, key: &StorageKey) -> bool {
|
||||
child::exists(&child_trie_info(trie_id), &blake2_256(key))
|
||||
/// Returns `Some(len)` (in bytes) if a storage item exists at `key`.
|
||||
///
|
||||
/// Returns `None` if the `key` wasn't previously set by `set_storage` or
|
||||
/// was deleted.
|
||||
pub fn size(trie_id: &TrieId, key: &StorageKey) -> Option<u32> {
|
||||
child::len(&child_trie_info(trie_id), &blake2_256(key))
|
||||
}
|
||||
|
||||
/// Update a storage entry into a contract's kv storage.
|
||||
|
||||
Reference in New Issue
Block a user