contracts: Don't read the previous value when overwriting a storage item (#7879)

* Add `len` function that can return the length of a storage item efficiently

* Make use of the new len function in contracts

* Fix benchmarks

* cargo run --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

* Remove unused imports

Co-authored-by: Parity Benchmarking Bot <admin@parity.io>
This commit is contained in:
Alexander Theißen
2021-01-13 13:31:14 +01:00
committed by GitHub
parent 4678da3efb
commit 19e58df126
4 changed files with 730 additions and 725 deletions
@@ -109,21 +109,18 @@ where
endowment: Endow,
) -> Result<Contract<T>, &'static str>
{
use sp_runtime::traits::{CheckedDiv, SaturatedConversion};
let (storage_size, endowment) = match endowment {
Endow::CollectRent => {
// storage_size cannot be zero because otherwise a contract that is just above
// the subsistence threshold does not pay rent given a large enough subsistence
// threshold. But we need rent payments to occur in order to benchmark for worst cases.
let storage_size = ConfigCache::<T>::subsistence_threshold_uncached()
.checked_div(&T::DepositPerStorageByte::get())
.unwrap_or_else(Zero::zero);
let storage_size = u32::max_value() / 10;
// Endowment should be large but not as large to inhibit rent payments.
// Balance will only cover half the storage
let endowment = T::DepositPerStorageByte::get()
.saturating_mul(storage_size)
.saturating_add(T::DepositPerContract::get())
.saturating_sub(1u32.into());
.saturating_mul(<BalanceOf<T>>::from(storage_size) / 2u32.into())
.saturating_add(T::DepositPerContract::get());
(storage_size, endowment)
},
@@ -159,7 +156,7 @@ where
};
let mut contract = result.alive_info()?;
contract.storage_size = storage_size.saturated_into::<u32>();
contract.storage_size = storage_size;
ContractInfoOf::<T>::insert(&result.account_id, ContractInfo::Alive(contract));
Ok(result)