Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit dbdd27f

Browse files
committed
Migrate away from SimpleDispatchInfo
1 parent d39981d commit dbdd27f

File tree

40 files changed

+439
-394
lines changed

40 files changed

+439
-394
lines changed

bin/node-template/pallets/template/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
/// https://github.com/paritytech/substrate/blob/master/frame/example/src/lib.rs
1111
1212
use frame_support::{decl_module, decl_storage, decl_event, decl_error, dispatch};
13-
use frame_support::weights::{SimpleDispatchInfo, MINIMUM_WEIGHT};
13+
use frame_support::weights::MINIMUM_WEIGHT;
1414
use frame_system::{self as system, ensure_signed};
1515

1616
#[cfg(test)]
@@ -76,7 +76,7 @@ decl_module! {
7676
/// Just a dummy entry point.
7777
/// function that can be called by the external world as an extrinsics call
7878
/// takes a parameter of the type `AccountId`, stores it, and emits an event
79-
#[weight = SimpleDispatchInfo::FixedNormal(MINIMUM_WEIGHT)]
79+
#[weight = MINIMUM_WEIGHT]
8080
pub fn do_something(origin, something: u32) -> dispatch::DispatchResult {
8181
// Check it was signed and get the signer. See also: ensure_root and ensure_none
8282
let who = ensure_signed(origin)?;
@@ -92,7 +92,7 @@ decl_module! {
9292

9393
/// Another dummy entry point.
9494
/// takes no parameters, attempts to increment storage value, and possibly throws an error
95-
#[weight = SimpleDispatchInfo::FixedNormal(MINIMUM_WEIGHT)]
95+
#[weight = MINIMUM_WEIGHT]
9696
pub fn cause_error(origin) -> dispatch::DispatchResult {
9797
// Check it was signed and get the signer. See also: ensure_root and ensure_none
9898
let _who = ensure_signed(origin)?;

frame/assets/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@
133133
#![cfg_attr(not(feature = "std"), no_std)]
134134

135135
use frame_support::{Parameter, decl_module, decl_event, decl_storage, decl_error, ensure};
136-
use frame_support::weights::{SimpleDispatchInfo, MINIMUM_WEIGHT};
136+
use frame_support::weights::MINIMUM_WEIGHT;
137137
use sp_runtime::traits::{Member, AtLeast32Bit, Zero, StaticLookup};
138138
use frame_system::{self as system, ensure_signed};
139139
use sp_runtime::traits::One;
@@ -158,7 +158,7 @@ decl_module! {
158158
/// Issue a new class of fungible assets. There are, and will only ever be, `total`
159159
/// such assets and they'll all belong to the `origin` initially. It will have an
160160
/// identifier `AssetId` instance: this will be specified in the `Issued` event.
161-
#[weight = SimpleDispatchInfo::FixedNormal(MINIMUM_WEIGHT)]
161+
#[weight = MINIMUM_WEIGHT]
162162
fn issue(origin, #[compact] total: T::Balance) {
163163
let origin = ensure_signed(origin)?;
164164

@@ -172,7 +172,7 @@ decl_module! {
172172
}
173173

174174
/// Move some assets from one holder to another.
175-
#[weight = SimpleDispatchInfo::FixedNormal(MINIMUM_WEIGHT)]
175+
#[weight = MINIMUM_WEIGHT]
176176
fn transfer(origin,
177177
#[compact] id: T::AssetId,
178178
target: <T::Lookup as StaticLookup>::Source,
@@ -191,7 +191,7 @@ decl_module! {
191191
}
192192

193193
/// Destroy any assets of `id` owned by `origin`.
194-
#[weight = SimpleDispatchInfo::FixedNormal(MINIMUM_WEIGHT)]
194+
#[weight = MINIMUM_WEIGHT]
195195
fn destroy(origin, #[compact] id: T::AssetId) {
196196
let origin = ensure_signed(origin)?;
197197
let balance = <Balances<T>>::take((id, &origin));

frame/authorship/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use frame_support::traits::{FindAuthor, VerifySeal, Get};
2727
use codec::{Encode, Decode};
2828
use frame_system::ensure_none;
2929
use sp_runtime::traits::{Header as HeaderT, One, Zero};
30-
use frame_support::weights::{Weight, MINIMUM_WEIGHT, SimpleDispatchInfo};
30+
use frame_support::weights::{Weight, MINIMUM_WEIGHT};
3131
use sp_inherents::{InherentIdentifier, ProvideInherent, InherentData};
3232
use sp_authorship::{INHERENT_IDENTIFIER, UnclesInherentData, InherentError};
3333

@@ -207,7 +207,7 @@ decl_module! {
207207
}
208208

209209
/// Provide a set of uncles.
210-
#[weight = SimpleDispatchInfo::FixedMandatory(MINIMUM_WEIGHT)]
210+
#[weight = (MINIMUM_WEIGHT, frame_support::weights::DispatchClass::Mandatory)]
211211
fn set_uncles(origin, new_uncles: Vec<T::Header>) -> dispatch::DispatchResult {
212212
ensure_none(origin)?;
213213
ensure!(new_uncles.len() <= MAX_UNCLES, Error::<T>::TooManyUncles);

frame/benchmark/src/lib.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#![cfg_attr(not(feature = "std"), no_std)]
2222

2323
use frame_support::{decl_module, decl_storage, decl_event, decl_error};
24-
use frame_support::weights::{SimpleDispatchInfo, MINIMUM_WEIGHT};
24+
use frame_support::weights::MINIMUM_WEIGHT;
2525
use frame_support::traits::Currency;
2626
use frame_system::{self as system, ensure_signed};
2727
use codec::{Encode, Decode};
@@ -71,7 +71,7 @@ decl_module! {
7171
fn deposit_event() = default;
7272

7373
/// Do nothing.
74-
#[weight = SimpleDispatchInfo::FixedNormal(MINIMUM_WEIGHT)]
74+
#[weight = MINIMUM_WEIGHT]
7575
pub fn do_nothing(_origin, input: u32) {
7676
if input > 0 {
7777
return Ok(());
@@ -83,15 +83,15 @@ decl_module! {
8383
/// storage database, however, the `repeat` calls will all pull from the
8484
/// storage overlay cache. You must consider this when analyzing the
8585
/// results of the benchmark.
86-
#[weight = SimpleDispatchInfo::FixedNormal(MINIMUM_WEIGHT)]
86+
#[weight = MINIMUM_WEIGHT]
8787
pub fn read_value(_origin, repeat: u32) {
8888
for _ in 0..repeat {
8989
MyValue::get();
9090
}
9191
}
9292

9393
/// Put a value into a storage value.
94-
#[weight = SimpleDispatchInfo::FixedNormal(MINIMUM_WEIGHT)]
94+
#[weight = MINIMUM_WEIGHT]
9595
pub fn put_value(_origin, repeat: u32) {
9696
for r in 0..repeat {
9797
MyValue::put(r);
@@ -103,69 +103,69 @@ decl_module! {
103103
/// storage database, however, the `repeat` calls will all pull from the
104104
/// storage overlay cache. You must consider this when analyzing the
105105
/// results of the benchmark.
106-
#[weight = SimpleDispatchInfo::FixedNormal(MINIMUM_WEIGHT)]
106+
#[weight = MINIMUM_WEIGHT]
107107
pub fn exists_value(_origin, repeat: u32) {
108108
for _ in 0..repeat {
109109
MyValue::exists();
110110
}
111111
}
112112

113113
/// Remove a value from storage `repeat` number of times.
114-
#[weight = SimpleDispatchInfo::FixedNormal(MINIMUM_WEIGHT)]
114+
#[weight = MINIMUM_WEIGHT]
115115
pub fn remove_value(_origin, repeat: u32) {
116116
for r in 0..repeat {
117117
MyMap::remove(r);
118118
}
119119
}
120120

121121
/// Read a value from storage map `repeat` number of times.
122-
#[weight = SimpleDispatchInfo::FixedNormal(MINIMUM_WEIGHT)]
122+
#[weight = MINIMUM_WEIGHT]
123123
pub fn read_map(_origin, repeat: u32) {
124124
for r in 0..repeat {
125125
MyMap::get(r);
126126
}
127127
}
128128

129129
/// Insert a value into a map.
130-
#[weight = SimpleDispatchInfo::FixedNormal(MINIMUM_WEIGHT)]
130+
#[weight = MINIMUM_WEIGHT]
131131
pub fn insert_map(_origin, repeat: u32) {
132132
for r in 0..repeat {
133133
MyMap::insert(r, r);
134134
}
135135
}
136136

137137
/// Check is a map contains a value `repeat` number of times.
138-
#[weight = SimpleDispatchInfo::FixedNormal(MINIMUM_WEIGHT)]
138+
#[weight = MINIMUM_WEIGHT]
139139
pub fn contains_key_map(_origin, repeat: u32) {
140140
for r in 0..repeat {
141141
MyMap::contains_key(r);
142142
}
143143
}
144144

145145
/// Read a value from storage `repeat` number of times.
146-
#[weight = SimpleDispatchInfo::FixedNormal(MINIMUM_WEIGHT)]
146+
#[weight = MINIMUM_WEIGHT]
147147
pub fn remove_prefix(_origin, repeat: u32) {
148148
for r in 0..repeat {
149149
MyDoubleMap::remove_prefix(r);
150150
}
151151
}
152152

153153
/// Add user to the list.
154-
#[weight = SimpleDispatchInfo::FixedNormal(MINIMUM_WEIGHT)]
154+
#[weight = MINIMUM_WEIGHT]
155155
pub fn add_member_list(origin) {
156156
let who = ensure_signed(origin)?;
157157
MyMemberList::<T>::mutate(|x| x.push(who));
158158
}
159159

160160
/// Append user to the list.
161-
#[weight = SimpleDispatchInfo::FixedNormal(MINIMUM_WEIGHT)]
161+
#[weight = MINIMUM_WEIGHT]
162162
pub fn append_member_list(origin) {
163163
let who = ensure_signed(origin)?;
164164
MyMemberList::<T>::append(&[who])?;
165165
}
166166

167167
/// Encode a vector of accounts to bytes.
168-
#[weight = SimpleDispatchInfo::FixedNormal(MINIMUM_WEIGHT)]
168+
#[weight = MINIMUM_WEIGHT]
169169
pub fn encode_accounts(_origin, accounts: Vec<T::AccountId>) {
170170
let bytes = accounts.encode();
171171

@@ -177,7 +177,7 @@ decl_module! {
177177
}
178178

179179
/// Decode bytes into a vector of accounts.
180-
#[weight = SimpleDispatchInfo::FixedNormal(MINIMUM_WEIGHT)]
180+
#[weight = MINIMUM_WEIGHT]
181181
pub fn decode_accounts(_origin, bytes: Vec<u8>) {
182182
let accounts: Vec<T::AccountId> = Decode::decode(&mut bytes.as_slice()).map_err(|_| "Could not decode")?;
183183

frame/benchmarking/src/tests.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use sp_std::prelude::*;
2424
use sp_runtime::{traits::{BlakeTwo256, IdentityLookup}, testing::{H256, Header}};
2525
use frame_support::{
2626
dispatch::DispatchResult,
27-
weights::{SimpleDispatchInfo, MINIMUM_WEIGHT},
27+
weights::MINIMUM_WEIGHT,
2828
decl_module, decl_storage, impl_outer_origin, assert_ok, assert_err, ensure
2929
};
3030
use frame_system::{RawOrigin, ensure_signed, ensure_none};
@@ -37,14 +37,14 @@ decl_storage! {
3737

3838
decl_module! {
3939
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
40-
#[weight = SimpleDispatchInfo::FixedNormal(MINIMUM_WEIGHT)]
40+
#[weight = MINIMUM_WEIGHT]
4141
fn set_value(origin, n: u32) -> DispatchResult {
4242
let _sender = ensure_signed(origin)?;
4343
Value::put(n);
4444
Ok(())
4545
}
4646

47-
#[weight = SimpleDispatchInfo::FixedNormal(MINIMUM_WEIGHT)]
47+
#[weight = MINIMUM_WEIGHT]
4848
fn dummy(origin, _n: u32) -> DispatchResult {
4949
let _sender = ensure_none(origin)?;
5050
Ok(())

frame/collective/src/lib.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ use sp_std::{prelude::*, result};
4040
use sp_core::u32_trait::Value as U32;
4141
use sp_runtime::RuntimeDebug;
4242
use sp_runtime::traits::Hash;
43-
use frame_support::weights::SimpleDispatchInfo;
4443
use frame_support::{
4544
dispatch::{Dispatchable, Parameter}, codec::{Encode, Decode},
4645
traits::{Get, ChangeMembers, InitializeMembers, EnsureOrigin}, decl_module, decl_event,
@@ -187,7 +186,7 @@ decl_module! {
187186
/// - `prime`: The prime member whose vote sets the default.
188187
///
189188
/// Requires root origin.
190-
#[weight = SimpleDispatchInfo::FixedOperational(100_000_000)]
189+
#[weight = (100_000_000, frame_support::weights::DispatchClass::Operational)]
191190
fn set_members(origin, new_members: Vec<T::AccountId>, prime: Option<T::AccountId>) {
192191
ensure_root(origin)?;
193192
let mut new_members = new_members;
@@ -200,7 +199,7 @@ decl_module! {
200199
/// Dispatch a proposal from a member using the `Member` origin.
201200
///
202201
/// Origin must be a member of the collective.
203-
#[weight = SimpleDispatchInfo::FixedOperational(100_000_000)]
202+
#[weight = (100_000_000, frame_support::weights::DispatchClass::Operational)]
204203
fn execute(origin, proposal: Box<<T as Trait<I>>::Proposal>) {
205204
let who = ensure_signed(origin)?;
206205
ensure!(Self::is_member(&who), Error::<T, I>::NotMember);
@@ -214,7 +213,7 @@ decl_module! {
214213
/// - Bounded storage reads and writes.
215214
/// - Argument `threshold` has bearing on weight.
216215
/// # </weight>
217-
#[weight = SimpleDispatchInfo::FixedOperational(5_000_000_000)]
216+
#[weight = (5_000_000_000, frame_support::weights::DispatchClass::Operational)]
218217
fn propose(origin, #[compact] threshold: MemberCount, proposal: Box<<T as Trait<I>>::Proposal>) {
219218
let who = ensure_signed(origin)?;
220219
ensure!(Self::is_member(&who), Error::<T, I>::NotMember);
@@ -244,7 +243,7 @@ decl_module! {
244243
/// - Bounded storage read and writes.
245244
/// - Will be slightly heavier if the proposal is approved / disapproved after the vote.
246245
/// # </weight>
247-
#[weight = SimpleDispatchInfo::FixedOperational(200_000_000)]
246+
#[weight = (200_000_000, frame_support::weights::DispatchClass::Operational)]
248247
fn vote(origin, proposal: T::Hash, #[compact] index: ProposalIndex, approve: bool) {
249248
let who = ensure_signed(origin)?;
250249
ensure!(Self::is_member(&who), Error::<T, I>::NotMember);
@@ -303,7 +302,7 @@ decl_module! {
303302
/// - `M` is number of members,
304303
/// - `P` is number of active proposals,
305304
/// - `L` is the encoded length of `proposal` preimage.
306-
#[weight = SimpleDispatchInfo::FixedOperational(200_000_000)]
305+
#[weight = (200_000_000, frame_support::weights::DispatchClass::Operational)]
307306
fn close(origin, proposal: T::Hash, #[compact] index: ProposalIndex) {
308307
let _ = ensure_signed(origin)?;
309308

frame/contracts/src/lib.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ use sp_runtime::{
123123
RuntimeDebug,
124124
};
125125
use frame_support::dispatch::{DispatchResult, Dispatchable};
126-
use frame_support::weights::{SimpleDispatchInfo, MINIMUM_WEIGHT};
126+
use frame_support::weights::MINIMUM_WEIGHT;
127127
use frame_support::{
128128
Parameter, decl_module, decl_event, decl_storage, decl_error, storage::child,
129129
parameter_types, IsSubType,
@@ -551,7 +551,7 @@ decl_module! {
551551
/// Updates the schedule for metering contracts.
552552
///
553553
/// The schedule must have a greater version than the stored schedule.
554-
#[weight = SimpleDispatchInfo::FixedNormal(MINIMUM_WEIGHT)]
554+
#[weight = MINIMUM_WEIGHT]
555555
pub fn update_schedule(origin, schedule: Schedule) -> DispatchResult {
556556
ensure_root(origin)?;
557557
if <Module<T>>::current_schedule().version >= schedule.version {
@@ -566,7 +566,7 @@ decl_module! {
566566

567567
/// Stores the given binary Wasm code into the chain's storage and returns its `codehash`.
568568
/// You can instantiate contracts only with stored code.
569-
#[weight = SimpleDispatchInfo::FixedNormal(MINIMUM_WEIGHT)]
569+
#[weight = MINIMUM_WEIGHT]
570570
pub fn put_code(
571571
origin,
572572
#[compact] gas_limit: Gas,
@@ -594,7 +594,7 @@ decl_module! {
594594
/// * If the account is a regular account, any value will be transferred.
595595
/// * If no account exists and the call value is not less than `existential_deposit`,
596596
/// a regular account will be created and any value will be transferred.
597-
#[weight = SimpleDispatchInfo::FixedNormal(MINIMUM_WEIGHT)]
597+
#[weight = MINIMUM_WEIGHT]
598598
pub fn call(
599599
origin,
600600
dest: <T::Lookup as StaticLookup>::Source,
@@ -620,7 +620,7 @@ decl_module! {
620620
/// after the execution is saved as the `code` of the account. That code will be invoked
621621
/// upon any call received by this account.
622622
/// - The contract is initialized.
623-
#[weight = SimpleDispatchInfo::FixedNormal(MINIMUM_WEIGHT)]
623+
#[weight = MINIMUM_WEIGHT]
624624
pub fn instantiate(
625625
origin,
626626
#[compact] endowment: BalanceOf<T>,
@@ -643,7 +643,7 @@ decl_module! {
643643
///
644644
/// If contract is not evicted as a result of this call, no actions are taken and
645645
/// the sender is not eligible for the reward.
646-
#[weight = SimpleDispatchInfo::FixedNormal(MINIMUM_WEIGHT)]
646+
#[weight = MINIMUM_WEIGHT]
647647
fn claim_surcharge(origin, dest: T::AccountId, aux_sender: Option<T::AccountId>) {
648648
let origin = origin.into();
649649
let (signed, rewarded) = match (origin, aux_sender) {

0 commit comments

Comments
 (0)