mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-18 10:41:01 +00:00
Ensure correct variant count in Runtime[Hold/Freeze]Reason (#1900)
closes https://github.com/paritytech/polkadot-sdk/issues/1882 ## Breaking Changes This PR introduces a new item to `pallet_balances::Config`: ```diff trait Config { ++ type RuntimeFreezeReasons; } ``` This value is only used to check it against `type MaxFreeze`. A similar check has been added for `MaxHolds` against `RuntimeHoldReasons`, which is already given to `pallet_balances`. In all contexts, you should pass the real `RuntimeFreezeReasons` generated by `construct_runtime` to `type RuntimeFreezeReasons`. Passing `()` would also work, but it would imply that the runtime uses no freezes at all. --------- Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
This commit is contained in:
@@ -207,7 +207,7 @@ pub mod pallet {
|
||||
use super::*;
|
||||
use frame_support::{
|
||||
pallet_prelude::*,
|
||||
traits::{fungible::Credit, tokens::Precision},
|
||||
traits::{fungible::Credit, tokens::Precision, VariantCount},
|
||||
};
|
||||
use frame_system::pallet_prelude::*;
|
||||
|
||||
@@ -229,6 +229,8 @@ pub mod pallet {
|
||||
type RuntimeEvent = ();
|
||||
#[inject_runtime_type]
|
||||
type RuntimeHoldReason = ();
|
||||
#[inject_runtime_type]
|
||||
type RuntimeFreezeReason = ();
|
||||
|
||||
type Balance = u64;
|
||||
type ExistentialDeposit = ConstU64<1>;
|
||||
@@ -256,7 +258,11 @@ pub mod pallet {
|
||||
|
||||
/// The overarching hold reason.
|
||||
#[pallet::no_default_bounds]
|
||||
type RuntimeHoldReason: Parameter + Member + MaxEncodedLen + Copy;
|
||||
type RuntimeHoldReason: Parameter + Member + MaxEncodedLen + Copy + VariantCount;
|
||||
|
||||
/// The overarching freeze reason.
|
||||
#[pallet::no_default_bounds]
|
||||
type RuntimeFreezeReason: VariantCount;
|
||||
|
||||
/// Weight information for extrinsics in this pallet.
|
||||
type WeightInfo: WeightInfo;
|
||||
@@ -544,6 +550,19 @@ pub mod pallet {
|
||||
!<T as Config<I>>::ExistentialDeposit::get().is_zero(),
|
||||
"The existential deposit must be greater than zero!"
|
||||
);
|
||||
|
||||
assert!(
|
||||
T::MaxHolds::get() >= <T::RuntimeHoldReason as VariantCount>::VARIANT_COUNT,
|
||||
"MaxHolds should be greater than or equal to the number of hold reasons: {} < {}",
|
||||
T::MaxHolds::get(),
|
||||
<T::RuntimeHoldReason as VariantCount>::VARIANT_COUNT
|
||||
);
|
||||
|
||||
assert!(
|
||||
T::MaxFreezes::get() >= <T::RuntimeFreezeReason as VariantCount>::VARIANT_COUNT,
|
||||
"MaxFreezes should be greater than or equal to the number of freeze reasons: {} < {}",
|
||||
T::MaxFreezes::get(), <T::RuntimeFreezeReason as VariantCount>::VARIANT_COUNT,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user