Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use aggregated types for RuntimeFreezeReason and better examples of MaxFreezes #4615

Merged
merged 13 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions polkadot/runtime/westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use frame_support::{
traits::{
fungible::HoldConsideration, tokens::UnityOrOuterConversion, ConstU32, Contains, EitherOf,
EitherOfDiverse, EverythingBut, FromContains, InstanceFilter, KeyOwnerProofSystem,
LinearStoragePrice, ProcessMessage, ProcessMessageError, WithdrawReasons,
LinearStoragePrice, ProcessMessage, ProcessMessageError, VariantCountOf, WithdrawReasons,
},
weights::{ConstantMultiplier, WeightMeter, WeightToFee as _},
PalletId,
Expand Down Expand Up @@ -313,7 +313,7 @@ impl pallet_balances::Config for Runtime {
type RuntimeHoldReason = RuntimeHoldReason;
type RuntimeFreezeReason = RuntimeFreezeReason;
type FreezeIdentifier = RuntimeFreezeReason;
type MaxFreezes = ConstU32<1>;
type MaxFreezes = VariantCountOf<RuntimeFreezeReason>;
}

parameter_types! {
Expand Down
4 changes: 2 additions & 2 deletions substrate/bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ use frame_support::{
AsEnsureOriginWithArg, ConstBool, ConstU128, ConstU16, ConstU32, Contains, Currency,
EitherOfDiverse, EnsureOriginWithArg, EqualPrivilegeOnly, Imbalance, InsideBoth,
InstanceFilter, KeyOwnerProofSystem, LinearStoragePrice, LockIdentifier, Nothing,
OnUnbalanced, WithdrawReasons,
OnUnbalanced, VariantCountOf, WithdrawReasons,
},
weights::{
constants::{
Expand Down Expand Up @@ -542,7 +542,7 @@ impl pallet_balances::Config for Runtime {
type AccountStore = frame_system::Pallet<Runtime>;
type WeightInfo = pallet_balances::weights::SubstrateWeight<Runtime>;
type FreezeIdentifier = RuntimeFreezeReason;
type MaxFreezes = ConstU32<1>;
type MaxFreezes = VariantCountOf<RuntimeFreezeReason>;
}

parameter_types! {
Expand Down
4 changes: 2 additions & 2 deletions substrate/frame/balances/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,13 +222,13 @@ pub mod pallet {
type ExistentialDeposit = ConstU64<1>;

type ReserveIdentifier = ();
type FreezeIdentifier = ();
type FreezeIdentifier = Self::RuntimeFreezeReason;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like there is still a few pallets that don't use TestDefaultConfig, reasonable to update them as a part of this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like there is still a few pallets that don't use TestDefaultConfig, reasonable to update them as a part of this PR?

yes, good point, I will do that here

Copy link
Contributor Author

@bkontur bkontur Jun 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kianenigma I updated all (hopefully) pallets for pallet_balances::Config and TestDefaultConfig, please take a look


type DustRemoval = ();

type MaxLocks = ConstU32<100>;
type MaxReserves = ConstU32<100>;
type MaxFreezes = ConstU32<100>;
type MaxFreezes = VariantCountOf<Self::RuntimeFreezeReason>;

type WeightInfo = ();
}
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/balances/src/tests/dispatchable_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ fn force_adjust_total_issuance_saturates() {
ExtBuilder::default().build_and_execute_with(|| {
assert_ok!(Balances::force_set_balance(RuntimeOrigin::root(), 1337, 64));
let ti = Balances::total_issuance();
let max = Balance::max_value();
let max = <Test as Config>::Balance::max_value();
assert_eq!(ti, 64);

// Increment saturates:
Expand Down
13 changes: 4 additions & 9 deletions substrate/frame/balances/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use frame_support::{
parameter_types,
traits::{
fungible, ConstU32, ConstU8, Imbalance as ImbalanceT, OnUnbalanced, StorageMapShim,
StoredMap, VariantCount, WhitelistedStorageKeys,
StoredMap, VariantCount, VariantCountOf, WhitelistedStorageKeys,
},
weights::{IdentityFee, Weight},
};
Expand Down Expand Up @@ -107,22 +107,17 @@ impl pallet_transaction_payment::Config for Test {
type FeeMultiplierUpdate = ();
}

pub(crate) type Balance = u64;

#[derive_impl(pallet_balances::config_preludes::TestDefaultConfig)]
impl Config for Test {
type Balance = Balance;
type DustRemoval = DustTrap;
type RuntimeEvent = RuntimeEvent;
type ExistentialDeposit = ExistentialDeposit;
type AccountStore = TestAccountStore;
type MaxLocks = ConstU32<50>;
type MaxReserves = ConstU32<2>;
type ReserveIdentifier = TestId;
type WeightInfo = ();
type RuntimeHoldReason = TestId;
type RuntimeFreezeReason = RuntimeFreezeReason;
type RuntimeFreezeReason = TestId;
type FreezeIdentifier = TestId;
type MaxFreezes = ConstU32<2>;
type MaxFreezes = VariantCountOf<TestId>;
}

#[derive(Clone)]
Expand Down
4 changes: 2 additions & 2 deletions substrate/frame/delegated-staking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use frame_support::{
assert_ok, derive_impl,
pallet_prelude::*,
parameter_types,
traits::{ConstU64, Currency},
traits::{ConstU64, Currency, VariantCountOf},
PalletId,
};

Expand Down Expand Up @@ -75,7 +75,7 @@ impl pallet_balances::Config for Runtime {
type AccountStore = System;
type WeightInfo = ();
type FreezeIdentifier = RuntimeFreezeReason;
type MaxFreezes = ConstU32<1>;
type MaxFreezes = VariantCountOf<RuntimeFreezeReason>;
type RuntimeHoldReason = RuntimeHoldReason;
type RuntimeFreezeReason = RuntimeFreezeReason;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

use frame_support::{
assert_ok, parameter_types, traits,
traits::{Hooks, UnfilteredDispatchable},
traits::{Hooks, UnfilteredDispatchable, VariantCountOf},
weights::constants,
};
use frame_system::EnsureRoot;
Expand Down Expand Up @@ -111,7 +111,7 @@ impl pallet_balances::Config for Runtime {
type DustRemoval = ();
type ExistentialDeposit = ExistentialDeposit;
type AccountStore = System;
type MaxFreezes = traits::ConstU32<1>;
type MaxFreezes = VariantCountOf<RuntimeFreezeReason>;
type RuntimeHoldReason = RuntimeHoldReason;
type RuntimeFreezeReason = RuntimeFreezeReason;
type FreezeIdentifier = RuntimeFreezeReason;
Expand Down
10 changes: 5 additions & 5 deletions substrate/frame/examples/basic/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::*;
use frame_support::{
assert_ok, derive_impl,
dispatch::{DispatchInfo, GetDispatchInfo},
traits::{ConstU64, OnInitialize},
traits::{ConstU64, OnInitialize, VariantCountOf},
};
use sp_core::H256;
// The testing primitives are very useful for avoiding having to work with signatures
Expand Down Expand Up @@ -81,10 +81,10 @@ impl pallet_balances::Config for Test {
type ExistentialDeposit = ConstU64<1>;
type AccountStore = System;
type WeightInfo = ();
type FreezeIdentifier = ();
type MaxFreezes = ();
type RuntimeHoldReason = ();
type RuntimeFreezeReason = ();
type FreezeIdentifier = RuntimeFreezeReason;
type MaxFreezes = VariantCountOf<RuntimeFreezeReason>;
type RuntimeHoldReason = RuntimeHoldReason;
type RuntimeFreezeReason = RuntimeHoldReason;
}

impl Config for Test {
Expand Down
13 changes: 8 additions & 5 deletions substrate/frame/examples/kitchensink/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
//! Tests for pallet-example-kitchensink.

use crate::*;
use frame_support::{assert_ok, derive_impl, parameter_types, traits::ConstU64};
use frame_support::{
assert_ok, derive_impl, parameter_types,
traits::{ConstU64, VariantCountOf},
};
use sp_runtime::BuildStorage;
// Reexport crate as its pallet name for construct_runtime.
use crate as pallet_example_kitchensink;
Expand Down Expand Up @@ -53,10 +56,10 @@ impl pallet_balances::Config for Test {
type ExistentialDeposit = ConstU64<1>;
type AccountStore = System;
type WeightInfo = ();
type FreezeIdentifier = ();
type MaxFreezes = ();
type RuntimeHoldReason = ();
type RuntimeFreezeReason = ();
type FreezeIdentifier = RuntimeFreezeReason;
type MaxFreezes = VariantCountOf<RuntimeFreezeReason>;
type RuntimeHoldReason = RuntimeHoldReason;
type RuntimeFreezeReason = RuntimeFreezeReason;
}

parameter_types! {
Expand Down
22 changes: 19 additions & 3 deletions substrate/frame/executive/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use frame_support::{
migrations::MultiStepMigrator,
pallet_prelude::*,
parameter_types,
traits::{fungible, ConstU8, Currency, IsInherent},
traits::{fungible, ConstU8, Currency, IsInherent, VariantCount, VariantCountOf},
weights::{ConstantMultiplier, IdentityFee, RuntimeDbWeight, Weight, WeightMeter, WeightToFee},
};
use frame_system::{pallet_prelude::*, ChainContext, LastRuntimeUpgrade, LastRuntimeUpgradeInfo};
Expand Down Expand Up @@ -325,12 +325,24 @@ impl frame_system::Config for Runtime {
type MultiBlockMigrator = MockedModeGetter;
}

#[derive(Encode, Decode, Copy, Clone, Eq, PartialEq, MaxEncodedLen, TypeInfo, RuntimeDebug)]
pub enum FreezeReasonId {
Foo,
}

impl VariantCount for FreezeReasonId {
const VARIANT_COUNT: u32 = 1;
}

type Balance = u64;

#[derive_impl(pallet_balances::config_preludes::TestDefaultConfig)]
impl pallet_balances::Config for Runtime {
type Balance = Balance;
type AccountStore = System;
type RuntimeFreezeReason = FreezeReasonId;
type FreezeIdentifier = FreezeReasonId;
type MaxFreezes = VariantCountOf<FreezeReasonId>;
}

parameter_types! {
Expand Down Expand Up @@ -743,8 +755,12 @@ fn validate_unsigned() {
fn can_not_pay_for_tx_fee_on_full_lock() {
let mut t = new_test_ext(1);
t.execute_with(|| {
<pallet_balances::Pallet<Runtime> as fungible::MutateFreeze<u64>>::set_freeze(&(), &1, 110)
.unwrap();
<pallet_balances::Pallet<Runtime> as fungible::MutateFreeze<u64>>::set_freeze(
&FreezeReasonId::Foo,
&1,
110,
)
.unwrap();
let xt = TestXt::new(
RuntimeCall::System(frame_system::Call::remark { remark: vec![1u8] }),
sign_extra(1, 0, 0),
Expand Down
12 changes: 9 additions & 3 deletions substrate/frame/nomination-pools/benchmarking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@

use crate::VoterBagsListInstance;
use frame_election_provider_support::VoteWeight;
use frame_support::{derive_impl, pallet_prelude::*, parameter_types, traits::ConstU64, PalletId};
use frame_support::{
derive_impl,
pallet_prelude::*,
parameter_types,
traits::{ConstU64, VariantCountOf},
PalletId,
};
use sp_runtime::{
traits::{Convert, IdentityLookup},
BuildStorage, FixedU128, Perbill,
Expand Down Expand Up @@ -76,9 +82,9 @@ impl pallet_balances::Config for Runtime {
type AccountStore = System;
type WeightInfo = ();
type FreezeIdentifier = RuntimeFreezeReason;
type MaxFreezes = ConstU32<1>;
type MaxFreezes = VariantCountOf<RuntimeFreezeReason>;
type RuntimeHoldReason = RuntimeHoldReason;
type RuntimeFreezeReason = ();
type RuntimeFreezeReason = RuntimeFreezeReason;
}

pallet_staking_reward_curve::build! {
Expand Down
7 changes: 4 additions & 3 deletions substrate/frame/nomination-pools/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
use super::*;
use crate::{self as pools};
use frame_support::{
assert_ok, derive_impl, ord_parameter_types, parameter_types, traits::fungible::Mutate,
assert_ok, derive_impl, ord_parameter_types, parameter_types,
traits::{fungible::Mutate, VariantCountOf},
PalletId,
};
use frame_system::{EnsureSignedBy, RawOrigin};
Expand Down Expand Up @@ -280,9 +281,9 @@ impl pallet_balances::Config for Runtime {
type AccountStore = System;
type WeightInfo = ();
type FreezeIdentifier = RuntimeFreezeReason;
type MaxFreezes = ConstU32<1>;
type MaxFreezes = VariantCountOf<RuntimeFreezeReason>;
type RuntimeHoldReason = ();
type RuntimeFreezeReason = ();
type RuntimeFreezeReason = RuntimeFreezeReason;
}

pub struct BalanceToU256;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use frame_support::{
assert_ok, derive_impl,
pallet_prelude::*,
parameter_types,
traits::{ConstU64, ConstU8},
traits::{ConstU64, ConstU8, VariantCountOf},
PalletId,
};
use frame_system::EnsureRoot;
Expand Down Expand Up @@ -89,9 +89,9 @@ impl pallet_balances::Config for Runtime {
type AccountStore = System;
type WeightInfo = ();
type FreezeIdentifier = RuntimeFreezeReason;
type MaxFreezes = ConstU32<1>;
type MaxFreezes = VariantCountOf<RuntimeFreezeReason>;
type RuntimeHoldReason = RuntimeHoldReason;
type RuntimeFreezeReason = ();
type RuntimeFreezeReason = RuntimeFreezeReason;
}

pallet_staking_reward_curve::build! {
Expand Down
8 changes: 5 additions & 3 deletions templates/parachain/runtime/src/configs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ use frame_support::{
derive_impl,
dispatch::DispatchClass,
parameter_types,
traits::{ConstBool, ConstU32, ConstU64, ConstU8, EitherOfDiverse, TransformOrigin},
traits::{
ConstBool, ConstU32, ConstU64, ConstU8, EitherOfDiverse, TransformOrigin, VariantCountOf,
},
weights::{ConstantMultiplier, Weight},
PalletId,
};
Expand Down Expand Up @@ -154,8 +156,8 @@ impl pallet_balances::Config for Runtime {
type ReserveIdentifier = [u8; 8];
type RuntimeHoldReason = RuntimeHoldReason;
type RuntimeFreezeReason = RuntimeFreezeReason;
type FreezeIdentifier = ();
type MaxFreezes = ConstU32<0>;
type FreezeIdentifier = RuntimeFreezeReason;
type MaxFreezes = VariantCountOf<RuntimeFreezeReason>;
}

parameter_types! {
Expand Down
13 changes: 8 additions & 5 deletions templates/solochain/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use sp_std::prelude::*;
use sp_version::NativeVersion;
use sp_version::RuntimeVersion;

use frame_support::genesis_builder_helper::{build_state, get_preset};
pub use frame_support::{
construct_runtime, derive_impl, parameter_types,
traits::{
Expand All @@ -33,6 +32,10 @@ pub use frame_support::{
},
StorageValue,
};
use frame_support::{
genesis_builder_helper::{build_state, get_preset},
traits::VariantCountOf,
};
pub use frame_system::Call as SystemCall;
pub use pallet_balances::Call as BalancesCall;
pub use pallet_timestamp::Call as TimestampCall;
Expand Down Expand Up @@ -218,10 +221,10 @@ impl pallet_balances::Config for Runtime {
type ExistentialDeposit = ConstU128<EXISTENTIAL_DEPOSIT>;
type AccountStore = System;
type WeightInfo = pallet_balances::weights::SubstrateWeight<Runtime>;
type FreezeIdentifier = ();
type MaxFreezes = ();
type RuntimeHoldReason = ();
type RuntimeFreezeReason = ();
type FreezeIdentifier = RuntimeFreezeReason;
type MaxFreezes = VariantCountOf<RuntimeFreezeReason>;
type RuntimeHoldReason = RuntimeHoldReason;
type RuntimeFreezeReason = RuntimeHoldReason;
}

parameter_types! {
Expand Down
Loading