mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 06:21:11 +00:00
Weight v1.5: Opaque Struct (#12138)
* initial idea * update frame_support * update a bunch more * add ord * adjust RuntimeDbWeight * frame_system builds * re-export * frame_support tests pass * frame_executive compile * frame_executive builds * frame_system tests passing * pallet-utility tests pass * fix a bunch of pallets * more * phragmen * state-trie-migration * scheduler and referenda * pallet-election-provider-multi-phase * aura * staking * more * babe * balances * bunch more * sudo * transaction-payment * asset-tx-payment * last pallets * fix alliance merge * fix node template runtime * fix pallet-contracts cc @athei * fix node runtime * fix compile on runtime-benchmarks feature * comment * fix frame-support-test * fix more tests * weight regex * frame system works * fix a bunch * more * more * more * more * more * more fixes * update templates * fix contracts benchmarks * Update lib.rs * Update lib.rs * fix ui * make scalar saturating mul const * more const functions * scalar div * refactor using constant functions * move impl * fix overhead template * use compactas * Update lib.rs
This commit is contained in:
@@ -2853,8 +2853,8 @@ benchmarks! {
|
||||
println!("{:#?}", Schedule::<T>::default());
|
||||
println!("###############################################");
|
||||
println!("Lazy deletion throughput per block (empty queue, full queue): {}, {}",
|
||||
weight_limit / weight_per_key,
|
||||
(weight_limit - weight_per_queue_item * queue_depth) / weight_per_key,
|
||||
weight_limit / weight_per_key.ref_time(),
|
||||
(weight_limit - weight_per_queue_item * queue_depth) / weight_per_key.ref_time(),
|
||||
);
|
||||
}
|
||||
#[cfg(not(feature = "std"))]
|
||||
|
||||
@@ -238,7 +238,7 @@ where
|
||||
///
|
||||
/// Weight is synonymous with gas in substrate.
|
||||
pub fn charge_weight(&mut self, amount: Weight) -> Result<ChargedAmount> {
|
||||
self.inner.runtime.charge_gas(RuntimeCosts::ChainExtension(amount))
|
||||
self.inner.runtime.charge_gas(RuntimeCosts::ChainExtension(amount.ref_time()))
|
||||
}
|
||||
|
||||
/// Adjust a previously charged amount down to its actual amount.
|
||||
@@ -248,7 +248,7 @@ where
|
||||
pub fn adjust_weight(&mut self, charged: ChargedAmount, actual_weight: Weight) {
|
||||
self.inner
|
||||
.runtime
|
||||
.adjust_gas(charged, RuntimeCosts::ChainExtension(actual_weight))
|
||||
.adjust_gas(charged, RuntimeCosts::ChainExtension(actual_weight.ref_time()))
|
||||
}
|
||||
|
||||
/// Grants access to the execution environment of the current contract call.
|
||||
@@ -411,7 +411,8 @@ where
|
||||
buffer,
|
||||
allow_skip,
|
||||
|len| {
|
||||
weight_per_byte.map(|w| RuntimeCosts::ChainExtension(w.saturating_mul(len.into())))
|
||||
weight_per_byte
|
||||
.map(|w| RuntimeCosts::ChainExtension(w.ref_time().saturating_mul(len.into())))
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
@@ -664,7 +664,7 @@ where
|
||||
debug_message: Option<&'a mut Vec<u8>>,
|
||||
) -> Result<(Self, E), ExecError> {
|
||||
let (first_frame, executable, nonce) =
|
||||
Self::new_frame(args, value, gas_meter, storage_meter, 0, schedule)?;
|
||||
Self::new_frame(args, value, gas_meter, storage_meter, Weight::zero(), schedule)?;
|
||||
let stack = Self {
|
||||
origin,
|
||||
schedule,
|
||||
@@ -1089,7 +1089,7 @@ where
|
||||
delegated_call: Some(DelegatedCall { executable, caller: self.caller().clone() }),
|
||||
},
|
||||
value,
|
||||
0,
|
||||
Weight::zero(),
|
||||
)?;
|
||||
self.run(executable, input_data)
|
||||
}
|
||||
@@ -1825,7 +1825,7 @@ mod tests {
|
||||
let value = Default::default();
|
||||
let recurse_ch = MockLoader::insert(Call, |ctx, _| {
|
||||
// Try to call into yourself.
|
||||
let r = ctx.ext.call(0, BOB, 0, vec![], true);
|
||||
let r = ctx.ext.call(Weight::zero(), BOB, 0, vec![], true);
|
||||
|
||||
REACHED_BOTTOM.with(|reached_bottom| {
|
||||
let mut reached_bottom = reached_bottom.borrow_mut();
|
||||
@@ -1880,7 +1880,7 @@ mod tests {
|
||||
.with(|caller| *caller.borrow_mut() = Some(ctx.ext.caller().clone()));
|
||||
|
||||
// Call into CHARLIE contract.
|
||||
assert_matches!(ctx.ext.call(0, CHARLIE, 0, vec![], true), Ok(_));
|
||||
assert_matches!(ctx.ext.call(Weight::zero(), CHARLIE, 0, vec![], true), Ok(_));
|
||||
exec_success()
|
||||
});
|
||||
let charlie_ch = MockLoader::insert(Call, |ctx, _| {
|
||||
@@ -2011,7 +2011,7 @@ mod tests {
|
||||
// ALICE is the origin of the call stack
|
||||
assert!(ctx.ext.caller_is_origin());
|
||||
// BOB calls CHARLIE
|
||||
ctx.ext.call(0, CHARLIE, 0, vec![], true)
|
||||
ctx.ext.call(Weight::zero(), CHARLIE, 0, vec![], true)
|
||||
});
|
||||
|
||||
ExtBuilder::default().build().execute_with(|| {
|
||||
@@ -2041,7 +2041,7 @@ mod tests {
|
||||
assert_eq!(*ctx.ext.address(), BOB);
|
||||
|
||||
// Call into charlie contract.
|
||||
assert_matches!(ctx.ext.call(0, CHARLIE, 0, vec![], true), Ok(_));
|
||||
assert_matches!(ctx.ext.call(Weight::zero(), CHARLIE, 0, vec![], true), Ok(_));
|
||||
exec_success()
|
||||
});
|
||||
let charlie_ch = MockLoader::insert(Call, |ctx, _| {
|
||||
@@ -2190,7 +2190,7 @@ mod tests {
|
||||
let (address, output) = ctx
|
||||
.ext
|
||||
.instantiate(
|
||||
0,
|
||||
Weight::zero(),
|
||||
dummy_ch,
|
||||
<Test as Config>::Currency::minimum_balance(),
|
||||
vec![],
|
||||
@@ -2250,7 +2250,7 @@ mod tests {
|
||||
// Instantiate a contract and save it's address in `instantiated_contract_address`.
|
||||
assert_matches!(
|
||||
ctx.ext.instantiate(
|
||||
0,
|
||||
Weight::zero(),
|
||||
dummy_ch,
|
||||
<Test as Config>::Currency::minimum_balance(),
|
||||
vec![],
|
||||
@@ -2342,13 +2342,13 @@ mod tests {
|
||||
let info = ctx.ext.contract_info();
|
||||
assert_eq!(info.storage_deposit, 0);
|
||||
info.storage_deposit = 42;
|
||||
assert_eq!(ctx.ext.call(0, CHARLIE, 0, vec![], true), exec_trapped());
|
||||
assert_eq!(ctx.ext.call(Weight::zero(), CHARLIE, 0, vec![], true), exec_trapped());
|
||||
assert_eq!(ctx.ext.contract_info().storage_deposit, 42);
|
||||
}
|
||||
exec_success()
|
||||
});
|
||||
let code_charlie = MockLoader::insert(Call, |ctx, _| {
|
||||
assert!(ctx.ext.call(0, BOB, 0, vec![99], true).is_ok());
|
||||
assert!(ctx.ext.call(Weight::zero(), BOB, 0, vec![99], true).is_ok());
|
||||
exec_trapped()
|
||||
});
|
||||
|
||||
@@ -2377,7 +2377,7 @@ mod tests {
|
||||
fn recursive_call_during_constructor_fails() {
|
||||
let code = MockLoader::insert(Constructor, |ctx, _| {
|
||||
assert_matches!(
|
||||
ctx.ext.call(0, ctx.ext.address().clone(), 0, vec![], true),
|
||||
ctx.ext.call(Weight::zero(), ctx.ext.address().clone(), 0, vec![], true),
|
||||
Err(ExecError{error, ..}) if error == <Error<Test>>::ContractNotFound.into()
|
||||
);
|
||||
exec_success()
|
||||
@@ -2479,7 +2479,7 @@ mod tests {
|
||||
// call the contract passed as input with disabled reentry
|
||||
let code_bob = MockLoader::insert(Call, |ctx, _| {
|
||||
let dest = Decode::decode(&mut ctx.input_data.as_ref()).unwrap();
|
||||
ctx.ext.call(0, dest, 0, vec![], false)
|
||||
ctx.ext.call(Weight::zero(), dest, 0, vec![], false)
|
||||
});
|
||||
|
||||
let code_charlie = MockLoader::insert(Call, |_, _| exec_success());
|
||||
@@ -2524,7 +2524,7 @@ mod tests {
|
||||
fn call_deny_reentry() {
|
||||
let code_bob = MockLoader::insert(Call, |ctx, _| {
|
||||
if ctx.input_data[0] == 0 {
|
||||
ctx.ext.call(0, CHARLIE, 0, vec![], false)
|
||||
ctx.ext.call(Weight::zero(), CHARLIE, 0, vec![], false)
|
||||
} else {
|
||||
exec_success()
|
||||
}
|
||||
@@ -2532,7 +2532,7 @@ mod tests {
|
||||
|
||||
// call BOB with input set to '1'
|
||||
let code_charlie =
|
||||
MockLoader::insert(Call, |ctx, _| ctx.ext.call(0, BOB, 0, vec![1], true));
|
||||
MockLoader::insert(Call, |ctx, _| ctx.ext.call(Weight::zero(), BOB, 0, vec![1], true));
|
||||
|
||||
ExtBuilder::default().build().execute_with(|| {
|
||||
let schedule = <Test as Config>::Schedule::get();
|
||||
@@ -2695,18 +2695,30 @@ mod tests {
|
||||
let success_code = MockLoader::insert(Constructor, |_, _| exec_success());
|
||||
let succ_fail_code = MockLoader::insert(Constructor, move |ctx, _| {
|
||||
ctx.ext
|
||||
.instantiate(0, fail_code, ctx.ext.minimum_balance() * 100, vec![], &[])
|
||||
.instantiate(
|
||||
Weight::zero(),
|
||||
fail_code,
|
||||
ctx.ext.minimum_balance() * 100,
|
||||
vec![],
|
||||
&[],
|
||||
)
|
||||
.ok();
|
||||
exec_success()
|
||||
});
|
||||
let succ_succ_code = MockLoader::insert(Constructor, move |ctx, _| {
|
||||
let (account_id, _) = ctx
|
||||
.ext
|
||||
.instantiate(0, success_code, ctx.ext.minimum_balance() * 100, vec![], &[])
|
||||
.instantiate(
|
||||
Weight::zero(),
|
||||
success_code,
|
||||
ctx.ext.minimum_balance() * 100,
|
||||
vec![],
|
||||
&[],
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
// a plain call should not influence the account counter
|
||||
ctx.ext.call(0, account_id, 0, vec![], false).unwrap();
|
||||
ctx.ext.call(Weight::zero(), account_id, 0, vec![], false).unwrap();
|
||||
|
||||
exec_success()
|
||||
});
|
||||
|
||||
@@ -107,7 +107,7 @@ where
|
||||
///
|
||||
/// Passing `0` as amount is interpreted as "all remaining gas".
|
||||
pub fn nested(&mut self, amount: Weight) -> Result<Self, DispatchError> {
|
||||
let amount = if amount == 0 { self.gas_left } else { amount };
|
||||
let amount = if amount == Weight::zero() { self.gas_left } else { amount };
|
||||
|
||||
// NOTE that it is ok to allocate all available gas since it still ensured
|
||||
// by `charge` that it doesn't reach zero.
|
||||
@@ -121,7 +121,7 @@ where
|
||||
|
||||
/// Absorb the remaining gas of a nested meter after we are done using it.
|
||||
pub fn absorb_nested(&mut self, nested: Self) {
|
||||
if self.gas_left == 0 {
|
||||
if self.gas_left == Weight::zero() {
|
||||
// All of the remaining gas was inherited by the nested gas meter. When absorbing
|
||||
// we can therefore safely inherit the lowest gas that the nested gas meter experienced
|
||||
// as long as it is lower than the lowest gas that was experienced by the parent.
|
||||
@@ -157,7 +157,7 @@ where
|
||||
}
|
||||
|
||||
let amount = token.weight();
|
||||
let new_value = self.gas_left.checked_sub(amount);
|
||||
let new_value = self.gas_left.checked_sub(&amount);
|
||||
|
||||
// We always consume the gas even if there is not enough gas.
|
||||
self.gas_left = new_value.unwrap_or_else(Zero::zero);
|
||||
@@ -227,7 +227,7 @@ where
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{GasMeter, Token};
|
||||
use super::{GasMeter, Token, Weight};
|
||||
use crate::tests::Test;
|
||||
|
||||
/// A simple utility macro that helps to match against a
|
||||
@@ -271,20 +271,20 @@ mod tests {
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
|
||||
struct SimpleToken(u64);
|
||||
impl Token<Test> for SimpleToken {
|
||||
fn weight(&self) -> u64 {
|
||||
self.0
|
||||
fn weight(&self) -> Weight {
|
||||
Weight::from_ref_time(self.0)
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn it_works() {
|
||||
let gas_meter = GasMeter::<Test>::new(50000);
|
||||
assert_eq!(gas_meter.gas_left(), 50000);
|
||||
let gas_meter = GasMeter::<Test>::new(Weight::from_ref_time(50000));
|
||||
assert_eq!(gas_meter.gas_left(), Weight::from_ref_time(50000));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tracing() {
|
||||
let mut gas_meter = GasMeter::<Test>::new(50000);
|
||||
let mut gas_meter = GasMeter::<Test>::new(Weight::from_ref_time(50000));
|
||||
assert!(!gas_meter.charge(SimpleToken(1)).is_err());
|
||||
|
||||
let mut tokens = gas_meter.tokens().iter();
|
||||
@@ -294,7 +294,7 @@ mod tests {
|
||||
// This test makes sure that nothing can be executed if there is no gas.
|
||||
#[test]
|
||||
fn refuse_to_execute_anything_if_zero() {
|
||||
let mut gas_meter = GasMeter::<Test>::new(0);
|
||||
let mut gas_meter = GasMeter::<Test>::new(Weight::zero());
|
||||
assert!(gas_meter.charge(SimpleToken(1)).is_err());
|
||||
}
|
||||
|
||||
@@ -305,7 +305,7 @@ mod tests {
|
||||
// if the gas meter runs out of gas. However, this is just a nice property to have.
|
||||
#[test]
|
||||
fn overcharge_is_unrecoverable() {
|
||||
let mut gas_meter = GasMeter::<Test>::new(200);
|
||||
let mut gas_meter = GasMeter::<Test>::new(Weight::from_ref_time(200));
|
||||
|
||||
// The first charge is should lead to OOG.
|
||||
assert!(gas_meter.charge(SimpleToken(300)).is_err());
|
||||
@@ -318,7 +318,7 @@ mod tests {
|
||||
// possible.
|
||||
#[test]
|
||||
fn charge_exact_amount() {
|
||||
let mut gas_meter = GasMeter::<Test>::new(25);
|
||||
let mut gas_meter = GasMeter::<Test>::new(Weight::from_ref_time(25));
|
||||
assert!(!gas_meter.charge(SimpleToken(25)).is_err());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ use frame_support::{
|
||||
dispatch::Dispatchable,
|
||||
ensure,
|
||||
traits::{ConstU32, Contains, Currency, Get, Randomness, ReservableCurrency, Time},
|
||||
weights::{DispatchClass, GetDispatchInfo, Pays, PostDispatchInfo, Weight},
|
||||
weights::{DispatchClass, GetDispatchInfo, Pays, PostDispatchInfo, RefTimeWeight, Weight},
|
||||
BoundedVec,
|
||||
};
|
||||
use frame_system::{limits::BlockWeights, Pallet as System};
|
||||
@@ -214,7 +214,7 @@ impl<B: Get<BlockWeights>, const P: u32> Get<Weight> for DefaultContractAccessWe
|
||||
.get(DispatchClass::Normal)
|
||||
.max_total
|
||||
.unwrap_or(block_weights.max_block) /
|
||||
Weight::from(P)
|
||||
RefTimeWeight::from(P)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -873,8 +873,8 @@ where
|
||||
);
|
||||
ContractExecResult {
|
||||
result: output.result.map_err(|r| r.error),
|
||||
gas_consumed: output.gas_meter.gas_consumed(),
|
||||
gas_required: output.gas_meter.gas_required(),
|
||||
gas_consumed: output.gas_meter.gas_consumed().ref_time(),
|
||||
gas_required: output.gas_meter.gas_required().ref_time(),
|
||||
storage_deposit: output.storage_deposit,
|
||||
debug_message: debug_message.unwrap_or_default(),
|
||||
}
|
||||
@@ -918,8 +918,8 @@ where
|
||||
.result
|
||||
.map(|(account_id, result)| InstantiateReturnValue { result, account_id })
|
||||
.map_err(|e| e.error),
|
||||
gas_consumed: output.gas_meter.gas_consumed(),
|
||||
gas_required: output.gas_meter.gas_required(),
|
||||
gas_consumed: output.gas_meter.gas_consumed().ref_time(),
|
||||
gas_required: output.gas_meter.gas_required().ref_time(),
|
||||
storage_deposit: output.storage_deposit,
|
||||
debug_message: debug_message.unwrap_or_default(),
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ use sp_std::{marker::PhantomData, prelude::*};
|
||||
/// Wrapper for all migrations of this pallet, based on `StorageVersion`.
|
||||
pub fn migrate<T: Config>() -> Weight {
|
||||
let version = StorageVersion::get::<Pallet<T>>();
|
||||
let mut weight: Weight = 0;
|
||||
let mut weight = Weight::new();
|
||||
|
||||
if version < 4 {
|
||||
weight = weight.saturating_add(v4::migrate::<T>());
|
||||
@@ -127,7 +127,7 @@ mod v5 {
|
||||
type DeletionQueue<T: Config> = StorageValue<Pallet<T>, Vec<DeletedContract>>;
|
||||
|
||||
pub fn migrate<T: Config>() -> Weight {
|
||||
let mut weight: Weight = 0;
|
||||
let mut weight = Weight::new();
|
||||
|
||||
<ContractInfoOf<T>>::translate(|_key, old: OldContractInfo<T>| {
|
||||
weight = weight.saturating_add(T::DbWeight::get().reads_writes(1, 1));
|
||||
@@ -216,7 +216,7 @@ mod v6 {
|
||||
type OwnerInfoOf<T: Config> = StorageMap<Pallet<T>, Identity, CodeHash<T>, OwnerInfo<T>>;
|
||||
|
||||
pub fn migrate<T: Config>() -> Weight {
|
||||
let mut weight: Weight = 0;
|
||||
let mut weight = Weight::new();
|
||||
|
||||
<ContractInfoOf<T>>::translate(|_key, old: OldContractInfo<T>| {
|
||||
weight = weight.saturating_add(T::DbWeight::get().reads_writes(1, 1));
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
use crate::{weights::WeightInfo, Config};
|
||||
|
||||
use codec::{Decode, Encode};
|
||||
use frame_support::{weights::Weight, DefaultNoBound};
|
||||
use frame_support::{weights::RefTimeWeight, DefaultNoBound};
|
||||
use pallet_contracts_proc_macro::{ScheduleDebug, WeightDebug};
|
||||
use scale_info::TypeInfo;
|
||||
#[cfg(feature = "std")]
|
||||
@@ -255,166 +255,166 @@ pub struct InstructionWeights<T: Config> {
|
||||
#[scale_info(skip_type_params(T))]
|
||||
pub struct HostFnWeights<T: Config> {
|
||||
/// Weight of calling `seal_caller`.
|
||||
pub caller: Weight,
|
||||
pub caller: RefTimeWeight,
|
||||
|
||||
/// Weight of calling `seal_is_contract`.
|
||||
pub is_contract: Weight,
|
||||
pub is_contract: RefTimeWeight,
|
||||
|
||||
/// Weight of calling `seal_code_hash`.
|
||||
pub code_hash: Weight,
|
||||
pub code_hash: RefTimeWeight,
|
||||
|
||||
/// Weight of calling `seal_own_code_hash`.
|
||||
pub own_code_hash: Weight,
|
||||
pub own_code_hash: RefTimeWeight,
|
||||
|
||||
/// Weight of calling `seal_caller_is_origin`.
|
||||
pub caller_is_origin: Weight,
|
||||
pub caller_is_origin: RefTimeWeight,
|
||||
|
||||
/// Weight of calling `seal_address`.
|
||||
pub address: Weight,
|
||||
pub address: RefTimeWeight,
|
||||
|
||||
/// Weight of calling `seal_gas_left`.
|
||||
pub gas_left: Weight,
|
||||
pub gas_left: RefTimeWeight,
|
||||
|
||||
/// Weight of calling `seal_balance`.
|
||||
pub balance: Weight,
|
||||
pub balance: RefTimeWeight,
|
||||
|
||||
/// Weight of calling `seal_value_transferred`.
|
||||
pub value_transferred: Weight,
|
||||
pub value_transferred: RefTimeWeight,
|
||||
|
||||
/// Weight of calling `seal_minimum_balance`.
|
||||
pub minimum_balance: Weight,
|
||||
pub minimum_balance: RefTimeWeight,
|
||||
|
||||
/// Weight of calling `seal_block_number`.
|
||||
pub block_number: Weight,
|
||||
pub block_number: RefTimeWeight,
|
||||
|
||||
/// Weight of calling `seal_now`.
|
||||
pub now: Weight,
|
||||
pub now: RefTimeWeight,
|
||||
|
||||
/// Weight of calling `seal_weight_to_fee`.
|
||||
pub weight_to_fee: Weight,
|
||||
pub weight_to_fee: RefTimeWeight,
|
||||
|
||||
/// Weight of calling `gas`.
|
||||
pub gas: Weight,
|
||||
pub gas: RefTimeWeight,
|
||||
|
||||
/// Weight of calling `seal_input`.
|
||||
pub input: Weight,
|
||||
pub input: RefTimeWeight,
|
||||
|
||||
/// Weight per input byte copied to contract memory by `seal_input`.
|
||||
pub input_per_byte: Weight,
|
||||
pub input_per_byte: RefTimeWeight,
|
||||
|
||||
/// Weight of calling `seal_return`.
|
||||
pub r#return: Weight,
|
||||
pub r#return: RefTimeWeight,
|
||||
|
||||
/// Weight per byte returned through `seal_return`.
|
||||
pub return_per_byte: Weight,
|
||||
pub return_per_byte: RefTimeWeight,
|
||||
|
||||
/// Weight of calling `seal_terminate`.
|
||||
pub terminate: Weight,
|
||||
pub terminate: RefTimeWeight,
|
||||
|
||||
/// Weight of calling `seal_random`.
|
||||
pub random: Weight,
|
||||
pub random: RefTimeWeight,
|
||||
|
||||
/// Weight of calling `seal_reposit_event`.
|
||||
pub deposit_event: Weight,
|
||||
pub deposit_event: RefTimeWeight,
|
||||
|
||||
/// Weight per topic supplied to `seal_deposit_event`.
|
||||
pub deposit_event_per_topic: Weight,
|
||||
pub deposit_event_per_topic: RefTimeWeight,
|
||||
|
||||
/// Weight per byte of an event deposited through `seal_deposit_event`.
|
||||
pub deposit_event_per_byte: Weight,
|
||||
pub deposit_event_per_byte: RefTimeWeight,
|
||||
|
||||
/// Weight of calling `seal_debug_message`.
|
||||
pub debug_message: Weight,
|
||||
pub debug_message: RefTimeWeight,
|
||||
|
||||
/// Weight of calling `seal_set_storage`.
|
||||
pub set_storage: Weight,
|
||||
pub set_storage: RefTimeWeight,
|
||||
|
||||
/// Weight per written byten of an item stored with `seal_set_storage`.
|
||||
pub set_storage_per_new_byte: Weight,
|
||||
pub set_storage_per_new_byte: RefTimeWeight,
|
||||
|
||||
/// Weight per overwritten byte of an item stored with `seal_set_storage`.
|
||||
pub set_storage_per_old_byte: Weight,
|
||||
pub set_storage_per_old_byte: RefTimeWeight,
|
||||
|
||||
/// Weight of calling `seal_set_code_hash`.
|
||||
pub set_code_hash: Weight,
|
||||
pub set_code_hash: RefTimeWeight,
|
||||
|
||||
/// Weight of calling `seal_clear_storage`.
|
||||
pub clear_storage: Weight,
|
||||
pub clear_storage: RefTimeWeight,
|
||||
|
||||
/// Weight of calling `seal_clear_storage` per byte of the stored item.
|
||||
pub clear_storage_per_byte: Weight,
|
||||
pub clear_storage_per_byte: RefTimeWeight,
|
||||
|
||||
/// Weight of calling `seal_contains_storage`.
|
||||
pub contains_storage: Weight,
|
||||
pub contains_storage: RefTimeWeight,
|
||||
|
||||
/// Weight of calling `seal_contains_storage` per byte of the stored item.
|
||||
pub contains_storage_per_byte: Weight,
|
||||
pub contains_storage_per_byte: RefTimeWeight,
|
||||
|
||||
/// Weight of calling `seal_get_storage`.
|
||||
pub get_storage: Weight,
|
||||
pub get_storage: RefTimeWeight,
|
||||
|
||||
/// Weight per byte of an item received via `seal_get_storage`.
|
||||
pub get_storage_per_byte: Weight,
|
||||
pub get_storage_per_byte: RefTimeWeight,
|
||||
|
||||
/// Weight of calling `seal_take_storage`.
|
||||
pub take_storage: Weight,
|
||||
pub take_storage: RefTimeWeight,
|
||||
|
||||
/// Weight per byte of an item received via `seal_take_storage`.
|
||||
pub take_storage_per_byte: Weight,
|
||||
pub take_storage_per_byte: RefTimeWeight,
|
||||
|
||||
/// Weight of calling `seal_transfer`.
|
||||
pub transfer: Weight,
|
||||
pub transfer: RefTimeWeight,
|
||||
|
||||
/// Weight of calling `seal_call`.
|
||||
pub call: Weight,
|
||||
pub call: RefTimeWeight,
|
||||
|
||||
/// Weight of calling `seal_delegate_call`.
|
||||
pub delegate_call: Weight,
|
||||
pub delegate_call: RefTimeWeight,
|
||||
|
||||
/// Weight surcharge that is claimed if `seal_call` does a balance transfer.
|
||||
pub call_transfer_surcharge: Weight,
|
||||
pub call_transfer_surcharge: RefTimeWeight,
|
||||
|
||||
/// Weight per byte that is cloned by supplying the `CLONE_INPUT` flag.
|
||||
pub call_per_cloned_byte: Weight,
|
||||
pub call_per_cloned_byte: RefTimeWeight,
|
||||
|
||||
/// Weight of calling `seal_instantiate`.
|
||||
pub instantiate: Weight,
|
||||
pub instantiate: RefTimeWeight,
|
||||
|
||||
/// Weight surcharge that is claimed if `seal_instantiate` does a balance transfer.
|
||||
pub instantiate_transfer_surcharge: Weight,
|
||||
pub instantiate_transfer_surcharge: RefTimeWeight,
|
||||
|
||||
/// Weight per salt byte supplied to `seal_instantiate`.
|
||||
pub instantiate_per_salt_byte: Weight,
|
||||
pub instantiate_per_salt_byte: RefTimeWeight,
|
||||
|
||||
/// Weight of calling `seal_hash_sha_256`.
|
||||
pub hash_sha2_256: Weight,
|
||||
pub hash_sha2_256: RefTimeWeight,
|
||||
|
||||
/// Weight per byte hashed by `seal_hash_sha_256`.
|
||||
pub hash_sha2_256_per_byte: Weight,
|
||||
pub hash_sha2_256_per_byte: RefTimeWeight,
|
||||
|
||||
/// Weight of calling `seal_hash_keccak_256`.
|
||||
pub hash_keccak_256: Weight,
|
||||
pub hash_keccak_256: RefTimeWeight,
|
||||
|
||||
/// Weight per byte hashed by `seal_hash_keccak_256`.
|
||||
pub hash_keccak_256_per_byte: Weight,
|
||||
pub hash_keccak_256_per_byte: RefTimeWeight,
|
||||
|
||||
/// Weight of calling `seal_hash_blake2_256`.
|
||||
pub hash_blake2_256: Weight,
|
||||
pub hash_blake2_256: RefTimeWeight,
|
||||
|
||||
/// Weight per byte hashed by `seal_hash_blake2_256`.
|
||||
pub hash_blake2_256_per_byte: Weight,
|
||||
pub hash_blake2_256_per_byte: RefTimeWeight,
|
||||
|
||||
/// Weight of calling `seal_hash_blake2_128`.
|
||||
pub hash_blake2_128: Weight,
|
||||
pub hash_blake2_128: RefTimeWeight,
|
||||
|
||||
/// Weight per byte hashed by `seal_hash_blake2_128`.
|
||||
pub hash_blake2_128_per_byte: Weight,
|
||||
pub hash_blake2_128_per_byte: RefTimeWeight,
|
||||
|
||||
/// Weight of calling `seal_ecdsa_recover`.
|
||||
pub ecdsa_recover: Weight,
|
||||
pub ecdsa_recover: RefTimeWeight,
|
||||
|
||||
/// Weight of calling `seal_ecdsa_to_eth_address`.
|
||||
pub ecdsa_to_eth_address: Weight,
|
||||
pub ecdsa_to_eth_address: RefTimeWeight,
|
||||
|
||||
/// The type parameter is used in the default implementation.
|
||||
#[codec(skip)]
|
||||
@@ -435,19 +435,19 @@ macro_rules! call_zero {
|
||||
|
||||
macro_rules! cost_args {
|
||||
($name:ident, $( $arg: expr ),+) => {
|
||||
(T::WeightInfo::$name($( $arg ),+).saturating_sub(call_zero!($name, $( $arg ),+)))
|
||||
(T::WeightInfo::$name($( $arg ),+).saturating_sub(call_zero!($name, $( $arg ),+))).ref_time()
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! cost_batched_args {
|
||||
($name:ident, $( $arg: expr ),+) => {
|
||||
cost_args!($name, $( $arg ),+) / Weight::from(API_BENCHMARK_BATCH_SIZE)
|
||||
cost_args!($name, $( $arg ),+) / RefTimeWeight::from(API_BENCHMARK_BATCH_SIZE)
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! cost_instr_no_params_with_batch_size {
|
||||
($name:ident, $batch_size:expr) => {
|
||||
(cost_args!($name, 1) / Weight::from($batch_size)) as u32
|
||||
(cost_args!($name, 1) / RefTimeWeight::from($batch_size)) as u32
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ use codec::{Decode, Encode, MaxEncodedLen};
|
||||
use frame_support::{
|
||||
dispatch::{DispatchError, DispatchResult},
|
||||
storage::child::{self, ChildInfo},
|
||||
weights::Weight,
|
||||
weights::{RefTimeWeight, Weight},
|
||||
};
|
||||
use scale_info::TypeInfo;
|
||||
use sp_core::crypto::UncheckedFrom;
|
||||
@@ -227,9 +227,11 @@ where
|
||||
let base_weight = T::WeightInfo::on_process_deletion_queue_batch();
|
||||
let weight_per_queue_item = T::WeightInfo::on_initialize_per_queue_item(1) -
|
||||
T::WeightInfo::on_initialize_per_queue_item(0);
|
||||
let weight_per_key = T::WeightInfo::on_initialize_per_trie_key(1) -
|
||||
T::WeightInfo::on_initialize_per_trie_key(0);
|
||||
let decoding_weight = weight_per_queue_item.saturating_mul(queue_len as Weight);
|
||||
let weight_per_key = (T::WeightInfo::on_initialize_per_trie_key(1) -
|
||||
T::WeightInfo::on_initialize_per_trie_key(0))
|
||||
.ref_time();
|
||||
let decoding_weight =
|
||||
weight_per_queue_item.scalar_saturating_mul(queue_len as RefTimeWeight);
|
||||
|
||||
// `weight_per_key` being zero makes no sense and would constitute a failure to
|
||||
// benchmark properly. We opt for not removing any keys at all in this case.
|
||||
@@ -237,7 +239,8 @@ where
|
||||
.saturating_sub(base_weight)
|
||||
.saturating_sub(decoding_weight)
|
||||
.checked_div(weight_per_key)
|
||||
.unwrap_or(0) as u32;
|
||||
.unwrap_or(Weight::zero())
|
||||
.ref_time() as u32;
|
||||
|
||||
(weight_per_key, key_budget)
|
||||
}
|
||||
@@ -248,7 +251,7 @@ where
|
||||
pub fn process_deletion_queue_batch(weight_limit: Weight) -> Weight {
|
||||
let queue_len = <DeletionQueue<T>>::decode_len().unwrap_or(0);
|
||||
if queue_len == 0 {
|
||||
return 0
|
||||
return Weight::zero()
|
||||
}
|
||||
|
||||
let (weight_per_key, mut remaining_key_budget) =
|
||||
@@ -282,7 +285,10 @@ where
|
||||
}
|
||||
|
||||
<DeletionQueue<T>>::put(queue);
|
||||
weight_limit.saturating_sub(weight_per_key.saturating_mul(remaining_key_budget as Weight))
|
||||
let ref_time_weight = weight_limit
|
||||
.ref_time()
|
||||
.saturating_sub(weight_per_key.saturating_mul(remaining_key_budget as RefTimeWeight));
|
||||
Weight::from_ref_time(ref_time_weight)
|
||||
}
|
||||
|
||||
/// Generates a unique trie id by returning `hash(account_id ++ nonce)`.
|
||||
|
||||
@@ -175,7 +175,7 @@ impl ChainExtension<Test> for TestExtension {
|
||||
},
|
||||
0x8002 => {
|
||||
let mut env = env.buf_in_buf_out();
|
||||
let weight = env.read(5)?[4].into();
|
||||
let weight = Weight::from_ref_time(env.read(5)?[4].into());
|
||||
env.charge_weight(weight)?;
|
||||
Ok(RetVal::Converging(id))
|
||||
},
|
||||
@@ -332,7 +332,7 @@ parameter_types! {
|
||||
|
||||
impl Convert<Weight, BalanceOf<Self>> for Test {
|
||||
fn convert(w: Weight) -> BalanceOf<Self> {
|
||||
w
|
||||
w.ref_time()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -355,6 +355,10 @@ impl Contains<Call> for TestFilter {
|
||||
}
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
pub const DeletionWeightLimit: Weight = Weight::from_ref_time(500_000_000_000);
|
||||
}
|
||||
|
||||
impl Config for Test {
|
||||
type Time = Timestamp;
|
||||
type Randomness = Randomness;
|
||||
@@ -368,7 +372,7 @@ impl Config for Test {
|
||||
type ChainExtension =
|
||||
(TestExtension, DisabledExtension, RevertingExtension, TempStorageExtension);
|
||||
type DeletionQueueDepth = ConstU32<1024>;
|
||||
type DeletionWeightLimit = ConstU64<500_000_000_000>;
|
||||
type DeletionWeightLimit = DeletionWeightLimit;
|
||||
type Schedule = MySchedule;
|
||||
type DepositPerByte = DepositPerByte;
|
||||
type DepositPerItem = DepositPerItem;
|
||||
@@ -384,7 +388,7 @@ pub const BOB: AccountId32 = AccountId32::new([2u8; 32]);
|
||||
pub const CHARLIE: AccountId32 = AccountId32::new([3u8; 32]);
|
||||
pub const DJANGO: AccountId32 = AccountId32::new([4u8; 32]);
|
||||
|
||||
pub const GAS_LIMIT: Weight = 100_000_000_000;
|
||||
pub const GAS_LIMIT: Weight = Weight::from_ref_time(100_000_000_000);
|
||||
|
||||
pub struct ExtBuilder {
|
||||
existential_deposit: u64,
|
||||
@@ -642,7 +646,7 @@ fn run_out_of_gas() {
|
||||
Origin::signed(ALICE),
|
||||
addr, // newly created account
|
||||
0,
|
||||
1_000_000_000_000,
|
||||
Weight::from_ref_time(1_000_000_000_000),
|
||||
None,
|
||||
vec![],
|
||||
),
|
||||
@@ -1826,7 +1830,7 @@ fn lazy_removal_works() {
|
||||
assert_matches!(child::get(trie, &[99]), Some(42));
|
||||
|
||||
// Run the lazy removal
|
||||
Contracts::on_idle(System::block_number(), Weight::max_value());
|
||||
Contracts::on_idle(System::block_number(), Weight::MAX);
|
||||
|
||||
// Value should be gone now
|
||||
assert_matches!(child::get::<i32>(trie, &[99]), None);
|
||||
@@ -1896,7 +1900,7 @@ fn lazy_batch_removal_works() {
|
||||
}
|
||||
|
||||
// Run single lazy removal
|
||||
Contracts::on_idle(System::block_number(), Weight::max_value());
|
||||
Contracts::on_idle(System::block_number(), Weight::MAX);
|
||||
|
||||
// The single lazy removal should have removed all queued tries
|
||||
for trie in tries.iter() {
|
||||
@@ -1911,7 +1915,7 @@ fn lazy_removal_partial_remove_works() {
|
||||
|
||||
// We create a contract with some extra keys above the weight limit
|
||||
let extra_keys = 7u32;
|
||||
let weight_limit = 5_000_000_000;
|
||||
let weight_limit = Weight::from_ref_time(5_000_000_000);
|
||||
let (_, max_keys) = Storage::<Test>::deletion_budget(1, weight_limit);
|
||||
let vals: Vec<_> = (0..max_keys + extra_keys)
|
||||
.map(|i| (blake2_256(&i.encode()), (i as u32), (i as u32).encode()))
|
||||
@@ -2085,7 +2089,7 @@ fn lazy_removal_does_no_run_on_low_remaining_weight() {
|
||||
assert_matches!(child::get::<i32>(trie, &[99]), Some(42));
|
||||
|
||||
// Run on_idle with max remaining weight, this should remove the value
|
||||
Contracts::on_idle(System::block_number(), Weight::max_value());
|
||||
Contracts::on_idle(System::block_number(), Weight::MAX);
|
||||
|
||||
// Value should be gone
|
||||
assert_matches!(child::get::<i32>(trie, &[99]), None);
|
||||
@@ -2096,7 +2100,7 @@ fn lazy_removal_does_no_run_on_low_remaining_weight() {
|
||||
fn lazy_removal_does_not_use_all_weight() {
|
||||
let (code, hash) = compile_module::<Test>("self_destruct").unwrap();
|
||||
|
||||
let weight_limit = 5_000_000_000;
|
||||
let weight_limit = Weight::from_ref_time(5_000_000_000);
|
||||
let mut ext = ExtBuilder::default().existential_deposit(50).build();
|
||||
|
||||
let (trie, vals, weight_per_key) = ext.execute_with(|| {
|
||||
@@ -2167,7 +2171,7 @@ fn lazy_removal_does_not_use_all_weight() {
|
||||
let weight_used = Storage::<Test>::process_deletion_queue_batch(weight_limit);
|
||||
|
||||
// We have one less key in our trie than our weight limit suffices for
|
||||
assert_eq!(weight_used, weight_limit - weight_per_key);
|
||||
assert_eq!(weight_used, weight_limit - Weight::from_ref_time(weight_per_key));
|
||||
|
||||
// All the keys are removed
|
||||
for val in vals {
|
||||
@@ -2322,7 +2326,7 @@ fn reinstrument_does_charge() {
|
||||
assert!(result2.gas_consumed > result1.gas_consumed);
|
||||
assert_eq!(
|
||||
result2.gas_consumed,
|
||||
result1.gas_consumed + <Test as Config>::WeightInfo::reinstrument(code_len),
|
||||
result1.gas_consumed + <Test as Config>::WeightInfo::reinstrument(code_len).ref_time(),
|
||||
);
|
||||
});
|
||||
}
|
||||
@@ -2430,7 +2434,7 @@ fn gas_estimation_nested_call_fixed_limit() {
|
||||
let input: Vec<u8> = AsRef::<[u8]>::as_ref(&addr_callee)
|
||||
.iter()
|
||||
.cloned()
|
||||
.chain((GAS_LIMIT / 5).to_le_bytes())
|
||||
.chain((GAS_LIMIT / 5).ref_time().to_le_bytes())
|
||||
.collect();
|
||||
|
||||
// Call in order to determine the gas that is required for this call
|
||||
@@ -2454,7 +2458,7 @@ fn gas_estimation_nested_call_fixed_limit() {
|
||||
ALICE,
|
||||
addr_caller,
|
||||
0,
|
||||
result.gas_required,
|
||||
Weight::from_ref_time(result.gas_required),
|
||||
Some(result.storage_deposit.charge_or_zero()),
|
||||
input,
|
||||
false,
|
||||
@@ -2524,7 +2528,7 @@ fn gas_estimation_call_runtime() {
|
||||
ALICE,
|
||||
addr_caller,
|
||||
0,
|
||||
result.gas_required,
|
||||
Weight::from_ref_time(result.gas_required),
|
||||
None,
|
||||
call.encode(),
|
||||
false,
|
||||
|
||||
@@ -218,14 +218,16 @@ impl<T: Config> Token<T> for CodeToken {
|
||||
// contract code. This is why we subtract `T::*::(0)`. We need to do this at this
|
||||
// point because when charging the general weight for calling the contract we not know the
|
||||
// size of the contract.
|
||||
match *self {
|
||||
let ref_time_weight = match *self {
|
||||
Reinstrument(len) => T::WeightInfo::reinstrument(len),
|
||||
Load(len) => {
|
||||
let computation = T::WeightInfo::call_with_code_per_byte(len)
|
||||
.saturating_sub(T::WeightInfo::call_with_code_per_byte(0));
|
||||
let bandwidth = T::ContractAccessWeight::get().saturating_mul(len.into());
|
||||
let bandwidth = T::ContractAccessWeight::get().scalar_saturating_mul(len as u64);
|
||||
computation.max(bandwidth)
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
ref_time_weight
|
||||
}
|
||||
}
|
||||
|
||||
@@ -365,7 +365,7 @@ mod tests {
|
||||
events: Default::default(),
|
||||
runtime_calls: Default::default(),
|
||||
schedule: Default::default(),
|
||||
gas_meter: GasMeter::new(10_000_000_000),
|
||||
gas_meter: GasMeter::new(Weight::from_ref_time(10_000_000_000)),
|
||||
debug_buffer: Default::default(),
|
||||
ecdsa_recover: Default::default(),
|
||||
}
|
||||
@@ -406,7 +406,7 @@ mod tests {
|
||||
code_hash,
|
||||
value,
|
||||
data: data.to_vec(),
|
||||
gas_left: gas_limit,
|
||||
gas_left: gas_limit.ref_time(),
|
||||
salt: salt.to_vec(),
|
||||
});
|
||||
Ok((
|
||||
@@ -520,7 +520,7 @@ mod tests {
|
||||
16_384
|
||||
}
|
||||
fn get_weight_price(&self, weight: Weight) -> BalanceOf<Self::T> {
|
||||
BalanceOf::<Self::T>::from(1312_u32).saturating_mul(weight.into())
|
||||
BalanceOf::<Self::T>::from(1312_u32).saturating_mul(weight.ref_time().into())
|
||||
}
|
||||
fn schedule(&self) -> &Schedule<Self::T> {
|
||||
&self.schedule
|
||||
@@ -1911,7 +1911,7 @@ mod tests {
|
||||
)]
|
||||
);
|
||||
|
||||
assert!(mock_ext.gas_meter.gas_left() > 0);
|
||||
assert!(mock_ext.gas_meter.gas_left() > Weight::zero());
|
||||
}
|
||||
|
||||
const CODE_DEPOSIT_EVENT_MAX_TOPICS: &str = r#"
|
||||
|
||||
@@ -327,14 +327,14 @@ impl RuntimeCosts {
|
||||
EcdsaRecovery => s.ecdsa_recover,
|
||||
ChainExtension(amount) => amount,
|
||||
#[cfg(feature = "unstable-interface")]
|
||||
CallRuntime(weight) => weight,
|
||||
CallRuntime(weight) => weight.ref_time(),
|
||||
SetCodeHash => s.set_code_hash,
|
||||
EcdsaToEthAddress => s.ecdsa_to_eth_address,
|
||||
};
|
||||
RuntimeToken {
|
||||
#[cfg(test)]
|
||||
_created_from: *self,
|
||||
weight,
|
||||
weight: Weight::from_ref_time(weight),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -857,7 +857,7 @@ where
|
||||
self.charge_gas(RuntimeCosts::CallSurchargeTransfer)?;
|
||||
}
|
||||
self.ext.call(
|
||||
gas,
|
||||
Weight::from_ref_time(gas),
|
||||
callee,
|
||||
value,
|
||||
input_data,
|
||||
@@ -906,6 +906,7 @@ where
|
||||
salt_ptr: u32,
|
||||
salt_len: u32,
|
||||
) -> Result<ReturnCode, TrapReason> {
|
||||
let gas = Weight::from_ref_time(gas);
|
||||
self.charge_gas(RuntimeCosts::InstantiateBase { input_data_len, salt_len })?;
|
||||
let value: BalanceOf<<E as Ext>::T> = self.read_sandbox_memory_as(value_ptr)?;
|
||||
if value > 0u32.into() {
|
||||
@@ -1704,6 +1705,7 @@ pub mod env {
|
||||
out_ptr: u32,
|
||||
out_len_ptr: u32,
|
||||
) -> Result<(), TrapReason> {
|
||||
let gas = Weight::from_ref_time(gas);
|
||||
ctx.charge_gas(RuntimeCosts::WeightToFee)?;
|
||||
Ok(ctx.write_sandbox_output(
|
||||
out_ptr,
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user