From da56e0bec047b79ede2eed77f1f4934ffcf2b534 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Thei=C3=9Fen?= Date: Mon, 7 Dec 2020 14:52:44 +0100 Subject: [PATCH 01/14] Do not evict a contract from within a call stack We don't want to trigger contract eviction automatically when a contract is called. This is because those changes can be reverted due to how storage transactions are used at the moment. More Information: https://github.com/paritytech/substrate/issues/6439#issuecomment-648754324 It can be re-introduced once the linked issue is resolved. In the meantime `claim_surcharge` must be called to evict a contract. --- frame/contracts/src/benchmarking/mod.rs | 4 +- frame/contracts/src/exec.rs | 12 ++--- frame/contracts/src/rent.rs | 58 ++++++++++++------------- frame/contracts/src/tests.rs | 33 ++++++-------- 4 files changed, 50 insertions(+), 57 deletions(-) diff --git a/frame/contracts/src/benchmarking/mod.rs b/frame/contracts/src/benchmarking/mod.rs index 4bdd279eb8b2c..22ad8bcad2606 100644 --- a/frame/contracts/src/benchmarking/mod.rs +++ b/frame/contracts/src/benchmarking/mod.rs @@ -39,7 +39,7 @@ use self::{ use frame_benchmarking::{benchmarks, account, whitelisted_caller}; use frame_system::{Module as System, RawOrigin}; use parity_wasm::elements::{Instruction, ValueType, BlockType}; -use sp_runtime::traits::{Hash, Bounded}; +use sp_runtime::traits::{Hash, Bounded, Zero}; use sp_std::{default::Default, convert::{TryInto}, vec::Vec, vec}; use pallet_contracts_primitives::RentProjection; @@ -232,7 +232,7 @@ where System::::set_block_number( contract.eviction_at()? + T::SignedClaimHandicap::get() + 5u32.into() ); - Rent::::collect(&contract.account_id); + Rent::::snitch_contract_should_be_evicted(&contract.account_id, Zero::zero()); contract.ensure_tombstone()?; Ok(Tombstone { diff --git a/frame/contracts/src/exec.rs b/frame/contracts/src/exec.rs index 8577d04452fa8..5d28214b9daa4 100644 --- a/frame/contracts/src/exec.rs +++ b/frame/contracts/src/exec.rs @@ -267,12 +267,12 @@ where Err(Error::::MaxCallDepthReached)? } - // Assumption: `collect` doesn't collide with overlay because - // `collect` will be done on first call and destination contract and balance - // cannot be changed before the first call - // We do not allow 'calling' plain accounts. For transfering value - // `seal_transfer` must be used. - let contract = if let Some(ContractInfo::Alive(info)) = Rent::::collect(&dest) { + // This charges the rent and denies access to a contract that is in need of + // eviction by returning `None`. We cannot evict eagerly here because those + // changes would be rolled back in case this contract is called by another + // contract. + // See: https://github.com/paritytech/substrate/issues/6439#issuecomment-648754324 + let contract = if let Some(ContractInfo::Alive(info)) = Rent::::charge(&dest) { info } else { Err(Error::::NotCallable)? diff --git a/frame/contracts/src/rent.rs b/frame/contracts/src/rent.rs index 8b6f81c916bef..af62072eb063c 100644 --- a/frame/contracts/src/rent.rs +++ b/frame/contracts/src/rent.rs @@ -23,9 +23,11 @@ use crate::{ use sp_std::prelude::*; use sp_io::hashing::blake2_256; use sp_core::crypto::UncheckedFrom; -use frame_support::storage::child; -use frame_support::traits::{Currency, ExistenceRequirement, Get, OnUnbalanced, WithdrawReasons}; -use frame_support::StorageMap; +use frame_support::{ + debug, StorageMap, + storage::child, + traits::{Currency, ExistenceRequirement, Get, OnUnbalanced, WithdrawReasons}, +}; use pallet_contracts_primitives::{ContractAccessError, RentProjection, RentProjectionResult}; use sp_runtime::{ DispatchError, @@ -73,10 +75,6 @@ enum Verdict { /// For example, it already paid its rent in the current block, or it has enough deposit for not /// paying rent at all. Exempt, - /// Funds dropped below the subsistence deposit. - /// - /// Remove the contract along with it's storage. - Kill, /// The contract cannot afford payment within its rent budget so it gets evicted. However, /// because its balance is greater than the subsistence threshold it leaves a tombstone. Evict { @@ -180,11 +178,17 @@ where let rent_budget = match Self::rent_budget(&total_balance, &free_balance, contract) { Some(rent_budget) => rent_budget, None => { - // The contract's total balance is already below subsistence threshold. That - // indicates that the contract cannot afford to leave a tombstone. - // - // So cleanly wipe the contract. - return Verdict::Kill; + // All functions that allow a contract to transfer balance enforce + // that the contract always stays above the subsistence threshold. + // We want the rent system to always leave a tombstone to prevent the + // accidental loss of a contract. Ony `seal_terminate` can remove a + // contract without a tombstone. Therefore this case should be never + // hit. + debug::error!( + "Tombstoned a contract that is below the subsistence threshold: {:?}", + account + ); + 0u32.into() } }; @@ -233,16 +237,11 @@ where alive_contract_info: AliveContractInfo, current_block_number: T::BlockNumber, verdict: Verdict, + allow_eviction: bool, ) -> Option> { match verdict { Verdict::Exempt => return Some(ContractInfo::Alive(alive_contract_info)), - Verdict::Kill => { - >::remove(account); - child::kill_storage( - &alive_contract_info.child_trie_info(), - None, - ); - >::deposit_event(RawEvent::Evicted(account.clone(), false)); + Verdict::Evict { amount: _ } if !allow_eviction => { None } Verdict::Evict { amount } => { @@ -286,9 +285,10 @@ where /// Make account paying the rent for the current block number /// - /// NOTE this function performs eviction eagerly. All changes are read and written directly to - /// storage. - pub fn collect(account: &T::AccountId) -> Option> { + /// This functions does **not** evict the contract. It returns `None` in case the + /// contract is in need of eviction. [`snitch_contract_should_be_evicted`] must + /// be called to perform the eviction. + pub fn charge(account: &T::AccountId) -> Option> { let contract_info = >::get(account); let alive_contract_info = match contract_info { None | Some(ContractInfo::Tombstone(_)) => return contract_info, @@ -302,7 +302,7 @@ where Zero::zero(), &alive_contract_info, ); - Self::enact_verdict(account, alive_contract_info, current_block_number, verdict) + Self::enact_verdict(account, alive_contract_info, current_block_number, verdict, false) } /// Process a report that a contract under the given address should be evicted. @@ -321,8 +321,8 @@ where account: &T::AccountId, handicap: T::BlockNumber, ) -> bool { - let contract_info = >::get(account); - let alive_contract_info = match contract_info { + let contract = >::get(account); + let contract = match contract { None | Some(ContractInfo::Tombstone(_)) => return false, Some(ContractInfo::Alive(contract)) => contract, }; @@ -331,13 +331,13 @@ where account, current_block_number, handicap, - &alive_contract_info, + &contract, ); // Enact the verdict only if the contract gets removed. match verdict { - Verdict::Kill | Verdict::Evict { .. } => { - Self::enact_verdict(account, alive_contract_info, current_block_number, verdict); + Verdict::Evict { .. } => { + Self::enact_verdict(account, contract, current_block_number, verdict, true); true } _ => false, @@ -371,7 +371,7 @@ where &alive_contract_info, ); let new_contract_info = - Self::enact_verdict(account, alive_contract_info, current_block_number, verdict); + Self::enact_verdict(account, alive_contract_info, current_block_number, verdict, false); // Check what happened after enaction of the verdict. let alive_contract_info = match new_contract_info { diff --git a/frame/contracts/src/tests.rs b/frame/contracts/src/tests.rs index c0b9b671068d6..91395e9642d10 100644 --- a/frame/contracts/src/tests.rs +++ b/frame/contracts/src/tests.rs @@ -774,15 +774,6 @@ fn deduct_blocks() { }); } -#[test] -fn call_contract_removals() { - removals(|addr| { - // Call on already-removed account might fail, and this is fine. - let _ = Contracts::call(Origin::signed(ALICE), addr, 0, GAS_LIMIT, call::null()); - true - }); -} - #[test] fn inherent_claim_surcharge_contract_removals() { removals(|addr| Contracts::claim_surcharge(Origin::none(), addr, Some(ALICE)).is_ok()); @@ -1046,25 +1037,23 @@ fn call_removed_contract() { // Advance blocks initialize_block(10); - // Calling contract should remove contract and fail. + // Calling contract should deny access because rent cannot be paid. assert_err_ignore_postinfo!( Contracts::call(Origin::signed(ALICE), addr.clone(), 0, GAS_LIMIT, call::null()), Error::::NotCallable ); - // Calling a contract that is about to evict shall emit an event. - assert_eq!(System::events(), vec![ - EventRecord { - phase: Phase::Initialization, - event: MetaEvent::contracts(RawEvent::Evicted(addr.clone(), true)), - topics: vec![], - }, - ]); + // No event is generated because the contract is not actually removed. + assert_eq!(System::events(), vec![]); // Subsequent contract calls should also fail. assert_err_ignore_postinfo!( - Contracts::call(Origin::signed(ALICE), addr, 0, GAS_LIMIT, call::null()), + Contracts::call(Origin::signed(ALICE), addr.clone(), 0, GAS_LIMIT, call::null()), Error::::NotCallable ); + + // A snitch can now remove the contract + assert_ok!(Contracts::claim_surcharge(Origin::none(), addr.clone(), Some(ALICE))); + assert!(ContractInfoOf::::get(&addr).unwrap().get_tombstone().is_some()); }) } @@ -1193,13 +1182,17 @@ fn restoration(test_different_storage: bool, test_restore_to_with_dirty_storage: initialize_block(5); // Call `BOB`, which makes it pay rent. Since the rent allowance is set to 0 - // we expect that it will get removed leaving tombstone. + // we expect that it is no longer callable but keeps existing until someone + // calls `claim_surcharge`. assert_err_ignore_postinfo!( Contracts::call( Origin::signed(ALICE), addr_bob.clone(), 0, GAS_LIMIT, call::null() ), Error::::NotCallable ); + assert_eq!(System::events(), vec![]); + assert!(ContractInfoOf::::get(&addr_bob).unwrap().get_alive().is_some()); + assert_ok!(Contracts::claim_surcharge(Origin::none(), addr_bob.clone(), Some(ALICE))); assert!(ContractInfoOf::::get(&addr_bob).unwrap().get_tombstone().is_some()); assert_eq!(System::events(), vec![ EventRecord { From 6456a361ca1f8cb515f74e019b3243d3704e8c23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Thei=C3=9Fen?= Date: Thu, 10 Dec 2020 17:41:53 +0100 Subject: [PATCH 02/14] Lazily delete storage in on_initialize instead of when removing the contract --- bin/node/runtime/src/lib.rs | 9 + frame/contracts/src/benchmarking/mod.rs | 75 +- frame/contracts/src/exec.rs | 19 +- frame/contracts/src/lib.rs | 45 +- frame/contracts/src/rent.rs | 45 +- frame/contracts/src/storage.rs | 129 ++- frame/contracts/src/tests.rs | 197 ++++- frame/contracts/src/weights.rs | 1038 ++++++++++++++--------- 8 files changed, 1090 insertions(+), 467 deletions(-) diff --git a/bin/node/runtime/src/lib.rs b/bin/node/runtime/src/lib.rs index fb77fd2ebd405..96c7631fdeb69 100644 --- a/bin/node/runtime/src/lib.rs +++ b/bin/node/runtime/src/lib.rs @@ -71,6 +71,7 @@ pub use pallet_transaction_payment::{Multiplier, TargetedFeeAdjustment, Currency use pallet_session::{historical as pallet_session_historical}; use sp_inherents::{InherentData, CheckInherentsResult}; use static_assertions::const_assert; +use pallet_contracts::WeightInfo; #[cfg(any(feature = "std", test))] pub use sp_runtime::BuildStorage; @@ -714,6 +715,12 @@ parameter_types! { pub const MaxDepth: u32 = 32; pub const StorageSizeOffset: u32 = 8; pub const MaxValueSize: u32 = 16 * 1024; + pub DeletionWeightLimit: Weight = Perbill::from_percent(20) * + RuntimeBlockWeights::get().max_block; + pub DeletionQueueDepth: u32 = ((DeletionWeightLimit::get() / ( + ::WeightInfo::on_initialize_per_queue_item(1) - + ::WeightInfo::on_initialize_per_queue_item(0) + )) / 5) as u32; } impl pallet_contracts::Config for Runtime { @@ -732,6 +739,8 @@ impl pallet_contracts::Config for Runtime { type MaxValueSize = MaxValueSize; type WeightPrice = pallet_transaction_payment::Module; type WeightInfo = pallet_contracts::weights::SubstrateWeight; + type DeletionQueueDepth = DeletionQueueDepth; + type DeletionWeightLimit = DeletionWeightLimit; } impl pallet_sudo::Config for Runtime { diff --git a/frame/contracts/src/benchmarking/mod.rs b/frame/contracts/src/benchmarking/mod.rs index 22ad8bcad2606..d672061d433e0 100644 --- a/frame/contracts/src/benchmarking/mod.rs +++ b/frame/contracts/src/benchmarking/mod.rs @@ -209,37 +209,52 @@ where } } -/// A `Contract` that was evicted after accumulating some storage. +/// A `Contract` that contains some storage items. /// -/// This is used to benchmark contract resurrection. -struct Tombstone { +/// This is used to benchmark contract destruction and resurection. Those operations' +/// weight depend on the amount of storage accumulated. +struct ContractWithStorage { /// The contract that was evicted. contract: Contract, /// The storage the contract held when it was avicted. storage: Vec<(StorageKey, Vec)>, } -impl Tombstone +impl ContractWithStorage where T: Config, T::AccountId: UncheckedFrom + AsRef<[u8]>, { - /// Create and evict a new contract with the supplied storage item count and size each. + /// Same as [`Self::with_code`] but with dummy contract code. fn new(stor_num: u32, stor_size: u32) -> Result { - let contract = Contract::::new(WasmModule::dummy(), vec![], Endow::CollectRent)?; + Self::with_code(WasmModule::dummy(), stor_num, stor_size) + } + + /// Create and evict a new contract with the supplied storage item count and size each. + fn with_code(code: WasmModule, stor_num: u32, stor_size: u32) -> Result { + let contract = Contract::::new(code, vec![], Endow::CollectRent)?; let storage_items = create_storage::(stor_num, stor_size)?; contract.store(&storage_items)?; - System::::set_block_number( - contract.eviction_at()? + T::SignedClaimHandicap::get() + 5u32.into() - ); - Rent::::snitch_contract_should_be_evicted(&contract.account_id, Zero::zero()); - contract.ensure_tombstone()?; - - Ok(Tombstone { + Ok(Self { contract, storage: storage_items, }) } + + /// Increase the system block number so that this contract is eligible for eviction. + fn set_block_num_for_eviction(&self) -> Result<(), &'static str> { + System::::set_block_number( + self.contract.eviction_at()? + T::SignedClaimHandicap::get() + 5u32.into() + ); + Ok(()) + } + + /// Evict this contract. + fn evict(&mut self) -> Result<(), &'static str> { + self.set_block_num_for_eviction()?; + Rent::::snitch_contract_should_be_evicted(&self.contract.account_id, Zero::zero())?; + self.contract.ensure_tombstone() + } } /// Generate `stor_num` storage items. Each has the size `stor_size`. @@ -270,6 +285,30 @@ benchmarks! { _ { } + // The base weight without any actual work performed apart from the setup costs. + on_initialize {}: { + Storage::::process_deletion_queue_batch(Weight::max_value()) + } + + on_initialize_per_trie_key { + let k in 0..1024; + let instance = ContractWithStorage::::new(k, T::MaxValueSize::get())?; + Storage::::queue_trie_for_deletion(&instance.contract.alive_info()?)?; + }: { + Storage::::process_deletion_queue_batch(Weight::max_value()) + } + + on_initialize_per_queue_item { + let q in 0..1024.min(T::DeletionQueueDepth::get()); + for i in 0 .. q { + let instance = Contract::::with_index(i, WasmModule::dummy(), vec![], Endow::Max)?; + Storage::::queue_trie_for_deletion(&instance.alive_info()?)?; + ContractInfoOf::::remove(instance.account_id); + } + }: { + Storage::::process_deletion_queue_batch(Weight::max_value()) + } + // This extrinsic is pretty much constant as it is only a simple setter. update_schedule { let schedule = Schedule { @@ -650,7 +689,8 @@ benchmarks! { // Restore just moves the trie id from origin to destination and therefore // does not depend on the size of the destination contract. However, to not // trigger any edge case we won't use an empty contract as destination. - let tombstone = Tombstone::::new(10, T::MaxValueSize::get())?; + let mut tombstone = ContractWithStorage::::new(10, T::MaxValueSize::get())?; + tombstone.evict()?; let dest = tombstone.contract.account_id.encode(); let dest_len = dest.len(); @@ -723,7 +763,8 @@ benchmarks! { seal_restore_to_per_delta { let d in 0 .. API_BENCHMARK_BATCHES; - let tombstone = Tombstone::::new(0, 0)?; + let mut tombstone = ContractWithStorage::::new(0, 0)?; + tombstone.evict()?; let delta = create_storage::(d * API_BENCHMARK_BATCH_SIZE, T::MaxValueSize::get())?; let dest = tombstone.contract.account_id.encode(); @@ -2394,6 +2435,10 @@ mod tests { } } + create_test!(on_initialize); + create_test!(on_initialize_per_trie_key); + create_test!(on_initialize_per_queue_item); + create_test!(update_schedule); create_test!(put_code); create_test!(instantiate); diff --git a/frame/contracts/src/exec.rs b/frame/contracts/src/exec.rs index 5d28214b9daa4..435473cadd24a 100644 --- a/frame/contracts/src/exec.rs +++ b/frame/contracts/src/exec.rs @@ -272,7 +272,7 @@ where // changes would be rolled back in case this contract is called by another // contract. // See: https://github.com/paritytech/substrate/issues/6439#issuecomment-648754324 - let contract = if let Some(ContractInfo::Alive(info)) = Rent::::charge(&dest) { + let contract = if let Ok(Some(ContractInfo::Alive(info))) = Rent::::charge(&dest) { info } else { Err(Error::::NotCallable)? @@ -574,13 +574,16 @@ where value, self.ctx, )?; - let self_trie_id = self.ctx.self_trie_id.as_ref().expect( - "this function is only invoked by in the context of a contract;\ - a contract has a trie id;\ - this can't be None; qed", - ); - Storage::::destroy_contract(&self_id, self_trie_id); - Ok(()) + if let Some(ContractInfo::Alive(info)) = ContractInfoOf::::take(&self_id) { + Storage::::queue_trie_for_deletion(&info)?; + Ok(()) + } else { + panic!( + "this function is only invoked by in the context of a contract;\ + this contract is therefore alive;\ + qed" + ); + } } fn call( diff --git a/frame/contracts/src/lib.rs b/frame/contracts/src/lib.rs index f0200fbd15fd4..92ef5bbb01b28 100644 --- a/frame/contracts/src/lib.rs +++ b/frame/contracts/src/lib.rs @@ -319,6 +319,12 @@ pub trait Config: frame_system::Config { /// Describes the weights of the dispatchables of this module and is also used to /// construct a default cost schedule. type WeightInfo: WeightInfo; + + /// The maximum number of tries that can be queued for deletion. + type DeletionQueueDepth: Get; + + /// The maximum amount of weight that can be consumed per block for lazy trie removal. + type DeletionWeightLimit: Get; } decl_error! { @@ -378,6 +384,13 @@ decl_error! { /// on the call stack. Those actions are contract self destruction and restoration /// of a tombstone. ReentranceDenied, + /// Removal of a contract failed because the deletion queue is full. + /// + /// This can happen when either calling [`Module::claim_surcharge`] or `seal_terminate`. + /// The queue is filled by deleting contracts and emptied by a fixed amount each block. + /// Trying again during another block is the only way to resolve this issue. + DeletionQueueFull, + ContractNotEvictable, } } @@ -431,8 +444,19 @@ decl_module! { /// The maximum size of a storage value in bytes. A reasonable default is 16 KiB. const MaxValueSize: u32 = T::MaxValueSize::get(); + /// The maximum number of tries that can be queued for deletion. + const DeletionQueueDepth: u32 = T::DeletionQueueDepth::get(); + + /// The maximum amount of weight that can be consumed per block for lazy trie removal. + const DeletionWeightLimit: Weight = T::DeletionWeightLimit::get(); + fn deposit_event() = default; + fn on_initialize() -> Weight { + Storage::::process_deletion_queue_batch(T::DeletionWeightLimit::get()) + .unwrap_or_else(T::WeightInfo::on_initialize) + } + /// Updates the schedule for metering contracts. /// /// The schedule must have a greater version than the stored schedule. @@ -531,10 +555,14 @@ decl_module! { /// Allows block producers to claim a small reward for evicting a contract. If a block producer /// fails to do so, a regular users will be allowed to claim the reward. /// - /// If contract is not evicted as a result of this call, no actions are taken and - /// the sender is not eligible for the reward. + /// If contract is not evicted as a result of this call, [`Error::ContractNotEvictable`] + /// is returned and the sender is not eligible for the reward. #[weight = T::WeightInfo::claim_surcharge()] - fn claim_surcharge(origin, dest: T::AccountId, aux_sender: Option) { + fn claim_surcharge( + origin, + dest: T::AccountId, + aux_sender: Option + ) -> DispatchResult { let origin = origin.into(); let (signed, rewarded) = match (origin, aux_sender) { (Ok(frame_system::RawOrigin::Signed(account)), None) => { @@ -556,8 +584,10 @@ decl_module! { }; // If poking the contract has lead to eviction of the contract, give out the rewards. - if Rent::::snitch_contract_should_be_evicted(&dest, handicap) { - T::Currency::deposit_into_existing(&rewarded, T::SurchargeReward::get())?; + if Rent::::snitch_contract_should_be_evicted(&dest, handicap)? { + T::Currency::deposit_into_existing(&rewarded, T::SurchargeReward::get()).map(|_| ()) + } else { + Err(Error::::ContractNotEvictable.into()) } } } @@ -715,6 +745,11 @@ decl_storage! { /// /// TWOX-NOTE: SAFE since `AccountId` is a secure hash. pub ContractInfoOf: map hasher(twox_64_concat) T::AccountId => Option>; + /// Evicted contracts that await child trie deletion. + /// + /// Child trie deletion is a heavy operation depending on the amount of storage items + /// stored in said trie. Therefore this operation is performed lazily in `on_initialize`. + pub DeletionQueue: Vec; } } diff --git a/frame/contracts/src/rent.rs b/frame/contracts/src/rent.rs index af62072eb063c..b3194e2252dc6 100644 --- a/frame/contracts/src/rent.rs +++ b/frame/contracts/src/rent.rs @@ -19,6 +19,7 @@ use crate::{ AliveContractInfo, BalanceOf, ContractInfo, ContractInfoOf, Module, RawEvent, TombstoneContractInfo, Config, CodeHash, ConfigCache, Error, + storage::Storage, }; use sp_std::prelude::*; use sp_io::hashing::blake2_256; @@ -238,13 +239,18 @@ where current_block_number: T::BlockNumber, verdict: Verdict, allow_eviction: bool, - ) -> Option> { + ) -> Result>, DispatchError> { match verdict { - Verdict::Exempt => return Some(ContractInfo::Alive(alive_contract_info)), + Verdict::Exempt => return Ok(Some(ContractInfo::Alive(alive_contract_info))), Verdict::Evict { amount: _ } if !allow_eviction => { - None + Ok(None) } Verdict::Evict { amount } => { + // We need to remove the trie first because it is the only operation + // that can fail and this function is called without a storage + // transaction when called through `claim_surcharge`. + Storage::::queue_trie_for_deletion(&alive_contract_info)?; + if let Some(amount) = amount { amount.withdraw(account); } @@ -260,14 +266,8 @@ where ); let tombstone_info = ContractInfo::Tombstone(tombstone); >::insert(account, &tombstone_info); - - child::kill_storage( - &alive_contract_info.child_trie_info(), - None, - ); - >::deposit_event(RawEvent::Evicted(account.clone(), true)); - Some(tombstone_info) + Ok(Some(tombstone_info)) } Verdict::Charge { amount } => { let contract_info = ContractInfo::Alive(AliveContractInfo:: { @@ -276,9 +276,8 @@ where ..alive_contract_info }); >::insert(account, &contract_info); - amount.withdraw(account); - Some(contract_info) + Ok(Some(contract_info)) } } } @@ -288,10 +287,10 @@ where /// This functions does **not** evict the contract. It returns `None` in case the /// contract is in need of eviction. [`snitch_contract_should_be_evicted`] must /// be called to perform the eviction. - pub fn charge(account: &T::AccountId) -> Option> { + pub fn charge(account: &T::AccountId) -> Result>, DispatchError> { let contract_info = >::get(account); let alive_contract_info = match contract_info { - None | Some(ContractInfo::Tombstone(_)) => return contract_info, + None | Some(ContractInfo::Tombstone(_)) => return Ok(contract_info), Some(ContractInfo::Alive(contract)) => contract, }; @@ -320,10 +319,10 @@ where pub fn snitch_contract_should_be_evicted( account: &T::AccountId, handicap: T::BlockNumber, - ) -> bool { + ) -> Result { let contract = >::get(account); let contract = match contract { - None | Some(ContractInfo::Tombstone(_)) => return false, + None | Some(ContractInfo::Tombstone(_)) => return Ok(false), Some(ContractInfo::Alive(contract)) => contract, }; let current_block_number = >::block_number(); @@ -337,10 +336,10 @@ where // Enact the verdict only if the contract gets removed. match verdict { Verdict::Evict { .. } => { - Self::enact_verdict(account, contract, current_block_number, verdict, true); - true + Self::enact_verdict(account, contract, current_block_number, verdict, true)?; + Ok(true) } - _ => false, + _ => Ok(false), } } @@ -358,9 +357,11 @@ where pub fn compute_projection( account: &T::AccountId, ) -> RentProjectionResult { + use ContractAccessError::IsTombstone; + let contract_info = >::get(account); let alive_contract_info = match contract_info { - None | Some(ContractInfo::Tombstone(_)) => return Err(ContractAccessError::IsTombstone), + None | Some(ContractInfo::Tombstone(_)) => return Err(IsTombstone), Some(ContractInfo::Alive(contract)) => contract, }; let current_block_number = >::block_number(); @@ -374,8 +375,8 @@ where Self::enact_verdict(account, alive_contract_info, current_block_number, verdict, false); // Check what happened after enaction of the verdict. - let alive_contract_info = match new_contract_info { - None | Some(ContractInfo::Tombstone(_)) => return Err(ContractAccessError::IsTombstone), + let alive_contract_info = match new_contract_info.map_err(|_| IsTombstone)? { + None | Some(ContractInfo::Tombstone(_)) => return Err(IsTombstone), Some(ContractInfo::Alive(contract)) => contract, }; diff --git a/frame/contracts/src/storage.rs b/frame/contracts/src/storage.rs index ba09adb285b93..8355a97f50028 100644 --- a/frame/contracts/src/storage.rs +++ b/frame/contracts/src/storage.rs @@ -19,20 +19,37 @@ use crate::{ exec::{AccountIdOf, StorageKey}, AliveContractInfo, BalanceOf, CodeHash, ContractInfo, ContractInfoOf, Config, TrieId, - AccountCounter, + AccountCounter, DeletionQueue, Error, + weights::WeightInfo, }; +use codec::{Encode, Decode}; use sp_std::prelude::*; use sp_std::marker::PhantomData; use sp_io::hashing::blake2_256; use sp_runtime::traits::Bounded; use sp_core::crypto::UncheckedFrom; -use frame_support::{storage::child, StorageMap}; +use frame_support::{ + dispatch::DispatchResult, + StorageMap, + debug, + storage::{child::{self, KillOutcome}, StorageValue}, + traits::Get, + weights::Weight, +}; /// An error that means that the account requested either doesn't exist or represents a tombstone /// account. #[cfg_attr(test, derive(PartialEq, Eq, Debug))] pub struct ContractAbsentError; +#[derive(Encode, Decode)] +pub struct DeletedContract { + pair_count: u32, + trie_id: TrieId, +} + + + pub struct Storage(PhantomData); impl Storage @@ -190,18 +207,103 @@ where }) } - /// Removes the contract and all the storage associated with it. + /// Push a contract's trie to the deletion queue for lazy removal. /// - /// This function doesn't affect the account. - pub fn destroy_contract(address: &AccountIdOf, trie_id: &TrieId) { - >::remove(address); - child::kill_storage(&crate::child_trie_info(&trie_id), None); + /// You must make sure that the contract is also removed or converted into a tombstone + /// when queuing the trie for deletion. + pub fn queue_trie_for_deletion(contract: &AliveContractInfo) -> DispatchResult { + if DeletionQueue::decode_len().unwrap_or(0) >= T::DeletionQueueDepth::get() as usize { + Err(Error::::DeletionQueueFull.into()) + } else { + DeletionQueue::append(DeletedContract { + pair_count: contract.total_pair_count, + trie_id: contract.trie_id.clone(), + }); + Ok(()) + } + } + + /// Calculates the weight that is necessary to remove one key from the trie and how many + /// of those keys can be deleted from the deletion queue given the supplied queue length + /// and weight limit. + pub fn deletion_budget(queue_len: usize, weight_limit: Weight) -> (u64, u32) { + let base_weight = T::WeightInfo::on_initialize(); + let weight_per_queue_item = T::WeightInfo::on_initialize_per_queue_item(1) - + T::WeightInfo::on_initialize_per_queue_item(0); + let weight_per_key = T::WeightInfo::on_initialize_per_trie_key(1) - + T::WeightInfo::on_initialize_per_trie_key(0); + let decoding_weight = weight_per_queue_item.saturating_mul(queue_len as Weight); + + // `weight_per_key` being zero makes no sense and would constitute a failure to + // benchmark properly. We opt for not removing any keys at all in this case. + let key_budget = weight_limit + .saturating_sub(base_weight) + .saturating_sub(decoding_weight) + .checked_div(weight_per_key) + .unwrap_or(0) as u32; + + (weight_per_key, key_budget) + } + + /// Delete as many items from the deletion queue possible within the supplied weight limit. + /// + /// It returns the amount of weight used for that task or `None` when no weight was used + /// apart from the base weight. + pub fn process_deletion_queue_batch(weight_limit: Weight) -> Option { + // We can decode the queue eagerly because we cap the queue depth and assume + // that the weight is large enough to do at least one round of deletions. + // We can assume that because any other static configuration of the runtime + // would make no sense at all. + let mut queue = DeletionQueue::get(); + if queue.is_empty() { + return None; + } + + let (weight_per_key, mut remaining_key_budget) = Self::deletion_budget( + queue.len(), + weight_limit, + ); + + while !queue.is_empty() && remaining_key_budget > 0 { + // Cannot panic due to loop condition + let trie = &mut queue[0]; + let pair_count = trie.pair_count; + let outcome = child::kill_storage( + &crate::child_trie_info(&trie.trie_id), + Some(remaining_key_budget), + ); + if pair_count > remaining_key_budget { + // Cannot underflow because of the if condition + trie.pair_count -= remaining_key_budget; + } else { + // We do not care to preserve order. The contract is deleted already and + // noone waits for the trie to be deleted. + let removed = queue.swap_remove(0); + match outcome { + // This should not happen as our budget was large enough to remove all keys. + KillOutcome::SomeRemaining => { + debug::warn!( + "After deletion keys are remaining in this child trie: {:?}", + removed.trie_id, + ); + }, + KillOutcome::AllRemoved => (), + } + } + remaining_key_budget = remaining_key_budget + .saturating_sub(remaining_key_budget.min(pair_count)); + } + + DeletionQueue::put(queue); + Some( + weight_limit + .saturating_sub(weight_per_key.saturating_mul(remaining_key_budget as Weight)) + ) } /// This generator uses inner counter for account id and applies the hash over `AccountId + /// accountid_counter`. pub fn generate_trie_id(account_id: &AccountIdOf) -> TrieId { - use frame_support::StorageValue; use sp_runtime::traits::Hash; // Note that skipping a value due to error is not an issue here. // We only need uniqueness, not sequence. @@ -225,4 +327,15 @@ where .and_then(|i| i.as_alive().map(|i| i.code_hash)) .ok_or(ContractAbsentError) } + + /// Fill up the queue in order to exercise the limits during testing. + #[cfg(test)] + pub fn fill_queue_with_dummies() { + let queue: Vec<_> = (0..T::DeletionQueueDepth::get()).map(|_| DeletedContract { + pair_count: 0, + trie_id: vec![], + }) + .collect(); + DeletionQueue::put(queue); + } } \ No newline at end of file diff --git a/frame/contracts/src/tests.rs b/frame/contracts/src/tests.rs index 91395e9642d10..043fdc5c04af5 100644 --- a/frame/contracts/src/tests.rs +++ b/frame/contracts/src/tests.rs @@ -27,12 +27,14 @@ use sp_runtime::{ testing::{Header, H256}, AccountId32, }; +use sp_io::hashing::blake2_256; use frame_support::{ - assert_ok, assert_err_ignore_postinfo, impl_outer_dispatch, impl_outer_event, + assert_ok, assert_err, assert_err_ignore_postinfo, impl_outer_dispatch, impl_outer_event, impl_outer_origin, parameter_types, StorageMap, - traits::{Currency, ReservableCurrency}, + traits::{Currency, ReservableCurrency, OnInitialize}, weights::{Weight, PostDispatchInfo}, dispatch::DispatchErrorWithPostInfo, + storage::child, }; use frame_system::{self as system, EventRecord, Phase}; @@ -158,6 +160,8 @@ parameter_types! { pub const SurchargeReward: u64 = 150; pub const MaxDepth: u32 = 100; pub const MaxValueSize: u32 = 16_384; + pub const DeletionQueueDepth: u32 = 1024; + pub const DeletionWeightLimit: Weight = 500_000_000_000; } parameter_types! { @@ -186,6 +190,8 @@ impl Config for Test { type MaxValueSize = MaxValueSize; type WeightPrice = Self; type WeightInfo = (); + type DeletionQueueDepth = DeletionQueueDepth; + type DeletionWeightLimit = DeletionWeightLimit; } type Balances = pallet_balances::Module; @@ -824,7 +830,7 @@ fn claim_surcharge(blocks: u64, trigger_call: impl Fn(AccountIdOf) -> bool initialize_block(blocks); // Trigger rent through call - assert!(trigger_call(addr.clone())); + assert_eq!(trigger_call(addr.clone()), removes); if removes { assert!(ContractInfoOf::::get(&addr).unwrap().get_tombstone().is_some()); @@ -862,7 +868,7 @@ fn removals(trigger_call: impl Fn(AccountIdOf) -> bool) { let subsistence_threshold = 50 /*existential_deposit*/ + 16 /*tombstone_deposit*/; // Trigger rent must have no effect - assert!(trigger_call(addr.clone())); + assert!(!trigger_call(addr.clone())); assert_eq!(ContractInfoOf::::get(&addr).unwrap().get_alive().unwrap().rent_allowance, 1_000); assert_eq!(Balances::free_balance(&addr), 100); @@ -878,7 +884,7 @@ fn removals(trigger_call: impl Fn(AccountIdOf) -> bool) { initialize_block(20); // Trigger rent must have no effect - assert!(trigger_call(addr.clone())); + assert!(!trigger_call(addr.clone())); assert!(ContractInfoOf::::get(&addr).unwrap().get_tombstone().is_some()); assert_eq!(Balances::free_balance(&addr), subsistence_threshold); }); @@ -902,7 +908,7 @@ fn removals(trigger_call: impl Fn(AccountIdOf) -> bool) { let addr = Contracts::contract_address(&ALICE, &code_hash, &[]); // Trigger rent must have no effect - assert!(trigger_call(addr.clone())); + assert!(!trigger_call(addr.clone())); assert_eq!( ContractInfoOf::::get(&addr) .unwrap() @@ -929,7 +935,7 @@ fn removals(trigger_call: impl Fn(AccountIdOf) -> bool) { initialize_block(20); // Trigger rent must have no effect - assert!(trigger_call(addr.clone())); + assert!(!trigger_call(addr.clone())); assert!(ContractInfoOf::::get(&addr) .unwrap() .get_tombstone() @@ -958,7 +964,7 @@ fn removals(trigger_call: impl Fn(AccountIdOf) -> bool) { let addr = Contracts::contract_address(&ALICE, &code_hash, &[]); // Trigger rent must have no effect - assert!(trigger_call(addr.clone())); + assert!(!trigger_call(addr.clone())); assert_eq!( ContractInfoOf::::get(&addr) .unwrap() @@ -1002,7 +1008,7 @@ fn removals(trigger_call: impl Fn(AccountIdOf) -> bool) { initialize_block(20); // Trigger rent must have no effect - assert!(trigger_call(addr.clone())); + assert!(!trigger_call(addr.clone())); assert_matches!(ContractInfoOf::::get(&addr), Some(ContractInfo::Tombstone(_))); assert_eq!(Balances::free_balance(&addr), subsistence_threshold); }); @@ -1912,3 +1918,176 @@ fn instantiate_return_code() { }); } + +#[test] +fn lazy_removal_works() { + let (code, hash) = compile_module::("self_destruct").unwrap(); + ExtBuilder::default().existential_deposit(50).build().execute_with(|| { + let subsistence = ConfigCache::::subsistence_threshold_uncached(); + let _ = Balances::deposit_creating(&ALICE, 10 * subsistence); + assert_ok!(Contracts::put_code(Origin::signed(ALICE), code)); + + assert_ok!( + Contracts::instantiate( + Origin::signed(ALICE), + subsistence, + GAS_LIMIT, + hash.into(), + vec![], + vec![], + ), + ); + + let addr = Contracts::contract_address(&ALICE, &hash, &[]); + let info = >::get(&addr).unwrap().get_alive().unwrap(); + let trie = &info.child_trie_info(); + + // Put value into the contracts child trie + child::put(trie, &[99], &42); + + // Terminate the contract + assert_ok!(Contracts::call( + Origin::signed(ALICE), + addr.clone(), + 0, + GAS_LIMIT, + vec![], + )); + + // Contract info should be gone + assert!(!>::contains_key(&addr)); + + // But value should be still there as the lazy removal did not run, yet. + assert_matches!(child::get(trie, &[99]), Some(42)); + + // Run the lazy removal + Contracts::on_initialize(0); + + // Value should be gone now + assert_matches!(child::get::(trie, &[99]), None); + }); +} + +#[test] +fn lazy_removal_does_not_use_all_weight() { + let (code, hash) = compile_module::("self_destruct").unwrap(); + ExtBuilder::default().existential_deposit(50).build().execute_with(|| { + let subsistence = ConfigCache::::subsistence_threshold_uncached(); + let _ = Balances::deposit_creating(&ALICE, 10 * subsistence); + assert_ok!(Contracts::put_code(Origin::signed(ALICE), code)); + + assert_ok!( + Contracts::instantiate( + Origin::signed(ALICE), + subsistence, + GAS_LIMIT, + hash.into(), + vec![], + vec![], + ), + ); + + let addr = Contracts::contract_address(&ALICE, &hash, &[]); + let info = >::get(&addr).unwrap().get_alive().unwrap(); + let trie = &info.child_trie_info(); + let weight_limit = 5_000_000_000; + let (weight_per_key, max_keys) = Storage::::deletion_budget(1, weight_limit); + + // We create a contract with one less storage item than we can remove within the limit + let vals: Vec<_> = (0..max_keys - 1).map(|i| { + (blake2_256(&i.encode()), (i as u32), (i as u32).encode()) + }) + .collect(); + + // Put value into the contracts child trie + for val in &vals { + Storage::::write( + &addr, + &info.trie_id, + &val.0, + Some(val.2.clone()), + ).unwrap(); + } + + // Terminate the contract + assert_ok!(Contracts::call( + Origin::signed(ALICE), + addr.clone(), + 0, + GAS_LIMIT, + vec![], + )); + + // Contract info should be gone + assert!(!>::contains_key(&addr)); + + // But value should be still there as the lazy removal did not run, yet. + for val in &vals { + assert_eq!(child::get::(trie, &blake2_256(&val.0)), Some(val.1)); + } + + // Run the lazy removal + let weight_used = Storage::::process_deletion_queue_batch(weight_limit).unwrap(); + + // We have one less key in our trie than our weight limit suffices for + assert_eq!(weight_used, weight_limit - weight_per_key); + + // All the keys are removed + for val in vals { + assert_eq!(child::get::(trie, &blake2_256(&val.0)), None); + } + }); +} + +#[test] +fn deletion_queue_full() { + let (code, hash) = compile_module::("self_destruct").unwrap(); + ExtBuilder::default().existential_deposit(50).build().execute_with(|| { + let subsistence = ConfigCache::::subsistence_threshold_uncached(); + let _ = Balances::deposit_creating(&ALICE, 10 * subsistence); + assert_ok!(Contracts::put_code(Origin::signed(ALICE), code)); + + assert_ok!( + Contracts::instantiate( + Origin::signed(ALICE), + subsistence, + GAS_LIMIT, + hash.into(), + vec![], + vec![], + ), + ); + + let addr = Contracts::contract_address(&ALICE, &hash, &[]); + + // fill the deletion queue up until its limit + Storage::::fill_queue_with_dummies(); + + // Terminate the contract should fail + assert_err_ignore_postinfo!( + Contracts::call( + Origin::signed(ALICE), + addr.clone(), + 0, + GAS_LIMIT, + vec![], + ), + Error::::DeletionQueueFull, + ); + + // Contract should be alive because removal failed + >::get(&addr).unwrap().get_alive().unwrap(); + + // make the contract ripe for eviction + initialize_block(5); + + // eviction should fail for the same reason as termination + assert_err!( + Contracts::claim_surcharge(Origin::none(), addr.clone(), Some(ALICE)), + Error::::DeletionQueueFull, + ); + + // Contract should be alive because removal failed + >::get(&addr).unwrap().get_alive().unwrap(); + }); +} diff --git a/frame/contracts/src/weights.rs b/frame/contracts/src/weights.rs index 24c1273a44ffb..8baaac977d63a 100644 --- a/frame/contracts/src/weights.rs +++ b/frame/contracts/src/weights.rs @@ -15,9 +15,10 @@ // See the License for the specific language governing permissions and // limitations under the License. -//! Weights for pallet_contracts +//! Autogenerated weights for pallet_contracts +//! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 2.0.0 -//! DATE: 2020-11-10, STEPS: [50, ], REPEAT: 20, LOW RANGE: [], HIGH RANGE: [] +//! DATE: 2020-12-12, STEPS: [50, ], REPEAT: 20, LOW RANGE: [], HIGH RANGE: [] //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 128 // Executed Command: @@ -43,6 +44,9 @@ use sp_std::marker::PhantomData; /// Weight functions needed for pallet_contracts. pub trait WeightInfo { + fn on_initialize() -> Weight; + fn on_initialize_per_trie_key(k: u32, ) -> Weight; + fn on_initialize_per_queue_item(q: u32, ) -> Weight; fn update_schedule() -> Weight; fn put_code(n: u32, ) -> Weight; fn instantiate(n: u32, s: u32, ) -> Weight; @@ -145,948 +149,1182 @@ pub trait WeightInfo { /// Weights for pallet_contracts using the Substrate node and recommended hardware. pub struct SubstrateWeight(PhantomData); impl WeightInfo for SubstrateWeight { + fn on_initialize() -> Weight { + (7_239_000 as Weight) + .saturating_add(T::DbWeight::get().reads(1 as Weight)) + } + fn on_initialize_per_trie_key(k: u32, ) -> Weight { + (40_584_000 as Weight) + // Standard Error: 4_000 + .saturating_add((2_314_000 as Weight).saturating_mul(k as Weight)) + .saturating_add(T::DbWeight::get().reads(1 as Weight)) + .saturating_add(T::DbWeight::get().writes((1 as Weight).saturating_mul(k as Weight))) + } + fn on_initialize_per_queue_item(q: u32, ) -> Weight { + (0 as Weight) + // Standard Error: 175_000 + .saturating_add((135_919_000 as Weight).saturating_mul(q as Weight)) + .saturating_add(T::DbWeight::get().reads(1 as Weight)) + } fn update_schedule() -> Weight { - (35_214_000 as Weight) + (36_262_000 as Weight) .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } fn put_code(n: u32, ) -> Weight { - (0 as Weight) - .saturating_add((109_242_000 as Weight).saturating_mul(n as Weight)) + (22_510_000 as Weight) + // Standard Error: 209_000 + .saturating_add((113_251_000 as Weight).saturating_mul(n as Weight)) .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } fn instantiate(n: u32, s: u32, ) -> Weight { - (195_276_000 as Weight) - .saturating_add((35_000 as Weight).saturating_mul(n as Weight)) - .saturating_add((2_244_000 as Weight).saturating_mul(s as Weight)) + (216_181_000 as Weight) + // Standard Error: 1_000 + .saturating_add((6_000 as Weight).saturating_mul(n as Weight)) + // Standard Error: 1_000 + .saturating_add((2_240_000 as Weight).saturating_mul(s as Weight)) .saturating_add(T::DbWeight::get().reads(6 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight)) } fn call() -> Weight { - (207_142_000 as Weight) + (209_785_000 as Weight) .saturating_add(T::DbWeight::get().reads(5 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } fn claim_surcharge() -> Weight { - (489_633_000 as Weight) - .saturating_add(T::DbWeight::get().reads(3 as Weight)) - .saturating_add(T::DbWeight::get().writes(2 as Weight)) + (302_124_000 as Weight) + .saturating_add(T::DbWeight::get().reads(4 as Weight)) + .saturating_add(T::DbWeight::get().writes(3 as Weight)) } fn seal_caller(r: u32, ) -> Weight { - (136_550_000 as Weight) - .saturating_add((373_182_000 as Weight).saturating_mul(r as Weight)) + (138_697_000 as Weight) + // Standard Error: 412_000 + .saturating_add((390_370_000 as Weight).saturating_mul(r as Weight)) .saturating_add(T::DbWeight::get().reads(4 as Weight)) } fn seal_address(r: u32, ) -> Weight { - (136_329_000 as Weight) - .saturating_add((373_392_000 as Weight).saturating_mul(r as Weight)) + (141_999_000 as Weight) + // Standard Error: 218_000 + .saturating_add((389_261_000 as Weight).saturating_mul(r as Weight)) .saturating_add(T::DbWeight::get().reads(4 as Weight)) } fn seal_gas_left(r: u32, ) -> Weight { - (111_577_000 as Weight) - .saturating_add((373_536_000 as Weight).saturating_mul(r as Weight)) + (134_956_000 as Weight) + // Standard Error: 205_000 + .saturating_add((384_439_000 as Weight).saturating_mul(r as Weight)) .saturating_add(T::DbWeight::get().reads(4 as Weight)) } fn seal_balance(r: u32, ) -> Weight { - (157_531_000 as Weight) - .saturating_add((810_382_000 as Weight).saturating_mul(r as Weight)) + (130_585_000 as Weight) + // Standard Error: 784_000 + .saturating_add((860_797_000 as Weight).saturating_mul(r as Weight)) .saturating_add(T::DbWeight::get().reads(5 as Weight)) } fn seal_value_transferred(r: u32, ) -> Weight { - (143_801_000 as Weight) - .saturating_add((369_769_000 as Weight).saturating_mul(r as Weight)) + (138_382_000 as Weight) + // Standard Error: 163_000 + .saturating_add((384_676_000 as Weight).saturating_mul(r as Weight)) .saturating_add(T::DbWeight::get().reads(4 as Weight)) } fn seal_minimum_balance(r: u32, ) -> Weight { - (133_546_000 as Weight) - .saturating_add((370_036_000 as Weight).saturating_mul(r as Weight)) + (137_766_000 as Weight) + // Standard Error: 218_000 + .saturating_add((386_002_000 as Weight).saturating_mul(r as Weight)) .saturating_add(T::DbWeight::get().reads(4 as Weight)) } fn seal_tombstone_deposit(r: u32, ) -> Weight { - (138_568_000 as Weight) - .saturating_add((370_322_000 as Weight).saturating_mul(r as Weight)) + (144_552_000 as Weight) + // Standard Error: 187_000 + .saturating_add((384_754_000 as Weight).saturating_mul(r as Weight)) .saturating_add(T::DbWeight::get().reads(4 as Weight)) } fn seal_rent_allowance(r: u32, ) -> Weight { - (144_431_000 as Weight) - .saturating_add((851_810_000 as Weight).saturating_mul(r as Weight)) + (150_812_000 as Weight) + // Standard Error: 276_000 + .saturating_add((903_965_000 as Weight).saturating_mul(r as Weight)) .saturating_add(T::DbWeight::get().reads(4 as Weight)) } fn seal_block_number(r: u32, ) -> Weight { - (133_237_000 as Weight) - .saturating_add((369_156_000 as Weight).saturating_mul(r as Weight)) + (145_168_000 as Weight) + // Standard Error: 191_000 + .saturating_add((382_798_000 as Weight).saturating_mul(r as Weight)) .saturating_add(T::DbWeight::get().reads(4 as Weight)) } fn seal_now(r: u32, ) -> Weight { - (139_700_000 as Weight) - .saturating_add((368_961_000 as Weight).saturating_mul(r as Weight)) + (145_806_000 as Weight) + // Standard Error: 195_000 + .saturating_add((382_888_000 as Weight).saturating_mul(r as Weight)) .saturating_add(T::DbWeight::get().reads(4 as Weight)) } fn seal_weight_to_fee(r: u32, ) -> Weight { - (149_395_000 as Weight) - .saturating_add((625_812_000 as Weight).saturating_mul(r as Weight)) + (154_081_000 as Weight) + // Standard Error: 248_000 + .saturating_add((716_294_000 as Weight).saturating_mul(r as Weight)) .saturating_add(T::DbWeight::get().reads(5 as Weight)) } fn seal_gas(r: u32, ) -> Weight { - (125_777_000 as Weight) - .saturating_add((187_585_000 as Weight).saturating_mul(r as Weight)) + (149_684_000 as Weight) + // Standard Error: 460_000 + .saturating_add((196_251_000 as Weight).saturating_mul(r as Weight)) .saturating_add(T::DbWeight::get().reads(4 as Weight)) } fn seal_input(r: u32, ) -> Weight { - (132_584_000 as Weight) - .saturating_add((7_661_000 as Weight).saturating_mul(r as Weight)) + (135_447_000 as Weight) + // Standard Error: 75_000 + .saturating_add((8_362_000 as Weight).saturating_mul(r as Weight)) .saturating_add(T::DbWeight::get().reads(4 as Weight)) } fn seal_input_per_kb(n: u32, ) -> Weight { - (143_408_000 as Weight) - .saturating_add((274_000 as Weight).saturating_mul(n as Weight)) + (146_099_000 as Weight) + // Standard Error: 0 + .saturating_add((270_000 as Weight).saturating_mul(n as Weight)) .saturating_add(T::DbWeight::get().reads(4 as Weight)) } fn seal_return(r: u32, ) -> Weight { - (126_257_000 as Weight) - .saturating_add((5_455_000 as Weight).saturating_mul(r as Weight)) + (125_358_000 as Weight) + // Standard Error: 52_000 + .saturating_add((5_454_000 as Weight).saturating_mul(r as Weight)) .saturating_add(T::DbWeight::get().reads(4 as Weight)) } fn seal_return_per_kb(n: u32, ) -> Weight { - (133_286_000 as Weight) - .saturating_add((698_000 as Weight).saturating_mul(n as Weight)) + (135_523_000 as Weight) + // Standard Error: 0 + .saturating_add((785_000 as Weight).saturating_mul(n as Weight)) .saturating_add(T::DbWeight::get().reads(4 as Weight)) } fn seal_terminate(r: u32, ) -> Weight { - (130_607_000 as Weight) - .saturating_add((358_370_000 as Weight).saturating_mul(r as Weight)) + (135_321_000 as Weight) + // Standard Error: 100_000 + .saturating_add((110_300_000 as Weight).saturating_mul(r as Weight)) .saturating_add(T::DbWeight::get().reads(4 as Weight)) - .saturating_add(T::DbWeight::get().reads((2 as Weight).saturating_mul(r as Weight))) - .saturating_add(T::DbWeight::get().writes((3 as Weight).saturating_mul(r as Weight))) + .saturating_add(T::DbWeight::get().reads((3 as Weight).saturating_mul(r as Weight))) + .saturating_add(T::DbWeight::get().writes((4 as Weight).saturating_mul(r as Weight))) } fn seal_restore_to(r: u32, ) -> Weight { - (233_645_000 as Weight) - .saturating_add((135_355_000 as Weight).saturating_mul(r as Weight)) + (242_790_000 as Weight) + // Standard Error: 823_000 + .saturating_add((135_544_000 as Weight).saturating_mul(r as Weight)) .saturating_add(T::DbWeight::get().reads(5 as Weight)) .saturating_add(T::DbWeight::get().reads((3 as Weight).saturating_mul(r as Weight))) .saturating_add(T::DbWeight::get().writes((4 as Weight).saturating_mul(r as Weight))) } fn seal_restore_to_per_delta(d: u32, ) -> Weight { - (74_573_000 as Weight) - .saturating_add((3_768_682_000 as Weight).saturating_mul(d as Weight)) + (34_052_000 as Weight) + // Standard Error: 2_395_000 + .saturating_add((3_970_866_000 as Weight).saturating_mul(d as Weight)) .saturating_add(T::DbWeight::get().reads(7 as Weight)) .saturating_add(T::DbWeight::get().reads((100 as Weight).saturating_mul(d as Weight))) .saturating_add(T::DbWeight::get().writes(5 as Weight)) .saturating_add(T::DbWeight::get().writes((100 as Weight).saturating_mul(d as Weight))) } fn seal_random(r: u32, ) -> Weight { - (140_286_000 as Weight) - .saturating_add((950_890_000 as Weight).saturating_mul(r as Weight)) + (154_549_000 as Weight) + // Standard Error: 692_000 + .saturating_add((989_540_000 as Weight).saturating_mul(r as Weight)) .saturating_add(T::DbWeight::get().reads(5 as Weight)) } fn seal_deposit_event(r: u32, ) -> Weight { - (167_735_000 as Weight) - .saturating_add((1_375_429_000 as Weight).saturating_mul(r as Weight)) + (125_367_000 as Weight) + // Standard Error: 977_000 + .saturating_add((1_424_216_000 as Weight).saturating_mul(r as Weight)) .saturating_add(T::DbWeight::get().reads(4 as Weight)) } fn seal_deposit_event_per_topic_and_kb(t: u32, n: u32, ) -> Weight { - (1_715_857_000 as Weight) - .saturating_add((760_777_000 as Weight).saturating_mul(t as Weight)) - .saturating_add((241_853_000 as Weight).saturating_mul(n as Weight)) + (1_843_333_000 as Weight) + // Standard Error: 3_040_000 + .saturating_add((771_663_000 as Weight).saturating_mul(t as Weight)) + // Standard Error: 599_000 + .saturating_add((251_555_000 as Weight).saturating_mul(n as Weight)) .saturating_add(T::DbWeight::get().reads(4 as Weight)) .saturating_add(T::DbWeight::get().reads((100 as Weight).saturating_mul(t as Weight))) .saturating_add(T::DbWeight::get().writes((100 as Weight).saturating_mul(t as Weight))) } fn seal_set_rent_allowance(r: u32, ) -> Weight { - (156_911_000 as Weight) - .saturating_add((1_006_139_000 as Weight).saturating_mul(r as Weight)) + (136_437_000 as Weight) + // Standard Error: 299_000 + .saturating_add((1_072_778_000 as Weight).saturating_mul(r as Weight)) .saturating_add(T::DbWeight::get().reads(4 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } fn seal_set_storage(r: u32, ) -> Weight { - (0 as Weight) - .saturating_add((14_938_793_000 as Weight).saturating_mul(r as Weight)) + (182_452_000 as Weight) + // Standard Error: 26_839_000 + .saturating_add((15_911_876_000 as Weight).saturating_mul(r as Weight)) .saturating_add(T::DbWeight::get().reads(4 as Weight)) .saturating_add(T::DbWeight::get().reads((100 as Weight).saturating_mul(r as Weight))) .saturating_add(T::DbWeight::get().writes(1 as Weight)) .saturating_add(T::DbWeight::get().writes((100 as Weight).saturating_mul(r as Weight))) } fn seal_set_storage_per_kb(n: u32, ) -> Weight { - (2_300_169_000 as Weight) - .saturating_add((204_543_000 as Weight).saturating_mul(n as Weight)) + (2_385_415_000 as Weight) + // Standard Error: 751_000 + .saturating_add((223_264_000 as Weight).saturating_mul(n as Weight)) .saturating_add(T::DbWeight::get().reads(5 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } fn seal_clear_storage(r: u32, ) -> Weight { (0 as Weight) - .saturating_add((5_140_241_000 as Weight).saturating_mul(r as Weight)) + // Standard Error: 2_154_000 + .saturating_add((5_341_117_000 as Weight).saturating_mul(r as Weight)) .saturating_add(T::DbWeight::get().reads(4 as Weight)) .saturating_add(T::DbWeight::get().reads((100 as Weight).saturating_mul(r as Weight))) .saturating_add(T::DbWeight::get().writes(1 as Weight)) .saturating_add(T::DbWeight::get().writes((100 as Weight).saturating_mul(r as Weight))) } fn seal_get_storage(r: u32, ) -> Weight { - (45_212_000 as Weight) - .saturating_add((1_131_504_000 as Weight).saturating_mul(r as Weight)) + (62_353_000 as Weight) + // Standard Error: 1_183_000 + .saturating_add((1_141_653_000 as Weight).saturating_mul(r as Weight)) .saturating_add(T::DbWeight::get().reads(4 as Weight)) .saturating_add(T::DbWeight::get().reads((100 as Weight).saturating_mul(r as Weight))) } fn seal_get_storage_per_kb(n: u32, ) -> Weight { - (885_531_000 as Weight) - .saturating_add((148_986_000 as Weight).saturating_mul(n as Weight)) + (905_905_000 as Weight) + // Standard Error: 363_000 + .saturating_add((155_161_000 as Weight).saturating_mul(n as Weight)) .saturating_add(T::DbWeight::get().reads(5 as Weight)) } fn seal_transfer(r: u32, ) -> Weight { - (92_276_000 as Weight) - .saturating_add((6_216_852_000 as Weight).saturating_mul(r as Weight)) + (60_519_000 as Weight) + // Standard Error: 1_942_000 + .saturating_add((6_453_551_000 as Weight).saturating_mul(r as Weight)) .saturating_add(T::DbWeight::get().reads(5 as Weight)) .saturating_add(T::DbWeight::get().reads((100 as Weight).saturating_mul(r as Weight))) .saturating_add(T::DbWeight::get().writes(1 as Weight)) .saturating_add(T::DbWeight::get().writes((100 as Weight).saturating_mul(r as Weight))) } fn seal_call(r: u32, ) -> Weight { - (0 as Weight) - .saturating_add((10_734_719_000 as Weight).saturating_mul(r as Weight)) + (192_122_000 as Weight) + // Standard Error: 7_851_000 + .saturating_add((10_736_771_000 as Weight).saturating_mul(r as Weight)) .saturating_add(T::DbWeight::get().reads(5 as Weight)) .saturating_add(T::DbWeight::get().reads((100 as Weight).saturating_mul(r as Weight))) } fn seal_call_per_transfer_input_output_kb(t: u32, i: u32, o: u32, ) -> Weight { - (12_735_614_000 as Weight) - .saturating_add((2_870_730_000 as Weight).saturating_mul(t as Weight)) - .saturating_add((52_569_000 as Weight).saturating_mul(i as Weight)) - .saturating_add((73_956_000 as Weight).saturating_mul(o as Weight)) + (10_599_501_000 as Weight) + // Standard Error: 133_182_000 + .saturating_add((5_423_848_000 as Weight).saturating_mul(t as Weight)) + // Standard Error: 47_000 + .saturating_add((60_108_000 as Weight).saturating_mul(i as Weight)) + // Standard Error: 50_000 + .saturating_add((82_691_000 as Weight).saturating_mul(o as Weight)) .saturating_add(T::DbWeight::get().reads(105 as Weight)) .saturating_add(T::DbWeight::get().reads((101 as Weight).saturating_mul(t as Weight))) .saturating_add(T::DbWeight::get().writes((101 as Weight).saturating_mul(t as Weight))) } fn seal_instantiate(r: u32, ) -> Weight { (0 as Weight) - .saturating_add((22_365_908_000 as Weight).saturating_mul(r as Weight)) + // Standard Error: 39_807_000 + .saturating_add((22_562_812_000 as Weight).saturating_mul(r as Weight)) .saturating_add(T::DbWeight::get().reads(6 as Weight)) .saturating_add(T::DbWeight::get().reads((300 as Weight).saturating_mul(r as Weight))) .saturating_add(T::DbWeight::get().writes(2 as Weight)) .saturating_add(T::DbWeight::get().writes((200 as Weight).saturating_mul(r as Weight))) } fn seal_instantiate_per_input_output_salt_kb(i: u32, o: u32, s: u32, ) -> Weight { - (18_899_296_000 as Weight) - .saturating_add((53_289_000 as Weight).saturating_mul(i as Weight)) - .saturating_add((76_026_000 as Weight).saturating_mul(o as Weight)) - .saturating_add((281_097_000 as Weight).saturating_mul(s as Weight)) + (19_823_256_000 as Weight) + // Standard Error: 153_000 + .saturating_add((60_707_000 as Weight).saturating_mul(i as Weight)) + // Standard Error: 153_000 + .saturating_add((83_770_000 as Weight).saturating_mul(o as Weight)) + // Standard Error: 153_000 + .saturating_add((284_423_000 as Weight).saturating_mul(s as Weight)) .saturating_add(T::DbWeight::get().reads(207 as Weight)) .saturating_add(T::DbWeight::get().writes(202 as Weight)) } fn seal_hash_sha2_256(r: u32, ) -> Weight { - (136_601_000 as Weight) - .saturating_add((323_373_000 as Weight).saturating_mul(r as Weight)) + (142_838_000 as Weight) + // Standard Error: 243_000 + .saturating_add((332_354_000 as Weight).saturating_mul(r as Weight)) .saturating_add(T::DbWeight::get().reads(4 as Weight)) } fn seal_hash_sha2_256_per_kb(n: u32, ) -> Weight { - (777_563_000 as Weight) - .saturating_add((423_353_000 as Weight).saturating_mul(n as Weight)) + (877_119_000 as Weight) + // Standard Error: 73_000 + .saturating_add((434_752_000 as Weight).saturating_mul(n as Weight)) .saturating_add(T::DbWeight::get().reads(4 as Weight)) } fn seal_hash_keccak_256(r: u32, ) -> Weight { - (136_771_000 as Weight) - .saturating_add((337_881_000 as Weight).saturating_mul(r as Weight)) + (139_913_000 as Weight) + // Standard Error: 160_000 + .saturating_add((345_830_000 as Weight).saturating_mul(r as Weight)) .saturating_add(T::DbWeight::get().reads(4 as Weight)) } fn seal_hash_keccak_256_per_kb(n: u32, ) -> Weight { - (337_906_000 as Weight) - .saturating_add((336_778_000 as Weight).saturating_mul(n as Weight)) + (723_122_000 as Weight) + // Standard Error: 29_000 + .saturating_add((343_949_000 as Weight).saturating_mul(n as Weight)) .saturating_add(T::DbWeight::get().reads(4 as Weight)) } fn seal_hash_blake2_256(r: u32, ) -> Weight { - (131_040_000 as Weight) - .saturating_add((312_992_000 as Weight).saturating_mul(r as Weight)) + (137_249_000 as Weight) + // Standard Error: 168_000 + .saturating_add((320_295_000 as Weight).saturating_mul(r as Weight)) .saturating_add(T::DbWeight::get().reads(4 as Weight)) } fn seal_hash_blake2_256_per_kb(n: u32, ) -> Weight { - (693_415_000 as Weight) - .saturating_add((152_745_000 as Weight).saturating_mul(n as Weight)) + (736_756_000 as Weight) + // Standard Error: 39_000 + .saturating_add((159_952_000 as Weight).saturating_mul(n as Weight)) .saturating_add(T::DbWeight::get().reads(4 as Weight)) } fn seal_hash_blake2_128(r: u32, ) -> Weight { - (135_654_000 as Weight) - .saturating_add((311_271_000 as Weight).saturating_mul(r as Weight)) + (124_530_000 as Weight) + // Standard Error: 203_000 + .saturating_add((321_292_000 as Weight).saturating_mul(r as Weight)) .saturating_add(T::DbWeight::get().reads(4 as Weight)) } fn seal_hash_blake2_128_per_kb(n: u32, ) -> Weight { - (839_521_000 as Weight) - .saturating_add((153_146_000 as Weight).saturating_mul(n as Weight)) + (782_032_000 as Weight) + // Standard Error: 36_000 + .saturating_add((159_878_000 as Weight).saturating_mul(n as Weight)) .saturating_add(T::DbWeight::get().reads(4 as Weight)) } fn instr_i64const(r: u32, ) -> Weight { - (26_679_000 as Weight) - .saturating_add((3_155_000 as Weight).saturating_mul(r as Weight)) + (24_624_000 as Weight) + // Standard Error: 18_000 + .saturating_add((3_280_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64load(r: u32, ) -> Weight { - (28_920_000 as Weight) - .saturating_add((159_343_000 as Weight).saturating_mul(r as Weight)) + (27_171_000 as Weight) + // Standard Error: 62_000 + .saturating_add((161_737_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64store(r: u32, ) -> Weight { - (28_928_000 as Weight) - .saturating_add((227_286_000 as Weight).saturating_mul(r as Weight)) + (27_106_000 as Weight) + // Standard Error: 94_000 + .saturating_add((229_960_000 as Weight).saturating_mul(r as Weight)) } fn instr_select(r: u32, ) -> Weight { - (26_591_000 as Weight) - .saturating_add((12_591_000 as Weight).saturating_mul(r as Weight)) + (24_566_000 as Weight) + // Standard Error: 18_000 + .saturating_add((12_157_000 as Weight).saturating_mul(r as Weight)) } fn instr_if(r: u32, ) -> Weight { - (26_597_000 as Weight) - .saturating_add((12_258_000 as Weight).saturating_mul(r as Weight)) + (24_531_000 as Weight) + // Standard Error: 17_000 + .saturating_add((12_007_000 as Weight).saturating_mul(r as Weight)) } fn instr_br(r: u32, ) -> Weight { - (26_586_000 as Weight) - .saturating_add((5_811_000 as Weight).saturating_mul(r as Weight)) + (24_567_000 as Weight) + // Standard Error: 20_000 + .saturating_add((6_132_000 as Weight).saturating_mul(r as Weight)) } fn instr_br_if(r: u32, ) -> Weight { - (26_581_000 as Weight) - .saturating_add((14_058_000 as Weight).saturating_mul(r as Weight)) + (24_628_000 as Weight) + // Standard Error: 21_000 + .saturating_add((13_480_000 as Weight).saturating_mul(r as Weight)) } fn instr_br_table(r: u32, ) -> Weight { - (26_615_000 as Weight) - .saturating_add((15_687_000 as Weight).saturating_mul(r as Weight)) + (24_653_000 as Weight) + // Standard Error: 21_000 + .saturating_add((15_005_000 as Weight).saturating_mul(r as Weight)) } fn instr_br_table_per_entry(e: u32, ) -> Weight { - (40_963_000 as Weight) - .saturating_add((92_000 as Weight).saturating_mul(e as Weight)) + (38_573_000 as Weight) + // Standard Error: 0 + .saturating_add((118_000 as Weight).saturating_mul(e as Weight)) } fn instr_call(r: u32, ) -> Weight { - (26_880_000 as Weight) - .saturating_add((97_523_000 as Weight).saturating_mul(r as Weight)) + (24_952_000 as Weight) + // Standard Error: 61_000 + .saturating_add((99_409_000 as Weight).saturating_mul(r as Weight)) } fn instr_call_indirect(r: u32, ) -> Weight { - (34_628_000 as Weight) - .saturating_add((201_913_000 as Weight).saturating_mul(r as Weight)) + (32_478_000 as Weight) + // Standard Error: 242_000 + .saturating_add((193_797_000 as Weight).saturating_mul(r as Weight)) } fn instr_call_indirect_per_param(p: u32, ) -> Weight { - (255_763_000 as Weight) - .saturating_add((3_612_000 as Weight).saturating_mul(p as Weight)) + (238_200_000 as Weight) + // Standard Error: 4_000 + .saturating_add((3_467_000 as Weight).saturating_mul(p as Weight)) } fn instr_local_get(r: u32, ) -> Weight { - (45_954_000 as Weight) - .saturating_add((3_439_000 as Weight).saturating_mul(r as Weight)) + (41_994_000 as Weight) + // Standard Error: 22_000 + .saturating_add((3_230_000 as Weight).saturating_mul(r as Weight)) } fn instr_local_set(r: u32, ) -> Weight { - (45_952_000 as Weight) - .saturating_add((3_601_000 as Weight).saturating_mul(r as Weight)) + (41_994_000 as Weight) + // Standard Error: 20_000 + .saturating_add((3_558_000 as Weight).saturating_mul(r as Weight)) } fn instr_local_tee(r: u32, ) -> Weight { - (45_883_000 as Weight) - .saturating_add((5_203_000 as Weight).saturating_mul(r as Weight)) + (41_965_000 as Weight) + // Standard Error: 33_000 + .saturating_add((4_806_000 as Weight).saturating_mul(r as Weight)) } fn instr_global_get(r: u32, ) -> Weight { - (29_895_000 as Weight) - .saturating_add((8_221_000 as Weight).saturating_mul(r as Weight)) + (27_997_000 as Weight) + // Standard Error: 26_000 + .saturating_add((7_859_000 as Weight).saturating_mul(r as Weight)) } fn instr_global_set(r: u32, ) -> Weight { - (29_916_000 as Weight) - .saturating_add((12_036_000 as Weight).saturating_mul(r as Weight)) + (28_118_000 as Weight) + // Standard Error: 33_000 + .saturating_add((11_825_000 as Weight).saturating_mul(r as Weight)) } fn instr_memory_current(r: u32, ) -> Weight { - (28_878_000 as Weight) - .saturating_add((3_794_000 as Weight).saturating_mul(r as Weight)) + (27_172_000 as Weight) + // Standard Error: 19_000 + .saturating_add((3_466_000 as Weight).saturating_mul(r as Weight)) } fn instr_memory_grow(r: u32, ) -> Weight { - (27_351_000 as Weight) - .saturating_add((2_302_301_000 as Weight).saturating_mul(r as Weight)) + (25_582_000 as Weight) + // Standard Error: 4_756_000 + .saturating_add((2_290_170_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64clz(r: u32, ) -> Weight { - (26_535_000 as Weight) - .saturating_add((5_450_000 as Weight).saturating_mul(r as Weight)) + (24_712_000 as Weight) + // Standard Error: 24_000 + .saturating_add((5_226_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64ctz(r: u32, ) -> Weight { - (26_489_000 as Weight) - .saturating_add((5_410_000 as Weight).saturating_mul(r as Weight)) + (24_631_000 as Weight) + // Standard Error: 23_000 + .saturating_add((5_282_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64popcnt(r: u32, ) -> Weight { - (26_576_000 as Weight) - .saturating_add((5_976_000 as Weight).saturating_mul(r as Weight)) + (24_640_000 as Weight) + // Standard Error: 17_000 + .saturating_add((5_964_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64eqz(r: u32, ) -> Weight { - (26_521_000 as Weight) - .saturating_add((5_465_000 as Weight).saturating_mul(r as Weight)) + (24_631_000 as Weight) + // Standard Error: 11_000 + .saturating_add((5_128_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64extendsi32(r: u32, ) -> Weight { - (26_534_000 as Weight) - .saturating_add((5_375_000 as Weight).saturating_mul(r as Weight)) + (24_540_000 as Weight) + // Standard Error: 11_000 + .saturating_add((5_224_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64extendui32(r: u32, ) -> Weight { - (26_560_000 as Weight) - .saturating_add((5_284_000 as Weight).saturating_mul(r as Weight)) + (24_623_000 as Weight) + // Standard Error: 16_000 + .saturating_add((5_138_000 as Weight).saturating_mul(r as Weight)) } fn instr_i32wrapi64(r: u32, ) -> Weight { - (26_554_000 as Weight) - .saturating_add((5_358_000 as Weight).saturating_mul(r as Weight)) + (24_623_000 as Weight) + // Standard Error: 15_000 + .saturating_add((5_242_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64eq(r: u32, ) -> Weight { - (26_549_000 as Weight) - .saturating_add((7_402_000 as Weight).saturating_mul(r as Weight)) + (24_575_000 as Weight) + // Standard Error: 9_000 + .saturating_add((7_328_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64ne(r: u32, ) -> Weight { - (26_582_000 as Weight) - .saturating_add((7_266_000 as Weight).saturating_mul(r as Weight)) + (24_674_000 as Weight) + // Standard Error: 14_000 + .saturating_add((7_147_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64lts(r: u32, ) -> Weight { - (26_558_000 as Weight) - .saturating_add((7_293_000 as Weight).saturating_mul(r as Weight)) + (24_645_000 as Weight) + // Standard Error: 20_000 + .saturating_add((7_158_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64ltu(r: u32, ) -> Weight { - (26_569_000 as Weight) - .saturating_add((7_278_000 as Weight).saturating_mul(r as Weight)) + (24_688_000 as Weight) + // Standard Error: 16_000 + .saturating_add((7_226_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64gts(r: u32, ) -> Weight { - (26_516_000 as Weight) - .saturating_add((7_334_000 as Weight).saturating_mul(r as Weight)) + (24_579_000 as Weight) + // Standard Error: 13_000 + .saturating_add((7_187_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64gtu(r: u32, ) -> Weight { - (26_561_000 as Weight) - .saturating_add((7_283_000 as Weight).saturating_mul(r as Weight)) + (24_578_000 as Weight) + // Standard Error: 15_000 + .saturating_add((7_235_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64les(r: u32, ) -> Weight { - (26_589_000 as Weight) - .saturating_add((7_244_000 as Weight).saturating_mul(r as Weight)) + (24_625_000 as Weight) + // Standard Error: 17_000 + .saturating_add((7_089_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64leu(r: u32, ) -> Weight { - (26_593_000 as Weight) - .saturating_add((7_318_000 as Weight).saturating_mul(r as Weight)) + (24_589_000 as Weight) + // Standard Error: 9_000 + .saturating_add((7_078_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64ges(r: u32, ) -> Weight { - (26_626_000 as Weight) - .saturating_add((7_348_000 as Weight).saturating_mul(r as Weight)) + (24_572_000 as Weight) + // Standard Error: 13_000 + .saturating_add((7_286_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64geu(r: u32, ) -> Weight { - (26_595_000 as Weight) - .saturating_add((7_330_000 as Weight).saturating_mul(r as Weight)) + (24_566_000 as Weight) + // Standard Error: 19_000 + .saturating_add((7_247_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64add(r: u32, ) -> Weight { - (26_568_000 as Weight) - .saturating_add((8_657_000 as Weight).saturating_mul(r as Weight)) + (24_581_000 as Weight) + // Standard Error: 18_000 + .saturating_add((7_190_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64sub(r: u32, ) -> Weight { - (27_393_000 as Weight) - .saturating_add((6_743_000 as Weight).saturating_mul(r as Weight)) + (24_565_000 as Weight) + // Standard Error: 10_000 + .saturating_add((7_242_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64mul(r: u32, ) -> Weight { - (26_571_000 as Weight) - .saturating_add((7_329_000 as Weight).saturating_mul(r as Weight)) + (24_542_000 as Weight) + // Standard Error: 11_000 + .saturating_add((7_216_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64divs(r: u32, ) -> Weight { - (26_585_000 as Weight) - .saturating_add((12_977_000 as Weight).saturating_mul(r as Weight)) + (24_608_000 as Weight) + // Standard Error: 16_000 + .saturating_add((12_966_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64divu(r: u32, ) -> Weight { - (26_554_000 as Weight) - .saturating_add((11_955_000 as Weight).saturating_mul(r as Weight)) + (24_564_000 as Weight) + // Standard Error: 1_424_000 + .saturating_add((13_665_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64rems(r: u32, ) -> Weight { - (26_570_000 as Weight) - .saturating_add((12_903_000 as Weight).saturating_mul(r as Weight)) + (24_611_000 as Weight) + // Standard Error: 16_000 + .saturating_add((12_932_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64remu(r: u32, ) -> Weight { - (26_561_000 as Weight) - .saturating_add((12_112_000 as Weight).saturating_mul(r as Weight)) + (24_590_000 as Weight) + // Standard Error: 10_000 + .saturating_add((12_207_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64and(r: u32, ) -> Weight { - (26_587_000 as Weight) - .saturating_add((7_411_000 as Weight).saturating_mul(r as Weight)) + (24_622_000 as Weight) + // Standard Error: 15_000 + .saturating_add((7_172_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64or(r: u32, ) -> Weight { - (26_588_000 as Weight) - .saturating_add((7_479_000 as Weight).saturating_mul(r as Weight)) + (24_585_000 as Weight) + // Standard Error: 18_000 + .saturating_add((7_202_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64xor(r: u32, ) -> Weight { - (26_541_000 as Weight) - .saturating_add((7_386_000 as Weight).saturating_mul(r as Weight)) + (24_600_000 as Weight) + // Standard Error: 20_000 + .saturating_add((7_182_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64shl(r: u32, ) -> Weight { - (26_562_000 as Weight) - .saturating_add((7_263_000 as Weight).saturating_mul(r as Weight)) + (24_621_000 as Weight) + // Standard Error: 11_000 + .saturating_add((7_226_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64shrs(r: u32, ) -> Weight { - (26_569_000 as Weight) - .saturating_add((7_353_000 as Weight).saturating_mul(r as Weight)) + (24_643_000 as Weight) + // Standard Error: 22_000 + .saturating_add((7_254_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64shru(r: u32, ) -> Weight { - (26_533_000 as Weight) - .saturating_add((7_342_000 as Weight).saturating_mul(r as Weight)) + (24_586_000 as Weight) + // Standard Error: 14_000 + .saturating_add((7_246_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64rotl(r: u32, ) -> Weight { - (26_545_000 as Weight) - .saturating_add((7_362_000 as Weight).saturating_mul(r as Weight)) + (24_631_000 as Weight) + // Standard Error: 22_000 + .saturating_add((7_306_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64rotr(r: u32, ) -> Weight { - (26_535_000 as Weight) - .saturating_add((7_330_000 as Weight).saturating_mul(r as Weight)) + (24_643_000 as Weight) + // Standard Error: 15_000 + .saturating_add((7_183_000 as Weight).saturating_mul(r as Weight)) } } // For backwards compatibility and tests impl WeightInfo for () { + fn on_initialize() -> Weight { + (7_239_000 as Weight) + .saturating_add(RocksDbWeight::get().reads(1 as Weight)) + } + fn on_initialize_per_trie_key(k: u32, ) -> Weight { + (40_584_000 as Weight) + // Standard Error: 4_000 + .saturating_add((2_314_000 as Weight).saturating_mul(k as Weight)) + .saturating_add(RocksDbWeight::get().reads(1 as Weight)) + .saturating_add(RocksDbWeight::get().writes((1 as Weight).saturating_mul(k as Weight))) + } + fn on_initialize_per_queue_item(q: u32, ) -> Weight { + (0 as Weight) + // Standard Error: 175_000 + .saturating_add((135_919_000 as Weight).saturating_mul(q as Weight)) + .saturating_add(RocksDbWeight::get().reads(1 as Weight)) + } fn update_schedule() -> Weight { - (35_214_000 as Weight) + (36_262_000 as Weight) .saturating_add(RocksDbWeight::get().reads(1 as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } fn put_code(n: u32, ) -> Weight { - (0 as Weight) - .saturating_add((109_242_000 as Weight).saturating_mul(n as Weight)) + (22_510_000 as Weight) + // Standard Error: 209_000 + .saturating_add((113_251_000 as Weight).saturating_mul(n as Weight)) .saturating_add(RocksDbWeight::get().reads(1 as Weight)) .saturating_add(RocksDbWeight::get().writes(2 as Weight)) } fn instantiate(n: u32, s: u32, ) -> Weight { - (195_276_000 as Weight) - .saturating_add((35_000 as Weight).saturating_mul(n as Weight)) - .saturating_add((2_244_000 as Weight).saturating_mul(s as Weight)) + (216_181_000 as Weight) + // Standard Error: 1_000 + .saturating_add((6_000 as Weight).saturating_mul(n as Weight)) + // Standard Error: 1_000 + .saturating_add((2_240_000 as Weight).saturating_mul(s as Weight)) .saturating_add(RocksDbWeight::get().reads(6 as Weight)) .saturating_add(RocksDbWeight::get().writes(3 as Weight)) } fn call() -> Weight { - (207_142_000 as Weight) + (209_785_000 as Weight) .saturating_add(RocksDbWeight::get().reads(5 as Weight)) .saturating_add(RocksDbWeight::get().writes(2 as Weight)) } fn claim_surcharge() -> Weight { - (489_633_000 as Weight) - .saturating_add(RocksDbWeight::get().reads(3 as Weight)) - .saturating_add(RocksDbWeight::get().writes(2 as Weight)) + (302_124_000 as Weight) + .saturating_add(RocksDbWeight::get().reads(4 as Weight)) + .saturating_add(RocksDbWeight::get().writes(3 as Weight)) } fn seal_caller(r: u32, ) -> Weight { - (136_550_000 as Weight) - .saturating_add((373_182_000 as Weight).saturating_mul(r as Weight)) + (138_697_000 as Weight) + // Standard Error: 412_000 + .saturating_add((390_370_000 as Weight).saturating_mul(r as Weight)) .saturating_add(RocksDbWeight::get().reads(4 as Weight)) } fn seal_address(r: u32, ) -> Weight { - (136_329_000 as Weight) - .saturating_add((373_392_000 as Weight).saturating_mul(r as Weight)) + (141_999_000 as Weight) + // Standard Error: 218_000 + .saturating_add((389_261_000 as Weight).saturating_mul(r as Weight)) .saturating_add(RocksDbWeight::get().reads(4 as Weight)) } fn seal_gas_left(r: u32, ) -> Weight { - (111_577_000 as Weight) - .saturating_add((373_536_000 as Weight).saturating_mul(r as Weight)) + (134_956_000 as Weight) + // Standard Error: 205_000 + .saturating_add((384_439_000 as Weight).saturating_mul(r as Weight)) .saturating_add(RocksDbWeight::get().reads(4 as Weight)) } fn seal_balance(r: u32, ) -> Weight { - (157_531_000 as Weight) - .saturating_add((810_382_000 as Weight).saturating_mul(r as Weight)) + (130_585_000 as Weight) + // Standard Error: 784_000 + .saturating_add((860_797_000 as Weight).saturating_mul(r as Weight)) .saturating_add(RocksDbWeight::get().reads(5 as Weight)) } fn seal_value_transferred(r: u32, ) -> Weight { - (143_801_000 as Weight) - .saturating_add((369_769_000 as Weight).saturating_mul(r as Weight)) + (138_382_000 as Weight) + // Standard Error: 163_000 + .saturating_add((384_676_000 as Weight).saturating_mul(r as Weight)) .saturating_add(RocksDbWeight::get().reads(4 as Weight)) } fn seal_minimum_balance(r: u32, ) -> Weight { - (133_546_000 as Weight) - .saturating_add((370_036_000 as Weight).saturating_mul(r as Weight)) + (137_766_000 as Weight) + // Standard Error: 218_000 + .saturating_add((386_002_000 as Weight).saturating_mul(r as Weight)) .saturating_add(RocksDbWeight::get().reads(4 as Weight)) } fn seal_tombstone_deposit(r: u32, ) -> Weight { - (138_568_000 as Weight) - .saturating_add((370_322_000 as Weight).saturating_mul(r as Weight)) + (144_552_000 as Weight) + // Standard Error: 187_000 + .saturating_add((384_754_000 as Weight).saturating_mul(r as Weight)) .saturating_add(RocksDbWeight::get().reads(4 as Weight)) } fn seal_rent_allowance(r: u32, ) -> Weight { - (144_431_000 as Weight) - .saturating_add((851_810_000 as Weight).saturating_mul(r as Weight)) + (150_812_000 as Weight) + // Standard Error: 276_000 + .saturating_add((903_965_000 as Weight).saturating_mul(r as Weight)) .saturating_add(RocksDbWeight::get().reads(4 as Weight)) } fn seal_block_number(r: u32, ) -> Weight { - (133_237_000 as Weight) - .saturating_add((369_156_000 as Weight).saturating_mul(r as Weight)) + (145_168_000 as Weight) + // Standard Error: 191_000 + .saturating_add((382_798_000 as Weight).saturating_mul(r as Weight)) .saturating_add(RocksDbWeight::get().reads(4 as Weight)) } fn seal_now(r: u32, ) -> Weight { - (139_700_000 as Weight) - .saturating_add((368_961_000 as Weight).saturating_mul(r as Weight)) + (145_806_000 as Weight) + // Standard Error: 195_000 + .saturating_add((382_888_000 as Weight).saturating_mul(r as Weight)) .saturating_add(RocksDbWeight::get().reads(4 as Weight)) } fn seal_weight_to_fee(r: u32, ) -> Weight { - (149_395_000 as Weight) - .saturating_add((625_812_000 as Weight).saturating_mul(r as Weight)) + (154_081_000 as Weight) + // Standard Error: 248_000 + .saturating_add((716_294_000 as Weight).saturating_mul(r as Weight)) .saturating_add(RocksDbWeight::get().reads(5 as Weight)) } fn seal_gas(r: u32, ) -> Weight { - (125_777_000 as Weight) - .saturating_add((187_585_000 as Weight).saturating_mul(r as Weight)) + (149_684_000 as Weight) + // Standard Error: 460_000 + .saturating_add((196_251_000 as Weight).saturating_mul(r as Weight)) .saturating_add(RocksDbWeight::get().reads(4 as Weight)) } fn seal_input(r: u32, ) -> Weight { - (132_584_000 as Weight) - .saturating_add((7_661_000 as Weight).saturating_mul(r as Weight)) + (135_447_000 as Weight) + // Standard Error: 75_000 + .saturating_add((8_362_000 as Weight).saturating_mul(r as Weight)) .saturating_add(RocksDbWeight::get().reads(4 as Weight)) } fn seal_input_per_kb(n: u32, ) -> Weight { - (143_408_000 as Weight) - .saturating_add((274_000 as Weight).saturating_mul(n as Weight)) + (146_099_000 as Weight) + // Standard Error: 0 + .saturating_add((270_000 as Weight).saturating_mul(n as Weight)) .saturating_add(RocksDbWeight::get().reads(4 as Weight)) } fn seal_return(r: u32, ) -> Weight { - (126_257_000 as Weight) - .saturating_add((5_455_000 as Weight).saturating_mul(r as Weight)) + (125_358_000 as Weight) + // Standard Error: 52_000 + .saturating_add((5_454_000 as Weight).saturating_mul(r as Weight)) .saturating_add(RocksDbWeight::get().reads(4 as Weight)) } fn seal_return_per_kb(n: u32, ) -> Weight { - (133_286_000 as Weight) - .saturating_add((698_000 as Weight).saturating_mul(n as Weight)) + (135_523_000 as Weight) + // Standard Error: 0 + .saturating_add((785_000 as Weight).saturating_mul(n as Weight)) .saturating_add(RocksDbWeight::get().reads(4 as Weight)) } fn seal_terminate(r: u32, ) -> Weight { - (130_607_000 as Weight) - .saturating_add((358_370_000 as Weight).saturating_mul(r as Weight)) + (135_321_000 as Weight) + // Standard Error: 100_000 + .saturating_add((110_300_000 as Weight).saturating_mul(r as Weight)) .saturating_add(RocksDbWeight::get().reads(4 as Weight)) - .saturating_add(RocksDbWeight::get().reads((2 as Weight).saturating_mul(r as Weight))) - .saturating_add(RocksDbWeight::get().writes((3 as Weight).saturating_mul(r as Weight))) + .saturating_add(RocksDbWeight::get().reads((3 as Weight).saturating_mul(r as Weight))) + .saturating_add(RocksDbWeight::get().writes((4 as Weight).saturating_mul(r as Weight))) } fn seal_restore_to(r: u32, ) -> Weight { - (233_645_000 as Weight) - .saturating_add((135_355_000 as Weight).saturating_mul(r as Weight)) + (242_790_000 as Weight) + // Standard Error: 823_000 + .saturating_add((135_544_000 as Weight).saturating_mul(r as Weight)) .saturating_add(RocksDbWeight::get().reads(5 as Weight)) .saturating_add(RocksDbWeight::get().reads((3 as Weight).saturating_mul(r as Weight))) .saturating_add(RocksDbWeight::get().writes((4 as Weight).saturating_mul(r as Weight))) } fn seal_restore_to_per_delta(d: u32, ) -> Weight { - (74_573_000 as Weight) - .saturating_add((3_768_682_000 as Weight).saturating_mul(d as Weight)) + (34_052_000 as Weight) + // Standard Error: 2_395_000 + .saturating_add((3_970_866_000 as Weight).saturating_mul(d as Weight)) .saturating_add(RocksDbWeight::get().reads(7 as Weight)) .saturating_add(RocksDbWeight::get().reads((100 as Weight).saturating_mul(d as Weight))) .saturating_add(RocksDbWeight::get().writes(5 as Weight)) .saturating_add(RocksDbWeight::get().writes((100 as Weight).saturating_mul(d as Weight))) } fn seal_random(r: u32, ) -> Weight { - (140_286_000 as Weight) - .saturating_add((950_890_000 as Weight).saturating_mul(r as Weight)) + (154_549_000 as Weight) + // Standard Error: 692_000 + .saturating_add((989_540_000 as Weight).saturating_mul(r as Weight)) .saturating_add(RocksDbWeight::get().reads(5 as Weight)) } fn seal_deposit_event(r: u32, ) -> Weight { - (167_735_000 as Weight) - .saturating_add((1_375_429_000 as Weight).saturating_mul(r as Weight)) + (125_367_000 as Weight) + // Standard Error: 977_000 + .saturating_add((1_424_216_000 as Weight).saturating_mul(r as Weight)) .saturating_add(RocksDbWeight::get().reads(4 as Weight)) } fn seal_deposit_event_per_topic_and_kb(t: u32, n: u32, ) -> Weight { - (1_715_857_000 as Weight) - .saturating_add((760_777_000 as Weight).saturating_mul(t as Weight)) - .saturating_add((241_853_000 as Weight).saturating_mul(n as Weight)) + (1_843_333_000 as Weight) + // Standard Error: 3_040_000 + .saturating_add((771_663_000 as Weight).saturating_mul(t as Weight)) + // Standard Error: 599_000 + .saturating_add((251_555_000 as Weight).saturating_mul(n as Weight)) .saturating_add(RocksDbWeight::get().reads(4 as Weight)) .saturating_add(RocksDbWeight::get().reads((100 as Weight).saturating_mul(t as Weight))) .saturating_add(RocksDbWeight::get().writes((100 as Weight).saturating_mul(t as Weight))) } fn seal_set_rent_allowance(r: u32, ) -> Weight { - (156_911_000 as Weight) - .saturating_add((1_006_139_000 as Weight).saturating_mul(r as Weight)) + (136_437_000 as Weight) + // Standard Error: 299_000 + .saturating_add((1_072_778_000 as Weight).saturating_mul(r as Weight)) .saturating_add(RocksDbWeight::get().reads(4 as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } fn seal_set_storage(r: u32, ) -> Weight { - (0 as Weight) - .saturating_add((14_938_793_000 as Weight).saturating_mul(r as Weight)) + (182_452_000 as Weight) + // Standard Error: 26_839_000 + .saturating_add((15_911_876_000 as Weight).saturating_mul(r as Weight)) .saturating_add(RocksDbWeight::get().reads(4 as Weight)) .saturating_add(RocksDbWeight::get().reads((100 as Weight).saturating_mul(r as Weight))) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) .saturating_add(RocksDbWeight::get().writes((100 as Weight).saturating_mul(r as Weight))) } fn seal_set_storage_per_kb(n: u32, ) -> Weight { - (2_300_169_000 as Weight) - .saturating_add((204_543_000 as Weight).saturating_mul(n as Weight)) + (2_385_415_000 as Weight) + // Standard Error: 751_000 + .saturating_add((223_264_000 as Weight).saturating_mul(n as Weight)) .saturating_add(RocksDbWeight::get().reads(5 as Weight)) .saturating_add(RocksDbWeight::get().writes(2 as Weight)) } fn seal_clear_storage(r: u32, ) -> Weight { (0 as Weight) - .saturating_add((5_140_241_000 as Weight).saturating_mul(r as Weight)) + // Standard Error: 2_154_000 + .saturating_add((5_341_117_000 as Weight).saturating_mul(r as Weight)) .saturating_add(RocksDbWeight::get().reads(4 as Weight)) .saturating_add(RocksDbWeight::get().reads((100 as Weight).saturating_mul(r as Weight))) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) .saturating_add(RocksDbWeight::get().writes((100 as Weight).saturating_mul(r as Weight))) } fn seal_get_storage(r: u32, ) -> Weight { - (45_212_000 as Weight) - .saturating_add((1_131_504_000 as Weight).saturating_mul(r as Weight)) + (62_353_000 as Weight) + // Standard Error: 1_183_000 + .saturating_add((1_141_653_000 as Weight).saturating_mul(r as Weight)) .saturating_add(RocksDbWeight::get().reads(4 as Weight)) .saturating_add(RocksDbWeight::get().reads((100 as Weight).saturating_mul(r as Weight))) } fn seal_get_storage_per_kb(n: u32, ) -> Weight { - (885_531_000 as Weight) - .saturating_add((148_986_000 as Weight).saturating_mul(n as Weight)) + (905_905_000 as Weight) + // Standard Error: 363_000 + .saturating_add((155_161_000 as Weight).saturating_mul(n as Weight)) .saturating_add(RocksDbWeight::get().reads(5 as Weight)) } fn seal_transfer(r: u32, ) -> Weight { - (92_276_000 as Weight) - .saturating_add((6_216_852_000 as Weight).saturating_mul(r as Weight)) + (60_519_000 as Weight) + // Standard Error: 1_942_000 + .saturating_add((6_453_551_000 as Weight).saturating_mul(r as Weight)) .saturating_add(RocksDbWeight::get().reads(5 as Weight)) .saturating_add(RocksDbWeight::get().reads((100 as Weight).saturating_mul(r as Weight))) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) .saturating_add(RocksDbWeight::get().writes((100 as Weight).saturating_mul(r as Weight))) } fn seal_call(r: u32, ) -> Weight { - (0 as Weight) - .saturating_add((10_734_719_000 as Weight).saturating_mul(r as Weight)) + (192_122_000 as Weight) + // Standard Error: 7_851_000 + .saturating_add((10_736_771_000 as Weight).saturating_mul(r as Weight)) .saturating_add(RocksDbWeight::get().reads(5 as Weight)) .saturating_add(RocksDbWeight::get().reads((100 as Weight).saturating_mul(r as Weight))) } fn seal_call_per_transfer_input_output_kb(t: u32, i: u32, o: u32, ) -> Weight { - (12_735_614_000 as Weight) - .saturating_add((2_870_730_000 as Weight).saturating_mul(t as Weight)) - .saturating_add((52_569_000 as Weight).saturating_mul(i as Weight)) - .saturating_add((73_956_000 as Weight).saturating_mul(o as Weight)) + (10_599_501_000 as Weight) + // Standard Error: 133_182_000 + .saturating_add((5_423_848_000 as Weight).saturating_mul(t as Weight)) + // Standard Error: 47_000 + .saturating_add((60_108_000 as Weight).saturating_mul(i as Weight)) + // Standard Error: 50_000 + .saturating_add((82_691_000 as Weight).saturating_mul(o as Weight)) .saturating_add(RocksDbWeight::get().reads(105 as Weight)) .saturating_add(RocksDbWeight::get().reads((101 as Weight).saturating_mul(t as Weight))) .saturating_add(RocksDbWeight::get().writes((101 as Weight).saturating_mul(t as Weight))) } fn seal_instantiate(r: u32, ) -> Weight { (0 as Weight) - .saturating_add((22_365_908_000 as Weight).saturating_mul(r as Weight)) + // Standard Error: 39_807_000 + .saturating_add((22_562_812_000 as Weight).saturating_mul(r as Weight)) .saturating_add(RocksDbWeight::get().reads(6 as Weight)) .saturating_add(RocksDbWeight::get().reads((300 as Weight).saturating_mul(r as Weight))) .saturating_add(RocksDbWeight::get().writes(2 as Weight)) .saturating_add(RocksDbWeight::get().writes((200 as Weight).saturating_mul(r as Weight))) } fn seal_instantiate_per_input_output_salt_kb(i: u32, o: u32, s: u32, ) -> Weight { - (18_899_296_000 as Weight) - .saturating_add((53_289_000 as Weight).saturating_mul(i as Weight)) - .saturating_add((76_026_000 as Weight).saturating_mul(o as Weight)) - .saturating_add((281_097_000 as Weight).saturating_mul(s as Weight)) + (19_823_256_000 as Weight) + // Standard Error: 153_000 + .saturating_add((60_707_000 as Weight).saturating_mul(i as Weight)) + // Standard Error: 153_000 + .saturating_add((83_770_000 as Weight).saturating_mul(o as Weight)) + // Standard Error: 153_000 + .saturating_add((284_423_000 as Weight).saturating_mul(s as Weight)) .saturating_add(RocksDbWeight::get().reads(207 as Weight)) .saturating_add(RocksDbWeight::get().writes(202 as Weight)) } fn seal_hash_sha2_256(r: u32, ) -> Weight { - (136_601_000 as Weight) - .saturating_add((323_373_000 as Weight).saturating_mul(r as Weight)) + (142_838_000 as Weight) + // Standard Error: 243_000 + .saturating_add((332_354_000 as Weight).saturating_mul(r as Weight)) .saturating_add(RocksDbWeight::get().reads(4 as Weight)) } fn seal_hash_sha2_256_per_kb(n: u32, ) -> Weight { - (777_563_000 as Weight) - .saturating_add((423_353_000 as Weight).saturating_mul(n as Weight)) + (877_119_000 as Weight) + // Standard Error: 73_000 + .saturating_add((434_752_000 as Weight).saturating_mul(n as Weight)) .saturating_add(RocksDbWeight::get().reads(4 as Weight)) } fn seal_hash_keccak_256(r: u32, ) -> Weight { - (136_771_000 as Weight) - .saturating_add((337_881_000 as Weight).saturating_mul(r as Weight)) + (139_913_000 as Weight) + // Standard Error: 160_000 + .saturating_add((345_830_000 as Weight).saturating_mul(r as Weight)) .saturating_add(RocksDbWeight::get().reads(4 as Weight)) } fn seal_hash_keccak_256_per_kb(n: u32, ) -> Weight { - (337_906_000 as Weight) - .saturating_add((336_778_000 as Weight).saturating_mul(n as Weight)) + (723_122_000 as Weight) + // Standard Error: 29_000 + .saturating_add((343_949_000 as Weight).saturating_mul(n as Weight)) .saturating_add(RocksDbWeight::get().reads(4 as Weight)) } fn seal_hash_blake2_256(r: u32, ) -> Weight { - (131_040_000 as Weight) - .saturating_add((312_992_000 as Weight).saturating_mul(r as Weight)) + (137_249_000 as Weight) + // Standard Error: 168_000 + .saturating_add((320_295_000 as Weight).saturating_mul(r as Weight)) .saturating_add(RocksDbWeight::get().reads(4 as Weight)) } fn seal_hash_blake2_256_per_kb(n: u32, ) -> Weight { - (693_415_000 as Weight) - .saturating_add((152_745_000 as Weight).saturating_mul(n as Weight)) + (736_756_000 as Weight) + // Standard Error: 39_000 + .saturating_add((159_952_000 as Weight).saturating_mul(n as Weight)) .saturating_add(RocksDbWeight::get().reads(4 as Weight)) } fn seal_hash_blake2_128(r: u32, ) -> Weight { - (135_654_000 as Weight) - .saturating_add((311_271_000 as Weight).saturating_mul(r as Weight)) + (124_530_000 as Weight) + // Standard Error: 203_000 + .saturating_add((321_292_000 as Weight).saturating_mul(r as Weight)) .saturating_add(RocksDbWeight::get().reads(4 as Weight)) } fn seal_hash_blake2_128_per_kb(n: u32, ) -> Weight { - (839_521_000 as Weight) - .saturating_add((153_146_000 as Weight).saturating_mul(n as Weight)) + (782_032_000 as Weight) + // Standard Error: 36_000 + .saturating_add((159_878_000 as Weight).saturating_mul(n as Weight)) .saturating_add(RocksDbWeight::get().reads(4 as Weight)) } fn instr_i64const(r: u32, ) -> Weight { - (26_679_000 as Weight) - .saturating_add((3_155_000 as Weight).saturating_mul(r as Weight)) + (24_624_000 as Weight) + // Standard Error: 18_000 + .saturating_add((3_280_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64load(r: u32, ) -> Weight { - (28_920_000 as Weight) - .saturating_add((159_343_000 as Weight).saturating_mul(r as Weight)) + (27_171_000 as Weight) + // Standard Error: 62_000 + .saturating_add((161_737_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64store(r: u32, ) -> Weight { - (28_928_000 as Weight) - .saturating_add((227_286_000 as Weight).saturating_mul(r as Weight)) + (27_106_000 as Weight) + // Standard Error: 94_000 + .saturating_add((229_960_000 as Weight).saturating_mul(r as Weight)) } fn instr_select(r: u32, ) -> Weight { - (26_591_000 as Weight) - .saturating_add((12_591_000 as Weight).saturating_mul(r as Weight)) + (24_566_000 as Weight) + // Standard Error: 18_000 + .saturating_add((12_157_000 as Weight).saturating_mul(r as Weight)) } fn instr_if(r: u32, ) -> Weight { - (26_597_000 as Weight) - .saturating_add((12_258_000 as Weight).saturating_mul(r as Weight)) + (24_531_000 as Weight) + // Standard Error: 17_000 + .saturating_add((12_007_000 as Weight).saturating_mul(r as Weight)) } fn instr_br(r: u32, ) -> Weight { - (26_586_000 as Weight) - .saturating_add((5_811_000 as Weight).saturating_mul(r as Weight)) + (24_567_000 as Weight) + // Standard Error: 20_000 + .saturating_add((6_132_000 as Weight).saturating_mul(r as Weight)) } fn instr_br_if(r: u32, ) -> Weight { - (26_581_000 as Weight) - .saturating_add((14_058_000 as Weight).saturating_mul(r as Weight)) + (24_628_000 as Weight) + // Standard Error: 21_000 + .saturating_add((13_480_000 as Weight).saturating_mul(r as Weight)) } fn instr_br_table(r: u32, ) -> Weight { - (26_615_000 as Weight) - .saturating_add((15_687_000 as Weight).saturating_mul(r as Weight)) + (24_653_000 as Weight) + // Standard Error: 21_000 + .saturating_add((15_005_000 as Weight).saturating_mul(r as Weight)) } fn instr_br_table_per_entry(e: u32, ) -> Weight { - (40_963_000 as Weight) - .saturating_add((92_000 as Weight).saturating_mul(e as Weight)) + (38_573_000 as Weight) + // Standard Error: 0 + .saturating_add((118_000 as Weight).saturating_mul(e as Weight)) } fn instr_call(r: u32, ) -> Weight { - (26_880_000 as Weight) - .saturating_add((97_523_000 as Weight).saturating_mul(r as Weight)) + (24_952_000 as Weight) + // Standard Error: 61_000 + .saturating_add((99_409_000 as Weight).saturating_mul(r as Weight)) } fn instr_call_indirect(r: u32, ) -> Weight { - (34_628_000 as Weight) - .saturating_add((201_913_000 as Weight).saturating_mul(r as Weight)) + (32_478_000 as Weight) + // Standard Error: 242_000 + .saturating_add((193_797_000 as Weight).saturating_mul(r as Weight)) } fn instr_call_indirect_per_param(p: u32, ) -> Weight { - (255_763_000 as Weight) - .saturating_add((3_612_000 as Weight).saturating_mul(p as Weight)) + (238_200_000 as Weight) + // Standard Error: 4_000 + .saturating_add((3_467_000 as Weight).saturating_mul(p as Weight)) } fn instr_local_get(r: u32, ) -> Weight { - (45_954_000 as Weight) - .saturating_add((3_439_000 as Weight).saturating_mul(r as Weight)) + (41_994_000 as Weight) + // Standard Error: 22_000 + .saturating_add((3_230_000 as Weight).saturating_mul(r as Weight)) } fn instr_local_set(r: u32, ) -> Weight { - (45_952_000 as Weight) - .saturating_add((3_601_000 as Weight).saturating_mul(r as Weight)) + (41_994_000 as Weight) + // Standard Error: 20_000 + .saturating_add((3_558_000 as Weight).saturating_mul(r as Weight)) } fn instr_local_tee(r: u32, ) -> Weight { - (45_883_000 as Weight) - .saturating_add((5_203_000 as Weight).saturating_mul(r as Weight)) + (41_965_000 as Weight) + // Standard Error: 33_000 + .saturating_add((4_806_000 as Weight).saturating_mul(r as Weight)) } fn instr_global_get(r: u32, ) -> Weight { - (29_895_000 as Weight) - .saturating_add((8_221_000 as Weight).saturating_mul(r as Weight)) + (27_997_000 as Weight) + // Standard Error: 26_000 + .saturating_add((7_859_000 as Weight).saturating_mul(r as Weight)) } fn instr_global_set(r: u32, ) -> Weight { - (29_916_000 as Weight) - .saturating_add((12_036_000 as Weight).saturating_mul(r as Weight)) + (28_118_000 as Weight) + // Standard Error: 33_000 + .saturating_add((11_825_000 as Weight).saturating_mul(r as Weight)) } fn instr_memory_current(r: u32, ) -> Weight { - (28_878_000 as Weight) - .saturating_add((3_794_000 as Weight).saturating_mul(r as Weight)) + (27_172_000 as Weight) + // Standard Error: 19_000 + .saturating_add((3_466_000 as Weight).saturating_mul(r as Weight)) } fn instr_memory_grow(r: u32, ) -> Weight { - (27_351_000 as Weight) - .saturating_add((2_302_301_000 as Weight).saturating_mul(r as Weight)) + (25_582_000 as Weight) + // Standard Error: 4_756_000 + .saturating_add((2_290_170_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64clz(r: u32, ) -> Weight { - (26_535_000 as Weight) - .saturating_add((5_450_000 as Weight).saturating_mul(r as Weight)) + (24_712_000 as Weight) + // Standard Error: 24_000 + .saturating_add((5_226_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64ctz(r: u32, ) -> Weight { - (26_489_000 as Weight) - .saturating_add((5_410_000 as Weight).saturating_mul(r as Weight)) + (24_631_000 as Weight) + // Standard Error: 23_000 + .saturating_add((5_282_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64popcnt(r: u32, ) -> Weight { - (26_576_000 as Weight) - .saturating_add((5_976_000 as Weight).saturating_mul(r as Weight)) + (24_640_000 as Weight) + // Standard Error: 17_000 + .saturating_add((5_964_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64eqz(r: u32, ) -> Weight { - (26_521_000 as Weight) - .saturating_add((5_465_000 as Weight).saturating_mul(r as Weight)) + (24_631_000 as Weight) + // Standard Error: 11_000 + .saturating_add((5_128_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64extendsi32(r: u32, ) -> Weight { - (26_534_000 as Weight) - .saturating_add((5_375_000 as Weight).saturating_mul(r as Weight)) + (24_540_000 as Weight) + // Standard Error: 11_000 + .saturating_add((5_224_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64extendui32(r: u32, ) -> Weight { - (26_560_000 as Weight) - .saturating_add((5_284_000 as Weight).saturating_mul(r as Weight)) + (24_623_000 as Weight) + // Standard Error: 16_000 + .saturating_add((5_138_000 as Weight).saturating_mul(r as Weight)) } fn instr_i32wrapi64(r: u32, ) -> Weight { - (26_554_000 as Weight) - .saturating_add((5_358_000 as Weight).saturating_mul(r as Weight)) + (24_623_000 as Weight) + // Standard Error: 15_000 + .saturating_add((5_242_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64eq(r: u32, ) -> Weight { - (26_549_000 as Weight) - .saturating_add((7_402_000 as Weight).saturating_mul(r as Weight)) + (24_575_000 as Weight) + // Standard Error: 9_000 + .saturating_add((7_328_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64ne(r: u32, ) -> Weight { - (26_582_000 as Weight) - .saturating_add((7_266_000 as Weight).saturating_mul(r as Weight)) + (24_674_000 as Weight) + // Standard Error: 14_000 + .saturating_add((7_147_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64lts(r: u32, ) -> Weight { - (26_558_000 as Weight) - .saturating_add((7_293_000 as Weight).saturating_mul(r as Weight)) + (24_645_000 as Weight) + // Standard Error: 20_000 + .saturating_add((7_158_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64ltu(r: u32, ) -> Weight { - (26_569_000 as Weight) - .saturating_add((7_278_000 as Weight).saturating_mul(r as Weight)) + (24_688_000 as Weight) + // Standard Error: 16_000 + .saturating_add((7_226_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64gts(r: u32, ) -> Weight { - (26_516_000 as Weight) - .saturating_add((7_334_000 as Weight).saturating_mul(r as Weight)) + (24_579_000 as Weight) + // Standard Error: 13_000 + .saturating_add((7_187_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64gtu(r: u32, ) -> Weight { - (26_561_000 as Weight) - .saturating_add((7_283_000 as Weight).saturating_mul(r as Weight)) + (24_578_000 as Weight) + // Standard Error: 15_000 + .saturating_add((7_235_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64les(r: u32, ) -> Weight { - (26_589_000 as Weight) - .saturating_add((7_244_000 as Weight).saturating_mul(r as Weight)) + (24_625_000 as Weight) + // Standard Error: 17_000 + .saturating_add((7_089_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64leu(r: u32, ) -> Weight { - (26_593_000 as Weight) - .saturating_add((7_318_000 as Weight).saturating_mul(r as Weight)) + (24_589_000 as Weight) + // Standard Error: 9_000 + .saturating_add((7_078_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64ges(r: u32, ) -> Weight { - (26_626_000 as Weight) - .saturating_add((7_348_000 as Weight).saturating_mul(r as Weight)) + (24_572_000 as Weight) + // Standard Error: 13_000 + .saturating_add((7_286_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64geu(r: u32, ) -> Weight { - (26_595_000 as Weight) - .saturating_add((7_330_000 as Weight).saturating_mul(r as Weight)) + (24_566_000 as Weight) + // Standard Error: 19_000 + .saturating_add((7_247_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64add(r: u32, ) -> Weight { - (26_568_000 as Weight) - .saturating_add((8_657_000 as Weight).saturating_mul(r as Weight)) + (24_581_000 as Weight) + // Standard Error: 18_000 + .saturating_add((7_190_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64sub(r: u32, ) -> Weight { - (27_393_000 as Weight) - .saturating_add((6_743_000 as Weight).saturating_mul(r as Weight)) + (24_565_000 as Weight) + // Standard Error: 10_000 + .saturating_add((7_242_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64mul(r: u32, ) -> Weight { - (26_571_000 as Weight) - .saturating_add((7_329_000 as Weight).saturating_mul(r as Weight)) + (24_542_000 as Weight) + // Standard Error: 11_000 + .saturating_add((7_216_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64divs(r: u32, ) -> Weight { - (26_585_000 as Weight) - .saturating_add((12_977_000 as Weight).saturating_mul(r as Weight)) + (24_608_000 as Weight) + // Standard Error: 16_000 + .saturating_add((12_966_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64divu(r: u32, ) -> Weight { - (26_554_000 as Weight) - .saturating_add((11_955_000 as Weight).saturating_mul(r as Weight)) + (24_564_000 as Weight) + // Standard Error: 1_424_000 + .saturating_add((13_665_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64rems(r: u32, ) -> Weight { - (26_570_000 as Weight) - .saturating_add((12_903_000 as Weight).saturating_mul(r as Weight)) + (24_611_000 as Weight) + // Standard Error: 16_000 + .saturating_add((12_932_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64remu(r: u32, ) -> Weight { - (26_561_000 as Weight) - .saturating_add((12_112_000 as Weight).saturating_mul(r as Weight)) + (24_590_000 as Weight) + // Standard Error: 10_000 + .saturating_add((12_207_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64and(r: u32, ) -> Weight { - (26_587_000 as Weight) - .saturating_add((7_411_000 as Weight).saturating_mul(r as Weight)) + (24_622_000 as Weight) + // Standard Error: 15_000 + .saturating_add((7_172_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64or(r: u32, ) -> Weight { - (26_588_000 as Weight) - .saturating_add((7_479_000 as Weight).saturating_mul(r as Weight)) + (24_585_000 as Weight) + // Standard Error: 18_000 + .saturating_add((7_202_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64xor(r: u32, ) -> Weight { - (26_541_000 as Weight) - .saturating_add((7_386_000 as Weight).saturating_mul(r as Weight)) + (24_600_000 as Weight) + // Standard Error: 20_000 + .saturating_add((7_182_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64shl(r: u32, ) -> Weight { - (26_562_000 as Weight) - .saturating_add((7_263_000 as Weight).saturating_mul(r as Weight)) + (24_621_000 as Weight) + // Standard Error: 11_000 + .saturating_add((7_226_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64shrs(r: u32, ) -> Weight { - (26_569_000 as Weight) - .saturating_add((7_353_000 as Weight).saturating_mul(r as Weight)) + (24_643_000 as Weight) + // Standard Error: 22_000 + .saturating_add((7_254_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64shru(r: u32, ) -> Weight { - (26_533_000 as Weight) - .saturating_add((7_342_000 as Weight).saturating_mul(r as Weight)) + (24_586_000 as Weight) + // Standard Error: 14_000 + .saturating_add((7_246_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64rotl(r: u32, ) -> Weight { - (26_545_000 as Weight) - .saturating_add((7_362_000 as Weight).saturating_mul(r as Weight)) + (24_631_000 as Weight) + // Standard Error: 22_000 + .saturating_add((7_306_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64rotr(r: u32, ) -> Weight { - (26_535_000 as Weight) - .saturating_add((7_330_000 as Weight).saturating_mul(r as Weight)) + (24_643_000 as Weight) + // Standard Error: 15_000 + .saturating_add((7_183_000 as Weight).saturating_mul(r as Weight)) } } From a702a469a9d258a85c1b9c14f283e20cea9cd3d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Thei=C3=9Fen?= Date: Thu, 17 Dec 2020 10:57:27 +0100 Subject: [PATCH 03/14] Add missing documentation of new error --- frame/contracts/src/lib.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/frame/contracts/src/lib.rs b/frame/contracts/src/lib.rs index 92ef5bbb01b28..08fa653db089d 100644 --- a/frame/contracts/src/lib.rs +++ b/frame/contracts/src/lib.rs @@ -390,6 +390,10 @@ decl_error! { /// The queue is filled by deleting contracts and emptied by a fixed amount each block. /// Trying again during another block is the only way to resolve this issue. DeletionQueueFull, + /// A contract could not be evicted because it has enough balance to pay rent. + /// + /// This can be returned from [`Module::claim_surcharge`] because the target + /// contract has enough balance to pay for its rent. ContractNotEvictable, } } From aa03aa720b8fe3a5f931321fd8e136dd20bb1709 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Thei=C3=9Fen?= Date: Thu, 17 Dec 2020 10:57:56 +0100 Subject: [PATCH 04/14] Make Module::claim_surcharge public It being the only dispatchable that is private is an oversight. --- frame/contracts/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/contracts/src/lib.rs b/frame/contracts/src/lib.rs index 08fa653db089d..c4bbf5c9a36e4 100644 --- a/frame/contracts/src/lib.rs +++ b/frame/contracts/src/lib.rs @@ -562,7 +562,7 @@ decl_module! { /// If contract is not evicted as a result of this call, [`Error::ContractNotEvictable`] /// is returned and the sender is not eligible for the reward. #[weight = T::WeightInfo::claim_surcharge()] - fn claim_surcharge( + pub fn claim_surcharge( origin, dest: T::AccountId, aux_sender: Option From e9be4d6578e4bd0428752ad631b9f8b4be26f9af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Thei=C3=9Fen?= Date: Tue, 29 Dec 2020 12:37:30 +0100 Subject: [PATCH 05/14] review: Add final newline --- frame/contracts/src/storage.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/contracts/src/storage.rs b/frame/contracts/src/storage.rs index 8355a97f50028..cb031ebb1e596 100644 --- a/frame/contracts/src/storage.rs +++ b/frame/contracts/src/storage.rs @@ -338,4 +338,4 @@ where .collect(); DeletionQueue::put(queue); } -} \ No newline at end of file +} From d0ccc0501e9cdf2e74620992573b81c56e453443 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Thei=C3=9Fen?= Date: Tue, 29 Dec 2020 12:38:27 +0100 Subject: [PATCH 06/14] review: Simplify assert statement --- frame/contracts/src/tests.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/contracts/src/tests.rs b/frame/contracts/src/tests.rs index 5fe4555333423..cf1b1c9e0ef59 100644 --- a/frame/contracts/src/tests.rs +++ b/frame/contracts/src/tests.rs @@ -1195,7 +1195,7 @@ fn restoration(test_different_storage: bool, test_restore_to_with_dirty_storage: ), Error::::NotCallable ); - assert_eq!(System::events(), vec![]); + assert!(System::events().is_empty()); assert!(ContractInfoOf::::get(&addr_bob).unwrap().get_alive().is_some()); assert_ok!(Contracts::claim_surcharge(Origin::none(), addr_bob.clone(), Some(ALICE))); assert!(ContractInfoOf::::get(&addr_bob).unwrap().get_tombstone().is_some()); From efa81bbe61bff95ad57b1d91c30f4649d174f2a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Thei=C3=9Fen?= Date: Wed, 30 Dec 2020 23:44:14 +0100 Subject: [PATCH 07/14] Add test that checks that partial remove of a contract works --- frame/contracts/src/tests.rs | 94 ++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) diff --git a/frame/contracts/src/tests.rs b/frame/contracts/src/tests.rs index 86a2d763154dc..43f7ecf0bb227 100644 --- a/frame/contracts/src/tests.rs +++ b/frame/contracts/src/tests.rs @@ -1981,6 +1981,100 @@ fn lazy_removal_works() { }); } +#[test] +fn lazy_removal_partial_remove_works() { + let (code, hash) = compile_module::("self_destruct").unwrap(); + + // We create a contract with some extra keys above the weight limit + let extra_keys = 7u32; + let weight_limit = 5_000_000_000; + let (_, max_keys) = Storage::::deletion_budget(1, weight_limit); + let vals: Vec<_> = (0..max_keys + extra_keys).map(|i| { + (blake2_256(&i.encode()), (i as u32), (i as u32).encode()) + }) + .collect(); + + let mut ext = ExtBuilder::default().existential_deposit(50).build(); + + let trie = ext.execute_with(|| { + let subsistence = ConfigCache::::subsistence_threshold_uncached(); + let _ = Balances::deposit_creating(&ALICE, 10 * subsistence); + assert_ok!(Contracts::put_code(Origin::signed(ALICE), code)); + + assert_ok!( + Contracts::instantiate( + Origin::signed(ALICE), + subsistence, + GAS_LIMIT, + hash.into(), + vec![], + vec![], + ), + ); + + let addr = Contracts::contract_address(&ALICE, &hash, &[]); + let info = >::get(&addr).unwrap().get_alive().unwrap(); + let trie = &info.child_trie_info(); + + // Put value into the contracts child trie + for val in &vals { + Storage::::write( + &addr, + &info.trie_id, + &val.0, + Some(val.2.clone()), + ).unwrap(); + } + + // Terminate the contract + assert_ok!(Contracts::call( + Origin::signed(ALICE), + addr.clone(), + 0, + GAS_LIMIT, + vec![], + )); + + // Contract info should be gone + assert!(!>::contains_key(&addr)); + + // But value should be still there as the lazy removal did not run, yet. + for val in &vals { + assert_eq!(child::get::(trie, &blake2_256(&val.0)), Some(val.1)); + } + + trie.clone() + }); + + // The lazy removal limit only applies to the backend but not to the overlay. + // This commits all keys from the overlay to the backend. + ext.commit_all().unwrap(); + + ext.execute_with(|| { + // Run the lazy removal + let weight_used = Storage::::process_deletion_queue_batch(weight_limit).unwrap(); + + // Weight should be exhausted because we could not even delete all keys + assert_eq!(weight_used, weight_limit); + + let mut num_deleted = 0u32; + let mut num_remaining = 0u32; + + for val in &vals { + match child::get::(&trie, &blake2_256(&val.0)) { + None => num_deleted += 1, + Some(x) if x == val.1 => num_remaining += 1, + Some(_) => panic!("Unexpected value in contract storage"), + } + } + + // All but one key is removed + assert_eq!(num_deleted + num_remaining, vals.len() as u32); + assert_eq!(num_deleted, max_keys); + assert_eq!(num_remaining, extra_keys); + }); +} + #[test] fn lazy_removal_does_not_use_all_weight() { let (code, hash) = compile_module::("self_destruct").unwrap(); From 91850a08ff568c0bd06c39f97e4f580e0e3cd401 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Thei=C3=9Fen?= Date: Wed, 30 Dec 2020 23:44:58 +0100 Subject: [PATCH 08/14] Premote warning to error --- frame/contracts/src/storage.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/contracts/src/storage.rs b/frame/contracts/src/storage.rs index cb031ebb1e596..4cdc50aa1bd29 100644 --- a/frame/contracts/src/storage.rs +++ b/frame/contracts/src/storage.rs @@ -282,7 +282,7 @@ where match outcome { // This should not happen as our budget was large enough to remove all keys. KillOutcome::SomeRemaining => { - debug::warn!( + debug::error!( "After deletion keys are remaining in this child trie: {:?}", removed.trie_id, ); From 91c2d76b2653ebe270a13a8b8b24b5b89c577894 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Thei=C3=9Fen?= Date: Wed, 30 Dec 2020 23:50:45 +0100 Subject: [PATCH 09/14] Added missing docs for seal_terminate --- frame/contracts/src/wasm/runtime.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/frame/contracts/src/wasm/runtime.rs b/frame/contracts/src/wasm/runtime.rs index c4365e2cb0f57..d98d162e8918c 100644 --- a/frame/contracts/src/wasm/runtime.rs +++ b/frame/contracts/src/wasm/runtime.rs @@ -890,6 +890,8 @@ define_env!(Env, , // # Traps // // - The contract is live i.e is already on the call stack. + // - Failed to send the balance to the beneficiary. + // - The deletion queue is full. seal_terminate( ctx, beneficiary_ptr: u32, From 8f2fc0c1a22234d7e6839b35dd3c0e068feea7f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Thei=C3=9Fen?= Date: Thu, 31 Dec 2020 19:32:32 +0100 Subject: [PATCH 10/14] Lazy deletion should only take AVERAGE_ON_INITIALIZE_RATIO of the block --- bin/node/runtime/src/lib.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bin/node/runtime/src/lib.rs b/bin/node/runtime/src/lib.rs index 63f5791bd5733..505e935c93082 100644 --- a/bin/node/runtime/src/lib.rs +++ b/bin/node/runtime/src/lib.rs @@ -717,8 +717,11 @@ parameter_types! { pub const MaxDepth: u32 = 32; pub const StorageSizeOffset: u32 = 8; pub const MaxValueSize: u32 = 16 * 1024; - pub DeletionWeightLimit: Weight = Perbill::from_percent(20) * + // The lazy deletion runs inside on_initialize. + pub DeletionWeightLimit: Weight = AVERAGE_ON_INITIALIZE_RATIO * RuntimeBlockWeights::get().max_block; + // The weight needed for decoding the queue should be less or equal than a fifth + // of the overall weight dedicated to the lazy deletion. pub DeletionQueueDepth: u32 = ((DeletionWeightLimit::get() / ( ::WeightInfo::on_initialize_per_queue_item(1) - ::WeightInfo::on_initialize_per_queue_item(0) From 98d3f28620e7c45120c8cfabeec7151ff45bbb3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Thei=C3=9Fen?= Date: Thu, 31 Dec 2020 19:54:11 +0100 Subject: [PATCH 11/14] Added informational about the lazy deletion throughput --- frame/contracts/src/benchmarking/mod.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/frame/contracts/src/benchmarking/mod.rs b/frame/contracts/src/benchmarking/mod.rs index d672061d433e0..0c178fc7cbbe4 100644 --- a/frame/contracts/src/benchmarking/mod.rs +++ b/frame/contracts/src/benchmarking/mod.rs @@ -2409,7 +2409,20 @@ benchmarks! { #[extra] print_schedule { #[cfg(feature = "std")] - println!("{:#?}", Schedule::::default()); + { + let weight_per_key = T::WeightInfo::on_initialize_per_trie_key(1) - + T::WeightInfo::on_initialize_per_trie_key(0); + let weight_per_queue_item = T::WeightInfo::on_initialize_per_queue_item(1) - + T::WeightInfo::on_initialize_per_queue_item(0); + let weight_limit = T::DeletionWeightLimit::get(); + let queue_depth: u64 = T::DeletionQueueDepth::get().into(); + println!("{:#?}", Schedule::::default()); + println!("###############################################"); + println!("Lazy deletion throughput per block (empty queue, full queue): {}, {}", + weight_limit / weight_per_key, + (weight_limit - weight_per_queue_item * queue_depth) / weight_per_key, + ); + } #[cfg(not(feature = "std"))] return Err("Run this bench with a native runtime in order to see the schedule."); }: {} From d5a820cd7a6800de0bbee1fb0b93a07cd4fd4189 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Thei=C3=9Fen?= Date: Fri, 1 Jan 2021 03:18:59 +0100 Subject: [PATCH 12/14] Avoid lazy deletion in case the block is already full --- frame/contracts/src/lib.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/frame/contracts/src/lib.rs b/frame/contracts/src/lib.rs index 143f620f9672d..8589350c04d23 100644 --- a/frame/contracts/src/lib.rs +++ b/frame/contracts/src/lib.rs @@ -120,7 +120,7 @@ use frame_support::{ dispatch::{DispatchResult, DispatchResultWithPostInfo}, traits::{OnUnbalanced, Currency, Get, Time, Randomness}, }; -use frame_system::{ensure_signed, ensure_root}; +use frame_system::{ensure_signed, ensure_root, Module as System}; use pallet_contracts_primitives::{ RentProjectionResult, GetStorageResult, ContractAccessError, ContractExecResult, ExecResult, }; @@ -465,7 +465,12 @@ decl_module! { fn deposit_event() = default; fn on_initialize() -> Weight { - Storage::::process_deletion_queue_batch(T::DeletionWeightLimit::get()) + // We do not want to go above the block limit and rather avoid lazy deletion + // in that case. This should only happen on runtime upgrades. + let weight_limit = T::BlockWeights::get().max_block + .saturating_sub(System::::block_weight().total()) + .min(T::DeletionWeightLimit::get()); + Storage::::process_deletion_queue_batch(weight_limit) .unwrap_or_else(T::WeightInfo::on_initialize) } From 57737ff83ee2c4627680505f132da2298df671f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Thei=C3=9Fen?= Date: Sat, 2 Jan 2021 17:43:08 +0100 Subject: [PATCH 13/14] Prevent queue decoding in case of an already full block --- frame/contracts/src/lib.rs | 2 +- frame/contracts/src/storage.rs | 28 +++++++++++++++------------- frame/contracts/src/tests.rs | 4 ++-- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/frame/contracts/src/lib.rs b/frame/contracts/src/lib.rs index 8589350c04d23..ac6dc2b95ae12 100644 --- a/frame/contracts/src/lib.rs +++ b/frame/contracts/src/lib.rs @@ -471,7 +471,7 @@ decl_module! { .saturating_sub(System::::block_weight().total()) .min(T::DeletionWeightLimit::get()); Storage::::process_deletion_queue_batch(weight_limit) - .unwrap_or_else(T::WeightInfo::on_initialize) + .saturating_add(T::WeightInfo::on_initialize()) } /// Updates the schedule for metering contracts. diff --git a/frame/contracts/src/storage.rs b/frame/contracts/src/storage.rs index 4cdc50aa1bd29..4038ac3037b83 100644 --- a/frame/contracts/src/storage.rs +++ b/frame/contracts/src/storage.rs @@ -249,21 +249,26 @@ where /// /// It returns the amount of weight used for that task or `None` when no weight was used /// apart from the base weight. - pub fn process_deletion_queue_batch(weight_limit: Weight) -> Option { - // We can decode the queue eagerly because we cap the queue depth and assume - // that the weight is large enough to do at least one round of deletions. - // We can assume that because any other static configuration of the runtime - // would make no sense at all. - let mut queue = DeletionQueue::get(); - if queue.is_empty() { - return None; + pub fn process_deletion_queue_batch(weight_limit: Weight) -> Weight { + let queue_len = DeletionQueue::decode_len().unwrap_or(0); + if queue_len == 0 { + return weight_limit; } let (weight_per_key, mut remaining_key_budget) = Self::deletion_budget( - queue.len(), + queue_len, weight_limit, ); + // We want to check whether we have enough weight to decode the queue before + // proceeding. Too little weight for decoding might happen during runtime upgrades + // which consume the whole block before the other `on_initialize` blocks are called. + if remaining_key_budget == 0 { + return weight_limit; + } + + let mut queue = DeletionQueue::get(); + while !queue.is_empty() && remaining_key_budget > 0 { // Cannot panic due to loop condition let trie = &mut queue[0]; @@ -295,10 +300,7 @@ where } DeletionQueue::put(queue); - Some( - weight_limit - .saturating_sub(weight_per_key.saturating_mul(remaining_key_budget as Weight)) - ) + weight_limit.saturating_sub(weight_per_key.saturating_mul(remaining_key_budget as Weight)) } /// This generator uses inner counter for account id and applies the hash over `AccountId + diff --git a/frame/contracts/src/tests.rs b/frame/contracts/src/tests.rs index 43f7ecf0bb227..e5cf2522ab7c6 100644 --- a/frame/contracts/src/tests.rs +++ b/frame/contracts/src/tests.rs @@ -2052,7 +2052,7 @@ fn lazy_removal_partial_remove_works() { ext.execute_with(|| { // Run the lazy removal - let weight_used = Storage::::process_deletion_queue_batch(weight_limit).unwrap(); + let weight_used = Storage::::process_deletion_queue_batch(weight_limit); // Weight should be exhausted because we could not even delete all keys assert_eq!(weight_used, weight_limit); @@ -2134,7 +2134,7 @@ fn lazy_removal_does_not_use_all_weight() { } // Run the lazy removal - let weight_used = Storage::::process_deletion_queue_batch(weight_limit).unwrap(); + let weight_used = Storage::::process_deletion_queue_batch(weight_limit); // We have one less key in our trie than our weight limit suffices for assert_eq!(weight_used, weight_limit - weight_per_key); From ed4c7e81df0c86ea40b4a7ea30fcf48c22bfbe01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Thei=C3=9Fen?= Date: Sat, 2 Jan 2021 18:17:23 +0100 Subject: [PATCH 14/14] Add test that checks that on_initialize honors block limits --- frame/contracts/src/tests.rs | 93 ++++++++++++++++++++++++++++++++++-- 1 file changed, 89 insertions(+), 4 deletions(-) diff --git a/frame/contracts/src/tests.rs b/frame/contracts/src/tests.rs index e5cf2522ab7c6..93b81734bfa3c 100644 --- a/frame/contracts/src/tests.rs +++ b/frame/contracts/src/tests.rs @@ -32,7 +32,7 @@ use frame_support::{ assert_ok, assert_err, assert_err_ignore_postinfo, impl_outer_dispatch, impl_outer_event, impl_outer_origin, parameter_types, StorageMap, traits::{Currency, ReservableCurrency, OnInitialize}, - weights::{Weight, PostDispatchInfo}, + weights::{Weight, PostDispatchInfo, DispatchClass, constants::WEIGHT_PER_SECOND}, dispatch::DispatchErrorWithPostInfo, storage::child, }; @@ -107,12 +107,12 @@ pub struct Test; parameter_types! { pub const BlockHashCount: u64 = 250; pub BlockWeights: frame_system::limits::BlockWeights = - frame_system::limits::BlockWeights::simple_max(1024); + frame_system::limits::BlockWeights::simple_max(2 * WEIGHT_PER_SECOND); pub static ExistentialDeposit: u64 = 0; } impl frame_system::Config for Test { type BaseCallFilter = (); - type BlockWeights = (); + type BlockWeights = BlockWeights; type BlockLength = (); type DbWeight = (); type Origin = Origin; @@ -1974,7 +1974,7 @@ fn lazy_removal_works() { assert_matches!(child::get(trie, &[99]), Some(42)); // Run the lazy removal - Contracts::on_initialize(0); + Contracts::on_initialize(Weight::max_value()); // Value should be gone now assert_matches!(child::get::(trie, &[99]), None); @@ -2075,6 +2075,91 @@ fn lazy_removal_partial_remove_works() { }); } +#[test] +fn lazy_removal_does_no_run_on_full_block() { + let (code, hash) = compile_module::("self_destruct").unwrap(); + ExtBuilder::default().existential_deposit(50).build().execute_with(|| { + let subsistence = ConfigCache::::subsistence_threshold_uncached(); + let _ = Balances::deposit_creating(&ALICE, 10 * subsistence); + assert_ok!(Contracts::put_code(Origin::signed(ALICE), code)); + + assert_ok!( + Contracts::instantiate( + Origin::signed(ALICE), + subsistence, + GAS_LIMIT, + hash.into(), + vec![], + vec![], + ), + ); + + let addr = Contracts::contract_address(&ALICE, &hash, &[]); + let info = >::get(&addr).unwrap().get_alive().unwrap(); + let trie = &info.child_trie_info(); + let max_keys = 30; + + // Create some storage items for the contract. + let vals: Vec<_> = (0..max_keys).map(|i| { + (blake2_256(&i.encode()), (i as u32), (i as u32).encode()) + }) + .collect(); + + // Put value into the contracts child trie + for val in &vals { + Storage::::write( + &addr, + &info.trie_id, + &val.0, + Some(val.2.clone()), + ).unwrap(); + } + + // Terminate the contract + assert_ok!(Contracts::call( + Origin::signed(ALICE), + addr.clone(), + 0, + GAS_LIMIT, + vec![], + )); + + // Contract info should be gone + assert!(!>::contains_key(&addr)); + + // But value should be still there as the lazy removal did not run, yet. + for val in &vals { + assert_eq!(child::get::(trie, &blake2_256(&val.0)), Some(val.1)); + } + + // Fill up the block which should prevent the lazy storage removal from running. + System::register_extra_weight_unchecked( + ::BlockWeights::get().max_block, + DispatchClass::Mandatory, + ); + + // Run the lazy removal without any limit so that all keys would be removed if there + // had been some weight left in the block. + let weight_used = Contracts::on_initialize(Weight::max_value()); + let base = <::WeightInfo as crate::WeightInfo>::on_initialize(); + assert_eq!(weight_used, base); + + // All the keys are still in place + for val in &vals { + assert_eq!(child::get::(trie, &blake2_256(&val.0)), Some(val.1)); + } + + // Run the lazy removal directly which disregards the block limits + Storage::::process_deletion_queue_batch(Weight::max_value()); + + // Now the keys should be gone + for val in &vals { + assert_eq!(child::get::(trie, &blake2_256(&val.0)), None); + } + }); +} + + #[test] fn lazy_removal_does_not_use_all_weight() { let (code, hash) = compile_module::("self_destruct").unwrap();