pallet-contracts: State rent fixes (#6147)

* Don't store the storage size offset in the contract itself.

* Clean the AccountDb code a bit

* Use `storage_size: 0` when creating AliveContractInfo

* Count empty storage items.

* Update frame/contracts/src/account_db.rs

Co-authored-by: Nikolay Volf <nikvolf@gmail.com>

* Use more clear wording.

Co-authored-by: Alexander Theißen <athei@users.noreply.github.com>

* Change the order of decrement and increment for storage size

Co-authored-by: Nikolay Volf <nikvolf@gmail.com>
Co-authored-by: Alexander Theißen <athei@users.noreply.github.com>
This commit is contained in:
Sergei Pepyakin
2020-05-28 20:07:25 +02:00
committed by GitHub
parent c672cce4bd
commit c8fe8b5378
5 changed files with 209 additions and 47 deletions
+7 -2
View File
@@ -92,8 +92,13 @@ fn compute_fee_per_block<T: Trait>(
.checked_div(&T::RentDepositOffset::get())
.unwrap_or_else(Zero::zero);
let effective_storage_size =
<BalanceOf<T>>::from(contract.storage_size).saturating_sub(free_storage);
// For now, we treat every empty KV pair as if it was one byte long.
let empty_pairs_equivalent = contract.empty_pair_count;
let effective_storage_size = <BalanceOf<T>>::from(
contract.storage_size + T::StorageSizeOffset::get() + empty_pairs_equivalent,
)
.saturating_sub(free_storage);
effective_storage_size
.checked_mul(&T::RentByteFee::get())