mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 23:21:06 +00:00
Remove RefTimeWeight (#12157)
* update api * update * remove unused * remove `one` api * fix unused * fmt * add saturating accrue * remove `Weight::new()` * use some macros * div makes no sense * Update weight_v2.rs * missed some * more patch * fixes * more fixes * more fix * more fix * remove RefTimeWeight * Update frame/contracts/src/storage.rs Co-authored-by: Alexander Theißen <alex.theissen@me.com> * not needed * Fixes Co-authored-by: Alexander Theißen <alex.theissen@me.com> Co-authored-by: Keith Yeung <kungfukeith11@gmail.com>
This commit is contained in:
@@ -1376,7 +1376,7 @@ pub mod pallet_prelude {
|
||||
ConstU32, EnsureOrigin, Get, GetDefault, GetStorageVersion, Hooks, IsType,
|
||||
PalletInfoAccess, StorageInfoTrait, StorageVersion, TypedGet,
|
||||
},
|
||||
weights::{DispatchClass, Pays, RefTimeWeight, Weight},
|
||||
weights::{DispatchClass, Pays, Weight},
|
||||
Blake2_128, Blake2_128Concat, Blake2_256, CloneNoBound, DebugNoBound, EqNoBound, Identity,
|
||||
PartialEqNoBound, RuntimeDebug, RuntimeDebugNoBound, Twox128, Twox256, Twox64Concat,
|
||||
};
|
||||
|
||||
@@ -456,8 +456,8 @@ impl<Call: Encode, Extra: Encode> GetDispatchInfo for sp_runtime::testing::TestX
|
||||
/// be updated all together once proof size is accounted for.
|
||||
#[derive(Clone, Copy, Eq, PartialEq, Default, RuntimeDebug, Encode, Decode, TypeInfo)]
|
||||
pub struct RuntimeDbWeight {
|
||||
pub read: RefTimeWeight,
|
||||
pub write: RefTimeWeight,
|
||||
pub read: u64,
|
||||
pub write: u64,
|
||||
}
|
||||
|
||||
impl RuntimeDbWeight {
|
||||
@@ -727,7 +727,7 @@ mod tests {
|
||||
fn f03(_origin) { unimplemented!(); }
|
||||
|
||||
// weight = a x 10 + b
|
||||
#[weight = ((_a * 10 + _eb * 1) as RefTimeWeight, DispatchClass::Normal, Pays::Yes)]
|
||||
#[weight = ((_a * 10 + _eb * 1) as u64, DispatchClass::Normal, Pays::Yes)]
|
||||
fn f11(_origin, _a: u32, _eb: u32) { unimplemented!(); }
|
||||
|
||||
#[weight = (0, DispatchClass::Operational, Pays::Yes)]
|
||||
|
||||
@@ -24,10 +24,6 @@ use sp_runtime::{
|
||||
|
||||
use super::*;
|
||||
|
||||
/// The unit of measurement for computational time spent when executing runtime logic on reference
|
||||
/// hardware.
|
||||
pub type RefTimeWeight = u64;
|
||||
|
||||
#[derive(
|
||||
Encode,
|
||||
Decode,
|
||||
@@ -46,27 +42,27 @@ pub type RefTimeWeight = u64;
|
||||
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
|
||||
pub struct Weight {
|
||||
/// The weight of computational time used based on some reference hardware.
|
||||
ref_time: RefTimeWeight,
|
||||
ref_time: u64,
|
||||
}
|
||||
|
||||
impl Weight {
|
||||
/// Set the reference time part of the weight.
|
||||
pub const fn set_ref_time(mut self, c: RefTimeWeight) -> Self {
|
||||
pub const fn set_ref_time(mut self, c: u64) -> Self {
|
||||
self.ref_time = c;
|
||||
self
|
||||
}
|
||||
|
||||
/// Return the reference time part of the weight.
|
||||
pub const fn ref_time(&self) -> RefTimeWeight {
|
||||
pub const fn ref_time(&self) -> u64 {
|
||||
self.ref_time
|
||||
}
|
||||
|
||||
/// Return a mutable reference time part of the weight.
|
||||
pub fn ref_time_mut(&mut self) -> &mut RefTimeWeight {
|
||||
pub fn ref_time_mut(&mut self) -> &mut u64 {
|
||||
&mut self.ref_time
|
||||
}
|
||||
|
||||
pub const MAX: Self = Self { ref_time: RefTimeWeight::MAX };
|
||||
pub const MAX: Self = Self { ref_time: u64::MAX };
|
||||
|
||||
/// Get the conservative min of `self` and `other` weight.
|
||||
pub fn min(&self, other: Self) -> Self {
|
||||
@@ -89,7 +85,7 @@ impl Weight {
|
||||
}
|
||||
|
||||
/// Construct [`Weight`] with reference time weight.
|
||||
pub const fn from_ref_time(ref_time: RefTimeWeight) -> Self {
|
||||
pub const fn from_ref_time(ref_time: u64) -> Self {
|
||||
Self { ref_time }
|
||||
}
|
||||
|
||||
@@ -380,8 +376,8 @@ impl sp_runtime::traits::Printable for Weight {
|
||||
|
||||
// TODO: Eventually remove these
|
||||
|
||||
impl From<Option<RefTimeWeight>> for PostDispatchInfo {
|
||||
fn from(maybe_actual_computation: Option<RefTimeWeight>) -> Self {
|
||||
impl From<Option<u64>> for PostDispatchInfo {
|
||||
fn from(maybe_actual_computation: Option<u64>) -> Self {
|
||||
let actual_weight = match maybe_actual_computation {
|
||||
Some(actual_computation) => Some(Weight::zero().set_ref_time(actual_computation)),
|
||||
None => None,
|
||||
@@ -390,8 +386,8 @@ impl From<Option<RefTimeWeight>> for PostDispatchInfo {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<(Option<RefTimeWeight>, Pays)> for PostDispatchInfo {
|
||||
fn from(post_weight_info: (Option<RefTimeWeight>, Pays)) -> Self {
|
||||
impl From<(Option<u64>, Pays)> for PostDispatchInfo {
|
||||
fn from(post_weight_info: (Option<u64>, Pays)) -> Self {
|
||||
let (maybe_actual_time, pays_fee) = post_weight_info;
|
||||
let actual_weight = match maybe_actual_time {
|
||||
Some(actual_time) => Some(Weight::zero().set_ref_time(actual_time)),
|
||||
@@ -401,73 +397,73 @@ impl From<(Option<RefTimeWeight>, Pays)> for PostDispatchInfo {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> WeighData<T> for RefTimeWeight {
|
||||
impl<T> WeighData<T> for u64 {
|
||||
fn weigh_data(&self, _: T) -> Weight {
|
||||
return Weight::zero().set_ref_time(*self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> ClassifyDispatch<T> for RefTimeWeight {
|
||||
impl<T> ClassifyDispatch<T> for u64 {
|
||||
fn classify_dispatch(&self, _: T) -> DispatchClass {
|
||||
DispatchClass::Normal
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> PaysFee<T> for RefTimeWeight {
|
||||
impl<T> PaysFee<T> for u64 {
|
||||
fn pays_fee(&self, _: T) -> Pays {
|
||||
Pays::Yes
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> WeighData<T> for (RefTimeWeight, DispatchClass, Pays) {
|
||||
impl<T> WeighData<T> for (u64, DispatchClass, Pays) {
|
||||
fn weigh_data(&self, args: T) -> Weight {
|
||||
return self.0.weigh_data(args)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> ClassifyDispatch<T> for (RefTimeWeight, DispatchClass, Pays) {
|
||||
impl<T> ClassifyDispatch<T> for (u64, DispatchClass, Pays) {
|
||||
fn classify_dispatch(&self, _: T) -> DispatchClass {
|
||||
self.1
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> PaysFee<T> for (RefTimeWeight, DispatchClass, Pays) {
|
||||
impl<T> PaysFee<T> for (u64, DispatchClass, Pays) {
|
||||
fn pays_fee(&self, _: T) -> Pays {
|
||||
self.2
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> WeighData<T> for (RefTimeWeight, DispatchClass) {
|
||||
impl<T> WeighData<T> for (u64, DispatchClass) {
|
||||
fn weigh_data(&self, args: T) -> Weight {
|
||||
return self.0.weigh_data(args)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> ClassifyDispatch<T> for (RefTimeWeight, DispatchClass) {
|
||||
impl<T> ClassifyDispatch<T> for (u64, DispatchClass) {
|
||||
fn classify_dispatch(&self, _: T) -> DispatchClass {
|
||||
self.1
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> PaysFee<T> for (RefTimeWeight, DispatchClass) {
|
||||
impl<T> PaysFee<T> for (u64, DispatchClass) {
|
||||
fn pays_fee(&self, _: T) -> Pays {
|
||||
Pays::Yes
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> WeighData<T> for (RefTimeWeight, Pays) {
|
||||
impl<T> WeighData<T> for (u64, Pays) {
|
||||
fn weigh_data(&self, args: T) -> Weight {
|
||||
return self.0.weigh_data(args)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> ClassifyDispatch<T> for (RefTimeWeight, Pays) {
|
||||
impl<T> ClassifyDispatch<T> for (u64, Pays) {
|
||||
fn classify_dispatch(&self, _: T) -> DispatchClass {
|
||||
DispatchClass::Normal
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> PaysFee<T> for (RefTimeWeight, Pays) {
|
||||
impl<T> PaysFee<T> for (u64, Pays) {
|
||||
fn pays_fee(&self, _: T) -> Pays {
|
||||
self.1
|
||||
}
|
||||
|
||||
@@ -31,10 +31,7 @@ impl SomeAssociation for u64 {
|
||||
mod pallet_old {
|
||||
use super::SomeAssociation;
|
||||
use frame_support::{
|
||||
decl_error, decl_event, decl_module, decl_storage,
|
||||
traits::Get,
|
||||
weights::{RefTimeWeight, Weight},
|
||||
Parameter,
|
||||
decl_error, decl_event, decl_module, decl_storage, traits::Get, weights::Weight, Parameter,
|
||||
};
|
||||
use frame_system::ensure_root;
|
||||
|
||||
@@ -43,7 +40,7 @@ mod pallet_old {
|
||||
type Balance: Parameter
|
||||
+ codec::HasCompact
|
||||
+ From<u32>
|
||||
+ Into<RefTimeWeight>
|
||||
+ Into<u64>
|
||||
+ Default
|
||||
+ SomeAssociation;
|
||||
type Event: From<Event<Self>> + Into<<Self as frame_system::Config>::Event>;
|
||||
@@ -78,7 +75,7 @@ mod pallet_old {
|
||||
fn deposit_event() = default;
|
||||
const SomeConst: T::Balance = T::SomeConst::get();
|
||||
|
||||
#[weight = <T::Balance as Into<RefTimeWeight>>::into(new_value.clone())]
|
||||
#[weight = <T::Balance as Into<u64>>::into(new_value.clone())]
|
||||
fn set_dummy(origin, #[compact] new_value: T::Balance) {
|
||||
ensure_root(origin)?;
|
||||
|
||||
@@ -116,7 +113,7 @@ pub mod pallet {
|
||||
type Balance: Parameter
|
||||
+ codec::HasCompact
|
||||
+ From<u32>
|
||||
+ Into<RefTimeWeight>
|
||||
+ Into<u64>
|
||||
+ Default
|
||||
+ MaybeSerializeDeserialize
|
||||
+ SomeAssociation
|
||||
@@ -144,7 +141,7 @@ pub mod pallet {
|
||||
|
||||
#[pallet::call]
|
||||
impl<T: Config> Pallet<T> {
|
||||
#[pallet::weight(<T::Balance as Into<RefTimeWeight>>::into(new_value.clone()))]
|
||||
#[pallet::weight(<T::Balance as Into<u64>>::into(new_value.clone()))]
|
||||
pub fn set_dummy(
|
||||
origin: OriginFor<T>,
|
||||
#[pallet::compact] new_value: T::Balance,
|
||||
|
||||
@@ -23,16 +23,13 @@ use frame_support::traits::{ConstU32, ConstU64};
|
||||
|
||||
mod pallet_old {
|
||||
use frame_support::{
|
||||
decl_error, decl_event, decl_module, decl_storage,
|
||||
traits::Get,
|
||||
weights::{RefTimeWeight, Weight},
|
||||
Parameter,
|
||||
decl_error, decl_event, decl_module, decl_storage, traits::Get, weights::Weight, Parameter,
|
||||
};
|
||||
use frame_system::ensure_root;
|
||||
|
||||
pub trait Config<I: Instance = DefaultInstance>: frame_system::Config {
|
||||
type SomeConst: Get<Self::Balance>;
|
||||
type Balance: Parameter + codec::HasCompact + From<u32> + Into<RefTimeWeight> + Default;
|
||||
type Balance: Parameter + codec::HasCompact + From<u32> + Into<u64> + Default;
|
||||
type Event: From<Event<Self, I>> + Into<<Self as frame_system::Config>::Event>;
|
||||
}
|
||||
|
||||
@@ -65,7 +62,7 @@ mod pallet_old {
|
||||
fn deposit_event() = default;
|
||||
const SomeConst: T::Balance = T::SomeConst::get();
|
||||
|
||||
#[weight = <T::Balance as Into<RefTimeWeight>>::into(new_value.clone())]
|
||||
#[weight = <T::Balance as Into<u64>>::into(new_value.clone())]
|
||||
fn set_dummy(origin, #[compact] new_value: T::Balance) {
|
||||
ensure_root(origin)?;
|
||||
|
||||
@@ -102,7 +99,7 @@ pub mod pallet {
|
||||
type Balance: Parameter
|
||||
+ codec::HasCompact
|
||||
+ From<u32>
|
||||
+ Into<RefTimeWeight>
|
||||
+ Into<u64>
|
||||
+ Default
|
||||
+ MaybeSerializeDeserialize
|
||||
+ scale_info::StaticTypeInfo;
|
||||
@@ -129,7 +126,7 @@ pub mod pallet {
|
||||
|
||||
#[pallet::call]
|
||||
impl<T: Config<I>, I: 'static> Pallet<T, I> {
|
||||
#[pallet::weight(<T::Balance as Into<RefTimeWeight>>::into(new_value.clone()))]
|
||||
#[pallet::weight(<T::Balance as Into<u64>>::into(new_value.clone()))]
|
||||
pub fn set_dummy(
|
||||
origin: OriginFor<T>,
|
||||
#[pallet::compact] new_value: T::Balance,
|
||||
|
||||
Reference in New Issue
Block a user