From 8929cba91d658908a835b36db94578df2c420c71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Thei=C3=9Fen?= Date: Wed, 24 Feb 2021 13:49:42 +0100 Subject: [PATCH 01/10] contracts: Expose rent parameter to contracts --- frame/contracts/CHANGELOG.md | 8 +- frame/contracts/src/benchmarking/mod.rs | 8 + frame/contracts/src/exec.rs | 375 ++++++++++++++++++++---- frame/contracts/src/storage.rs | 8 +- frame/contracts/src/tests.rs | 1 - frame/contracts/src/wasm/mod.rs | 70 ++++- frame/contracts/src/wasm/runtime.rs | 23 ++ 7 files changed, 420 insertions(+), 73 deletions(-) diff --git a/frame/contracts/CHANGELOG.md b/frame/contracts/CHANGELOG.md index ce35abbd86b2a..ef69e050a2c5f 100644 --- a/frame/contracts/CHANGELOG.md +++ b/frame/contracts/CHANGELOG.md @@ -16,7 +16,13 @@ The interface provided to smart contracts will adhere to semver with one excepti major version bumps will be backwards compatible with regard to already deployed contracts. In other words: Upgrading this pallet will not break pre-existing contracts. -## [v3.0.0] +## [Unreleased] + +### Added + +- Add `seal_rent_params` contract callable function. + +## [v3.0.0] 2021-02-25 This version constitutes the first release that brings any stability guarantees (see above). diff --git a/frame/contracts/src/benchmarking/mod.rs b/frame/contracts/src/benchmarking/mod.rs index d01a2bce2c27b..d41154e995a67 100644 --- a/frame/contracts/src/benchmarking/mod.rs +++ b/frame/contracts/src/benchmarking/mod.rs @@ -533,6 +533,14 @@ benchmarks! { let origin = RawOrigin::Signed(instance.caller.clone()); }: call(origin, instance.addr, 0u32.into(), Weight::max_value(), vec![]) + seal_rent_params { + let r in 0 .. API_BENCHMARK_BATCHES; + let instance = Contract::::new(WasmModule::getter( + "seal_rent_params", r * API_BENCHMARK_BATCH_SIZE + ), vec![], Endow::Max)?; + let origin = RawOrigin::Signed(instance.caller.clone()); + }: call(origin, instance.addr, 0u32.into(), Weight::max_value(), vec![]) + seal_weight_to_fee { let r in 0 .. API_BENCHMARK_BATCHES; let pages = code::max_pages::(); diff --git a/frame/contracts/src/exec.rs b/frame/contracts/src/exec.rs index 745384a8674bc..3159e267f5891 100644 --- a/frame/contracts/src/exec.rs +++ b/frame/contracts/src/exec.rs @@ -18,14 +18,14 @@ use crate::{ CodeHash, Event, Config, Module as Contracts, TrieId, BalanceOf, ContractInfo, gas::GasMeter, rent::Rent, storage::{self, Storage}, - Error, ContractInfoOf, Schedule, + Error, ContractInfoOf, Schedule, AliveContractInfo, }; use sp_core::crypto::UncheckedFrom; use sp_std::{ prelude::*, marker::PhantomData, }; -use sp_runtime::traits::{Bounded, Zero, Convert, Saturating}; +use sp_runtime::{Perbill, traits::{Bounded, Zero, Convert, Saturating}}; use frame_support::{ dispatch::{DispatchResult, DispatchError}, traits::{ExistenceRequirement, Currency, Time, Randomness, Get}, @@ -43,13 +43,82 @@ pub type StorageKey = [u8; 32]; /// A type that represents a topic of an event. At the moment a hash is used. pub type TopicOf = ::Hash; -/// Describes whether we deal with a contract or a plain account. -pub enum TransactorKind { - /// Transaction was initiated from a plain account. That can be either be through a - /// signed transaction or through RPC. - PlainAccount, - /// The call was initiated by a contract account. - Contract, +/// Information needed for rent calculations that can be requested by a contract. +#[derive(codec::Encode)] +#[cfg_attr(test, derive(Debug, PartialEq))] +pub struct RentParams { + /// The free balance of the contract. + total_balance: BalanceOf, + /// The free balance of the contract. + free_balance: BalanceOf, + /// See crate [`Contracts::subsistence_threshold()`]. + subsistence_threshold: BalanceOf, + /// See crate [`Config::DepositPerContract`]. + deposit_per_contract: BalanceOf, + /// See crate [`Config::DepositPerStorageByte`]. + deposit_per_storage_byte: BalanceOf, + /// See crate [`Config::DepositPerStorageItem`]. + deposit_per_storage_item: BalanceOf, + /// See crate [`Ext::rent_allowance()`]. + rent_allowance: BalanceOf, + /// See crate [`Config::RentFraction`]. + rent_fraction: Perbill, + /// See crate [`AliveContractInfo::storage_size`]. + storage_size: u32, + /// See crate [`Executable::code_len()`]. + code_size: u32, + /// See crate [`Executable::refcount()`]. + code_refcount: u32, + /// Reserved for backwards compatible changes to this data structure. + _reserved: Option<()>, +} + +impl RentParams +where + T: Config, + T::AccountId: UncheckedFrom + AsRef<[u8]>, +{ + fn new>( + account_id: &T::AccountId, + contract: &AliveContractInfo, + executable: &E + ) -> Self { + Self { + total_balance: T::Currency::total_balance(account_id), + free_balance: T::Currency::free_balance(account_id), + subsistence_threshold: >::subsistence_threshold(), + deposit_per_contract: T::DepositPerContract::get(), + deposit_per_storage_byte: T::DepositPerStorageByte::get(), + deposit_per_storage_item: T::DepositPerStorageItem::get(), + rent_allowance: contract.rent_allowance, + rent_fraction: T::RentFraction::get(), + storage_size: contract.storage_size, + code_size: executable.code_len().saturating_add(executable.origignal_code_len()), + code_refcount: executable.refcount(), + _reserved: None, + } + } +} + +/// We cannot derive `Default` because `T` does not necessarily implement `Default`. +#[cfg(test)] +impl Default for RentParams { + fn default() -> Self { + Self { + total_balance: Default::default(), + free_balance: Default::default(), + subsistence_threshold: Default::default(), + deposit_per_contract: Default::default(), + deposit_per_storage_byte: Default::default(), + deposit_per_storage_item: Default::default(), + rent_allowance: Default::default(), + rent_fraction: Default::default(), + storage_size: Default::default(), + code_size: Default::default(), + code_refcount: Default::default(), + _reserved: Default::default(), + } + } } /// An interface that provides access to the external environment in which the @@ -198,9 +267,13 @@ pub trait Ext: sealing::Sealed { /// Get a reference to the schedule used by the current call. fn schedule(&self) -> &Schedule; + + /// Information needed for rent calculations. + fn rent_params(&self) -> &RentParams; } /// Describes the different functions that can be exported by an [`Executable`]. +#[cfg_attr(test, derive(Clone, Copy, PartialEq))] pub enum ExportedFunction { /// The constructor function which is executed on deployment of a contract. Constructor, @@ -273,16 +346,22 @@ pub trait Executable: Sized { /// Size of the instrumented code in bytes. fn code_len(&self) -> u32; + + /// Size of the original code in bytes. + fn origignal_code_len(&self) -> u32; + + // The number of contracts using this executable. + fn refcount(&self) -> u32; } pub struct ExecutionContext<'a, T: Config + 'a, E> { - pub caller: Option<&'a ExecutionContext<'a, T, E>>, - pub self_account: T::AccountId, - pub self_trie_id: Option, - pub depth: usize, - pub schedule: &'a Schedule, - pub timestamp: MomentOf, - pub block_number: T::BlockNumber, + caller: Option<&'a ExecutionContext<'a, T, E>>, + self_account: T::AccountId, + self_trie_id: Option, + depth: usize, + schedule: &'a Schedule, + timestamp: MomentOf, + block_number: T::BlockNumber, _phantom: PhantomData, } @@ -371,8 +450,12 @@ where )? } + let call_context = nested.new_call_context( + caller, &dest, value, &contract, &executable, + ); + let output = executable.execute( - nested.new_call_context(caller, value), + call_context, &ExportedFunction::Call, input_data, gas_meter, @@ -403,7 +486,7 @@ where let dest_trie_id = Storage::::generate_trie_id(&dest); let output = self.with_nested_context(dest.clone(), dest_trie_id, |nested| { - Storage::::place_contract( + let contract = Storage::::place_contract( &dest, nested .self_trie_id @@ -428,8 +511,16 @@ where // spawned. This is OK as overcharging is always safe. let occupied_storage = executable.occupied_storage(); + let call_context = nested.new_call_context( + caller.clone(), + &dest, + endowment, + &contract, + &executable, + ); + let output = executable.execute( - nested.new_call_context(caller.clone(), endowment), + call_context, &ExportedFunction::Constructor, input_data, gas_meter, @@ -468,7 +559,10 @@ where fn new_call_context<'b>( &'b mut self, caller: T::AccountId, + dest: &T::AccountId, value: BalanceOf, + contract: &AliveContractInfo, + executable: &E, ) -> CallContext<'b, 'a, T, E> { let timestamp = self.timestamp.clone(); let block_number = self.block_number.clone(); @@ -478,6 +572,7 @@ where value_transferred: value, timestamp, block_number, + rent_params: RentParams::new(dest, contract, executable), _phantom: Default::default(), } } @@ -517,6 +612,15 @@ where } } +/// Describes whether we deal with a contract or a plain account. +enum TransactorKind { + /// Transaction was initiated from a plain account. That can be either be through a + /// signed transaction or through RPC. + PlainAccount, + /// The call was initiated by a contract account. + Contract, +} + /// Describes possible transfer causes. enum TransferCause { Call, @@ -581,6 +685,7 @@ struct CallContext<'a, 'b: 'a, T: Config + 'b, E> { value_transferred: BalanceOf, timestamp: MomentOf, block_number: T::BlockNumber, + rent_params: RentParams, _phantom: PhantomData, } @@ -791,6 +896,10 @@ where fn schedule(&self) -> &Schedule { &self.ctx.schedule } + + fn rent_params(&self) -> &RentParams { + &self.rent_params + } } fn deposit_event( @@ -832,11 +941,13 @@ mod tests { ALICE, BOB, CHARLIE, test_utils::{place_contract, set_balance, get_balance}, }, + exec::ExportedFunction::*, Error, Weight, }; use sp_runtime::DispatchError; use assert_matches::assert_matches; use std::{cell::RefCell, collections::HashMap, rc::Rc}; + use pretty_assertions::{assert_eq, assert_ne}; type MockContext<'a> = ExecutionContext<'a, Test, MockExecutable>; @@ -863,7 +974,12 @@ mod tests { } #[derive(Clone)] - struct MockExecutable(Rc ExecResult + 'static>, CodeHash); + struct MockExecutable { + func: Rc ExecResult + 'static>, + func_type: ExportedFunction, + code_hash: CodeHash, + refcount: u64, + } #[derive(Default)] struct MockLoader { @@ -872,16 +988,61 @@ mod tests { } impl MockLoader { - fn insert(f: impl Fn(MockCtx) -> ExecResult + 'static) -> CodeHash { + fn insert( + func_type: ExportedFunction, + f: impl Fn(MockCtx, &MockExecutable, + ) -> ExecResult + 'static) -> CodeHash { LOADER.with(|loader| { let mut loader = loader.borrow_mut(); // Generate code hashes as monotonically increasing values. let hash = ::Hash::from_low_u64_be(loader.counter); loader.counter += 1; - loader.map.insert(hash, MockExecutable (Rc::new(f), hash.clone())); + loader.map.insert(hash, MockExecutable { + func: Rc::new(f), + func_type, + code_hash: hash.clone(), + refcount: 1, + }); hash }) } + + fn increment_refcount(code_hash: CodeHash) { + LOADER.with(|loader| { + let mut loader = loader.borrow_mut(); + loader.map + .entry(code_hash) + .and_modify(|executable| executable.refcount += 1) + .or_insert_with(|| panic!("code_hash does not exist")); + }); + } + + fn decrement_refcount(code_hash: CodeHash) { + use std::collections::hash_map::Entry::Occupied; + LOADER.with(|loader| { + let mut loader = loader.borrow_mut(); + let mut entry = match loader.map.entry(code_hash) { + Occupied(e) => e, + _ => panic!("code_hash does not exist"), + }; + let refcount = &mut entry.get_mut().refcount; + *refcount -= 1; + if *refcount == 0 { + entry.remove(); + } + }); + } + + fn refcount(code_hash: &CodeHash) -> u32 { + LOADER.with(|loader| { + loader + .borrow() + .map + .get(code_hash) + .expect("code_hash does not exist") + .refcount() + }) + } } impl Executable for MockExecutable { @@ -903,30 +1064,43 @@ mod tests { }) } - fn drop_from_storage(self) {} + fn drop_from_storage(self) { + MockLoader::decrement_refcount(self.code_hash); + } - fn add_user(_code_hash: CodeHash) -> Result { + fn add_user(code_hash: CodeHash) -> Result { + MockLoader::increment_refcount(code_hash); Ok(0) } - fn remove_user(_code_hash: CodeHash) -> u32 { 0 } + fn remove_user(code_hash: CodeHash) -> u32 { + MockLoader::decrement_refcount(code_hash); + 0 + } fn execute>( self, mut ext: E, - _function: &ExportedFunction, + function: &ExportedFunction, input_data: Vec, gas_meter: &mut GasMeter, ) -> ExecResult { - (self.0)(MockCtx { - ext: &mut ext, - input_data, - gas_meter, - }) + if let &Constructor = function { + MockLoader::increment_refcount(self.code_hash); + } + if function == &self.func_type { + (self.func)(MockCtx { + ext: &mut ext, + input_data, + gas_meter, + }, &self) + } else { + exec_success() + } } fn code_hash(&self) -> &CodeHash { - &self.1 + &self.code_hash } fn occupied_storage(&self) -> u32 { @@ -936,6 +1110,14 @@ mod tests { fn code_len(&self) -> u32 { 0 } + + fn origignal_code_len(&self) -> u32 { + 0 + } + + fn refcount(&self) -> u32 { + self.refcount as u32 + } } fn exec_success() -> ExecResult { @@ -950,7 +1132,7 @@ mod tests { let value = Default::default(); let mut gas_meter = GasMeter::::new(GAS_LIMIT); - let exec_ch = MockLoader::insert(|_ctx| { + let exec_ch = MockLoader::insert(Call, |_ctx, _executable| { TEST_DATA.with(|data| data.borrow_mut().push(1)); exec_success() }); @@ -1001,7 +1183,8 @@ mod tests { let dest = BOB; let return_ch = MockLoader::insert( - |_| Ok(ExecReturnValue { flags: ReturnFlags::REVERT, data: Vec::new() }) + Call, + |_, _| Ok(ExecReturnValue { flags: ReturnFlags::REVERT, data: Vec::new() }) ); ExtBuilder::default().build().execute_with(|| { @@ -1060,7 +1243,8 @@ mod tests { let origin = ALICE; let dest = BOB; let return_ch = MockLoader::insert( - |_| Ok(ExecReturnValue { flags: ReturnFlags::empty(), data: vec![1, 2, 3, 4] }) + Call, + |_, _| Ok(ExecReturnValue { flags: ReturnFlags::empty(), data: vec![1, 2, 3, 4] }) ); ExtBuilder::default().build().execute_with(|| { @@ -1088,7 +1272,8 @@ mod tests { let origin = ALICE; let dest = BOB; let return_ch = MockLoader::insert( - |_| Ok(ExecReturnValue { flags: ReturnFlags::REVERT, data: vec![1, 2, 3, 4] }) + Call, + |_, _| Ok(ExecReturnValue { flags: ReturnFlags::REVERT, data: vec![1, 2, 3, 4] }) ); ExtBuilder::default().build().execute_with(|| { @@ -1111,7 +1296,7 @@ mod tests { #[test] fn input_data_to_call() { - let input_data_ch = MockLoader::insert(|ctx| { + let input_data_ch = MockLoader::insert(Call, |ctx, _| { assert_eq!(ctx.input_data, &[1, 2, 3, 4]); exec_success() }); @@ -1134,7 +1319,7 @@ mod tests { #[test] fn input_data_to_instantiate() { - let input_data_ch = MockLoader::insert(|ctx| { + let input_data_ch = MockLoader::insert(Constructor, |ctx, _| { assert_eq!(ctx.input_data, &[1, 2, 3, 4]); exec_success() }); @@ -1170,7 +1355,7 @@ mod tests { static REACHED_BOTTOM: RefCell = RefCell::new(false); } let value = Default::default(); - let recurse_ch = MockLoader::insert(|ctx| { + let recurse_ch = MockLoader::insert(Call, |ctx, _| { // Try to call into yourself. let r = ctx.ext.call(&BOB, 0, ctx.gas_meter, vec![]); @@ -1220,7 +1405,7 @@ mod tests { static WITNESSED_CALLER_CHARLIE: RefCell>> = RefCell::new(None); } - let bob_ch = MockLoader::insert(|ctx| { + let bob_ch = MockLoader::insert(Call, |ctx, _| { // Record the caller for bob. WITNESSED_CALLER_BOB.with(|caller| *caller.borrow_mut() = Some(ctx.ext.caller().clone()) @@ -1233,7 +1418,7 @@ mod tests { ); exec_success() }); - let charlie_ch = MockLoader::insert(|ctx| { + let charlie_ch = MockLoader::insert(Call, |ctx, _| { // Record the caller for charlie. WITNESSED_CALLER_CHARLIE.with(|caller| *caller.borrow_mut() = Some(ctx.ext.caller().clone()) @@ -1263,7 +1448,7 @@ mod tests { #[test] fn address_returns_proper_values() { - let bob_ch = MockLoader::insert(|ctx| { + let bob_ch = MockLoader::insert(Call, |ctx, _| { // Verify that address matches BOB. assert_eq!(*ctx.ext.address(), BOB); @@ -1274,7 +1459,7 @@ mod tests { ); exec_success() }); - let charlie_ch = MockLoader::insert(|ctx| { + let charlie_ch = MockLoader::insert(Call, |ctx, _| { assert_eq!(*ctx.ext.address(), CHARLIE); exec_success() }); @@ -1298,7 +1483,7 @@ mod tests { #[test] fn refuse_instantiate_with_value_below_existential_deposit() { - let dummy_ch = MockLoader::insert(|_| exec_success()); + let dummy_ch = MockLoader::insert(Constructor, |_, _| exec_success()); ExtBuilder::default().existential_deposit(15).build().execute_with(|| { let schedule = Contracts::current_schedule(); @@ -1324,7 +1509,8 @@ mod tests { #[test] fn instantiation_work_with_success_output() { let dummy_ch = MockLoader::insert( - |_| Ok(ExecReturnValue { flags: ReturnFlags::empty(), data: vec![80, 65, 83, 83] }) + Constructor, + |_, _| Ok(ExecReturnValue { flags: ReturnFlags::empty(), data: vec![80, 65, 83, 83] }) ); ExtBuilder::default().existential_deposit(15).build().execute_with(|| { @@ -1359,7 +1545,8 @@ mod tests { #[test] fn instantiation_fails_with_failing_output() { let dummy_ch = MockLoader::insert( - |_| Ok(ExecReturnValue { flags: ReturnFlags::REVERT, data: vec![70, 65, 73, 76] }) + Constructor, + |_, _| Ok(ExecReturnValue { flags: ReturnFlags::REVERT, data: vec![70, 65, 73, 76] }) ); ExtBuilder::default().existential_deposit(15).build().execute_with(|| { @@ -1390,12 +1577,12 @@ mod tests { #[test] fn instantiation_from_contract() { - let dummy_ch = MockLoader::insert(|_| exec_success()); + let dummy_ch = MockLoader::insert(Call, |_, _| exec_success()); let instantiated_contract_address = Rc::new(RefCell::new(None::>)); - let instantiator_ch = MockLoader::insert({ + let instantiator_ch = MockLoader::insert(Call, { let dummy_ch = dummy_ch.clone(); let instantiated_contract_address = Rc::clone(&instantiated_contract_address); - move |ctx| { + move |ctx, _| { // Instantiate a contract and save it's address in `instantiated_contract_address`. let (address, output, _) = ctx.ext.instantiate( dummy_ch, @@ -1434,12 +1621,12 @@ mod tests { #[test] fn instantiation_traps() { - let dummy_ch = MockLoader::insert( - |_| Err("It's a trap!".into()) + let dummy_ch = MockLoader::insert(Constructor, + |_, _| Err("It's a trap!".into()) ); - let instantiator_ch = MockLoader::insert({ + let instantiator_ch = MockLoader::insert(Call, { let dummy_ch = dummy_ch.clone(); - move |ctx| { + move |ctx, _| { // Instantiate a contract and save it's address in `instantiated_contract_address`. assert_matches!( ctx.ext.instantiate( @@ -1479,7 +1666,7 @@ mod tests { #[test] fn termination_from_instantiate_fails() { - let terminate_ch = MockLoader::insert(|ctx| { + let terminate_ch = MockLoader::insert(Constructor, |ctx, _| { ctx.ext.terminate(&ALICE).unwrap(); exec_success() }); @@ -1516,7 +1703,7 @@ mod tests { #[test] fn rent_allowance() { - let rent_allowance_ch = MockLoader::insert(|ctx| { + let rent_allowance_ch = MockLoader::insert(Constructor, |ctx, _| { let subsistence = Contracts::::subsistence_threshold(); let allowance = subsistence * 3; assert_eq!(ctx.ext.rent_allowance(), >::max_value()); @@ -1545,4 +1732,82 @@ mod tests { assert_matches!(result, Ok(_)); }); } + + #[test] + fn rent_params_works() { + let code_hash = MockLoader::insert(Call, |ctx, executable| { + let address = ctx.ext.address(); + let contract = >::get(address) + .and_then(|c| c.get_alive()) + .unwrap(); + assert_eq!(ctx.ext.rent_params(), &RentParams::new(address, &contract, executable)); + exec_success() + }); + + // This one tests passing the input data into a contract via call. + ExtBuilder::default().build().execute_with(|| { + let subsistence = Contracts::::subsistence_threshold(); + let schedule = Contracts::current_schedule(); + let mut ctx = MockContext::top_level(ALICE, &schedule); + let mut gas_meter = GasMeter::::new(GAS_LIMIT); + set_balance(&ALICE, subsistence * 10); + place_contract(&BOB, code_hash); + + ctx.call( + BOB, + 0, + &mut gas_meter, + vec![], + ).unwrap(); + }); + } + + #[test] + fn rent_params_snapshotted() { + let code_hash = MockLoader::insert(Call, |ctx, executable| { + let subsistence = Contracts::::subsistence_threshold(); + let address = ctx.ext.address(); + let contract = >::get(address) + .and_then(|c| c.get_alive()) + .unwrap(); + let rent_params = RentParams::new(address, &contract, executable); + + // Changing the allowance during the call: rent params stay unchanged. + let allowance = 42; + assert_ne!(allowance, rent_params.rent_allowance); + ctx.ext.set_rent_allowance(allowance); + assert_eq!(ctx.ext.rent_params(), &rent_params); + + // Creating another instance from the same code_hash increases the refcount. + // This is also not reflected in the rent params. + assert_eq!(MockLoader::refcount(&executable.code_hash), 1); + ctx.ext.instantiate( + executable.code_hash, + subsistence * 25, + &mut GasMeter::::new(GAS_LIMIT), + vec![], + &[], + ).unwrap(); + assert_eq!(MockLoader::refcount(&executable.code_hash), 2); + assert_eq!(ctx.ext.rent_params(), &rent_params); + + exec_success() + }); + + // This one tests passing the input data into a contract via call. + ExtBuilder::default().build().execute_with(|| { + let subsistence = Contracts::::subsistence_threshold(); + let schedule = Contracts::current_schedule(); + let mut ctx = MockContext::top_level(ALICE, &schedule); + let mut gas_meter = GasMeter::::new(GAS_LIMIT); + set_balance(&ALICE, subsistence * 100); + place_contract(&BOB, code_hash); + ctx.call( + BOB, + subsistence * 50, + &mut gas_meter, + vec![], + ).unwrap(); + }); + } } diff --git a/frame/contracts/src/storage.rs b/frame/contracts/src/storage.rs index dbf993bc3bc00..db7282282c645 100644 --- a/frame/contracts/src/storage.rs +++ b/frame/contracts/src/storage.rs @@ -30,7 +30,7 @@ use sp_io::hashing::blake2_256; use sp_runtime::traits::{Bounded, Saturating, Zero}; use sp_core::crypto::UncheckedFrom; use frame_support::{ - dispatch::DispatchResult, + dispatch::{DispatchError, DispatchResult}, debug, storage::child::{self, KillChildStorageResult}, traits::Get, @@ -163,7 +163,7 @@ where account: &AccountIdOf, trie_id: TrieId, ch: CodeHash, - ) -> DispatchResult { + ) -> Result, DispatchError> { >::try_mutate(account, |existing| { if existing.is_some() { return Err(Error::::DuplicateContract.into()); @@ -185,9 +185,9 @@ where _reserved: None, }; - *existing = Some(contract.into()); + *existing = Some(contract.clone().into()); - Ok(()) + Ok(contract) }) } diff --git a/frame/contracts/src/tests.rs b/frame/contracts/src/tests.rs index c17434300d454..2fa09e3405c1c 100644 --- a/frame/contracts/src/tests.rs +++ b/frame/contracts/src/tests.rs @@ -2736,7 +2736,6 @@ fn refcounter() { }); } - #[test] fn reinstrument_does_charge() { let (wasm, code_hash) = compile_module::("return_with_data").unwrap(); diff --git a/frame/contracts/src/wasm/mod.rs b/frame/contracts/src/wasm/mod.rs index 9001e2b8e92d7..29f07caed7b91 100644 --- a/frame/contracts/src/wasm/mod.rs +++ b/frame/contracts/src/wasm/mod.rs @@ -231,6 +231,14 @@ where fn code_len(&self) -> u32 { self.code.len() as u32 } + + fn origignal_code_len(&self) -> u32 { + self.original_code_len + } + + fn refcount(&self) -> u32 { + self.refcount as u32 + } } #[cfg(test)] @@ -238,7 +246,7 @@ mod tests { use super::*; use crate::{ CodeHash, BalanceOf, Error, Module as Contracts, - exec::{Ext, StorageKey, AccountIdOf, Executable}, + exec::{Ext, StorageKey, AccountIdOf, Executable, RentParams}, gas::GasMeter, tests::{Test, Call, ALICE, BOB}, }; @@ -249,6 +257,7 @@ mod tests { use frame_support::{dispatch::DispatchResult, weights::Weight}; use assert_matches::assert_matches; use pallet_contracts_primitives::{ExecReturnValue, ReturnFlags, ExecError, ErrorOrigin}; + use pretty_assertions::assert_eq; const GAS_LIMIT: Weight = 10_000_000_000; @@ -295,6 +304,7 @@ mod tests { // (topics, data) events: Vec<(Vec, Vec)>, schedule: Schedule, + rent_params: RentParams, } impl Ext for MockExt { @@ -395,46 +405,38 @@ mod tests { fn value_transferred(&self) -> u64 { 1337 } - fn now(&self) -> &u64 { &1111 } - fn minimum_balance(&self) -> u64 { 666 } - fn tombstone_deposit(&self) -> u64 { 16 } - fn random(&self, subject: &[u8]) -> H256 { H256::from_slice(subject) } - fn deposit_event(&mut self, topics: Vec, data: Vec) { self.events.push((topics, data)) } - fn set_rent_allowance(&mut self, rent_allowance: u64) { self.rent_allowance = rent_allowance; } - fn rent_allowance(&self) -> u64 { self.rent_allowance } - fn block_number(&self) -> u64 { 121 } - fn max_value_size(&self) -> u32 { 16_384 } - fn get_weight_price(&self, weight: Weight) -> BalanceOf { BalanceOf::::from(1312_u32).saturating_mul(weight.into()) } - fn schedule(&self) -> &Schedule { &self.schedule } + fn rent_params(&self) -> &RentParams { + &self.rent_params + } } impl Ext for &mut MockExt { @@ -537,6 +539,9 @@ mod tests { fn schedule(&self) -> &Schedule { (**self).schedule() } + fn rent_params(&self) -> &RentParams { + (**self).rent_params() + } } fn execute( @@ -1840,4 +1845,45 @@ mod tests { ); } + const CODE_RENT_PARAMS: &str = r#" +(module + (import "seal0" "seal_rent_params" (func $seal_rent_params (param i32 i32))) + (import "seal0" "seal_return" (func $seal_return (param i32 i32 i32))) + (import "env" "memory" (memory 1 1)) + + ;; [0, 4) buffer size = 128 bytes + (data (i32.const 0) "\80") + + ;; [4; inf) buffer where the result is copied + + (func (export "call") + ;; Load the rent params into memory + (call $seal_rent_params + (i32.const 4) ;; Pointer to the output buffer + (i32.const 0) ;; Pointer to the size of the buffer + ) + + ;; Return the contents of the buffer + (call $seal_return + (i32.const 0) ;; return flags + (i32.const 4) ;; buffer pointer + (i32.load (i32.const 0)) ;; buffer size + ) + ) + + (func (export "deploy")) +) +"#; + + #[test] + fn rent_params_work() { + let output = execute( + CODE_RENT_PARAMS, + vec![], + MockExt::default(), + &mut GasMeter::new(GAS_LIMIT), + ).unwrap(); + let rent_params = >::default().encode(); + assert_eq!(output, ExecReturnValue { flags: ReturnFlags::empty(), data: rent_params }); + } } diff --git a/frame/contracts/src/wasm/runtime.rs b/frame/contracts/src/wasm/runtime.rs index c383fdcc2ac25..568e95bc055b8 100644 --- a/frame/contracts/src/wasm/runtime.rs +++ b/frame/contracts/src/wasm/runtime.rs @@ -1513,4 +1513,27 @@ define_env!(Env, , })), } }, + + // Stores the rent params into the supplied buffer. + // + // The value is stored to linear memory at the address pointed to by `out_ptr`. + // `out_len_ptr` must point to a u32 value that describes the available space at + // `out_ptr`. This call overwrites it with the size of the value. If the available + // space at `out_ptr` is less than the size of the value a trap is triggered. + // + // The data is encoded as [`crate::exec::RentParams`]. + // + // # Note + // + // The returned information was collected and cached when the current contract call + // starts execution. Any change to those values that happens due to actions of the + // current call or contracts that are called by this contract are not considered. + // The fields that are subject to these changes are `refcount` and `rent_allowance`. + seal_rent_params(ctx, out_ptr: u32, out_len_ptr: u32) => { + // TODO: create benchmark and runtime token + ctx.charge_gas(RuntimeToken::RentAllowance)?; + Ok(ctx.write_sandbox_output( + out_ptr, out_len_ptr, &ctx.ext.rent_params().encode(), false, already_charged + )?) + }, ); From 967ebe4f23ae5a9b5a8412b8153441e4c8d14551 Mon Sep 17 00:00:00 2001 From: Parity Benchmarking Bot Date: Mon, 1 Mar 2021 16:02:21 +0000 Subject: [PATCH 02/10] cargo run --release --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_contracts --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/contracts/src/weights.rs --template=./.maintain/frame-weight-template.hbs --- frame/contracts/src/weights.rs | 1259 ++++++++++++++++---------------- 1 file changed, 636 insertions(+), 623 deletions(-) diff --git a/frame/contracts/src/weights.rs b/frame/contracts/src/weights.rs index 905ccf8cb5a2f..823e18611c3fe 100644 --- a/frame/contracts/src/weights.rs +++ b/frame/contracts/src/weights.rs @@ -18,7 +18,7 @@ //! Autogenerated weights for pallet_contracts //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 3.0.0 -//! DATE: 2021-02-18, STEPS: [50, ], REPEAT: 20, LOW RANGE: [], HIGH RANGE: [] +//! DATE: 2021-03-01, STEPS: [50, ], REPEAT: 20, LOW RANGE: [], HIGH RANGE: [] //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 128 // Executed Command: @@ -63,6 +63,7 @@ pub trait WeightInfo { fn seal_rent_allowance(r: u32, ) -> Weight; fn seal_block_number(r: u32, ) -> Weight; fn seal_now(r: u32, ) -> Weight; + fn seal_rent_params(r: u32, ) -> Weight; fn seal_weight_to_fee(r: u32, ) -> Weight; fn seal_gas(r: u32, ) -> Weight; fn seal_input(r: u32, ) -> Weight; @@ -152,271 +153,277 @@ pub trait WeightInfo { pub struct SubstrateWeight(PhantomData); impl WeightInfo for SubstrateWeight { fn on_initialize() -> Weight { - (3_733_000 as Weight) + (3_850_000 as Weight) .saturating_add(T::DbWeight::get().reads(1 as Weight)) } fn on_initialize_per_trie_key(k: u32, ) -> Weight { - (49_569_000 as Weight) + (52_925_000 as Weight) // Standard Error: 5_000 - .saturating_add((2_295_000 as Weight).saturating_mul(k as Weight)) + .saturating_add((2_297_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_add(T::DbWeight::get().writes((1 as Weight).saturating_mul(k as Weight))) } fn on_initialize_per_queue_item(q: u32, ) -> Weight { - (358_064_000 as Weight) - // Standard Error: 143_000 - .saturating_add((140_992_000 as Weight).saturating_mul(q as Weight)) + (434_698_000 as Weight) + // Standard Error: 210_000 + .saturating_add((166_559_000 as Weight).saturating_mul(q as Weight)) .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } fn instrument(c: u32, ) -> Weight { - (44_198_000 as Weight) - // Standard Error: 188_000 - .saturating_add((125_833_000 as Weight).saturating_mul(c as Weight)) + (29_918_000 as Weight) + // Standard Error: 185_000 + .saturating_add((123_774_000 as Weight).saturating_mul(c as Weight)) .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } fn update_schedule() -> Weight { - (29_190_000 as Weight) + (29_795_000 as Weight) .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } fn instantiate_with_code(c: u32, s: u32, ) -> Weight { - (180_015_000 as Weight) - // Standard Error: 197_000 - .saturating_add((167_480_000 as Weight).saturating_mul(c as Weight)) - // Standard Error: 12_000 - .saturating_add((2_581_000 as Weight).saturating_mul(s as Weight)) + (225_834_000 as Weight) + // Standard Error: 144_000 + .saturating_add((165_632_000 as Weight).saturating_mul(c as Weight)) + // Standard Error: 9_000 + .saturating_add((2_563_000 as Weight).saturating_mul(s as Weight)) .saturating_add(T::DbWeight::get().reads(6 as Weight)) .saturating_add(T::DbWeight::get().writes(5 as Weight)) } fn instantiate(c: u32, s: u32, ) -> Weight { - (180_996_000 as Weight) - // Standard Error: 14_000 - .saturating_add((8_684_000 as Weight).saturating_mul(c as Weight)) + (190_482_000 as Weight) + // Standard Error: 12_000 + .saturating_add((8_724_000 as Weight).saturating_mul(c as Weight)) // Standard Error: 1_000 - .saturating_add((2_518_000 as Weight).saturating_mul(s as Weight)) + .saturating_add((2_512_000 as Weight).saturating_mul(s as Weight)) .saturating_add(T::DbWeight::get().reads(6 as Weight)) .saturating_add(T::DbWeight::get().writes(4 as Weight)) } fn call(c: u32, ) -> Weight { - (184_326_000 as Weight) + (195_414_000 as Weight) // Standard Error: 2_000 .saturating_add((3_920_000 as Weight).saturating_mul(c as Weight)) .saturating_add(T::DbWeight::get().reads(5 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } fn claim_surcharge(c: u32, ) -> Weight { - (303_270_000 as Weight) - // Standard Error: 5_000 - .saturating_add((5_108_000 as Weight).saturating_mul(c as Weight)) + (336_867_000 as Weight) + // Standard Error: 10_000 + .saturating_add((5_262_000 as Weight).saturating_mul(c as Weight)) .saturating_add(T::DbWeight::get().reads(5 as Weight)) .saturating_add(T::DbWeight::get().writes(4 as Weight)) } fn seal_caller(r: u32, ) -> Weight { - (128_965_000 as Weight) - // Standard Error: 130_000 - .saturating_add((270_123_000 as Weight).saturating_mul(r as Weight)) + (143_935_000 as Weight) + // Standard Error: 128_000 + .saturating_add((266_876_000 as Weight).saturating_mul(r as Weight)) .saturating_add(T::DbWeight::get().reads(5 as Weight)) } fn seal_address(r: u32, ) -> Weight { - (137_748_000 as Weight) - // Standard Error: 184_000 - .saturating_add((270_103_000 as Weight).saturating_mul(r as Weight)) + (150_342_000 as Weight) + // Standard Error: 127_000 + .saturating_add((266_051_000 as Weight).saturating_mul(r as Weight)) .saturating_add(T::DbWeight::get().reads(5 as Weight)) } fn seal_gas_left(r: u32, ) -> Weight { - (118_784_000 as Weight) - // Standard Error: 234_000 - .saturating_add((264_467_000 as Weight).saturating_mul(r as Weight)) + (144_833_000 as Weight) + // Standard Error: 124_000 + .saturating_add((259_279_000 as Weight).saturating_mul(r as Weight)) .saturating_add(T::DbWeight::get().reads(5 as Weight)) } fn seal_balance(r: u32, ) -> Weight { - (146_072_000 as Weight) - // Standard Error: 207_000 - .saturating_add((573_282_000 as Weight).saturating_mul(r as Weight)) + (152_032_000 as Weight) + // Standard Error: 218_000 + .saturating_add((573_038_000 as Weight).saturating_mul(r as Weight)) .saturating_add(T::DbWeight::get().reads(5 as Weight)) } fn seal_value_transferred(r: u32, ) -> Weight { - (133_857_000 as Weight) - // Standard Error: 151_000 - .saturating_add((263_110_000 as Weight).saturating_mul(r as Weight)) + (148_831_000 as Weight) + // Standard Error: 147_000 + .saturating_add((260_718_000 as Weight).saturating_mul(r as Weight)) .saturating_add(T::DbWeight::get().reads(5 as Weight)) } fn seal_minimum_balance(r: u32, ) -> Weight { - (130_447_000 as Weight) - // Standard Error: 125_000 - .saturating_add((265_565_000 as Weight).saturating_mul(r as Weight)) + (142_925_000 as Weight) + // Standard Error: 130_000 + .saturating_add((260_426_000 as Weight).saturating_mul(r as Weight)) .saturating_add(T::DbWeight::get().reads(5 as Weight)) } fn seal_tombstone_deposit(r: u32, ) -> Weight { - (116_232_000 as Weight) - // Standard Error: 327_000 - .saturating_add((265_728_000 as Weight).saturating_mul(r as Weight)) + (143_151_000 as Weight) + // Standard Error: 119_000 + .saturating_add((260_964_000 as Weight).saturating_mul(r as Weight)) .saturating_add(T::DbWeight::get().reads(5 as Weight)) } fn seal_rent_allowance(r: u32, ) -> Weight { - (175_561_000 as Weight) - // Standard Error: 292_000 - .saturating_add((604_373_000 as Weight).saturating_mul(r as Weight)) + (155_126_000 as Weight) + // Standard Error: 225_000 + .saturating_add((599_056_000 as Weight).saturating_mul(r as Weight)) .saturating_add(T::DbWeight::get().reads(5 as Weight)) } fn seal_block_number(r: u32, ) -> Weight { - (133_961_000 as Weight) - // Standard Error: 150_000 - .saturating_add((262_329_000 as Weight).saturating_mul(r as Weight)) + (144_566_000 as Weight) + // Standard Error: 110_000 + .saturating_add((257_620_000 as Weight).saturating_mul(r as Weight)) .saturating_add(T::DbWeight::get().reads(5 as Weight)) } fn seal_now(r: u32, ) -> Weight { - (128_662_000 as Weight) - // Standard Error: 150_000 - .saturating_add((263_234_000 as Weight).saturating_mul(r as Weight)) + (147_274_000 as Weight) + // Standard Error: 115_000 + .saturating_add((258_627_000 as Weight).saturating_mul(r as Weight)) + .saturating_add(T::DbWeight::get().reads(5 as Weight)) + } + fn seal_rent_params(r: u32, ) -> Weight { + (168_575_000 as Weight) + // Standard Error: 394_000 + .saturating_add((397_754_000 as Weight).saturating_mul(r as Weight)) .saturating_add(T::DbWeight::get().reads(5 as Weight)) } fn seal_weight_to_fee(r: u32, ) -> Weight { - (142_580_000 as Weight) - // Standard Error: 205_000 - .saturating_add((505_378_000 as Weight).saturating_mul(r as Weight)) + (148_102_000 as Weight) + // Standard Error: 201_000 + .saturating_add((537_088_000 as Weight).saturating_mul(r as Weight)) .saturating_add(T::DbWeight::get().reads(6 as Weight)) } fn seal_gas(r: u32, ) -> Weight { - (116_346_000 as Weight) - // Standard Error: 86_000 - .saturating_add((124_599_000 as Weight).saturating_mul(r as Weight)) + (125_122_000 as Weight) + // Standard Error: 89_000 + .saturating_add((122_350_000 as Weight).saturating_mul(r as Weight)) .saturating_add(T::DbWeight::get().reads(5 as Weight)) } fn seal_input(r: u32, ) -> Weight { - (124_679_000 as Weight) - // Standard Error: 81_000 - .saturating_add((7_310_000 as Weight).saturating_mul(r as Weight)) + (137_334_000 as Weight) + // Standard Error: 99_000 + .saturating_add((7_359_000 as Weight).saturating_mul(r as Weight)) .saturating_add(T::DbWeight::get().reads(5 as Weight)) } fn seal_input_per_kb(n: u32, ) -> Weight { - (136_069_000 as Weight) + (145_094_000 as Weight) // Standard Error: 0 - .saturating_add((274_000 as Weight).saturating_mul(n as Weight)) + .saturating_add((283_000 as Weight).saturating_mul(n as Weight)) .saturating_add(T::DbWeight::get().reads(5 as Weight)) } fn seal_return(r: u32, ) -> Weight { - (118_807_000 as Weight) - // Standard Error: 66_000 - .saturating_add((4_740_000 as Weight).saturating_mul(r as Weight)) + (127_544_000 as Weight) + // Standard Error: 138_000 + .saturating_add((4_640_000 as Weight).saturating_mul(r as Weight)) .saturating_add(T::DbWeight::get().reads(5 as Weight)) } fn seal_return_per_kb(n: u32, ) -> Weight { - (127_702_000 as Weight) + (137_517_000 as Weight) // Standard Error: 0 - .saturating_add((784_000 as Weight).saturating_mul(n as Weight)) + .saturating_add((783_000 as Weight).saturating_mul(n as Weight)) .saturating_add(T::DbWeight::get().reads(5 as Weight)) } fn seal_terminate(r: u32, ) -> Weight { - (124_847_000 as Weight) - // Standard Error: 87_000 - .saturating_add((107_679_000 as Weight).saturating_mul(r as Weight)) + (138_292_000 as Weight) + // Standard Error: 689_000 + .saturating_add((111_698_000 as Weight).saturating_mul(r as Weight)) .saturating_add(T::DbWeight::get().reads(5 as Weight)) .saturating_add(T::DbWeight::get().reads((2 as Weight).saturating_mul(r as Weight))) .saturating_add(T::DbWeight::get().writes((5 as Weight).saturating_mul(r as Weight))) } fn seal_terminate_per_code_kb(c: u32, ) -> Weight { - (237_115_000 as Weight) - // Standard Error: 6_000 - .saturating_add((8_556_000 as Weight).saturating_mul(c as Weight)) + (263_507_000 as Weight) + // Standard Error: 12_000 + .saturating_add((8_409_000 as Weight).saturating_mul(c as Weight)) .saturating_add(T::DbWeight::get().reads(7 as Weight)) .saturating_add(T::DbWeight::get().writes(5 as Weight)) } fn seal_restore_to(r: u32, ) -> Weight { - (217_959_000 as Weight) - // Standard Error: 455_000 - .saturating_add((134_528_000 as Weight).saturating_mul(r as Weight)) + (232_291_000 as Weight) + // Standard Error: 301_000 + .saturating_add((136_379_000 as Weight).saturating_mul(r as Weight)) .saturating_add(T::DbWeight::get().reads(5 as Weight)) .saturating_add(T::DbWeight::get().reads((4 as Weight).saturating_mul(r as Weight))) .saturating_add(T::DbWeight::get().writes((6 as Weight).saturating_mul(r as Weight))) } fn seal_restore_to_per_code_kb_delta(c: u32, t: u32, d: u32, ) -> Weight { (0 as Weight) - // Standard Error: 151_000 - .saturating_add((9_061_000 as Weight).saturating_mul(c as Weight)) - // Standard Error: 151_000 - .saturating_add((4_807_000 as Weight).saturating_mul(t as Weight)) - // Standard Error: 1_331_000 - .saturating_add((3_736_196_000 as Weight).saturating_mul(d as Weight)) + // Standard Error: 162_000 + .saturating_add((8_619_000 as Weight).saturating_mul(c as Weight)) + // Standard Error: 162_000 + .saturating_add((4_877_000 as Weight).saturating_mul(t as Weight)) + // Standard Error: 1_433_000 + .saturating_add((3_762_810_000 as Weight).saturating_mul(d as Weight)) .saturating_add(T::DbWeight::get().reads(8 as Weight)) .saturating_add(T::DbWeight::get().reads((100 as Weight).saturating_mul(d as Weight))) .saturating_add(T::DbWeight::get().writes(7 as Weight)) .saturating_add(T::DbWeight::get().writes((100 as Weight).saturating_mul(d as Weight))) } fn seal_random(r: u32, ) -> Weight { - (134_143_000 as Weight) - // Standard Error: 233_000 - .saturating_add((643_555_000 as Weight).saturating_mul(r as Weight)) + (153_634_000 as Weight) + // Standard Error: 267_000 + .saturating_add((650_160_000 as Weight).saturating_mul(r as Weight)) .saturating_add(T::DbWeight::get().reads(6 as Weight)) } fn seal_deposit_event(r: u32, ) -> Weight { - (142_838_000 as Weight) - // Standard Error: 367_000 - .saturating_add((937_126_000 as Weight).saturating_mul(r as Weight)) + (137_080_000 as Weight) + // Standard Error: 1_009_000 + .saturating_add((949_228_000 as Weight).saturating_mul(r as Weight)) .saturating_add(T::DbWeight::get().reads(5 as Weight)) } fn seal_deposit_event_per_topic_and_kb(t: u32, n: u32, ) -> Weight { - (1_210_711_000 as Weight) - // Standard Error: 2_124_000 - .saturating_add((594_541_000 as Weight).saturating_mul(t as Weight)) - // Standard Error: 418_000 - .saturating_add((251_068_000 as Weight).saturating_mul(n as Weight)) + (1_259_129_000 as Weight) + // Standard Error: 2_542_000 + .saturating_add((609_859_000 as Weight).saturating_mul(t as Weight)) + // Standard Error: 501_000 + .saturating_add((249_496_000 as Weight).saturating_mul(n as Weight)) .saturating_add(T::DbWeight::get().reads(5 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 { - (144_533_000 as Weight) - // Standard Error: 220_000 - .saturating_add((714_590_000 as Weight).saturating_mul(r as Weight)) + (170_417_000 as Weight) + // Standard Error: 434_000 + .saturating_add((721_511_000 as Weight).saturating_mul(r as Weight)) .saturating_add(T::DbWeight::get().reads(5 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } fn seal_set_storage(r: u32, ) -> Weight { - (406_366_000 as Weight) - // Standard Error: 3_533_000 - .saturating_add((16_167_082_000 as Weight).saturating_mul(r as Weight)) + (1_870_542_000 as Weight) + // Standard Error: 26_871_000 + .saturating_add((18_312_239_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_set_storage_per_kb(n: u32, ) -> Weight { - (1_739_590_000 as Weight) - // Standard Error: 390_000 - .saturating_add((74_815_000 as Weight).saturating_mul(n as Weight)) + (1_763_732_000 as Weight) + // Standard Error: 258_000 + .saturating_add((74_848_000 as Weight).saturating_mul(n as Weight)) .saturating_add(T::DbWeight::get().reads(6 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } fn seal_clear_storage(r: u32, ) -> Weight { (0 as Weight) - // Standard Error: 2_284_000 - .saturating_add((2_281_347_000 as Weight).saturating_mul(r as Weight)) + // Standard Error: 2_745_000 + .saturating_add((2_316_433_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_get_storage(r: u32, ) -> Weight { - (81_889_000 as Weight) - // Standard Error: 1_171_000 - .saturating_add((930_704_000 as Weight).saturating_mul(r as Weight)) + (87_218_000 as Weight) + // Standard Error: 745_000 + .saturating_add((948_121_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_get_storage_per_kb(n: u32, ) -> Weight { - (709_323_000 as Weight) - // Standard Error: 391_000 - .saturating_add((155_689_000 as Weight).saturating_mul(n as Weight)) + (719_050_000 as Weight) + // Standard Error: 266_000 + .saturating_add((154_812_000 as Weight).saturating_mul(n as Weight)) .saturating_add(T::DbWeight::get().reads(6 as Weight)) } fn seal_transfer(r: u32, ) -> Weight { - (0 as Weight) - // Standard Error: 1_846_000 - .saturating_add((5_566_275_000 as Weight).saturating_mul(r as Weight)) + (19_439_000 as Weight) + // Standard Error: 2_468_000 + .saturating_add((5_674_822_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)) @@ -424,619 +431,625 @@ impl WeightInfo for SubstrateWeight { } fn seal_call(r: u32, ) -> Weight { (0 as Weight) - // Standard Error: 4_823_000 - .saturating_add((10_461_861_000 as Weight).saturating_mul(r as Weight)) + // Standard Error: 7_465_000 + .saturating_add((11_066_530_000 as Weight).saturating_mul(r as Weight)) .saturating_add(T::DbWeight::get().reads(6 as Weight)) .saturating_add(T::DbWeight::get().reads((200 as Weight).saturating_mul(r as Weight))) } fn seal_call_per_code_transfer_input_output_kb(c: u32, t: u32, i: u32, o: u32, ) -> Weight { - (9_686_594_000 as Weight) - // Standard Error: 473_000 - .saturating_add((393_132_000 as Weight).saturating_mul(c as Weight)) - // Standard Error: 197_094_000 - .saturating_add((4_957_181_000 as Weight).saturating_mul(t as Weight)) - // Standard Error: 62_000 - .saturating_add((59_974_000 as Weight).saturating_mul(i as Weight)) - // Standard Error: 66_000 - .saturating_add((83_027_000 as Weight).saturating_mul(o as Weight)) + (9_916_288_000 as Weight) + // Standard Error: 552_000 + .saturating_add((397_842_000 as Weight).saturating_mul(c as Weight)) + // Standard Error: 229_902_000 + .saturating_add((5_243_673_000 as Weight).saturating_mul(t as Weight)) + // Standard Error: 72_000 + .saturating_add((59_737_000 as Weight).saturating_mul(i as Weight)) + // Standard Error: 77_000 + .saturating_add((82_259_000 as Weight).saturating_mul(o as Weight)) .saturating_add(T::DbWeight::get().reads(206 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) - // Standard Error: 34_133_000 - .saturating_add((21_407_630_000 as Weight).saturating_mul(r as Weight)) + // Standard Error: 32_016_000 + .saturating_add((22_206_489_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((300 as Weight).saturating_mul(r as Weight))) } fn seal_instantiate_per_code_input_output_salt_kb(c: u32, i: u32, o: u32, s: u32, ) -> Weight { - (9_705_322_000 as Weight) - // Standard Error: 674_000 - .saturating_add((879_118_000 as Weight).saturating_mul(c as Weight)) - // Standard Error: 95_000 - .saturating_add((63_025_000 as Weight).saturating_mul(i as Weight)) - // Standard Error: 95_000 - .saturating_add((87_633_000 as Weight).saturating_mul(o as Weight)) - // Standard Error: 95_000 - .saturating_add((311_987_000 as Weight).saturating_mul(s as Weight)) + (9_991_947_000 as Weight) + // Standard Error: 637_000 + .saturating_add((881_981_000 as Weight).saturating_mul(c as Weight)) + // Standard Error: 90_000 + .saturating_add((63_638_000 as Weight).saturating_mul(i as Weight)) + // Standard Error: 90_000 + .saturating_add((87_288_000 as Weight).saturating_mul(o as Weight)) + // Standard Error: 90_000 + .saturating_add((311_808_000 as Weight).saturating_mul(s as Weight)) .saturating_add(T::DbWeight::get().reads(207 as Weight)) .saturating_add(T::DbWeight::get().writes(203 as Weight)) } fn seal_hash_sha2_256(r: u32, ) -> Weight { - (125_486_000 as Weight) - // Standard Error: 266_000 - .saturating_add((240_913_000 as Weight).saturating_mul(r as Weight)) + (132_452_000 as Weight) + // Standard Error: 227_000 + .saturating_add((239_671_000 as Weight).saturating_mul(r as Weight)) .saturating_add(T::DbWeight::get().reads(5 as Weight)) } fn seal_hash_sha2_256_per_kb(n: u32, ) -> Weight { - (636_153_000 as Weight) - // Standard Error: 47_000 - .saturating_add((429_541_000 as Weight).saturating_mul(n as Weight)) + (756_802_000 as Weight) + // Standard Error: 48_000 + .saturating_add((429_454_000 as Weight).saturating_mul(n as Weight)) .saturating_add(T::DbWeight::get().reads(5 as Weight)) } fn seal_hash_keccak_256(r: u32, ) -> Weight { - (131_768_000 as Weight) - // Standard Error: 176_000 - .saturating_add((256_946_000 as Weight).saturating_mul(r as Weight)) + (139_440_000 as Weight) + // Standard Error: 128_000 + .saturating_add((249_514_000 as Weight).saturating_mul(r as Weight)) .saturating_add(T::DbWeight::get().reads(5 as Weight)) } fn seal_hash_keccak_256_per_kb(n: u32, ) -> Weight { - (647_777_000 as Weight) - // Standard Error: 29_000 - .saturating_add((344_145_000 as Weight).saturating_mul(n as Weight)) + (658_595_000 as Weight) + // Standard Error: 35_000 + .saturating_add((343_814_000 as Weight).saturating_mul(n as Weight)) .saturating_add(T::DbWeight::get().reads(5 as Weight)) } fn seal_hash_blake2_256(r: u32, ) -> Weight { - (130_042_000 as Weight) - // Standard Error: 158_000 - .saturating_add((225_474_000 as Weight).saturating_mul(r as Weight)) + (138_124_000 as Weight) + // Standard Error: 140_000 + .saturating_add((223_189_000 as Weight).saturating_mul(r as Weight)) .saturating_add(T::DbWeight::get().reads(5 as Weight)) } fn seal_hash_blake2_256_per_kb(n: u32, ) -> Weight { - (638_275_000 as Weight) - // Standard Error: 30_000 - .saturating_add((159_832_000 as Weight).saturating_mul(n as Weight)) + (689_667_000 as Weight) + // Standard Error: 41_000 + .saturating_add((160_006_000 as Weight).saturating_mul(n as Weight)) .saturating_add(T::DbWeight::get().reads(5 as Weight)) } fn seal_hash_blake2_128(r: u32, ) -> Weight { - (126_632_000 as Weight) - // Standard Error: 143_000 - .saturating_add((225_612_000 as Weight).saturating_mul(r as Weight)) + (140_225_000 as Weight) + // Standard Error: 156_000 + .saturating_add((223_696_000 as Weight).saturating_mul(r as Weight)) .saturating_add(T::DbWeight::get().reads(5 as Weight)) } fn seal_hash_blake2_128_per_kb(n: u32, ) -> Weight { - (656_936_000 as Weight) - // Standard Error: 35_000 - .saturating_add((159_763_000 as Weight).saturating_mul(n as Weight)) + (693_756_000 as Weight) + // Standard Error: 40_000 + .saturating_add((159_996_000 as Weight).saturating_mul(n as Weight)) .saturating_add(T::DbWeight::get().reads(5 as Weight)) } fn instr_i64const(r: u32, ) -> Weight { - (25_205_000 as Weight) - // Standard Error: 26_000 - .saturating_add((3_311_000 as Weight).saturating_mul(r as Weight)) + (24_250_000 as Weight) + // Standard Error: 14_000 + .saturating_add((3_134_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64load(r: u32, ) -> Weight { - (27_394_000 as Weight) - // Standard Error: 28_000 - .saturating_add((159_123_000 as Weight).saturating_mul(r as Weight)) + (26_509_000 as Weight) + // Standard Error: 27_000 + .saturating_add((161_556_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64store(r: u32, ) -> Weight { - (27_398_000 as Weight) - // Standard Error: 57_000 - .saturating_add((229_775_000 as Weight).saturating_mul(r as Weight)) + (26_499_000 as Weight) + // Standard Error: 59_000 + .saturating_add((233_755_000 as Weight).saturating_mul(r as Weight)) } fn instr_select(r: u32, ) -> Weight { - (25_212_000 as Weight) - // Standard Error: 22_000 - .saturating_add((12_291_000 as Weight).saturating_mul(r as Weight)) + (24_175_000 as Weight) + // Standard Error: 16_000 + .saturating_add((12_450_000 as Weight).saturating_mul(r as Weight)) } fn instr_if(r: u32, ) -> Weight { - (25_116_000 as Weight) - // Standard Error: 16_000 - .saturating_add((12_146_000 as Weight).saturating_mul(r as Weight)) + (24_219_000 as Weight) + // Standard Error: 26_000 + .saturating_add((12_058_000 as Weight).saturating_mul(r as Weight)) } fn instr_br(r: u32, ) -> Weight { - (25_119_000 as Weight) - // Standard Error: 19_000 - .saturating_add((6_608_000 as Weight).saturating_mul(r as Weight)) + (24_146_000 as Weight) + // Standard Error: 20_000 + .saturating_add((6_017_000 as Weight).saturating_mul(r as Weight)) } fn instr_br_if(r: u32, ) -> Weight { - (25_146_000 as Weight) - // Standard Error: 23_000 - .saturating_add((14_017_000 as Weight).saturating_mul(r as Weight)) + (24_229_000 as Weight) + // Standard Error: 24_000 + .saturating_add((13_726_000 as Weight).saturating_mul(r as Weight)) } fn instr_br_table(r: u32, ) -> Weight { - (25_192_000 as Weight) - // Standard Error: 21_000 - .saturating_add((15_460_000 as Weight).saturating_mul(r as Weight)) + (24_219_000 as Weight) + // Standard Error: 27_000 + .saturating_add((15_115_000 as Weight).saturating_mul(r as Weight)) } fn instr_br_table_per_entry(e: u32, ) -> Weight { - (37_079_000 as Weight) + (34_981_000 as Weight) // Standard Error: 1_000 - .saturating_add((160_000 as Weight).saturating_mul(e as Weight)) + .saturating_add((156_000 as Weight).saturating_mul(e as Weight)) } fn instr_call(r: u32, ) -> Weight { - (25_599_000 as Weight) - // Standard Error: 201_000 - .saturating_add((99_705_000 as Weight).saturating_mul(r as Weight)) + (24_599_000 as Weight) + // Standard Error: 102_000 + .saturating_add((95_771_000 as Weight).saturating_mul(r as Weight)) } fn instr_call_indirect(r: u32, ) -> Weight { - (33_236_000 as Weight) - // Standard Error: 368_000 - .saturating_add((199_753_000 as Weight).saturating_mul(r as Weight)) + (32_584_000 as Weight) + // Standard Error: 176_000 + .saturating_add((193_216_000 as Weight).saturating_mul(r as Weight)) } fn instr_call_indirect_per_param(p: u32, ) -> Weight { - (247_488_000 as Weight) + (240_739_000 as Weight) // Standard Error: 6_000 - .saturating_add((3_374_000 as Weight).saturating_mul(p as Weight)) + .saturating_add((3_407_000 as Weight).saturating_mul(p as Weight)) } fn instr_local_get(r: u32, ) -> Weight { - (44_133_000 as Weight) - // Standard Error: 20_000 - .saturating_add((3_235_000 as Weight).saturating_mul(r as Weight)) + (41_963_000 as Weight) + // Standard Error: 15_000 + .saturating_add((3_110_000 as Weight).saturating_mul(r as Weight)) } fn instr_local_set(r: u32, ) -> Weight { - (44_107_000 as Weight) - // Standard Error: 20_000 - .saturating_add((3_486_000 as Weight).saturating_mul(r as Weight)) + (41_956_000 as Weight) + // Standard Error: 9_000 + .saturating_add((3_460_000 as Weight).saturating_mul(r as Weight)) } fn instr_local_tee(r: u32, ) -> Weight { - (44_116_000 as Weight) - // Standard Error: 23_000 - .saturating_add((4_757_000 as Weight).saturating_mul(r as Weight)) + (42_002_000 as Weight) + // Standard Error: 20_000 + .saturating_add((4_591_000 as Weight).saturating_mul(r as Weight)) } fn instr_global_get(r: u32, ) -> Weight { - (28_712_000 as Weight) - // Standard Error: 29_000 - .saturating_add((7_659_000 as Weight).saturating_mul(r as Weight)) + (27_646_000 as Weight) + // Standard Error: 23_000 + .saturating_add((7_821_000 as Weight).saturating_mul(r as Weight)) } fn instr_global_set(r: u32, ) -> Weight { - (28_624_000 as Weight) - // Standard Error: 25_000 - .saturating_add((11_841_000 as Weight).saturating_mul(r as Weight)) + (27_615_000 as Weight) + // Standard Error: 27_000 + .saturating_add((11_807_000 as Weight).saturating_mul(r as Weight)) } fn instr_memory_current(r: u32, ) -> Weight { - (27_445_000 as Weight) - // Standard Error: 18_000 - .saturating_add((3_487_000 as Weight).saturating_mul(r as Weight)) + (27_106_000 as Weight) + // Standard Error: 78_000 + .saturating_add((2_952_000 as Weight).saturating_mul(r as Weight)) } fn instr_memory_grow(r: u32, ) -> Weight { - (26_016_000 as Weight) - // Standard Error: 4_230_000 - .saturating_add((2_300_044_000 as Weight).saturating_mul(r as Weight)) + (24_956_000 as Weight) + // Standard Error: 3_541_000 + .saturating_add((2_332_414_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64clz(r: u32, ) -> Weight { - (25_227_000 as Weight) - // Standard Error: 29_000 - .saturating_add((5_341_000 as Weight).saturating_mul(r as Weight)) + (24_183_000 as Weight) + // Standard Error: 18_000 + .saturating_add((5_166_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64ctz(r: u32, ) -> Weight { - (25_163_000 as Weight) - // Standard Error: 26_000 - .saturating_add((5_355_000 as Weight).saturating_mul(r as Weight)) + (24_142_000 as Weight) + // Standard Error: 17_000 + .saturating_add((5_146_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64popcnt(r: u32, ) -> Weight { - (25_204_000 as Weight) - // Standard Error: 29_000 - .saturating_add((5_930_000 as Weight).saturating_mul(r as Weight)) + (24_161_000 as Weight) + // Standard Error: 23_000 + .saturating_add((5_807_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64eqz(r: u32, ) -> Weight { - (25_177_000 as Weight) - // Standard Error: 21_000 - .saturating_add((5_457_000 as Weight).saturating_mul(r as Weight)) + (24_167_000 as Weight) + // Standard Error: 24_000 + .saturating_add((5_288_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64extendsi32(r: u32, ) -> Weight { - (25_206_000 as Weight) - // Standard Error: 19_000 - .saturating_add((5_229_000 as Weight).saturating_mul(r as Weight)) + (24_252_000 as Weight) + // Standard Error: 9_000 + .saturating_add((5_091_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64extendui32(r: u32, ) -> Weight { - (25_165_000 as Weight) - // Standard Error: 17_000 - .saturating_add((5_301_000 as Weight).saturating_mul(r as Weight)) + (24_243_000 as Weight) + // Standard Error: 16_000 + .saturating_add((5_076_000 as Weight).saturating_mul(r as Weight)) } fn instr_i32wrapi64(r: u32, ) -> Weight { - (25_184_000 as Weight) - // Standard Error: 28_000 - .saturating_add((5_356_000 as Weight).saturating_mul(r as Weight)) + (24_227_000 as Weight) + // Standard Error: 15_000 + .saturating_add((5_135_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64eq(r: u32, ) -> Weight { - (25_195_000 as Weight) - // Standard Error: 48_000 - .saturating_add((7_406_000 as Weight).saturating_mul(r as Weight)) + (24_278_000 as Weight) + // Standard Error: 15_000 + .saturating_add((7_124_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64ne(r: u32, ) -> Weight { - (25_192_000 as Weight) + (24_254_000 as Weight) // Standard Error: 19_000 - .saturating_add((7_303_000 as Weight).saturating_mul(r as Weight)) + .saturating_add((7_067_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64lts(r: u32, ) -> Weight { - (25_165_000 as Weight) - // Standard Error: 34_000 - .saturating_add((7_247_000 as Weight).saturating_mul(r as Weight)) + (24_220_000 as Weight) + // Standard Error: 14_000 + .saturating_add((7_122_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64ltu(r: u32, ) -> Weight { - (25_152_000 as Weight) - // Standard Error: 46_000 - .saturating_add((7_464_000 as Weight).saturating_mul(r as Weight)) + (24_221_000 as Weight) + // Standard Error: 19_000 + .saturating_add((7_221_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64gts(r: u32, ) -> Weight { - (25_140_000 as Weight) - // Standard Error: 27_000 - .saturating_add((7_308_000 as Weight).saturating_mul(r as Weight)) + (24_259_000 as Weight) + // Standard Error: 13_000 + .saturating_add((7_135_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64gtu(r: u32, ) -> Weight { - (25_723_000 as Weight) - // Standard Error: 29_000 - .saturating_add((6_846_000 as Weight).saturating_mul(r as Weight)) + (24_245_000 as Weight) + // Standard Error: 10_000 + .saturating_add((7_193_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64les(r: u32, ) -> Weight { - (25_201_000 as Weight) - // Standard Error: 20_000 - .saturating_add((7_226_000 as Weight).saturating_mul(r as Weight)) + (24_289_000 as Weight) + // Standard Error: 22_000 + .saturating_add((7_023_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64leu(r: u32, ) -> Weight { - (25_192_000 as Weight) - // Standard Error: 24_000 - .saturating_add((7_143_000 as Weight).saturating_mul(r as Weight)) + (24_239_000 as Weight) + // Standard Error: 21_000 + .saturating_add((7_065_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64ges(r: u32, ) -> Weight { - (25_146_000 as Weight) - // Standard Error: 37_000 - .saturating_add((7_451_000 as Weight).saturating_mul(r as Weight)) + (24_256_000 as Weight) + // Standard Error: 13_000 + .saturating_add((7_119_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64geu(r: u32, ) -> Weight { - (25_193_000 as Weight) - // Standard Error: 30_000 - .saturating_add((7_391_000 as Weight).saturating_mul(r as Weight)) + (24_240_000 as Weight) + // Standard Error: 18_000 + .saturating_add((7_225_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64add(r: u32, ) -> Weight { - (25_192_000 as Weight) - // Standard Error: 30_000 - .saturating_add((7_214_000 as Weight).saturating_mul(r as Weight)) + (24_266_000 as Weight) + // Standard Error: 24_000 + .saturating_add((6_996_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64sub(r: u32, ) -> Weight { - (25_221_000 as Weight) - // Standard Error: 34_000 - .saturating_add((7_168_000 as Weight).saturating_mul(r as Weight)) + (24_265_000 as Weight) + // Standard Error: 17_000 + .saturating_add((6_974_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64mul(r: u32, ) -> Weight { - (25_221_000 as Weight) - // Standard Error: 28_000 - .saturating_add((7_200_000 as Weight).saturating_mul(r as Weight)) + (24_232_000 as Weight) + // Standard Error: 15_000 + .saturating_add((7_103_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64divs(r: u32, ) -> Weight { - (25_229_000 as Weight) - // Standard Error: 32_000 - .saturating_add((13_066_000 as Weight).saturating_mul(r as Weight)) + (24_245_000 as Weight) + // Standard Error: 20_000 + .saturating_add((12_915_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64divu(r: u32, ) -> Weight { - (25_210_000 as Weight) - // Standard Error: 28_000 - .saturating_add((12_314_000 as Weight).saturating_mul(r as Weight)) + (24_177_000 as Weight) + // Standard Error: 21_000 + .saturating_add((12_232_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64rems(r: u32, ) -> Weight { - (25_186_000 as Weight) - // Standard Error: 24_000 - .saturating_add((13_055_000 as Weight).saturating_mul(r as Weight)) + (24_171_000 as Weight) + // Standard Error: 15_000 + .saturating_add((12_939_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64remu(r: u32, ) -> Weight { - (25_162_000 as Weight) - // Standard Error: 25_000 - .saturating_add((12_327_000 as Weight).saturating_mul(r as Weight)) + (24_788_000 as Weight) + // Standard Error: 22_000 + .saturating_add((11_657_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64and(r: u32, ) -> Weight { - (25_191_000 as Weight) - // Standard Error: 24_000 - .saturating_add((7_153_000 as Weight).saturating_mul(r as Weight)) + (24_252_000 as Weight) + // Standard Error: 19_000 + .saturating_add((7_003_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64or(r: u32, ) -> Weight { - (25_184_000 as Weight) - // Standard Error: 23_000 - .saturating_add((7_120_000 as Weight).saturating_mul(r as Weight)) + (24_263_000 as Weight) + // Standard Error: 12_000 + .saturating_add((7_005_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64xor(r: u32, ) -> Weight { - (25_129_000 as Weight) - // Standard Error: 31_000 - .saturating_add((7_247_000 as Weight).saturating_mul(r as Weight)) + (24_239_000 as Weight) + // Standard Error: 17_000 + .saturating_add((7_020_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64shl(r: u32, ) -> Weight { - (25_156_000 as Weight) - // Standard Error: 16_000 - .saturating_add((7_333_000 as Weight).saturating_mul(r as Weight)) + (24_212_000 as Weight) + // Standard Error: 13_000 + .saturating_add((7_172_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64shrs(r: u32, ) -> Weight { - (25_159_000 as Weight) - // Standard Error: 25_000 - .saturating_add((7_415_000 as Weight).saturating_mul(r as Weight)) + (24_220_000 as Weight) + // Standard Error: 27_000 + .saturating_add((7_246_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64shru(r: u32, ) -> Weight { - (25_181_000 as Weight) - // Standard Error: 25_000 - .saturating_add((7_265_000 as Weight).saturating_mul(r as Weight)) + (24_213_000 as Weight) + // Standard Error: 14_000 + .saturating_add((7_191_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64rotl(r: u32, ) -> Weight { - (25_165_000 as Weight) - // Standard Error: 17_000 - .saturating_add((7_443_000 as Weight).saturating_mul(r as Weight)) + (24_221_000 as Weight) + // Standard Error: 18_000 + .saturating_add((7_192_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64rotr(r: u32, ) -> Weight { - (25_103_000 as Weight) - // Standard Error: 44_000 - .saturating_add((7_463_000 as Weight).saturating_mul(r as Weight)) + (24_235_000 as Weight) + // Standard Error: 12_000 + .saturating_add((7_106_000 as Weight).saturating_mul(r as Weight)) } } // For backwards compatibility and tests impl WeightInfo for () { fn on_initialize() -> Weight { - (3_733_000 as Weight) + (3_850_000 as Weight) .saturating_add(RocksDbWeight::get().reads(1 as Weight)) } fn on_initialize_per_trie_key(k: u32, ) -> Weight { - (49_569_000 as Weight) + (52_925_000 as Weight) // Standard Error: 5_000 - .saturating_add((2_295_000 as Weight).saturating_mul(k as Weight)) + .saturating_add((2_297_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_add(RocksDbWeight::get().writes((1 as Weight).saturating_mul(k as Weight))) } fn on_initialize_per_queue_item(q: u32, ) -> Weight { - (358_064_000 as Weight) - // Standard Error: 143_000 - .saturating_add((140_992_000 as Weight).saturating_mul(q as Weight)) + (434_698_000 as Weight) + // Standard Error: 210_000 + .saturating_add((166_559_000 as Weight).saturating_mul(q as Weight)) .saturating_add(RocksDbWeight::get().reads(1 as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } fn instrument(c: u32, ) -> Weight { - (44_198_000 as Weight) - // Standard Error: 188_000 - .saturating_add((125_833_000 as Weight).saturating_mul(c as Weight)) + (29_918_000 as Weight) + // Standard Error: 185_000 + .saturating_add((123_774_000 as Weight).saturating_mul(c as Weight)) .saturating_add(RocksDbWeight::get().reads(1 as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } fn update_schedule() -> Weight { - (29_190_000 as Weight) + (29_795_000 as Weight) .saturating_add(RocksDbWeight::get().reads(1 as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } fn instantiate_with_code(c: u32, s: u32, ) -> Weight { - (180_015_000 as Weight) - // Standard Error: 197_000 - .saturating_add((167_480_000 as Weight).saturating_mul(c as Weight)) - // Standard Error: 12_000 - .saturating_add((2_581_000 as Weight).saturating_mul(s as Weight)) + (225_834_000 as Weight) + // Standard Error: 144_000 + .saturating_add((165_632_000 as Weight).saturating_mul(c as Weight)) + // Standard Error: 9_000 + .saturating_add((2_563_000 as Weight).saturating_mul(s as Weight)) .saturating_add(RocksDbWeight::get().reads(6 as Weight)) .saturating_add(RocksDbWeight::get().writes(5 as Weight)) } fn instantiate(c: u32, s: u32, ) -> Weight { - (180_996_000 as Weight) - // Standard Error: 14_000 - .saturating_add((8_684_000 as Weight).saturating_mul(c as Weight)) + (190_482_000 as Weight) + // Standard Error: 12_000 + .saturating_add((8_724_000 as Weight).saturating_mul(c as Weight)) // Standard Error: 1_000 - .saturating_add((2_518_000 as Weight).saturating_mul(s as Weight)) + .saturating_add((2_512_000 as Weight).saturating_mul(s as Weight)) .saturating_add(RocksDbWeight::get().reads(6 as Weight)) .saturating_add(RocksDbWeight::get().writes(4 as Weight)) } fn call(c: u32, ) -> Weight { - (184_326_000 as Weight) + (195_414_000 as Weight) // Standard Error: 2_000 .saturating_add((3_920_000 as Weight).saturating_mul(c as Weight)) .saturating_add(RocksDbWeight::get().reads(5 as Weight)) .saturating_add(RocksDbWeight::get().writes(2 as Weight)) } fn claim_surcharge(c: u32, ) -> Weight { - (303_270_000 as Weight) - // Standard Error: 5_000 - .saturating_add((5_108_000 as Weight).saturating_mul(c as Weight)) + (336_867_000 as Weight) + // Standard Error: 10_000 + .saturating_add((5_262_000 as Weight).saturating_mul(c as Weight)) .saturating_add(RocksDbWeight::get().reads(5 as Weight)) .saturating_add(RocksDbWeight::get().writes(4 as Weight)) } fn seal_caller(r: u32, ) -> Weight { - (128_965_000 as Weight) - // Standard Error: 130_000 - .saturating_add((270_123_000 as Weight).saturating_mul(r as Weight)) + (143_935_000 as Weight) + // Standard Error: 128_000 + .saturating_add((266_876_000 as Weight).saturating_mul(r as Weight)) .saturating_add(RocksDbWeight::get().reads(5 as Weight)) } fn seal_address(r: u32, ) -> Weight { - (137_748_000 as Weight) - // Standard Error: 184_000 - .saturating_add((270_103_000 as Weight).saturating_mul(r as Weight)) + (150_342_000 as Weight) + // Standard Error: 127_000 + .saturating_add((266_051_000 as Weight).saturating_mul(r as Weight)) .saturating_add(RocksDbWeight::get().reads(5 as Weight)) } fn seal_gas_left(r: u32, ) -> Weight { - (118_784_000 as Weight) - // Standard Error: 234_000 - .saturating_add((264_467_000 as Weight).saturating_mul(r as Weight)) + (144_833_000 as Weight) + // Standard Error: 124_000 + .saturating_add((259_279_000 as Weight).saturating_mul(r as Weight)) .saturating_add(RocksDbWeight::get().reads(5 as Weight)) } fn seal_balance(r: u32, ) -> Weight { - (146_072_000 as Weight) - // Standard Error: 207_000 - .saturating_add((573_282_000 as Weight).saturating_mul(r as Weight)) + (152_032_000 as Weight) + // Standard Error: 218_000 + .saturating_add((573_038_000 as Weight).saturating_mul(r as Weight)) .saturating_add(RocksDbWeight::get().reads(5 as Weight)) } fn seal_value_transferred(r: u32, ) -> Weight { - (133_857_000 as Weight) - // Standard Error: 151_000 - .saturating_add((263_110_000 as Weight).saturating_mul(r as Weight)) + (148_831_000 as Weight) + // Standard Error: 147_000 + .saturating_add((260_718_000 as Weight).saturating_mul(r as Weight)) .saturating_add(RocksDbWeight::get().reads(5 as Weight)) } fn seal_minimum_balance(r: u32, ) -> Weight { - (130_447_000 as Weight) - // Standard Error: 125_000 - .saturating_add((265_565_000 as Weight).saturating_mul(r as Weight)) + (142_925_000 as Weight) + // Standard Error: 130_000 + .saturating_add((260_426_000 as Weight).saturating_mul(r as Weight)) .saturating_add(RocksDbWeight::get().reads(5 as Weight)) } fn seal_tombstone_deposit(r: u32, ) -> Weight { - (116_232_000 as Weight) - // Standard Error: 327_000 - .saturating_add((265_728_000 as Weight).saturating_mul(r as Weight)) + (143_151_000 as Weight) + // Standard Error: 119_000 + .saturating_add((260_964_000 as Weight).saturating_mul(r as Weight)) .saturating_add(RocksDbWeight::get().reads(5 as Weight)) } fn seal_rent_allowance(r: u32, ) -> Weight { - (175_561_000 as Weight) - // Standard Error: 292_000 - .saturating_add((604_373_000 as Weight).saturating_mul(r as Weight)) + (155_126_000 as Weight) + // Standard Error: 225_000 + .saturating_add((599_056_000 as Weight).saturating_mul(r as Weight)) .saturating_add(RocksDbWeight::get().reads(5 as Weight)) } fn seal_block_number(r: u32, ) -> Weight { - (133_961_000 as Weight) - // Standard Error: 150_000 - .saturating_add((262_329_000 as Weight).saturating_mul(r as Weight)) + (144_566_000 as Weight) + // Standard Error: 110_000 + .saturating_add((257_620_000 as Weight).saturating_mul(r as Weight)) .saturating_add(RocksDbWeight::get().reads(5 as Weight)) } fn seal_now(r: u32, ) -> Weight { - (128_662_000 as Weight) - // Standard Error: 150_000 - .saturating_add((263_234_000 as Weight).saturating_mul(r as Weight)) + (147_274_000 as Weight) + // Standard Error: 115_000 + .saturating_add((258_627_000 as Weight).saturating_mul(r as Weight)) + .saturating_add(RocksDbWeight::get().reads(5 as Weight)) + } + fn seal_rent_params(r: u32, ) -> Weight { + (168_575_000 as Weight) + // Standard Error: 394_000 + .saturating_add((397_754_000 as Weight).saturating_mul(r as Weight)) .saturating_add(RocksDbWeight::get().reads(5 as Weight)) } fn seal_weight_to_fee(r: u32, ) -> Weight { - (142_580_000 as Weight) - // Standard Error: 205_000 - .saturating_add((505_378_000 as Weight).saturating_mul(r as Weight)) + (148_102_000 as Weight) + // Standard Error: 201_000 + .saturating_add((537_088_000 as Weight).saturating_mul(r as Weight)) .saturating_add(RocksDbWeight::get().reads(6 as Weight)) } fn seal_gas(r: u32, ) -> Weight { - (116_346_000 as Weight) - // Standard Error: 86_000 - .saturating_add((124_599_000 as Weight).saturating_mul(r as Weight)) + (125_122_000 as Weight) + // Standard Error: 89_000 + .saturating_add((122_350_000 as Weight).saturating_mul(r as Weight)) .saturating_add(RocksDbWeight::get().reads(5 as Weight)) } fn seal_input(r: u32, ) -> Weight { - (124_679_000 as Weight) - // Standard Error: 81_000 - .saturating_add((7_310_000 as Weight).saturating_mul(r as Weight)) + (137_334_000 as Weight) + // Standard Error: 99_000 + .saturating_add((7_359_000 as Weight).saturating_mul(r as Weight)) .saturating_add(RocksDbWeight::get().reads(5 as Weight)) } fn seal_input_per_kb(n: u32, ) -> Weight { - (136_069_000 as Weight) + (145_094_000 as Weight) // Standard Error: 0 - .saturating_add((274_000 as Weight).saturating_mul(n as Weight)) + .saturating_add((283_000 as Weight).saturating_mul(n as Weight)) .saturating_add(RocksDbWeight::get().reads(5 as Weight)) } fn seal_return(r: u32, ) -> Weight { - (118_807_000 as Weight) - // Standard Error: 66_000 - .saturating_add((4_740_000 as Weight).saturating_mul(r as Weight)) + (127_544_000 as Weight) + // Standard Error: 138_000 + .saturating_add((4_640_000 as Weight).saturating_mul(r as Weight)) .saturating_add(RocksDbWeight::get().reads(5 as Weight)) } fn seal_return_per_kb(n: u32, ) -> Weight { - (127_702_000 as Weight) + (137_517_000 as Weight) // Standard Error: 0 - .saturating_add((784_000 as Weight).saturating_mul(n as Weight)) + .saturating_add((783_000 as Weight).saturating_mul(n as Weight)) .saturating_add(RocksDbWeight::get().reads(5 as Weight)) } fn seal_terminate(r: u32, ) -> Weight { - (124_847_000 as Weight) - // Standard Error: 87_000 - .saturating_add((107_679_000 as Weight).saturating_mul(r as Weight)) + (138_292_000 as Weight) + // Standard Error: 689_000 + .saturating_add((111_698_000 as Weight).saturating_mul(r as Weight)) .saturating_add(RocksDbWeight::get().reads(5 as Weight)) .saturating_add(RocksDbWeight::get().reads((2 as Weight).saturating_mul(r as Weight))) .saturating_add(RocksDbWeight::get().writes((5 as Weight).saturating_mul(r as Weight))) } fn seal_terminate_per_code_kb(c: u32, ) -> Weight { - (237_115_000 as Weight) - // Standard Error: 6_000 - .saturating_add((8_556_000 as Weight).saturating_mul(c as Weight)) + (263_507_000 as Weight) + // Standard Error: 12_000 + .saturating_add((8_409_000 as Weight).saturating_mul(c as Weight)) .saturating_add(RocksDbWeight::get().reads(7 as Weight)) .saturating_add(RocksDbWeight::get().writes(5 as Weight)) } fn seal_restore_to(r: u32, ) -> Weight { - (217_959_000 as Weight) - // Standard Error: 455_000 - .saturating_add((134_528_000 as Weight).saturating_mul(r as Weight)) + (232_291_000 as Weight) + // Standard Error: 301_000 + .saturating_add((136_379_000 as Weight).saturating_mul(r as Weight)) .saturating_add(RocksDbWeight::get().reads(5 as Weight)) .saturating_add(RocksDbWeight::get().reads((4 as Weight).saturating_mul(r as Weight))) .saturating_add(RocksDbWeight::get().writes((6 as Weight).saturating_mul(r as Weight))) } fn seal_restore_to_per_code_kb_delta(c: u32, t: u32, d: u32, ) -> Weight { (0 as Weight) - // Standard Error: 151_000 - .saturating_add((9_061_000 as Weight).saturating_mul(c as Weight)) - // Standard Error: 151_000 - .saturating_add((4_807_000 as Weight).saturating_mul(t as Weight)) - // Standard Error: 1_331_000 - .saturating_add((3_736_196_000 as Weight).saturating_mul(d as Weight)) + // Standard Error: 162_000 + .saturating_add((8_619_000 as Weight).saturating_mul(c as Weight)) + // Standard Error: 162_000 + .saturating_add((4_877_000 as Weight).saturating_mul(t as Weight)) + // Standard Error: 1_433_000 + .saturating_add((3_762_810_000 as Weight).saturating_mul(d as Weight)) .saturating_add(RocksDbWeight::get().reads(8 as Weight)) .saturating_add(RocksDbWeight::get().reads((100 as Weight).saturating_mul(d as Weight))) .saturating_add(RocksDbWeight::get().writes(7 as Weight)) .saturating_add(RocksDbWeight::get().writes((100 as Weight).saturating_mul(d as Weight))) } fn seal_random(r: u32, ) -> Weight { - (134_143_000 as Weight) - // Standard Error: 233_000 - .saturating_add((643_555_000 as Weight).saturating_mul(r as Weight)) + (153_634_000 as Weight) + // Standard Error: 267_000 + .saturating_add((650_160_000 as Weight).saturating_mul(r as Weight)) .saturating_add(RocksDbWeight::get().reads(6 as Weight)) } fn seal_deposit_event(r: u32, ) -> Weight { - (142_838_000 as Weight) - // Standard Error: 367_000 - .saturating_add((937_126_000 as Weight).saturating_mul(r as Weight)) + (137_080_000 as Weight) + // Standard Error: 1_009_000 + .saturating_add((949_228_000 as Weight).saturating_mul(r as Weight)) .saturating_add(RocksDbWeight::get().reads(5 as Weight)) } fn seal_deposit_event_per_topic_and_kb(t: u32, n: u32, ) -> Weight { - (1_210_711_000 as Weight) - // Standard Error: 2_124_000 - .saturating_add((594_541_000 as Weight).saturating_mul(t as Weight)) - // Standard Error: 418_000 - .saturating_add((251_068_000 as Weight).saturating_mul(n as Weight)) + (1_259_129_000 as Weight) + // Standard Error: 2_542_000 + .saturating_add((609_859_000 as Weight).saturating_mul(t as Weight)) + // Standard Error: 501_000 + .saturating_add((249_496_000 as Weight).saturating_mul(n as Weight)) .saturating_add(RocksDbWeight::get().reads(5 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 { - (144_533_000 as Weight) - // Standard Error: 220_000 - .saturating_add((714_590_000 as Weight).saturating_mul(r as Weight)) + (170_417_000 as Weight) + // Standard Error: 434_000 + .saturating_add((721_511_000 as Weight).saturating_mul(r as Weight)) .saturating_add(RocksDbWeight::get().reads(5 as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } fn seal_set_storage(r: u32, ) -> Weight { - (406_366_000 as Weight) - // Standard Error: 3_533_000 - .saturating_add((16_167_082_000 as Weight).saturating_mul(r as Weight)) + (1_870_542_000 as Weight) + // Standard Error: 26_871_000 + .saturating_add((18_312_239_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_set_storage_per_kb(n: u32, ) -> Weight { - (1_739_590_000 as Weight) - // Standard Error: 390_000 - .saturating_add((74_815_000 as Weight).saturating_mul(n as Weight)) + (1_763_732_000 as Weight) + // Standard Error: 258_000 + .saturating_add((74_848_000 as Weight).saturating_mul(n as Weight)) .saturating_add(RocksDbWeight::get().reads(6 as Weight)) .saturating_add(RocksDbWeight::get().writes(2 as Weight)) } fn seal_clear_storage(r: u32, ) -> Weight { (0 as Weight) - // Standard Error: 2_284_000 - .saturating_add((2_281_347_000 as Weight).saturating_mul(r as Weight)) + // Standard Error: 2_745_000 + .saturating_add((2_316_433_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_get_storage(r: u32, ) -> Weight { - (81_889_000 as Weight) - // Standard Error: 1_171_000 - .saturating_add((930_704_000 as Weight).saturating_mul(r as Weight)) + (87_218_000 as Weight) + // Standard Error: 745_000 + .saturating_add((948_121_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_get_storage_per_kb(n: u32, ) -> Weight { - (709_323_000 as Weight) - // Standard Error: 391_000 - .saturating_add((155_689_000 as Weight).saturating_mul(n as Weight)) + (719_050_000 as Weight) + // Standard Error: 266_000 + .saturating_add((154_812_000 as Weight).saturating_mul(n as Weight)) .saturating_add(RocksDbWeight::get().reads(6 as Weight)) } fn seal_transfer(r: u32, ) -> Weight { - (0 as Weight) - // Standard Error: 1_846_000 - .saturating_add((5_566_275_000 as Weight).saturating_mul(r as Weight)) + (19_439_000 as Weight) + // Standard Error: 2_468_000 + .saturating_add((5_674_822_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)) @@ -1044,347 +1057,347 @@ impl WeightInfo for () { } fn seal_call(r: u32, ) -> Weight { (0 as Weight) - // Standard Error: 4_823_000 - .saturating_add((10_461_861_000 as Weight).saturating_mul(r as Weight)) + // Standard Error: 7_465_000 + .saturating_add((11_066_530_000 as Weight).saturating_mul(r as Weight)) .saturating_add(RocksDbWeight::get().reads(6 as Weight)) .saturating_add(RocksDbWeight::get().reads((200 as Weight).saturating_mul(r as Weight))) } fn seal_call_per_code_transfer_input_output_kb(c: u32, t: u32, i: u32, o: u32, ) -> Weight { - (9_686_594_000 as Weight) - // Standard Error: 473_000 - .saturating_add((393_132_000 as Weight).saturating_mul(c as Weight)) - // Standard Error: 197_094_000 - .saturating_add((4_957_181_000 as Weight).saturating_mul(t as Weight)) - // Standard Error: 62_000 - .saturating_add((59_974_000 as Weight).saturating_mul(i as Weight)) - // Standard Error: 66_000 - .saturating_add((83_027_000 as Weight).saturating_mul(o as Weight)) + (9_916_288_000 as Weight) + // Standard Error: 552_000 + .saturating_add((397_842_000 as Weight).saturating_mul(c as Weight)) + // Standard Error: 229_902_000 + .saturating_add((5_243_673_000 as Weight).saturating_mul(t as Weight)) + // Standard Error: 72_000 + .saturating_add((59_737_000 as Weight).saturating_mul(i as Weight)) + // Standard Error: 77_000 + .saturating_add((82_259_000 as Weight).saturating_mul(o as Weight)) .saturating_add(RocksDbWeight::get().reads(206 as Weight)) .saturating_add(RocksDbWeight::get().writes((101 as Weight).saturating_mul(t as Weight))) } fn seal_instantiate(r: u32, ) -> Weight { (0 as Weight) - // Standard Error: 34_133_000 - .saturating_add((21_407_630_000 as Weight).saturating_mul(r as Weight)) + // Standard Error: 32_016_000 + .saturating_add((22_206_489_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((300 as Weight).saturating_mul(r as Weight))) } fn seal_instantiate_per_code_input_output_salt_kb(c: u32, i: u32, o: u32, s: u32, ) -> Weight { - (9_705_322_000 as Weight) - // Standard Error: 674_000 - .saturating_add((879_118_000 as Weight).saturating_mul(c as Weight)) - // Standard Error: 95_000 - .saturating_add((63_025_000 as Weight).saturating_mul(i as Weight)) - // Standard Error: 95_000 - .saturating_add((87_633_000 as Weight).saturating_mul(o as Weight)) - // Standard Error: 95_000 - .saturating_add((311_987_000 as Weight).saturating_mul(s as Weight)) + (9_991_947_000 as Weight) + // Standard Error: 637_000 + .saturating_add((881_981_000 as Weight).saturating_mul(c as Weight)) + // Standard Error: 90_000 + .saturating_add((63_638_000 as Weight).saturating_mul(i as Weight)) + // Standard Error: 90_000 + .saturating_add((87_288_000 as Weight).saturating_mul(o as Weight)) + // Standard Error: 90_000 + .saturating_add((311_808_000 as Weight).saturating_mul(s as Weight)) .saturating_add(RocksDbWeight::get().reads(207 as Weight)) .saturating_add(RocksDbWeight::get().writes(203 as Weight)) } fn seal_hash_sha2_256(r: u32, ) -> Weight { - (125_486_000 as Weight) - // Standard Error: 266_000 - .saturating_add((240_913_000 as Weight).saturating_mul(r as Weight)) + (132_452_000 as Weight) + // Standard Error: 227_000 + .saturating_add((239_671_000 as Weight).saturating_mul(r as Weight)) .saturating_add(RocksDbWeight::get().reads(5 as Weight)) } fn seal_hash_sha2_256_per_kb(n: u32, ) -> Weight { - (636_153_000 as Weight) - // Standard Error: 47_000 - .saturating_add((429_541_000 as Weight).saturating_mul(n as Weight)) + (756_802_000 as Weight) + // Standard Error: 48_000 + .saturating_add((429_454_000 as Weight).saturating_mul(n as Weight)) .saturating_add(RocksDbWeight::get().reads(5 as Weight)) } fn seal_hash_keccak_256(r: u32, ) -> Weight { - (131_768_000 as Weight) - // Standard Error: 176_000 - .saturating_add((256_946_000 as Weight).saturating_mul(r as Weight)) + (139_440_000 as Weight) + // Standard Error: 128_000 + .saturating_add((249_514_000 as Weight).saturating_mul(r as Weight)) .saturating_add(RocksDbWeight::get().reads(5 as Weight)) } fn seal_hash_keccak_256_per_kb(n: u32, ) -> Weight { - (647_777_000 as Weight) - // Standard Error: 29_000 - .saturating_add((344_145_000 as Weight).saturating_mul(n as Weight)) + (658_595_000 as Weight) + // Standard Error: 35_000 + .saturating_add((343_814_000 as Weight).saturating_mul(n as Weight)) .saturating_add(RocksDbWeight::get().reads(5 as Weight)) } fn seal_hash_blake2_256(r: u32, ) -> Weight { - (130_042_000 as Weight) - // Standard Error: 158_000 - .saturating_add((225_474_000 as Weight).saturating_mul(r as Weight)) + (138_124_000 as Weight) + // Standard Error: 140_000 + .saturating_add((223_189_000 as Weight).saturating_mul(r as Weight)) .saturating_add(RocksDbWeight::get().reads(5 as Weight)) } fn seal_hash_blake2_256_per_kb(n: u32, ) -> Weight { - (638_275_000 as Weight) - // Standard Error: 30_000 - .saturating_add((159_832_000 as Weight).saturating_mul(n as Weight)) + (689_667_000 as Weight) + // Standard Error: 41_000 + .saturating_add((160_006_000 as Weight).saturating_mul(n as Weight)) .saturating_add(RocksDbWeight::get().reads(5 as Weight)) } fn seal_hash_blake2_128(r: u32, ) -> Weight { - (126_632_000 as Weight) - // Standard Error: 143_000 - .saturating_add((225_612_000 as Weight).saturating_mul(r as Weight)) + (140_225_000 as Weight) + // Standard Error: 156_000 + .saturating_add((223_696_000 as Weight).saturating_mul(r as Weight)) .saturating_add(RocksDbWeight::get().reads(5 as Weight)) } fn seal_hash_blake2_128_per_kb(n: u32, ) -> Weight { - (656_936_000 as Weight) - // Standard Error: 35_000 - .saturating_add((159_763_000 as Weight).saturating_mul(n as Weight)) + (693_756_000 as Weight) + // Standard Error: 40_000 + .saturating_add((159_996_000 as Weight).saturating_mul(n as Weight)) .saturating_add(RocksDbWeight::get().reads(5 as Weight)) } fn instr_i64const(r: u32, ) -> Weight { - (25_205_000 as Weight) - // Standard Error: 26_000 - .saturating_add((3_311_000 as Weight).saturating_mul(r as Weight)) + (24_250_000 as Weight) + // Standard Error: 14_000 + .saturating_add((3_134_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64load(r: u32, ) -> Weight { - (27_394_000 as Weight) - // Standard Error: 28_000 - .saturating_add((159_123_000 as Weight).saturating_mul(r as Weight)) + (26_509_000 as Weight) + // Standard Error: 27_000 + .saturating_add((161_556_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64store(r: u32, ) -> Weight { - (27_398_000 as Weight) - // Standard Error: 57_000 - .saturating_add((229_775_000 as Weight).saturating_mul(r as Weight)) + (26_499_000 as Weight) + // Standard Error: 59_000 + .saturating_add((233_755_000 as Weight).saturating_mul(r as Weight)) } fn instr_select(r: u32, ) -> Weight { - (25_212_000 as Weight) - // Standard Error: 22_000 - .saturating_add((12_291_000 as Weight).saturating_mul(r as Weight)) + (24_175_000 as Weight) + // Standard Error: 16_000 + .saturating_add((12_450_000 as Weight).saturating_mul(r as Weight)) } fn instr_if(r: u32, ) -> Weight { - (25_116_000 as Weight) - // Standard Error: 16_000 - .saturating_add((12_146_000 as Weight).saturating_mul(r as Weight)) + (24_219_000 as Weight) + // Standard Error: 26_000 + .saturating_add((12_058_000 as Weight).saturating_mul(r as Weight)) } fn instr_br(r: u32, ) -> Weight { - (25_119_000 as Weight) - // Standard Error: 19_000 - .saturating_add((6_608_000 as Weight).saturating_mul(r as Weight)) + (24_146_000 as Weight) + // Standard Error: 20_000 + .saturating_add((6_017_000 as Weight).saturating_mul(r as Weight)) } fn instr_br_if(r: u32, ) -> Weight { - (25_146_000 as Weight) - // Standard Error: 23_000 - .saturating_add((14_017_000 as Weight).saturating_mul(r as Weight)) + (24_229_000 as Weight) + // Standard Error: 24_000 + .saturating_add((13_726_000 as Weight).saturating_mul(r as Weight)) } fn instr_br_table(r: u32, ) -> Weight { - (25_192_000 as Weight) - // Standard Error: 21_000 - .saturating_add((15_460_000 as Weight).saturating_mul(r as Weight)) + (24_219_000 as Weight) + // Standard Error: 27_000 + .saturating_add((15_115_000 as Weight).saturating_mul(r as Weight)) } fn instr_br_table_per_entry(e: u32, ) -> Weight { - (37_079_000 as Weight) + (34_981_000 as Weight) // Standard Error: 1_000 - .saturating_add((160_000 as Weight).saturating_mul(e as Weight)) + .saturating_add((156_000 as Weight).saturating_mul(e as Weight)) } fn instr_call(r: u32, ) -> Weight { - (25_599_000 as Weight) - // Standard Error: 201_000 - .saturating_add((99_705_000 as Weight).saturating_mul(r as Weight)) + (24_599_000 as Weight) + // Standard Error: 102_000 + .saturating_add((95_771_000 as Weight).saturating_mul(r as Weight)) } fn instr_call_indirect(r: u32, ) -> Weight { - (33_236_000 as Weight) - // Standard Error: 368_000 - .saturating_add((199_753_000 as Weight).saturating_mul(r as Weight)) + (32_584_000 as Weight) + // Standard Error: 176_000 + .saturating_add((193_216_000 as Weight).saturating_mul(r as Weight)) } fn instr_call_indirect_per_param(p: u32, ) -> Weight { - (247_488_000 as Weight) + (240_739_000 as Weight) // Standard Error: 6_000 - .saturating_add((3_374_000 as Weight).saturating_mul(p as Weight)) + .saturating_add((3_407_000 as Weight).saturating_mul(p as Weight)) } fn instr_local_get(r: u32, ) -> Weight { - (44_133_000 as Weight) - // Standard Error: 20_000 - .saturating_add((3_235_000 as Weight).saturating_mul(r as Weight)) + (41_963_000 as Weight) + // Standard Error: 15_000 + .saturating_add((3_110_000 as Weight).saturating_mul(r as Weight)) } fn instr_local_set(r: u32, ) -> Weight { - (44_107_000 as Weight) - // Standard Error: 20_000 - .saturating_add((3_486_000 as Weight).saturating_mul(r as Weight)) + (41_956_000 as Weight) + // Standard Error: 9_000 + .saturating_add((3_460_000 as Weight).saturating_mul(r as Weight)) } fn instr_local_tee(r: u32, ) -> Weight { - (44_116_000 as Weight) - // Standard Error: 23_000 - .saturating_add((4_757_000 as Weight).saturating_mul(r as Weight)) + (42_002_000 as Weight) + // Standard Error: 20_000 + .saturating_add((4_591_000 as Weight).saturating_mul(r as Weight)) } fn instr_global_get(r: u32, ) -> Weight { - (28_712_000 as Weight) - // Standard Error: 29_000 - .saturating_add((7_659_000 as Weight).saturating_mul(r as Weight)) + (27_646_000 as Weight) + // Standard Error: 23_000 + .saturating_add((7_821_000 as Weight).saturating_mul(r as Weight)) } fn instr_global_set(r: u32, ) -> Weight { - (28_624_000 as Weight) - // Standard Error: 25_000 - .saturating_add((11_841_000 as Weight).saturating_mul(r as Weight)) + (27_615_000 as Weight) + // Standard Error: 27_000 + .saturating_add((11_807_000 as Weight).saturating_mul(r as Weight)) } fn instr_memory_current(r: u32, ) -> Weight { - (27_445_000 as Weight) - // Standard Error: 18_000 - .saturating_add((3_487_000 as Weight).saturating_mul(r as Weight)) + (27_106_000 as Weight) + // Standard Error: 78_000 + .saturating_add((2_952_000 as Weight).saturating_mul(r as Weight)) } fn instr_memory_grow(r: u32, ) -> Weight { - (26_016_000 as Weight) - // Standard Error: 4_230_000 - .saturating_add((2_300_044_000 as Weight).saturating_mul(r as Weight)) + (24_956_000 as Weight) + // Standard Error: 3_541_000 + .saturating_add((2_332_414_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64clz(r: u32, ) -> Weight { - (25_227_000 as Weight) - // Standard Error: 29_000 - .saturating_add((5_341_000 as Weight).saturating_mul(r as Weight)) + (24_183_000 as Weight) + // Standard Error: 18_000 + .saturating_add((5_166_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64ctz(r: u32, ) -> Weight { - (25_163_000 as Weight) - // Standard Error: 26_000 - .saturating_add((5_355_000 as Weight).saturating_mul(r as Weight)) + (24_142_000 as Weight) + // Standard Error: 17_000 + .saturating_add((5_146_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64popcnt(r: u32, ) -> Weight { - (25_204_000 as Weight) - // Standard Error: 29_000 - .saturating_add((5_930_000 as Weight).saturating_mul(r as Weight)) + (24_161_000 as Weight) + // Standard Error: 23_000 + .saturating_add((5_807_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64eqz(r: u32, ) -> Weight { - (25_177_000 as Weight) - // Standard Error: 21_000 - .saturating_add((5_457_000 as Weight).saturating_mul(r as Weight)) + (24_167_000 as Weight) + // Standard Error: 24_000 + .saturating_add((5_288_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64extendsi32(r: u32, ) -> Weight { - (25_206_000 as Weight) - // Standard Error: 19_000 - .saturating_add((5_229_000 as Weight).saturating_mul(r as Weight)) + (24_252_000 as Weight) + // Standard Error: 9_000 + .saturating_add((5_091_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64extendui32(r: u32, ) -> Weight { - (25_165_000 as Weight) - // Standard Error: 17_000 - .saturating_add((5_301_000 as Weight).saturating_mul(r as Weight)) + (24_243_000 as Weight) + // Standard Error: 16_000 + .saturating_add((5_076_000 as Weight).saturating_mul(r as Weight)) } fn instr_i32wrapi64(r: u32, ) -> Weight { - (25_184_000 as Weight) - // Standard Error: 28_000 - .saturating_add((5_356_000 as Weight).saturating_mul(r as Weight)) + (24_227_000 as Weight) + // Standard Error: 15_000 + .saturating_add((5_135_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64eq(r: u32, ) -> Weight { - (25_195_000 as Weight) - // Standard Error: 48_000 - .saturating_add((7_406_000 as Weight).saturating_mul(r as Weight)) + (24_278_000 as Weight) + // Standard Error: 15_000 + .saturating_add((7_124_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64ne(r: u32, ) -> Weight { - (25_192_000 as Weight) + (24_254_000 as Weight) // Standard Error: 19_000 - .saturating_add((7_303_000 as Weight).saturating_mul(r as Weight)) + .saturating_add((7_067_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64lts(r: u32, ) -> Weight { - (25_165_000 as Weight) - // Standard Error: 34_000 - .saturating_add((7_247_000 as Weight).saturating_mul(r as Weight)) + (24_220_000 as Weight) + // Standard Error: 14_000 + .saturating_add((7_122_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64ltu(r: u32, ) -> Weight { - (25_152_000 as Weight) - // Standard Error: 46_000 - .saturating_add((7_464_000 as Weight).saturating_mul(r as Weight)) + (24_221_000 as Weight) + // Standard Error: 19_000 + .saturating_add((7_221_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64gts(r: u32, ) -> Weight { - (25_140_000 as Weight) - // Standard Error: 27_000 - .saturating_add((7_308_000 as Weight).saturating_mul(r as Weight)) + (24_259_000 as Weight) + // Standard Error: 13_000 + .saturating_add((7_135_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64gtu(r: u32, ) -> Weight { - (25_723_000 as Weight) - // Standard Error: 29_000 - .saturating_add((6_846_000 as Weight).saturating_mul(r as Weight)) + (24_245_000 as Weight) + // Standard Error: 10_000 + .saturating_add((7_193_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64les(r: u32, ) -> Weight { - (25_201_000 as Weight) - // Standard Error: 20_000 - .saturating_add((7_226_000 as Weight).saturating_mul(r as Weight)) + (24_289_000 as Weight) + // Standard Error: 22_000 + .saturating_add((7_023_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64leu(r: u32, ) -> Weight { - (25_192_000 as Weight) - // Standard Error: 24_000 - .saturating_add((7_143_000 as Weight).saturating_mul(r as Weight)) + (24_239_000 as Weight) + // Standard Error: 21_000 + .saturating_add((7_065_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64ges(r: u32, ) -> Weight { - (25_146_000 as Weight) - // Standard Error: 37_000 - .saturating_add((7_451_000 as Weight).saturating_mul(r as Weight)) + (24_256_000 as Weight) + // Standard Error: 13_000 + .saturating_add((7_119_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64geu(r: u32, ) -> Weight { - (25_193_000 as Weight) - // Standard Error: 30_000 - .saturating_add((7_391_000 as Weight).saturating_mul(r as Weight)) + (24_240_000 as Weight) + // Standard Error: 18_000 + .saturating_add((7_225_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64add(r: u32, ) -> Weight { - (25_192_000 as Weight) - // Standard Error: 30_000 - .saturating_add((7_214_000 as Weight).saturating_mul(r as Weight)) + (24_266_000 as Weight) + // Standard Error: 24_000 + .saturating_add((6_996_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64sub(r: u32, ) -> Weight { - (25_221_000 as Weight) - // Standard Error: 34_000 - .saturating_add((7_168_000 as Weight).saturating_mul(r as Weight)) + (24_265_000 as Weight) + // Standard Error: 17_000 + .saturating_add((6_974_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64mul(r: u32, ) -> Weight { - (25_221_000 as Weight) - // Standard Error: 28_000 - .saturating_add((7_200_000 as Weight).saturating_mul(r as Weight)) + (24_232_000 as Weight) + // Standard Error: 15_000 + .saturating_add((7_103_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64divs(r: u32, ) -> Weight { - (25_229_000 as Weight) - // Standard Error: 32_000 - .saturating_add((13_066_000 as Weight).saturating_mul(r as Weight)) + (24_245_000 as Weight) + // Standard Error: 20_000 + .saturating_add((12_915_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64divu(r: u32, ) -> Weight { - (25_210_000 as Weight) - // Standard Error: 28_000 - .saturating_add((12_314_000 as Weight).saturating_mul(r as Weight)) + (24_177_000 as Weight) + // Standard Error: 21_000 + .saturating_add((12_232_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64rems(r: u32, ) -> Weight { - (25_186_000 as Weight) - // Standard Error: 24_000 - .saturating_add((13_055_000 as Weight).saturating_mul(r as Weight)) + (24_171_000 as Weight) + // Standard Error: 15_000 + .saturating_add((12_939_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64remu(r: u32, ) -> Weight { - (25_162_000 as Weight) - // Standard Error: 25_000 - .saturating_add((12_327_000 as Weight).saturating_mul(r as Weight)) + (24_788_000 as Weight) + // Standard Error: 22_000 + .saturating_add((11_657_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64and(r: u32, ) -> Weight { - (25_191_000 as Weight) - // Standard Error: 24_000 - .saturating_add((7_153_000 as Weight).saturating_mul(r as Weight)) + (24_252_000 as Weight) + // Standard Error: 19_000 + .saturating_add((7_003_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64or(r: u32, ) -> Weight { - (25_184_000 as Weight) - // Standard Error: 23_000 - .saturating_add((7_120_000 as Weight).saturating_mul(r as Weight)) + (24_263_000 as Weight) + // Standard Error: 12_000 + .saturating_add((7_005_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64xor(r: u32, ) -> Weight { - (25_129_000 as Weight) - // Standard Error: 31_000 - .saturating_add((7_247_000 as Weight).saturating_mul(r as Weight)) + (24_239_000 as Weight) + // Standard Error: 17_000 + .saturating_add((7_020_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64shl(r: u32, ) -> Weight { - (25_156_000 as Weight) - // Standard Error: 16_000 - .saturating_add((7_333_000 as Weight).saturating_mul(r as Weight)) + (24_212_000 as Weight) + // Standard Error: 13_000 + .saturating_add((7_172_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64shrs(r: u32, ) -> Weight { - (25_159_000 as Weight) - // Standard Error: 25_000 - .saturating_add((7_415_000 as Weight).saturating_mul(r as Weight)) + (24_220_000 as Weight) + // Standard Error: 27_000 + .saturating_add((7_246_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64shru(r: u32, ) -> Weight { - (25_181_000 as Weight) - // Standard Error: 25_000 - .saturating_add((7_265_000 as Weight).saturating_mul(r as Weight)) + (24_213_000 as Weight) + // Standard Error: 14_000 + .saturating_add((7_191_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64rotl(r: u32, ) -> Weight { - (25_165_000 as Weight) - // Standard Error: 17_000 - .saturating_add((7_443_000 as Weight).saturating_mul(r as Weight)) + (24_221_000 as Weight) + // Standard Error: 18_000 + .saturating_add((7_192_000 as Weight).saturating_mul(r as Weight)) } fn instr_i64rotr(r: u32, ) -> Weight { - (25_103_000 as Weight) - // Standard Error: 44_000 - .saturating_add((7_463_000 as Weight).saturating_mul(r as Weight)) + (24_235_000 as Weight) + // Standard Error: 12_000 + .saturating_add((7_106_000 as Weight).saturating_mul(r as Weight)) } } From 8de707bb67f7b587792a6e3a3891d394f78defd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Thei=C3=9Fen?= Date: Tue, 2 Mar 2021 08:30:20 +0100 Subject: [PATCH 03/10] Fix typos --- frame/contracts/src/exec.rs | 8 ++++---- frame/contracts/src/wasm/mod.rs | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/frame/contracts/src/exec.rs b/frame/contracts/src/exec.rs index 3159e267f5891..5a5679aa71fc8 100644 --- a/frame/contracts/src/exec.rs +++ b/frame/contracts/src/exec.rs @@ -47,7 +47,7 @@ pub type TopicOf = ::Hash; #[derive(codec::Encode)] #[cfg_attr(test, derive(Debug, PartialEq))] pub struct RentParams { - /// The free balance of the contract. + /// The total balance of the contract. total_balance: BalanceOf, /// The free balance of the contract. free_balance: BalanceOf, @@ -93,7 +93,7 @@ where rent_allowance: contract.rent_allowance, rent_fraction: T::RentFraction::get(), storage_size: contract.storage_size, - code_size: executable.code_len().saturating_add(executable.origignal_code_len()), + code_size: executable.code_len().saturating_add(executable.original_code_len()), code_refcount: executable.refcount(), _reserved: None, } @@ -348,7 +348,7 @@ pub trait Executable: Sized { fn code_len(&self) -> u32; /// Size of the original code in bytes. - fn origignal_code_len(&self) -> u32; + fn original_code_len(&self) -> u32; // The number of contracts using this executable. fn refcount(&self) -> u32; @@ -1111,7 +1111,7 @@ mod tests { 0 } - fn origignal_code_len(&self) -> u32 { + fn original_code_len(&self) -> u32 { 0 } diff --git a/frame/contracts/src/wasm/mod.rs b/frame/contracts/src/wasm/mod.rs index 29f07caed7b91..785a3ed710fc6 100644 --- a/frame/contracts/src/wasm/mod.rs +++ b/frame/contracts/src/wasm/mod.rs @@ -232,7 +232,7 @@ where self.code.len() as u32 } - fn origignal_code_len(&self) -> u32 { + fn original_code_len(&self) -> u32 { self.original_code_len } From 16c5c8e8ff25ac21e0dda12ac5369806428c3d6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Thei=C3=9Fen?= Date: Tue, 2 Mar 2021 08:33:18 +0100 Subject: [PATCH 04/10] Improve comments --- frame/contracts/src/exec.rs | 4 ++-- frame/contracts/src/wasm/runtime.rs | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/frame/contracts/src/exec.rs b/frame/contracts/src/exec.rs index 5a5679aa71fc8..d4154af898523 100644 --- a/frame/contracts/src/exec.rs +++ b/frame/contracts/src/exec.rs @@ -47,9 +47,9 @@ pub type TopicOf = ::Hash; #[derive(codec::Encode)] #[cfg_attr(test, derive(Debug, PartialEq))] pub struct RentParams { - /// The total balance of the contract. + /// The total balance of the contract. Includes the balance transferred from the caller. total_balance: BalanceOf, - /// The free balance of the contract. + /// The free balance of the contract. Includes the balance transferred from the caller. free_balance: BalanceOf, /// See crate [`Contracts::subsistence_threshold()`]. subsistence_threshold: BalanceOf, diff --git a/frame/contracts/src/wasm/runtime.rs b/frame/contracts/src/wasm/runtime.rs index 61fdebf9d1eda..63fe406726c6f 100644 --- a/frame/contracts/src/wasm/runtime.rs +++ b/frame/contracts/src/wasm/runtime.rs @@ -1526,9 +1526,8 @@ define_env!(Env, , // # Note // // The returned information was collected and cached when the current contract call - // starts execution. Any change to those values that happens due to actions of the + // started execution. Any change to those values that happens due to actions of the // current call or contracts that are called by this contract are not considered. - // The fields that are subject to these changes are `refcount` and `rent_allowance`. seal_rent_params(ctx, out_ptr: u32, out_len_ptr: u32) => { // TODO: create benchmark and runtime token ctx.charge_gas(RuntimeToken::RentAllowance)?; From db786e46adf4f8da75b0608ca6ca37ca5b93ecf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Thei=C3=9Fen?= Date: Tue, 2 Mar 2021 08:46:46 +0100 Subject: [PATCH 05/10] Add rent parameter weights --- frame/contracts/src/schedule.rs | 4 ++++ frame/contracts/src/wasm/runtime.rs | 6 ++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/frame/contracts/src/schedule.rs b/frame/contracts/src/schedule.rs index c86134bc415d1..f9929aa6778d3 100644 --- a/frame/contracts/src/schedule.rs +++ b/frame/contracts/src/schedule.rs @@ -348,6 +348,9 @@ pub struct HostFnWeights { /// Weight per byte hashed by `seal_hash_blake2_128`. pub hash_blake2_128_per_byte: Weight, + /// Weight of calling `seal_rent_params`. + pub rent_params: Weight, + /// The type parameter is used in the default implementation. pub _phantom: PhantomData } @@ -572,6 +575,7 @@ impl Default for HostFnWeights { hash_blake2_256_per_byte: cost_byte_batched!(seal_hash_blake2_256_per_kb), hash_blake2_128: cost_batched!(seal_hash_blake2_128), hash_blake2_128_per_byte: cost_byte_batched!(seal_hash_blake2_128_per_kb), + rent_params: cost_batched!(seal_rent_params), _phantom: PhantomData, } } diff --git a/frame/contracts/src/wasm/runtime.rs b/frame/contracts/src/wasm/runtime.rs index 63fe406726c6f..2ceac1c51604e 100644 --- a/frame/contracts/src/wasm/runtime.rs +++ b/frame/contracts/src/wasm/runtime.rs @@ -215,6 +215,8 @@ pub enum RuntimeToken { ChainExtension(u64), /// Weight charged for copying data from the sandbox. CopyIn(u32), + /// Weight of calling `seal_rent_params`. + RentParams, } impl Token for RuntimeToken @@ -283,6 +285,7 @@ where .saturating_add(s.hash_blake2_128_per_byte.saturating_mul(len.into())), ChainExtension(amount) => amount, CopyIn(len) => s.return_per_byte.saturating_mul(len.into()), + RentParams => s.rent_params, } } } @@ -1529,8 +1532,7 @@ define_env!(Env, , // started execution. Any change to those values that happens due to actions of the // current call or contracts that are called by this contract are not considered. seal_rent_params(ctx, out_ptr: u32, out_len_ptr: u32) => { - // TODO: create benchmark and runtime token - ctx.charge_gas(RuntimeToken::RentAllowance)?; + ctx.charge_gas(RuntimeToken::RentParams)?; Ok(ctx.write_sandbox_output( out_ptr, out_len_ptr, &ctx.ext.rent_params().encode(), false, already_charged )?) From 755d305fe93dd1667a67f3a6343e6463bc07c9b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Thei=C3=9Fen?= Date: Tue, 2 Mar 2021 09:48:13 +0100 Subject: [PATCH 06/10] Allow deploying a new schedule with the same version --- frame/contracts/src/lib.rs | 7 +++++-- frame/contracts/src/schedule.rs | 13 +++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/frame/contracts/src/lib.rs b/frame/contracts/src/lib.rs index 2ce2014075a88..ee653c46ad9b2 100644 --- a/frame/contracts/src/lib.rs +++ b/frame/contracts/src/lib.rs @@ -275,14 +275,17 @@ pub mod pallet { { /// Updates the schedule for metering contracts. /// - /// The schedule must have a greater version than the stored schedule. + /// The schedule's version cannot be less than the version of the stored schedule. + /// If a schedule does not change the instruction weights the version does not + /// need to be increased. Therefore we allow storing a schedule that has the same + /// version as the stored one. #[pallet::weight(T::WeightInfo::update_schedule())] pub fn update_schedule( origin: OriginFor, schedule: Schedule ) -> DispatchResultWithPostInfo { ensure_root(origin)?; - if >::current_schedule().version >= schedule.version { + if >::current_schedule().version > schedule.version { Err(Error::::InvalidScheduleVersion)? } Self::deposit_event(Event::ScheduleUpdated(schedule.version)); diff --git a/frame/contracts/src/schedule.rs b/frame/contracts/src/schedule.rs index f9929aa6778d3..728fc2be361c8 100644 --- a/frame/contracts/src/schedule.rs +++ b/frame/contracts/src/schedule.rs @@ -45,6 +45,14 @@ pub const INSTR_BENCHMARK_BATCH_SIZE: u32 = 1_000; #[derive(Clone, Encode, Decode, PartialEq, Eq, ScheduleDebug)] pub struct Schedule { /// Version of the schedule. + /// + /// # Note + /// + /// Must be incremented whenever the [`self.instruction_weights`] are changed. The + /// reason is that changes to instruction weights require a re-instrumentation + /// of all contracts which are triggered by a version comparison on call. + /// Changes to other parts of the schedule should not increment the version in + /// order to avoid unnecessary re-instrumentations. pub version: u32, /// Whether the `seal_println` function is allowed to be used contracts. @@ -62,6 +70,11 @@ pub struct Schedule { } /// Describes the upper limits on various metrics. +/// +/// # Note +/// +/// The values in this struct should only ever be increased for a deployed chain. The reason +/// is that decreasing those values will break existing contracts which are above the new limits. #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] #[derive(Clone, Encode, Decode, PartialEq, Eq, RuntimeDebug)] pub struct Limits { From 98b7cb7b4db7a1f57629b70d710e50b01afe2a43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Thei=C3=9Fen?= Date: Tue, 2 Mar 2021 10:07:29 +0100 Subject: [PATCH 07/10] Add storage migration for new schedule --- frame/contracts/src/lib.rs | 5 + frame/contracts/src/migration.rs | 183 +++++++++++++++++++++++++++++++ frame/contracts/src/schedule.rs | 2 + 3 files changed, 190 insertions(+) create mode 100644 frame/contracts/src/migration.rs diff --git a/frame/contracts/src/lib.rs b/frame/contracts/src/lib.rs index ee653c46ad9b2..205de107fe936 100644 --- a/frame/contracts/src/lib.rs +++ b/frame/contracts/src/lib.rs @@ -90,6 +90,7 @@ mod wasm; mod rent; mod benchmarking; mod schedule; +mod migration; pub mod chain_extension; pub mod weights; @@ -265,6 +266,10 @@ pub mod pallet { Storage::::process_deletion_queue_batch(weight_limit) .saturating_add(T::WeightInfo::on_initialize()) } + + fn on_runtime_upgrade() -> Weight { + migration::migrate::() + } } #[pallet::call] diff --git a/frame/contracts/src/migration.rs b/frame/contracts/src/migration.rs new file mode 100644 index 0000000000000..029a0254f13f0 --- /dev/null +++ b/frame/contracts/src/migration.rs @@ -0,0 +1,183 @@ +// This file is part of Substrate. + +// Copyright (C) 2018-2021 Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +use crate::{Config, Weight, CurrentSchedule, Pallet, Schedule}; +use codec::{Encode, Decode}; +use frame_support::traits::{GetPalletVersion, PalletVersion, Get}; +use sp_std::marker::PhantomData; + +pub fn migrate() -> Weight { + let mut weight: Weight = 0; + + match >::storage_version() { + Some(version) if version == PalletVersion::new(3, 0, 0) => { + weight = weight.saturating_add(T::DbWeight::get().reads_writes(1, 1)); + let _ = >::translate::, _>(|old| { + if let Some(old) = old { + Some(Schedule { + version: old.version.saturating_add(1), + // Default limits were not decreased. Therefore it is OK to overwrite + // the schedule with the new defaults. + .. Default::default() + }) + } else { + None + } + }); + } + _ => (), + } + + weight +} + +mod v3_0 { + use super::*; + + #[derive(Clone, Encode, Decode, PartialEq, Eq)] + pub struct Schedule { + pub version: u32, + pub enable_println: bool, + pub limits: Limits, + pub instruction_weights: InstructionWeights, + pub host_fn_weights: HostFnWeights, + } + + #[derive(Clone, Encode, Decode, PartialEq, Eq)] + pub struct Limits { + pub event_topics: u32, + pub stack_height: u32, + pub globals: u32, + pub parameters: u32, + pub memory_pages: u32, + pub table_size: u32, + pub br_table_size: u32, + pub subject_len: u32, + } + + #[derive(Clone, Encode, Decode, PartialEq, Eq)] + pub struct InstructionWeights { + pub i64const: u32, + pub i64load: u32, + pub i64store: u32, + pub select: u32, + pub r#if: u32, + pub br: u32, + pub br_if: u32, + pub br_table: u32, + pub br_table_per_entry: u32, + pub call: u32, + pub call_indirect: u32, + pub call_indirect_per_param: u32, + pub local_get: u32, + pub local_set: u32, + pub local_tee: u32, + pub global_get: u32, + pub global_set: u32, + pub memory_current: u32, + pub memory_grow: u32, + pub i64clz: u32, + pub i64ctz: u32, + pub i64popcnt: u32, + pub i64eqz: u32, + pub i64extendsi32: u32, + pub i64extendui32: u32, + pub i32wrapi64: u32, + pub i64eq: u32, + pub i64ne: u32, + pub i64lts: u32, + pub i64ltu: u32, + pub i64gts: u32, + pub i64gtu: u32, + pub i64les: u32, + pub i64leu: u32, + pub i64ges: u32, + pub i64geu: u32, + pub i64add: u32, + pub i64sub: u32, + pub i64mul: u32, + pub i64divs: u32, + pub i64divu: u32, + pub i64rems: u32, + pub i64remu: u32, + pub i64and: u32, + pub i64or: u32, + pub i64xor: u32, + pub i64shl: u32, + pub i64shrs: u32, + pub i64shru: u32, + pub i64rotl: u32, + pub i64rotr: u32, + pub _phantom: PhantomData, + } + + #[derive(Clone, Encode, Decode, PartialEq, Eq)] + pub struct HostFnWeights { + pub caller: Weight, + pub address: Weight, + pub gas_left: Weight, + pub balance: Weight, + pub value_transferred: Weight, + pub minimum_balance: Weight, + pub tombstone_deposit: Weight, + pub rent_allowance: Weight, + pub block_number: Weight, + pub now: Weight, + pub weight_to_fee: Weight, + pub gas: Weight, + pub input: Weight, + pub input_per_byte: Weight, + pub r#return: Weight, + pub return_per_byte: Weight, + pub terminate: Weight, + pub terminate_per_code_byte: Weight, + pub restore_to: Weight, + pub restore_to_per_caller_code_byte: Weight, + pub restore_to_per_tombstone_code_byte: Weight, + pub restore_to_per_delta: Weight, + pub random: Weight, + pub deposit_event: Weight, + pub deposit_event_per_topic: Weight, + pub deposit_event_per_byte: Weight, + pub set_rent_allowance: Weight, + pub set_storage: Weight, + pub set_storage_per_byte: Weight, + pub clear_storage: Weight, + pub get_storage: Weight, + pub get_storage_per_byte: Weight, + pub transfer: Weight, + pub call: Weight, + pub call_per_code_byte: Weight, + pub call_transfer_surcharge: Weight, + pub call_per_input_byte: Weight, + pub call_per_output_byte: Weight, + pub instantiate: Weight, + pub instantiate_per_code_byte: Weight, + pub instantiate_per_input_byte: Weight, + pub instantiate_per_output_byte: Weight, + pub instantiate_per_salt_byte: Weight, + pub hash_sha2_256: Weight, + pub hash_sha2_256_per_byte: Weight, + pub hash_keccak_256: Weight, + pub hash_keccak_256_per_byte: Weight, + pub hash_blake2_256: Weight, + pub hash_blake2_256_per_byte: Weight, + pub hash_blake2_128: Weight, + pub hash_blake2_128_per_byte: Weight, + pub _phantom: PhantomData + } +} diff --git a/frame/contracts/src/schedule.rs b/frame/contracts/src/schedule.rs index 728fc2be361c8..24ba83cc1b799 100644 --- a/frame/contracts/src/schedule.rs +++ b/frame/contracts/src/schedule.rs @@ -201,6 +201,7 @@ pub struct InstructionWeights { pub i64rotl: u32, pub i64rotr: u32, /// The type parameter is used in the default implementation. + #[codec(skip)] pub _phantom: PhantomData, } @@ -365,6 +366,7 @@ pub struct HostFnWeights { pub rent_params: Weight, /// The type parameter is used in the default implementation. + #[codec(skip)] pub _phantom: PhantomData } From cbc0625e77b631806757566b5bf6edaf847808ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Thei=C3=9Fen?= Date: Tue, 2 Mar 2021 12:23:18 +0100 Subject: [PATCH 08/10] Only decode the schedule version in storage migration --- frame/contracts/src/migration.rs | 146 +------------------------------ 1 file changed, 4 insertions(+), 142 deletions(-) diff --git a/frame/contracts/src/migration.rs b/frame/contracts/src/migration.rs index 029a0254f13f0..2e10f4b7ff685 100644 --- a/frame/contracts/src/migration.rs +++ b/frame/contracts/src/migration.rs @@ -16,20 +16,19 @@ // limitations under the License. use crate::{Config, Weight, CurrentSchedule, Pallet, Schedule}; -use codec::{Encode, Decode}; use frame_support::traits::{GetPalletVersion, PalletVersion, Get}; -use sp_std::marker::PhantomData; pub fn migrate() -> Weight { let mut weight: Weight = 0; match >::storage_version() { + // Replace the schedule with the new default and increment its version. Some(version) if version == PalletVersion::new(3, 0, 0) => { weight = weight.saturating_add(T::DbWeight::get().reads_writes(1, 1)); - let _ = >::translate::, _>(|old| { - if let Some(old) = old { + let _ = >::translate::(|version| { + if let Some(version) = version { Some(Schedule { - version: old.version.saturating_add(1), + version: version.saturating_add(1), // Default limits were not decreased. Therefore it is OK to overwrite // the schedule with the new defaults. .. Default::default() @@ -44,140 +43,3 @@ pub fn migrate() -> Weight { weight } - -mod v3_0 { - use super::*; - - #[derive(Clone, Encode, Decode, PartialEq, Eq)] - pub struct Schedule { - pub version: u32, - pub enable_println: bool, - pub limits: Limits, - pub instruction_weights: InstructionWeights, - pub host_fn_weights: HostFnWeights, - } - - #[derive(Clone, Encode, Decode, PartialEq, Eq)] - pub struct Limits { - pub event_topics: u32, - pub stack_height: u32, - pub globals: u32, - pub parameters: u32, - pub memory_pages: u32, - pub table_size: u32, - pub br_table_size: u32, - pub subject_len: u32, - } - - #[derive(Clone, Encode, Decode, PartialEq, Eq)] - pub struct InstructionWeights { - pub i64const: u32, - pub i64load: u32, - pub i64store: u32, - pub select: u32, - pub r#if: u32, - pub br: u32, - pub br_if: u32, - pub br_table: u32, - pub br_table_per_entry: u32, - pub call: u32, - pub call_indirect: u32, - pub call_indirect_per_param: u32, - pub local_get: u32, - pub local_set: u32, - pub local_tee: u32, - pub global_get: u32, - pub global_set: u32, - pub memory_current: u32, - pub memory_grow: u32, - pub i64clz: u32, - pub i64ctz: u32, - pub i64popcnt: u32, - pub i64eqz: u32, - pub i64extendsi32: u32, - pub i64extendui32: u32, - pub i32wrapi64: u32, - pub i64eq: u32, - pub i64ne: u32, - pub i64lts: u32, - pub i64ltu: u32, - pub i64gts: u32, - pub i64gtu: u32, - pub i64les: u32, - pub i64leu: u32, - pub i64ges: u32, - pub i64geu: u32, - pub i64add: u32, - pub i64sub: u32, - pub i64mul: u32, - pub i64divs: u32, - pub i64divu: u32, - pub i64rems: u32, - pub i64remu: u32, - pub i64and: u32, - pub i64or: u32, - pub i64xor: u32, - pub i64shl: u32, - pub i64shrs: u32, - pub i64shru: u32, - pub i64rotl: u32, - pub i64rotr: u32, - pub _phantom: PhantomData, - } - - #[derive(Clone, Encode, Decode, PartialEq, Eq)] - pub struct HostFnWeights { - pub caller: Weight, - pub address: Weight, - pub gas_left: Weight, - pub balance: Weight, - pub value_transferred: Weight, - pub minimum_balance: Weight, - pub tombstone_deposit: Weight, - pub rent_allowance: Weight, - pub block_number: Weight, - pub now: Weight, - pub weight_to_fee: Weight, - pub gas: Weight, - pub input: Weight, - pub input_per_byte: Weight, - pub r#return: Weight, - pub return_per_byte: Weight, - pub terminate: Weight, - pub terminate_per_code_byte: Weight, - pub restore_to: Weight, - pub restore_to_per_caller_code_byte: Weight, - pub restore_to_per_tombstone_code_byte: Weight, - pub restore_to_per_delta: Weight, - pub random: Weight, - pub deposit_event: Weight, - pub deposit_event_per_topic: Weight, - pub deposit_event_per_byte: Weight, - pub set_rent_allowance: Weight, - pub set_storage: Weight, - pub set_storage_per_byte: Weight, - pub clear_storage: Weight, - pub get_storage: Weight, - pub get_storage_per_byte: Weight, - pub transfer: Weight, - pub call: Weight, - pub call_per_code_byte: Weight, - pub call_transfer_surcharge: Weight, - pub call_per_input_byte: Weight, - pub call_per_output_byte: Weight, - pub instantiate: Weight, - pub instantiate_per_code_byte: Weight, - pub instantiate_per_input_byte: Weight, - pub instantiate_per_output_byte: Weight, - pub instantiate_per_salt_byte: Weight, - pub hash_sha2_256: Weight, - pub hash_sha2_256_per_byte: Weight, - pub hash_keccak_256: Weight, - pub hash_keccak_256_per_byte: Weight, - pub hash_blake2_256: Weight, - pub hash_blake2_256_per_byte: Weight, - pub hash_blake2_128: Weight, - pub hash_blake2_128_per_byte: Weight, - pub _phantom: PhantomData - } -} From 0ee15dd52bf3da26b61acb4c7fa7b2aba4d091f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Thei=C3=9Fen?= Date: Fri, 12 Mar 2021 11:00:48 +0100 Subject: [PATCH 09/10] Remove confusing docs --- frame/contracts/src/exec.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/frame/contracts/src/exec.rs b/frame/contracts/src/exec.rs index d4154af898523..13e20cd45cdf4 100644 --- a/frame/contracts/src/exec.rs +++ b/frame/contracts/src/exec.rs @@ -1744,7 +1744,6 @@ mod tests { exec_success() }); - // This one tests passing the input data into a contract via call. ExtBuilder::default().build().execute_with(|| { let subsistence = Contracts::::subsistence_threshold(); let schedule = Contracts::current_schedule(); @@ -1752,7 +1751,6 @@ mod tests { let mut gas_meter = GasMeter::::new(GAS_LIMIT); set_balance(&ALICE, subsistence * 10); place_contract(&BOB, code_hash); - ctx.call( BOB, 0, @@ -1794,7 +1792,6 @@ mod tests { exec_success() }); - // This one tests passing the input data into a contract via call. ExtBuilder::default().build().execute_with(|| { let subsistence = Contracts::::subsistence_threshold(); let schedule = Contracts::current_schedule(); From 16e97fbd3489367f3f9e7e6a4e754070ad21b05c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Thei=C3=9Fen?= Date: Fri, 12 Mar 2021 11:08:40 +0100 Subject: [PATCH 10/10] Replace original_code_len() by aggregate_code_len() --- frame/contracts/src/exec.rs | 11 ++++++----- frame/contracts/src/wasm/mod.rs | 6 +++--- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/frame/contracts/src/exec.rs b/frame/contracts/src/exec.rs index 13e20cd45cdf4..6907ee944d333 100644 --- a/frame/contracts/src/exec.rs +++ b/frame/contracts/src/exec.rs @@ -65,7 +65,7 @@ pub struct RentParams { rent_fraction: Perbill, /// See crate [`AliveContractInfo::storage_size`]. storage_size: u32, - /// See crate [`Executable::code_len()`]. + /// See crate [`Executable::aggregate_code_len()`]. code_size: u32, /// See crate [`Executable::refcount()`]. code_refcount: u32, @@ -93,7 +93,7 @@ where rent_allowance: contract.rent_allowance, rent_fraction: T::RentFraction::get(), storage_size: contract.storage_size, - code_size: executable.code_len().saturating_add(executable.original_code_len()), + code_size: executable.aggregate_code_len(), code_refcount: executable.refcount(), _reserved: None, } @@ -336,6 +336,7 @@ pub trait Executable: Sized { /// The storage that is occupied by the instrumented executable and its pristine source. /// /// The returned size is already divided by the number of users who share the code. + /// This is essentially `aggregate_code_len() / refcount()`. /// /// # Note /// @@ -347,8 +348,8 @@ pub trait Executable: Sized { /// Size of the instrumented code in bytes. fn code_len(&self) -> u32; - /// Size of the original code in bytes. - fn original_code_len(&self) -> u32; + /// Sum of instrumented and pristine code len. + fn aggregate_code_len(&self) -> u32; // The number of contracts using this executable. fn refcount(&self) -> u32; @@ -1111,7 +1112,7 @@ mod tests { 0 } - fn original_code_len(&self) -> u32 { + fn aggregate_code_len(&self) -> u32 { 0 } diff --git a/frame/contracts/src/wasm/mod.rs b/frame/contracts/src/wasm/mod.rs index 785a3ed710fc6..6fc6bc1764e4a 100644 --- a/frame/contracts/src/wasm/mod.rs +++ b/frame/contracts/src/wasm/mod.rs @@ -224,7 +224,7 @@ where fn occupied_storage(&self) -> u32 { // We disregard the size of the struct itself as the size is completely // dominated by the code size. - let len = self.original_code_len.saturating_add(self.code.len() as u32); + let len = self.aggregate_code_len(); len.checked_div(self.refcount as u32).unwrap_or(len) } @@ -232,8 +232,8 @@ where self.code.len() as u32 } - fn original_code_len(&self) -> u32 { - self.original_code_len + fn aggregate_code_len(&self) -> u32 { + self.original_code_len.saturating_add(self.code_len()) } fn refcount(&self) -> u32 {