Skip to content

Commit

Permalink
Create sp-weights crate to store weight primitives (paritytech#12219)
Browse files Browse the repository at this point in the history
* Create sp-weights crate to store weight primitives

* Fix templates

* Fix templates

* Fixes

* Fixes

* cargo fmt

* Fixes

* Fixes

* Use deprecated type alias instead of deprecated unit types

* Use deprecated subtraits instead of deprecated hollow new traits

* Fixes

* Allow deprecation in macro expansion

* Add missing where clause during call macro expansion

* cargo fmt

* Fixes

* cargo fmt

* Fixes

* Fixes

* Fixes

* Fixes

* Move FRAME-specific weight files back to frame_support

* Fixes

* Update frame/support/src/dispatch.rs

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>

* Update frame/support/src/dispatch.rs

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>

* Update frame/support/src/dispatch.rs

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>

* Add missing header

* Rewrite module docs

* Fixes

* Fixes

* Fixes

* Fixes

* cargo fmt

Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
  • Loading branch information
3 people authored and ark0f committed Feb 27, 2023
1 parent 3647674 commit 8d55d9b
Show file tree
Hide file tree
Showing 69 changed files with 1,328 additions and 1,237 deletions.
18 changes: 18 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ members = [
"primitives/version",
"primitives/version/proc-macro",
"primitives/wasm-interface",
"primitives/weights",
"test-utils/client",
"test-utils/derive",
"test-utils/runtime",
Expand Down
3 changes: 2 additions & 1 deletion bin/node/executor/tests/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@

use codec::{Decode, Encode, Joiner};
use frame_support::{
dispatch::{DispatchClass, DispatchInfo, GetDispatchInfo},
traits::Currency,
weights::{DispatchClass, DispatchInfo, GetDispatchInfo, Weight},
weights::Weight,
};
use frame_system::{self, AccountInfo, EventRecord, Phase};
use sp_core::{storage::well_known_keys, traits::Externalities};
Expand Down
3 changes: 2 additions & 1 deletion bin/node/executor/tests/fees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@

use codec::{Encode, Joiner};
use frame_support::{
dispatch::GetDispatchInfo,
traits::Currency,
weights::{constants::ExtrinsicBaseWeight, GetDispatchInfo, IdentityFee, WeightToFee},
weights::{constants::ExtrinsicBaseWeight, IdentityFee, WeightToFee},
};
use kitchensink_runtime::{
constants::{currency::*, time::SLOT_DURATION},
Expand Down
5 changes: 4 additions & 1 deletion bin/node/runtime/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,10 @@ mod multiplier_tests {
AdjustmentVariable, MinimumMultiplier, Runtime, RuntimeBlockWeights as BlockWeights,
System, TargetBlockFullness, TransactionPayment,
};
use frame_support::weights::{DispatchClass, Weight, WeightToFee};
use frame_support::{
dispatch::DispatchClass,
weights::{Weight, WeightToFee},
};

fn max_normal() -> Weight {
BlockWeights::get()
Expand Down
3 changes: 2 additions & 1 deletion bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use frame_election_provider_support::{
};
use frame_support::{
construct_runtime,
dispatch::DispatchClass,
pallet_prelude::Get,
parameter_types,
traits::{
Expand All @@ -37,7 +38,7 @@ use frame_support::{
},
weights::{
constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_PER_SECOND},
ConstantMultiplier, DispatchClass, IdentityFee, Weight,
ConstantMultiplier, IdentityFee, Weight,
},
PalletId, RuntimeDebug,
};
Expand Down
4 changes: 2 additions & 2 deletions frame/babe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@

use codec::{Decode, Encode};
use frame_support::{
dispatch::DispatchResultWithPostInfo,
dispatch::{DispatchResultWithPostInfo, Pays},
ensure,
traits::{
ConstU32, DisabledValidators, FindAuthor, Get, KeyOwnerProofSystem, OnTimestampSet,
OneSessionHandler,
},
weights::{Pays, Weight},
weights::Weight,
BoundedVec, WeakBoundedVec,
};
use sp_application_crypto::ByteArray;
Expand Down
2 changes: 1 addition & 1 deletion frame/babe/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
use super::{Call, *};
use frame_support::{
assert_err, assert_noop, assert_ok,
dispatch::{GetDispatchInfo, Pays},
traits::{Currency, EstimateNextSessionRotation, OnFinalize},
weights::{GetDispatchInfo, Pays},
};
use mock::*;
use pallet_session::ShouldEndSession;
Expand Down
3 changes: 2 additions & 1 deletion frame/balances/src/tests_composite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@

use crate::{self as pallet_balances, decl_tests, Config, Pallet};
use frame_support::{
dispatch::DispatchInfo,
parameter_types,
traits::{ConstU32, ConstU64, ConstU8},
weights::{DispatchInfo, IdentityFee, Weight},
weights::{IdentityFee, Weight},
};
use pallet_transaction_payment::CurrencyAdapter;
use sp_core::H256;
Expand Down
3 changes: 2 additions & 1 deletion frame/balances/src/tests_local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@

use crate::{self as pallet_balances, decl_tests, Config, Pallet};
use frame_support::{
dispatch::DispatchInfo,
parameter_types,
traits::{ConstU32, ConstU64, ConstU8, StorageMapShim},
weights::{DispatchInfo, IdentityFee, Weight},
weights::{IdentityFee, Weight},
};
use pallet_transaction_payment::CurrencyAdapter;
use sp_core::H256;
Expand Down
7 changes: 5 additions & 2 deletions frame/collective/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,15 @@ use sp_std::{marker::PhantomData, prelude::*, result};

use frame_support::{
codec::{Decode, Encode, MaxEncodedLen},
dispatch::{DispatchError, DispatchResultWithPostInfo, Dispatchable, PostDispatchInfo},
dispatch::{
DispatchError, DispatchResultWithPostInfo, Dispatchable, GetDispatchInfo, Pays,
PostDispatchInfo,
},
ensure,
traits::{
Backing, ChangeMembers, EnsureOrigin, Get, GetBacking, InitializeMembers, StorageVersion,
},
weights::{GetDispatchInfo, Pays, Weight},
weights::Weight,
};

#[cfg(test)]
Expand Down
5 changes: 3 additions & 2 deletions frame/collective/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@
use super::{Event as CollectiveEvent, *};
use crate as pallet_collective;
use frame_support::{
assert_noop, assert_ok, parameter_types,
assert_noop, assert_ok,
dispatch::Pays,
parameter_types,
traits::{ConstU32, ConstU64, GenesisBuild, StorageVersion},
weights::Pays,
Hashable,
};
use frame_system::{EventRecord, Phase};
Expand Down
4 changes: 2 additions & 2 deletions frame/contracts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ use crate::{
};
use codec::{Encode, HasCompact};
use frame_support::{
dispatch::Dispatchable,
dispatch::{DispatchClass, Dispatchable, GetDispatchInfo, Pays, PostDispatchInfo},
ensure,
traits::{ConstU32, Contains, Currency, Get, Randomness, ReservableCurrency, Time},
weights::{DispatchClass, GetDispatchInfo, Pays, PostDispatchInfo, Weight},
weights::Weight,
BoundedVec,
};
use frame_system::{limits::BlockWeights, Pallet as System};
Expand Down
4 changes: 2 additions & 2 deletions frame/contracts/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ use assert_matches::assert_matches;
use codec::Encode;
use frame_support::{
assert_err, assert_err_ignore_postinfo, assert_noop, assert_ok,
dispatch::DispatchErrorWithPostInfo,
dispatch::{DispatchClass, DispatchErrorWithPostInfo, PostDispatchInfo},
parameter_types,
storage::child,
traits::{
BalanceStatus, ConstU32, ConstU64, Contains, Currency, Get, OnIdle, OnInitialize,
ReservableCurrency,
},
weights::{constants::WEIGHT_PER_SECOND, DispatchClass, PostDispatchInfo, Weight},
weights::{constants::WEIGHT_PER_SECOND, Weight},
};
use frame_system::{self as system, EventRecord, Phase};
use pretty_assertions::{assert_eq, assert_ne};
Expand Down
2 changes: 1 addition & 1 deletion frame/contracts/src/wasm/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2314,7 +2314,7 @@ pub mod env {
call_ptr: u32,
call_len: u32,
) -> Result<ReturnCode, TrapReason> {
use frame_support::{dispatch::GetDispatchInfo, weights::extract_actual_weight};
use frame_support::dispatch::{extract_actual_weight, GetDispatchInfo};
ctx.charge_gas(RuntimeCosts::CopyFromContract(call_len))?;
let call: <E::T as Config>::RuntimeCall =
ctx.read_sandbox_memory_as_unbounded(call_ptr, call_len)?;
Expand Down
3 changes: 2 additions & 1 deletion frame/election-provider-multi-phase/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,10 @@ use frame_election_provider_support::{
ElectionDataProvider, ElectionProvider, InstantElectionProvider, NposSolution,
};
use frame_support::{
dispatch::DispatchClass,
ensure,
traits::{Currency, Get, OnUnbalanced, ReservableCurrency},
weights::{DispatchClass, Weight},
weights::Weight,
};
use frame_system::{ensure_none, offchain::SendTransactionTypes};
use scale_info::TypeInfo;
Expand Down
2 changes: 1 addition & 1 deletion frame/election-provider-support/src/onchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
use crate::{
Debug, ElectionDataProvider, ElectionProvider, InstantElectionProvider, NposSolver, WeightInfo,
};
use frame_support::{traits::Get, weights::DispatchClass};
use frame_support::{dispatch::DispatchClass, traits::Get};
use sp_npos_elections::*;
use sp_std::{collections::btree_map::BTreeMap, marker::PhantomData, prelude::*};

Expand Down
4 changes: 2 additions & 2 deletions frame/examples/basic/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,9 +273,9 @@

use codec::{Decode, Encode};
use frame_support::{
dispatch::DispatchResult,
dispatch::{ClassifyDispatch, DispatchClass, DispatchResult, Pays, PaysFee, WeighData},
traits::IsSubType,
weights::{ClassifyDispatch, DispatchClass, Pays, PaysFee, WeighData, Weight},
weights::Weight,
};
use frame_system::ensure_signed;
use log::info;
Expand Down
5 changes: 3 additions & 2 deletions frame/examples/basic/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@

use crate::*;
use frame_support::{
assert_ok, parameter_types,
assert_ok,
dispatch::{DispatchInfo, GetDispatchInfo},
parameter_types,
traits::{ConstU64, OnInitialize},
weights::{DispatchInfo, GetDispatchInfo},
};
use sp_core::H256;
// The testing primitives are very useful for avoiding having to work with signatures
Expand Down
4 changes: 2 additions & 2 deletions frame/executive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,12 @@

use codec::{Codec, Encode};
use frame_support::{
dispatch::PostDispatchInfo,
dispatch::{DispatchClass, DispatchInfo, GetDispatchInfo, PostDispatchInfo},
traits::{
EnsureInherentsAreFirst, ExecuteBlock, OffchainWorker, OnFinalize, OnIdle, OnInitialize,
OnRuntimeUpgrade,
},
weights::{DispatchClass, DispatchInfo, GetDispatchInfo, Weight},
weights::Weight,
};
use sp_runtime::{
generic::Digest,
Expand Down
4 changes: 2 additions & 2 deletions frame/grandpa/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ use fg_primitives::{
GRANDPA_ENGINE_ID,
};
use frame_support::{
dispatch::DispatchResultWithPostInfo,
dispatch::{DispatchResultWithPostInfo, Pays},
pallet_prelude::Get,
storage,
traits::{KeyOwnerProofSystem, OneSessionHandler},
weights::{Pays, Weight},
weights::Weight,
WeakBoundedVec,
};
use scale_info::TypeInfo;
Expand Down
2 changes: 1 addition & 1 deletion frame/grandpa/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ use codec::Encode;
use fg_primitives::ScheduledChange;
use frame_support::{
assert_err, assert_noop, assert_ok,
dispatch::{GetDispatchInfo, Pays},
traits::{Currency, OnFinalize, OneSessionHandler},
weights::{GetDispatchInfo, Pays},
};
use frame_system::{EventRecord, Phase};
use sp_core::H256;
Expand Down
5 changes: 3 additions & 2 deletions frame/multisig/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,12 @@ pub mod weights;
use codec::{Decode, Encode};
use frame_support::{
dispatch::{
DispatchErrorWithPostInfo, DispatchResult, DispatchResultWithPostInfo, PostDispatchInfo,
DispatchErrorWithPostInfo, DispatchResult, DispatchResultWithPostInfo, GetDispatchInfo,
PostDispatchInfo,
},
ensure,
traits::{Currency, Get, ReservableCurrency, WrapperKeepOpaque},
weights::{GetDispatchInfo, Weight},
weights::Weight,
RuntimeDebug,
};
use frame_system::{self as system, RawOrigin};
Expand Down
2 changes: 1 addition & 1 deletion frame/preimage/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ use sp_std::prelude::*;

use codec::{Decode, Encode, MaxEncodedLen};
use frame_support::{
dispatch::Pays,
ensure,
pallet_prelude::Get,
traits::{Currency, PreimageProvider, PreimageRecipient, ReservableCurrency},
weights::Pays,
BoundedVec,
};
use scale_info::TypeInfo;
Expand Down
3 changes: 1 addition & 2 deletions frame/proxy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,9 @@ pub mod weights;

use codec::{Decode, Encode, MaxEncodedLen};
use frame_support::{
dispatch::DispatchError,
dispatch::{DispatchError, GetDispatchInfo},
ensure,
traits::{Currency, Get, InstanceFilter, IsSubType, IsType, OriginTrait, ReservableCurrency},
weights::GetDispatchInfo,
RuntimeDebug,
};
use frame_system::{self as system};
Expand Down
3 changes: 1 addition & 2 deletions frame/ranked-collective/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,9 @@ use sp_std::{marker::PhantomData, prelude::*};

use frame_support::{
codec::{Decode, Encode, MaxEncodedLen},
dispatch::{DispatchError, DispatchResultWithPostInfo},
dispatch::{DispatchError, DispatchResultWithPostInfo, PostDispatchInfo},
ensure,
traits::{EnsureOrigin, PollStatus, Polling, VoteTally},
weights::PostDispatchInfo,
CloneNoBound, EqNoBound, PartialEqNoBound, RuntimeDebugNoBound,
};

Expand Down
3 changes: 1 addition & 2 deletions frame/recovery/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,8 @@ use sp_runtime::traits::{CheckedAdd, CheckedMul, Dispatchable, SaturatedConversi
use sp_std::prelude::*;

use frame_support::{
dispatch::PostDispatchInfo,
dispatch::{GetDispatchInfo, PostDispatchInfo},
traits::{BalanceStatus, Currency, ReservableCurrency},
weights::GetDispatchInfo,
BoundedVec, RuntimeDebug,
};

Expand Down
4 changes: 2 additions & 2 deletions frame/scheduler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ pub mod weights;

use codec::{Codec, Decode, Encode};
use frame_support::{
dispatch::{DispatchError, DispatchResult, Dispatchable, Parameter},
dispatch::{DispatchError, DispatchResult, Dispatchable, GetDispatchInfo, Parameter},
traits::{
schedule::{self, DispatchTime, MaybeHashed},
EnsureOrigin, Get, IsType, OriginTrait, PalletInfoAccess, PrivilegeCmp, StorageVersion,
},
weights::{GetDispatchInfo, Weight},
weights::Weight,
};
use frame_system::{self as system, ensure_signed};
pub use pallet::*;
Expand Down
Loading

0 comments on commit 8d55d9b

Please sign in to comment.