Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

[contracts] Fix *storage_per_kb benchmarks #11756

Closed
wants to merge 10 commits into from
44 changes: 37 additions & 7 deletions frame/contracts/src/benchmarking/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -991,14 +991,19 @@ benchmarks! {
let instance = Contract::<T>::new(code, vec![])?;
let info = instance.info()?;
for key in keys {
let key = &VarSizedKey::<T>::try_from(key).map_err(|e| "Key has wrong length")?;
Storage::<T>::write(
&info.trie_id,
&VarSizedKey::<T>::try_from(key).map_err(|e| "Key has wrong length")?,
key,
Some(vec![]),
None,
false,
)
.map_err(|_| "Failed to write to storage during setup.")?;
// Whitelist the key hash from further DB operations
let hash =
<frame_support::BoundedVec<u8, <T as pallet::Config>::MaxStorageKeyLen> as exec::StorageKey<T>>::hash(key);
frame_benchmarking::benchmarking::add_to_whitelist(hash.into());
}
let origin = RawOrigin::Signed(instance.caller.clone());
}: call(origin, instance.addr, 0u32.into(), Weight::MAX, None, vec![])
Expand Down Expand Up @@ -1039,15 +1044,20 @@ benchmarks! {
let instance = Contract::<T>::new(code, vec![])?;
let info = instance.info()?;
for key in keys {
let key = &VarSizedKey::<T>::try_from(key).map_err(|e| "Key has wrong length")?;
Storage::<T>::write(
&info.trie_id,
&VarSizedKey::<T>::try_from(key).map_err(|e| "Key has wrong length")?,
key,
Some(vec![42u8; (n * 2048) as usize]), // value_len increments by 2kb up to max payload_len
None,
false,
)
.map_err(|_| "Failed to write to storage during setup.")?;
}
// Whitelist the key hash from further DB operations
let hash =
<frame_support::BoundedVec<u8, <T as pallet::Config>::MaxStorageKeyLen> as exec::StorageKey<T>>::hash(key);
frame_benchmarking::benchmarking::add_to_whitelist(hash.into());
}
let origin = RawOrigin::Signed(instance.caller.clone());
}: call(origin, instance.addr, 0u32.into(), Weight::MAX, None, vec![])

Expand Down Expand Up @@ -1136,14 +1146,19 @@ benchmarks! {
let instance = Contract::<T>::new(code, vec![])?;
let info = instance.info()?;
for key in keys {
let key = &VarSizedKey::<T>::try_from(key).map_err(|e| "Key has wrong length")?;
Storage::<T>::write(
&info.trie_id,
&VarSizedKey::<T>::try_from(key).map_err(|e| "Key has wrong length")?,
key,
Some(vec![42u8; (n * 2048) as usize]), // value_len increments by 2kb up to max payload_len
None,
false,
)
.map_err(|_| "Failed to write to storage during setup.")?;
// Whitelist the key hash from further DB operations
let hash =
<frame_support::BoundedVec<u8, <T as pallet::Config>::MaxStorageKeyLen> as exec::StorageKey<T>>::hash(key);
frame_benchmarking::benchmarking::add_to_whitelist(hash.into());
}
let origin = RawOrigin::Signed(instance.caller.clone());
}: call(origin, instance.addr, 0u32.into(), Weight::MAX, None, vec![])
Expand Down Expand Up @@ -1244,14 +1259,19 @@ benchmarks! {
let instance = Contract::<T>::new(code, vec![])?;
let info = instance.info()?;
for key in keys {
let key = &VarSizedKey::<T>::try_from(key).map_err(|e| "Key has wrong length")?;
Storage::<T>::write(
&info.trie_id,
&VarSizedKey::<T>::try_from(key).map_err(|e| "Key has wrong length")?,
key,
Some(vec![42u8; (n * 2048) as usize]), // value_len increments by 2kb up to max payload_len
None,
false,
)
.map_err(|_| "Failed to write to storage during setup.")?;
// Whitelist the key hash from further DB operations
let hash =
<frame_support::BoundedVec<u8, <T as pallet::Config>::MaxStorageKeyLen> as exec::StorageKey<T>>::hash(key);
frame_benchmarking::benchmarking::add_to_whitelist(hash.into());
}
<ContractInfoOf<T>>::insert(&instance.account_id, info);
let origin = RawOrigin::Signed(instance.caller.clone());
Expand Down Expand Up @@ -1340,14 +1360,19 @@ benchmarks! {
let instance = Contract::<T>::new(code, vec![])?;
let info = instance.info()?;
for key in keys {
let key = &VarSizedKey::<T>::try_from(key.clone()).map_err(|e| "Key has wrong length")?;
Storage::<T>::write(
&info.trie_id,
&VarSizedKey::<T>::try_from(key).map_err(|e| "Key has wrong length")?,
key,
Some(vec![42u8; (n * 2048) as usize]), // value_len increments by 2kb up to max payload_len
None,
false,
)
.map_err(|_| "Failed to write to storage during setup.")?;
// Whitelist the key hash from further DB operations
let hash =
<frame_support::BoundedVec<u8, <T as pallet::Config>::MaxStorageKeyLen> as exec::StorageKey<T>>::hash(key);
frame_benchmarking::benchmarking::add_to_whitelist(hash.into());
}
<ContractInfoOf<T>>::insert(&instance.account_id, info);
let origin = RawOrigin::Signed(instance.caller.clone());
Expand Down Expand Up @@ -1448,14 +1473,19 @@ benchmarks! {
let instance = Contract::<T>::new(code, vec![])?;
let info = instance.info()?;
for key in keys {
let key = &VarSizedKey::<T>::try_from(key.clone()).map_err(|e| "Key has wrong length")?;
Storage::<T>::write(
&info.trie_id,
&VarSizedKey::<T>::try_from(key).map_err(|e| "Key has wrong length")?,
key,
Some(vec![42u8; (n * 2048) as usize]), // value_len increments by 2kb up to max payload_len
None,
false,
)
.map_err(|_| "Failed to write to storage during setup.")?;
// Whitelist the key hash from further DB operations
let hash =
<frame_support::BoundedVec<u8, <T as pallet::Config>::MaxStorageKeyLen> as exec::StorageKey<T>>::hash(key);
frame_benchmarking::benchmarking::add_to_whitelist(hash.into());
}
<ContractInfoOf<T>>::insert(&instance.account_id, info);
let origin = RawOrigin::Signed(instance.caller.clone());
Expand Down
Loading