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

Introduce ConstUint to make dependent types in DefaultConfig more adaptable #6425

Merged
merged 4 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all 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 Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ bitvec = { version = "1.0.1", default-features = false }
blake2 = { version = "0.10.4", default-features = false }
blake2b_simd = { version = "1.0.2", default-features = false }
blake3 = { version = "1.5" }
bounded-collections = { version = "0.2.0", default-features = false }
bounded-collections = { version = "0.2.2", default-features = false }
bounded-vec = { version = "0.7" }
bp-asset-hub-rococo = { path = "bridges/chains/chain-asset-hub-rococo", default-features = false }
bp-asset-hub-westend = { path = "bridges/chains/chain-asset-hub-westend", default-features = false }
Expand Down
27 changes: 27 additions & 0 deletions prdoc/pr_6425.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
title: Introduce `ConstUint` to make dependent types in `DefaultConfig` more adaptable
author: conr2d
topic: runtime

doc:
- audience: Runtime Dev
description: |-
Introduce `ConstUint` that is a unified alternative to `ConstU8`, `ConstU16`, and
similar types, particularly useful for configuring `DefaultConfig` in pallets.
It enables configuring the underlying integer for a specific type without the need
to update all dependent types, offering enhanced flexibility in type management.

crates:
- name: frame-support
bump: patch
- name: frame-system
bump: none
- name: pallet-assets
bump: none
- name: pallet-balances
bump: none
- name: pallet-timestamp
bump: none
- name: sp-core
bump: patch
- name: sp-runtime
bump: patch
12 changes: 6 additions & 6 deletions substrate/frame/assets/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ pub mod pallet {
/// Default implementations of [`DefaultConfig`], which can be used to implement [`Config`].
pub mod config_preludes {
use super::*;
use frame_support::{derive_impl, traits::ConstU64};
use frame_support::derive_impl;
pub struct TestDefaultConfig;

#[derive_impl(frame_system::config_preludes::TestDefaultConfig, no_aggregated_types)]
Expand All @@ -289,11 +289,11 @@ pub mod pallet {
type RemoveItemsLimit = ConstU32<5>;
type AssetId = u32;
type AssetIdParameter = u32;
type AssetDeposit = ConstU64<1>;
type AssetAccountDeposit = ConstU64<10>;
type MetadataDepositBase = ConstU64<1>;
type MetadataDepositPerByte = ConstU64<1>;
type ApprovalDeposit = ConstU64<1>;
type AssetDeposit = ConstUint<1>;
type AssetAccountDeposit = ConstUint<10>;
type MetadataDepositBase = ConstUint<1>;
type MetadataDepositPerByte = ConstUint<1>;
type ApprovalDeposit = ConstUint<1>;
type StringLimit = ConstU32<50>;
type Extra = ();
type CallbackHandle = ();
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 @@ -205,7 +205,7 @@ pub mod pallet {
/// Default implementations of [`DefaultConfig`], which can be used to implement [`Config`].
pub mod config_preludes {
use super::*;
use frame_support::{derive_impl, traits::ConstU64};
use frame_support::derive_impl;

pub struct TestDefaultConfig;

Expand All @@ -222,7 +222,7 @@ pub mod pallet {
type RuntimeFreezeReason = ();

type Balance = u64;
type ExistentialDeposit = ConstU64<1>;
type ExistentialDeposit = ConstUint<1>;

type ReserveIdentifier = ();
type FreezeIdentifier = Self::RuntimeFreezeReason;
Expand Down
5 changes: 3 additions & 2 deletions substrate/frame/support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -904,8 +904,9 @@ pub mod pallet_prelude {
StorageList,
},
traits::{
BuildGenesisConfig, ConstU32, EnsureOrigin, Get, GetDefault, GetStorageVersion, Hooks,
IsType, PalletInfoAccess, StorageInfoTrait, StorageVersion, Task, TypedGet,
BuildGenesisConfig, ConstU32, ConstUint, EnsureOrigin, Get, GetDefault,
GetStorageVersion, Hooks, IsType, PalletInfoAccess, StorageInfoTrait, StorageVersion,
Task, TypedGet,
},
Blake2_128, Blake2_128Concat, Blake2_256, CloneNoBound, DebugNoBound, EqNoBound, Identity,
PartialEqNoBound, RuntimeDebugNoBound, Twox128, Twox256, Twox64Concat,
Expand Down
14 changes: 7 additions & 7 deletions substrate/frame/support/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ pub use filter::{ClearFilterGuard, FilterStack, FilterStackGuard, InstanceFilter
mod misc;
pub use misc::{
defensive_prelude::{self, *},
AccountTouch, Backing, ConstBool, ConstI128, ConstI16, ConstI32, ConstI64, ConstI8, ConstU128,
ConstU16, ConstU32, ConstU64, ConstU8, DefensiveMax, DefensiveMin, DefensiveSaturating,
DefensiveTruncateFrom, EnsureInherentsAreFirst, EqualPrivilegeOnly, EstimateCallFee,
ExecuteBlock, ExtrinsicCall, Get, GetBacking, GetDefault, HandleLifetime, InherentBuilder,
IsInherent, IsSubType, IsType, Len, OffchainWorker, OnKilledAccount, OnNewAccount,
PrivilegeCmp, SameOrOther, SignedTransactionBuilder, Time, TryCollect, TryDrop, TypedGet,
UnixTime, VariantCount, VariantCountOf, WrapperKeepOpaque, WrapperOpaque,
AccountTouch, Backing, ConstBool, ConstI128, ConstI16, ConstI32, ConstI64, ConstI8, ConstInt,
ConstU128, ConstU16, ConstU32, ConstU64, ConstU8, ConstUint, DefensiveMax, DefensiveMin,
DefensiveSaturating, DefensiveTruncateFrom, EnsureInherentsAreFirst, EqualPrivilegeOnly,
EstimateCallFee, ExecuteBlock, ExtrinsicCall, Get, GetBacking, GetDefault, HandleLifetime,
InherentBuilder, IsInherent, IsSubType, IsType, Len, OffchainWorker, OnKilledAccount,
OnNewAccount, PrivilegeCmp, SameOrOther, SignedTransactionBuilder, Time, TryCollect, TryDrop,
TypedGet, UnixTime, VariantCount, VariantCountOf, WrapperKeepOpaque, WrapperOpaque,
};
#[allow(deprecated)]
pub use misc::{PreimageProvider, PreimageRecipient};
Expand Down
4 changes: 2 additions & 2 deletions substrate/frame/support/src/traits/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ use sp_core::bounded::bounded_vec::TruncateFrom;
use core::cmp::Ordering;
#[doc(hidden)]
pub use sp_runtime::traits::{
ConstBool, ConstI128, ConstI16, ConstI32, ConstI64, ConstI8, ConstU128, ConstU16, ConstU32,
ConstU64, ConstU8, Get, GetDefault, TryCollect, TypedGet,
ConstBool, ConstI128, ConstI16, ConstI32, ConstI64, ConstI8, ConstInt, ConstU128, ConstU16,
ConstU32, ConstU64, ConstU8, ConstUint, Get, GetDefault, TryCollect, TypedGet,
};
use sp_runtime::{traits::Block as BlockT, DispatchError};

Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/system/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ pub mod pallet {
type Hash = sp_core::hash::H256;
type Hashing = sp_runtime::traits::BlakeTwo256;
type AccountId = u64;
type Lookup = sp_runtime::traits::IdentityLookup<u64>;
type Lookup = sp_runtime::traits::IdentityLookup<Self::AccountId>;
type MaxConsumers = frame_support::traits::ConstU32<16>;
type AccountData = ();
type OnNewAccount = ();
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/timestamp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ pub mod pallet {
impl DefaultConfig for TestDefaultConfig {
type Moment = u64;
type OnTimestampSet = ();
type MinimumPeriod = frame_support::traits::ConstU64<1>;
type MinimumPeriod = ConstUint<1>;
type WeightInfo = ();
}
}
Expand Down
5 changes: 3 additions & 2 deletions substrate/primitives/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,9 @@ pub use bounded_collections as bounded;
#[cfg(feature = "std")]
pub use bounded_collections::{bounded_btree_map, bounded_vec};
pub use bounded_collections::{
parameter_types, ConstBool, ConstI128, ConstI16, ConstI32, ConstI64, ConstI8, ConstU128,
ConstU16, ConstU32, ConstU64, ConstU8, Get, GetDefault, TryCollect, TypedGet,
parameter_types, ConstBool, ConstI128, ConstI16, ConstI32, ConstI64, ConstI8, ConstInt,
ConstU128, ConstU16, ConstU32, ConstU64, ConstU8, ConstUint, Get, GetDefault, TryCollect,
TypedGet,
};
pub use sp_storage as storage;

Expand Down
5 changes: 3 additions & 2 deletions substrate/primitives/runtime/src/traits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ pub use sp_arithmetic::traits::{
use sp_core::{self, storage::StateVersion, Hasher, RuntimeDebug, TypeId, U256};
#[doc(hidden)]
pub use sp_core::{
parameter_types, ConstBool, ConstI128, ConstI16, ConstI32, ConstI64, ConstI8, ConstU128,
ConstU16, ConstU32, ConstU64, ConstU8, Get, GetDefault, TryCollect, TypedGet,
parameter_types, ConstBool, ConstI128, ConstI16, ConstI32, ConstI64, ConstI8, ConstInt,
ConstU128, ConstU16, ConstU32, ConstU64, ConstU8, ConstUint, Get, GetDefault, TryCollect,
TypedGet,
};
#[cfg(feature = "std")]
use std::fmt::Display;
Expand Down
Loading