diff --git a/substrate/bin/node/runtime/src/lib.rs b/substrate/bin/node/runtime/src/lib.rs
index 1d460762e4..a98b1700fe 100644
--- a/substrate/bin/node/runtime/src/lib.rs
+++ b/substrate/bin/node/runtime/src/lib.rs
@@ -82,8 +82,8 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
// and set impl_version to 0. If only runtime
// implementation changes and behavior does not, then leave spec_version as
// is and increment impl_version.
- spec_version: 220,
- impl_version: 1,
+ spec_version: 221,
+ impl_version: 0,
apis: RUNTIME_API_VERSIONS,
};
diff --git a/substrate/frame/recovery/src/lib.rs b/substrate/frame/recovery/src/lib.rs
index b456d17c68..6fa00af751 100644
--- a/substrate/frame/recovery/src/lib.rs
+++ b/substrate/frame/recovery/src/lib.rs
@@ -160,10 +160,7 @@ use codec::{Encode, Decode};
use frame_support::{
decl_module, decl_event, decl_storage, decl_error, ensure,
Parameter, RuntimeDebug,
- weights::{
- GetDispatchInfo, PaysFee, DispatchClass, ClassifyDispatch, Weight, WeighData,
- SimpleDispatchInfo,
- },
+ weights::{GetDispatchInfo, SimpleDispatchInfo, FunctionOf},
traits::{Currency, ReservableCurrency, Get, OnReapAccount, BalanceStatus},
};
use frame_system::{self as system, ensure_signed, ensure_root};
@@ -331,10 +328,14 @@ decl_module! {
/// - `call`: The call you want to make with the recovered account.
///
/// #
- /// - The weight of the `call`.
+ /// - The weight of the `call` + 10,000.
/// - One storage lookup to check account is recovered by `who`. O(1)
/// #
- #[weight = ::Call>>::new()]
+ #[weight = FunctionOf(
+ |args: (&T::AccountId, &Box<::Call>)| args.1.get_dispatch_info().weight + 10_000,
+ |args: (&T::AccountId, &Box<::Call>)| args.1.get_dispatch_info().class,
+ true
+ )]
fn as_recovered(origin,
account: T::AccountId,
call: Box<::Call>
@@ -646,25 +647,3 @@ impl OnReapAccount for Module {
>::remove(who);
}
}
-
-/// Simple pass through for the weight functions.
-struct Passthrough(sp_std::marker::PhantomData<(AccountId, Call)>);
-
-impl Passthrough {
- fn new() -> Self { Self(Default::default()) }
-}
-impl WeighData<(&AccountId, &Box)> for Passthrough {
- fn weigh_data(&self, (_, call): (&AccountId, &Box)) -> Weight {
- call.get_dispatch_info().weight + 10_000
- }
-}
-impl ClassifyDispatch<(&AccountId, &Box)> for Passthrough {
- fn classify_dispatch(&self, (_, call): (&AccountId, &Box)) -> DispatchClass {
- call.get_dispatch_info().class
- }
-}
-impl PaysFee<(&AccountId, &Box)> for Passthrough {
- fn pays_fee(&self, (_, call): (&AccountId, &Box)) -> bool {
- call.get_dispatch_info().pays_fee
- }
-}
diff --git a/substrate/frame/utility/src/lib.rs b/substrate/frame/utility/src/lib.rs
index c19b044ad7..501e04ad55 100644
--- a/substrate/frame/utility/src/lib.rs
+++ b/substrate/frame/utility/src/lib.rs
@@ -66,9 +66,9 @@ use codec::{Encode, Decode};
use sp_core::TypeId;
use sp_io::hashing::blake2_256;
use frame_support::{decl_module, decl_event, decl_error, decl_storage, Parameter, ensure, RuntimeDebug};
-use frame_support::{traits::{Get, ReservableCurrency, Currency}, weights::{
- GetDispatchInfo, ClassifyDispatch, WeighData, Weight, DispatchClass, PaysFee
-}};
+use frame_support::{traits::{Get, ReservableCurrency, Currency},
+ weights::{GetDispatchInfo, DispatchClass,FunctionOf},
+};
use frame_system::{self as system, ensure_signed};
use sp_runtime::{DispatchError, DispatchResult, traits::Dispatchable};
@@ -188,126 +188,6 @@ decl_event! {
}
}
-/// Simple index-based pass through for the weight functions.
-struct Passthrough(sp_std::marker::PhantomData);
-
-impl Passthrough {
- fn new() -> Self { Self(Default::default()) }
-}
-impl WeighData<(&u16, &Box)> for Passthrough {
- fn weigh_data(&self, (_, call): (&u16, &Box)) -> Weight {
- call.get_dispatch_info().weight + 10_000
- }
-}
-impl ClassifyDispatch<(&u16, &Box)> for Passthrough {
- fn classify_dispatch(&self, (_, call): (&u16, &Box)) -> DispatchClass {
- call.get_dispatch_info().class
- }
-}
-impl PaysFee<(&u16, &Box)> for Passthrough {
- fn pays_fee(&self, (_, call): (&u16, &Box)) -> bool {
- call.get_dispatch_info().pays_fee
- }
-}
-
-/// Summation pass-through for the weight function of the batch call.
-///
-/// This just adds all of the weights together of all of the calls.
-struct BatchPassthrough(sp_std::marker::PhantomData);
-
-impl BatchPassthrough {
- fn new() -> Self { Self(Default::default()) }
-}
-impl WeighData<(&Vec,)> for BatchPassthrough {
- fn weigh_data(&self, (calls,): (&Vec,)) -> Weight {
- calls.iter()
- .map(|call| call.get_dispatch_info().weight)
- .fold(10_000, |a, n| a + n)
- }
-}
-impl ClassifyDispatch<(&Vec,)> for BatchPassthrough {
- fn classify_dispatch(&self, (calls,): (&Vec,)) -> DispatchClass {
- let all_operational = calls.iter()
- .map(|call| call.get_dispatch_info().class)
- .all(|class| class == DispatchClass::Operational);
- if all_operational {
- DispatchClass::Operational
- } else {
- DispatchClass::Normal
- }
- }
-}
-impl PaysFee<(&Vec,)> for BatchPassthrough {
- fn pays_fee(&self, (calls,): (&Vec,)) -> bool {
- calls.iter()
- .any(|call| call.get_dispatch_info().pays_fee)
- }
-}
-
-/// Simple index-based pass through for the weight functions.
-struct MultiPassthrough(
- sp_std::marker::PhantomData<(Call, AccountId, Timepoint)>
-);
-
-impl MultiPassthrough {
- fn new() -> Self { Self(Default::default()) }
-}
-impl WeighData<(&u16, &Vec, &Timepoint, &Box)>
-for MultiPassthrough
-{
- fn weigh_data(&self, (_, sigs, _, call): (&u16, &Vec, &Timepoint, &Box)) -> Weight {
- call.get_dispatch_info().weight + 10_000 * (sigs.len() as u32 + 1)
- }
-}
-impl ClassifyDispatch<(&u16, &Vec, &Timepoint, &Box)>
-for MultiPassthrough
-{
- fn classify_dispatch(&self, (_, _, _, call): (&u16, &Vec, &Timepoint, &Box))
- -> DispatchClass
- {
- call.get_dispatch_info().class
- }
-}
-impl PaysFee<(&u16, &Vec, &Timepoint, &Box)>
-for MultiPassthrough
-{
- fn pays_fee(&self, _: (&u16, &Vec, &Timepoint, &Box)) -> bool {
- true
- }
-}
-
-/// Simple index-based pass through for the weight functions.
-struct SigsLen(
- sp_std::marker::PhantomData<(AccountId, Timepoint)>
-);
-
-impl SigsLen {
- fn new() -> Self { Self(Default::default()) }
-}
-impl WeighData<(&u16, &Vec, &Timepoint, &[u8; 32])>
-for SigsLen
-{
- fn weigh_data(&self, (_, sigs, _, _): (&u16, &Vec, &Timepoint, &[u8; 32])) -> Weight {
- 10_000 * (sigs.len() as u32 + 1)
- }
-}
-impl ClassifyDispatch<(&u16, &Vec, &Timepoint, &[u8; 32])>
-for SigsLen
-{
- fn classify_dispatch(&self, _: (&u16, &Vec, &Timepoint, &[u8; 32]))
- -> DispatchClass
- {
- DispatchClass::Normal
- }
-}
-impl PaysFee<(&u16, &Vec, &Timepoint, &[u8; 32])>
-for SigsLen
-{
- fn pays_fee(&self, _: (&u16, &Vec, &Timepoint, &[u8; 32])) -> bool {
- true
- }
-}
-
/// A module identifier. These are per module and should be stored in a registry somewhere.
#[derive(Clone, Copy, Eq, PartialEq, Encode, Decode)]
struct IndexedUtilityModuleId(u16);
@@ -341,7 +221,24 @@ decl_module! {
/// `BatchInterrupted` event is deposited, along with the number of successful calls made
/// and the error of the failed call. If all were successful, then the `BatchCompleted`
/// event is deposited.
- #[weight = ::Call>>::new()]
+ #[weight = FunctionOf(
+ |args: (&Vec<::Call>,)| {
+ args.0.iter()
+ .map(|call| call.get_dispatch_info().weight)
+ .fold(10_000, |a, n| a + n)
+ },
+ |args: (&Vec<::Call>,)| {
+ let all_operational = args.0.iter()
+ .map(|call| call.get_dispatch_info().class)
+ .all(|class| class == DispatchClass::Operational);
+ if all_operational {
+ DispatchClass::Operational
+ } else {
+ DispatchClass::Normal
+ }
+ },
+ true
+ )]
fn batch(origin, calls: Vec<::Call>) {
for (index, call) in calls.into_iter().enumerate() {
let result = call.dispatch(origin.clone());
@@ -358,9 +255,13 @@ decl_module! {
/// The dispatch origin for this call must be _Signed_.
///
/// #
- /// - The weight of the `call`.
+ /// - The weight of the `call` + 10,000.
/// #
- #[weight = ::Call>>::new()]
+ #[weight = FunctionOf(
+ |args: (&u16, &Box<::Call>)| args.1.get_dispatch_info().weight + 10_000,
+ |args: (&u16, &Box<::Call>)| args.1.get_dispatch_info().class,
+ true
+ )]
fn as_sub(origin, index: u16, call: Box<::Call>) -> DispatchResult {
let who = ensure_signed(origin)?;
let pseudonym = Self::sub_account_id(who, index);
@@ -408,7 +309,15 @@ decl_module! {
/// deposit taken for its lifetime of
/// `MultisigDepositBase + threshold * MultisigDepositFactor`.
/// #
- #[weight = ::Call, T::AccountId, Option>>>::new()]
+ #[weight = FunctionOf(
+ |args: (&u16, &Vec, &Option>, &Box<::Call>)| {
+ args.3.get_dispatch_info().weight + 10_000 * (args.1.len() as u32 + 1)
+ },
+ |args: (&u16, &Vec, &Option>, &Box<::Call>)| {
+ args.3.get_dispatch_info().class
+ },
+ true
+ )]
fn as_multi(origin,
threshold: u16,
other_signatories: Vec,
@@ -498,7 +407,13 @@ decl_module! {
/// deposit taken for its lifetime of
/// `MultisigDepositBase + threshold * MultisigDepositFactor`.
/// #
- #[weight = >>>::new()]
+ #[weight = FunctionOf(
+ |args: (&u16, &Vec, &Option>, &[u8; 32])| {
+ 10_000 * (args.1.len() as u32 + 1)
+ },
+ DispatchClass::Normal,
+ true
+ )]
fn approve_as_multi(origin,
threshold: u16,
other_signatories: Vec,
@@ -567,7 +482,13 @@ decl_module! {
/// - I/O: 1 read `O(S)`, one remove.
/// - Storage: removes one item.
/// #
- #[weight = >>::new()]
+ #[weight = FunctionOf(
+ |args: (&u16, &Vec, &Timepoint, &[u8; 32])| {
+ 10_000 * (args.1.len() as u32 + 1)
+ },
+ DispatchClass::Normal,
+ true
+ )]
fn cancel_as_multi(origin,
threshold: u16,
other_signatories: Vec,