mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 11:07:56 +00:00
Deprecate V1 Weights (#13699)
* Remove deprecated pallet calls Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Deprecate old weight Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Update Runtime API Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Fix tests Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Delete shitty code Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Fix doctest Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Update frame/alliance/src/lib.rs Co-authored-by: Koute <koute@users.noreply.github.com> * Add doc Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * contracts: Use u64 as old weight type Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Update frame/contracts/src/lib.rs Co-authored-by: Alexander Theißen <alex.theissen@me.com> --------- Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> Co-authored-by: Koute <koute@users.noreply.github.com> Co-authored-by: Alexander Theißen <alex.theissen@me.com> Co-authored-by: parity-processbot <>
This commit is contained in:
committed by
GitHub
parent
0766072393
commit
36957d6760
@@ -550,27 +550,6 @@ impl<T> ClassifyDispatch<T> for (Weight, DispatchClass, Pays) {
|
||||
|
||||
// TODO: Eventually remove these
|
||||
|
||||
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::from_parts(actual_computation, 0)),
|
||||
None => None,
|
||||
};
|
||||
Self { actual_weight, pays_fee: Default::default() }
|
||||
}
|
||||
}
|
||||
|
||||
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::from_parts(actual_time, 0)),
|
||||
None => None,
|
||||
};
|
||||
Self { actual_weight, pays_fee }
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> ClassifyDispatch<T> for u64 {
|
||||
fn classify_dispatch(&self, _: T) -> DispatchClass {
|
||||
DispatchClass::Normal
|
||||
@@ -730,7 +709,7 @@ impl<T> PaysFee<T> for (u64, Pays) {
|
||||
/// ```
|
||||
/// # #[macro_use]
|
||||
/// # extern crate frame_support;
|
||||
/// # use frame_support::{weights::Weight, dispatch::{DispatchResultWithPostInfo, WithPostDispatchInfo}};
|
||||
/// # use frame_support::{weights::Weight, dispatch::{DispatchResultWithPostInfo, WithPostDispatchInfo, PostDispatchInfo}};
|
||||
/// # use frame_system::{Config, ensure_signed};
|
||||
/// decl_module! {
|
||||
/// pub struct Module<T: Config> for enum Call where origin: T::RuntimeOrigin {
|
||||
@@ -744,7 +723,7 @@ impl<T> PaysFee<T> for (u64, Pays) {
|
||||
/// return Ok(None::<Weight>.into());
|
||||
/// }
|
||||
/// // expensive calculation not executed: use only a portion of the weight
|
||||
/// Ok(Some(100_000).into())
|
||||
/// Ok(PostDispatchInfo { actual_weight: Some(Weight::from_parts(100_000, 0)), ..Default::default() })
|
||||
/// }
|
||||
/// }
|
||||
/// }
|
||||
@@ -3214,7 +3193,7 @@ mod tests {
|
||||
OnInitialize, OnRuntimeUpgrade, PalletInfo,
|
||||
},
|
||||
};
|
||||
use sp_weights::RuntimeDbWeight;
|
||||
use sp_weights::{RuntimeDbWeight, Weight};
|
||||
|
||||
pub trait Config: system::Config + Sized
|
||||
where
|
||||
@@ -3535,13 +3514,24 @@ mod tests {
|
||||
fn test_new_call_variant() {
|
||||
Call::<TraitImpl>::new_call_variant_aux_0();
|
||||
}
|
||||
|
||||
pub fn from_actual_ref_time(ref_time: Option<u64>) -> PostDispatchInfo {
|
||||
PostDispatchInfo {
|
||||
actual_weight: ref_time.map(|t| Weight::from_all(t)),
|
||||
pays_fee: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from_post_weight_info(ref_time: Option<u64>, pays_fee: Pays) -> PostDispatchInfo {
|
||||
PostDispatchInfo { actual_weight: ref_time.map(|t| Weight::from_all(t)), pays_fee }
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
// Do not complain about unused `dispatch` and `dispatch_aux`.
|
||||
#[allow(dead_code)]
|
||||
mod weight_tests {
|
||||
use super::*;
|
||||
use super::{tests::*, *};
|
||||
use sp_core::{parameter_types, Get};
|
||||
use sp_weights::RuntimeDbWeight;
|
||||
|
||||
@@ -3655,9 +3645,12 @@ mod weight_tests {
|
||||
#[test]
|
||||
fn extract_actual_weight_works() {
|
||||
let pre = DispatchInfo { weight: Weight::from_parts(1000, 0), ..Default::default() };
|
||||
assert_eq!(extract_actual_weight(&Ok(Some(7).into()), &pre), Weight::from_parts(7, 0));
|
||||
assert_eq!(
|
||||
extract_actual_weight(&Ok(Some(1000).into()), &pre),
|
||||
extract_actual_weight(&Ok(from_actual_ref_time(Some(7))), &pre),
|
||||
Weight::from_parts(7, 0)
|
||||
);
|
||||
assert_eq!(
|
||||
extract_actual_weight(&Ok(from_actual_ref_time(Some(1000))), &pre),
|
||||
Weight::from_parts(1000, 0)
|
||||
);
|
||||
assert_eq!(
|
||||
@@ -3673,7 +3666,7 @@ mod weight_tests {
|
||||
fn extract_actual_weight_caps_at_pre_weight() {
|
||||
let pre = DispatchInfo { weight: Weight::from_parts(1000, 0), ..Default::default() };
|
||||
assert_eq!(
|
||||
extract_actual_weight(&Ok(Some(1250).into()), &pre),
|
||||
extract_actual_weight(&Ok(from_actual_ref_time(Some(1250))), &pre),
|
||||
Weight::from_parts(1000, 0)
|
||||
);
|
||||
assert_eq!(
|
||||
@@ -3688,10 +3681,19 @@ mod weight_tests {
|
||||
#[test]
|
||||
fn extract_actual_pays_fee_works() {
|
||||
let pre = DispatchInfo { weight: Weight::from_parts(1000, 0), ..Default::default() };
|
||||
assert_eq!(extract_actual_pays_fee(&Ok(Some(7).into()), &pre), Pays::Yes);
|
||||
assert_eq!(extract_actual_pays_fee(&Ok(Some(1000).into()), &pre), Pays::Yes);
|
||||
assert_eq!(extract_actual_pays_fee(&Ok((Some(1000), Pays::Yes).into()), &pre), Pays::Yes);
|
||||
assert_eq!(extract_actual_pays_fee(&Ok((Some(1000), Pays::No).into()), &pre), Pays::No);
|
||||
assert_eq!(extract_actual_pays_fee(&Ok(from_actual_ref_time(Some(7))), &pre), Pays::Yes);
|
||||
assert_eq!(
|
||||
extract_actual_pays_fee(&Ok(from_actual_ref_time(Some(1000)).into()), &pre),
|
||||
Pays::Yes
|
||||
);
|
||||
assert_eq!(
|
||||
extract_actual_pays_fee(&Ok(from_post_weight_info(Some(1000), Pays::Yes)), &pre),
|
||||
Pays::Yes
|
||||
);
|
||||
assert_eq!(
|
||||
extract_actual_pays_fee(&Ok(from_post_weight_info(Some(1000), Pays::No)), &pre),
|
||||
Pays::No
|
||||
);
|
||||
assert_eq!(
|
||||
extract_actual_pays_fee(
|
||||
&Err(DispatchError::BadOrigin.with_weight(Weight::from_parts(9, 0))),
|
||||
@@ -3715,9 +3717,12 @@ mod weight_tests {
|
||||
pays_fee: Pays::No,
|
||||
..Default::default()
|
||||
};
|
||||
assert_eq!(extract_actual_pays_fee(&Ok(Some(7).into()), &pre), Pays::No);
|
||||
assert_eq!(extract_actual_pays_fee(&Ok(Some(1000).into()), &pre), Pays::No);
|
||||
assert_eq!(extract_actual_pays_fee(&Ok((Some(1000), Pays::Yes).into()), &pre), Pays::No);
|
||||
assert_eq!(extract_actual_pays_fee(&Ok(from_actual_ref_time(Some(7))), &pre), Pays::No);
|
||||
assert_eq!(extract_actual_pays_fee(&Ok(from_actual_ref_time(Some(1000))), &pre), Pays::No);
|
||||
assert_eq!(
|
||||
extract_actual_pays_fee(&Ok(from_post_weight_info(Some(1000), Pays::Yes)), &pre),
|
||||
Pays::No
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user