Skip to content

Commit

Permalink
Replace const parameters types (paritytech#1691)
Browse files Browse the repository at this point in the history
* Replace const parameters

* fmt

* missed out Maxlocks
  • Loading branch information
Binston Sukhael Cardoza authored and serban300 committed Apr 9, 2024
1 parent b81a3c3 commit 27a7b7d
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 95 deletions.
41 changes: 15 additions & 26 deletions bridges/bin/millau/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ pub use frame_support::{
construct_runtime,
dispatch::DispatchClass,
parameter_types,
traits::{Currency, ExistenceRequirement, Imbalance, KeyOwnerProofSystem},
traits::{ConstU32, ConstU8, Currency, ExistenceRequirement, Imbalance, KeyOwnerProofSystem},
weights::{
constants::WEIGHT_PER_SECOND, ConstantMultiplier, IdentityFee, RuntimeDbWeight, Weight,
},
Expand Down Expand Up @@ -215,19 +215,15 @@ impl frame_system::Config for Runtime {

impl pallet_randomness_collective_flip::Config for Runtime {}

parameter_types! {
pub const MaxAuthorities: u32 = 10;
}

impl pallet_aura::Config for Runtime {
type AuthorityId = AuraId;
type MaxAuthorities = MaxAuthorities;
type MaxAuthorities = ConstU32<10>;
type DisabledValidators = ();
}

impl pallet_beefy::Config for Runtime {
type BeefyId = BeefyId;
type MaxAuthorities = MaxAuthorities;
type MaxAuthorities = ConstU32<10>;
type OnNewValidatorSet = MmrLeaf;
}

Expand All @@ -243,7 +239,7 @@ impl pallet_grandpa::Config for Runtime {
type HandleEquivocation = ();
// TODO: update me (https://github.com/paritytech/parity-bridges-common/issues/78)
type WeightInfo = ();
type MaxAuthorities = MaxAuthorities;
type MaxAuthorities = ConstU32<10>;
}

/// MMR helper types.
Expand Down Expand Up @@ -311,10 +307,6 @@ impl pallet_timestamp::Config for Runtime {

parameter_types! {
pub const ExistentialDeposit: bp_millau::Balance = 500;
// For weight estimation, we assume that the most locks on an individual account will be 50.
// This number may need to be adjusted in the future if this assumption no longer holds true.
pub const MaxLocks: u32 = 50;
pub const MaxReserves: u32 = 50;
}

impl pallet_balances::Config for Runtime {
Expand All @@ -327,15 +319,16 @@ impl pallet_balances::Config for Runtime {
type AccountStore = System;
// TODO: update me (https://github.com/paritytech/parity-bridges-common/issues/78)
type WeightInfo = ();
type MaxLocks = MaxLocks;
type MaxReserves = MaxReserves;
// For weight estimation, we assume that the most locks on an individual account will be 50.
// This number may need to be adjusted in the future if this assumption no longer holds true.
type MaxLocks = ConstU32<50>;
type MaxReserves = ConstU32<50>;
type ReserveIdentifier = [u8; 8];
}

parameter_types! {
pub const TransactionBaseFee: Balance = 0;
pub const TransactionByteFee: Balance = 1;
pub const OperationalFeeMultiplier: u8 = 5;
// values for following parameters are copied from polkadot repo, but it is fine
// not to sync them - we're not going to make Rialto a full copy of one of Polkadot-like chains
pub const TargetBlockFullness: Perquintill = Perquintill::from_percent(25);
Expand All @@ -346,7 +339,7 @@ parameter_types! {

impl pallet_transaction_payment::Config for Runtime {
type OnChargeTransaction = pallet_transaction_payment::CurrencyAdapter<Balances, ()>;
type OperationalFeeMultiplier = OperationalFeeMultiplier;
type OperationalFeeMultiplier = ConstU8<5>;
type WeightToFee = bp_millau::WeightToFee;
type LengthToFee = ConstantMultiplier<Balance, TransactionByteFee>;
type FeeMultiplierUpdate = pallet_transaction_payment::TargetedFeeAdjustment<
Expand Down Expand Up @@ -383,14 +376,6 @@ impl pallet_session::Config for Runtime {
type WeightInfo = ();
}

parameter_types! {
// This is a pretty unscientific cap.
//
// Note that once this is hit the pallet will essentially throttle incoming requests down to one
// call per block.
pub const MaxRequests: u32 = 50;
}

impl pallet_bridge_relayers::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type Reward = Balance;
Expand Down Expand Up @@ -439,7 +424,11 @@ parameter_types! {
pub type RialtoGrandpaInstance = ();
impl pallet_bridge_grandpa::Config for Runtime {
type BridgedChain = bp_rialto::Rialto;
type MaxRequests = MaxRequests;
// This is a pretty unscientific cap.
//
// Note that once this is hit the pallet will essentially throttle incoming requests down to one
// call per block.
type MaxRequests = ConstU32<50>;
type HeadersToKeep = HeadersToKeep;
type MaxBridgedAuthorities = MaxAuthoritiesAtRialto;
type MaxBridgedHeaderSize = MaxRialtoHeaderSize;
Expand All @@ -450,7 +439,7 @@ impl pallet_bridge_grandpa::Config for Runtime {
pub type WestendGrandpaInstance = pallet_bridge_grandpa::Instance1;
impl pallet_bridge_grandpa::Config<WestendGrandpaInstance> for Runtime {
type BridgedChain = bp_westend::Westend;
type MaxRequests = MaxRequests;
type MaxRequests = ConstU32<50>;
type HeadersToKeep = HeadersToKeep;
type MaxBridgedAuthorities = MaxAuthoritiesAtWestend;
type MaxBridgedHeaderSize = MaxWestendHeaderSize;
Expand Down
8 changes: 2 additions & 6 deletions bridges/bin/millau/runtime/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use bridge_runtime_common::{
};
use frame_support::{
parameter_types,
traits::{Everything, Nothing},
traits::{ConstU32, Everything, Nothing},
};
use xcm::latest::prelude::*;
use xcm_builder::{
Expand Down Expand Up @@ -112,10 +112,6 @@ pub type XcmRouter = (
XcmBridgeAdapter<ToRialtoParachainBridge>,
);

parameter_types! {
pub const MaxAssetsIntoHolding: u32 = 64;
}

/// The barriers one of which must be passed for an XCM message to be executed.
pub type Barrier = (
// Weight that is paid for may be consumed.
Expand Down Expand Up @@ -149,7 +145,7 @@ impl xcm_executor::Config for XcmConfig {
type AssetClaims = XcmPallet;
type SubscriptionService = XcmPallet;
type PalletInstancesInfo = AllPalletsWithSystem;
type MaxAssetsIntoHolding = MaxAssetsIntoHolding;
type MaxAssetsIntoHolding = ConstU32<64>;
type FeeManager = ();
type MessageExporter = ();
type UniversalAliases = Nothing;
Expand Down
20 changes: 8 additions & 12 deletions bridges/bin/rialto-parachain/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub use frame_support::{
construct_runtime,
dispatch::DispatchClass,
match_types, parameter_types,
traits::{Everything, IsInVec, Nothing, Randomness},
traits::{ConstU32, Everything, IsInVec, Nothing, Randomness},
weights::{
constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_PER_SECOND},
IdentityFee, Weight,
Expand Down Expand Up @@ -249,8 +249,6 @@ parameter_types! {
pub const CreationFee: u128 = MILLIUNIT;
pub const TransactionByteFee: u128 = MICROUNIT;
pub const OperationalFeeMultiplier: u8 = 5;
pub const MaxLocks: u32 = 50;
pub const MaxReserves: u32 = 50;
}

impl pallet_balances::Config for Runtime {
Expand All @@ -262,8 +260,8 @@ impl pallet_balances::Config for Runtime {
type ExistentialDeposit = ExistentialDeposit;
type AccountStore = System;
type WeightInfo = pallet_balances::weights::SubstrateWeight<Runtime>;
type MaxLocks = MaxLocks;
type MaxReserves = MaxReserves;
type MaxLocks = ConstU32<50>;
type MaxReserves = ConstU32<50>;
type ReserveIdentifier = [u8; 8];
}

Expand Down Expand Up @@ -518,12 +516,6 @@ impl pallet_bridge_relayers::Config for Runtime {
}

parameter_types! {
/// This is a pretty unscientific cap.
///
/// Note that once this is hit the pallet will essentially throttle incoming requests down to one
/// call per block.
pub const MaxRequests: u32 = 50;

/// Number of headers to keep.
///
/// Assuming the worst case of every header being finalized, we will keep headers at least for a
Expand All @@ -539,7 +531,11 @@ parameter_types! {
pub type MillauGrandpaInstance = ();
impl pallet_bridge_grandpa::Config for Runtime {
type BridgedChain = bp_millau::Millau;
type MaxRequests = MaxRequests;
/// This is a pretty unscientific cap.
///
/// Note that once this is hit the pallet will essentially throttle incoming requests down to
/// one call per block.
type MaxRequests = ConstU32<50>;
type HeadersToKeep = HeadersToKeep;
type MaxBridgedAuthorities = MaxAuthoritiesAtMillau;
type MaxBridgedHeaderSize = MaxMillauHeaderSize;
Expand Down
36 changes: 15 additions & 21 deletions bridges/bin/rialto/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub use frame_support::{
construct_runtime,
dispatch::DispatchClass,
parameter_types,
traits::{Currency, ExistenceRequirement, Imbalance, KeyOwnerProofSystem},
traits::{ConstU32, ConstU8, Currency, ExistenceRequirement, Imbalance, KeyOwnerProofSystem},
weights::{constants::WEIGHT_PER_SECOND, IdentityFee, RuntimeDbWeight, Weight},
StorageValue,
};
Expand Down Expand Up @@ -222,13 +222,12 @@ pub const BABE_GENESIS_EPOCH_CONFIG: sp_consensus_babe::BabeEpochConfiguration =
parameter_types! {
pub const EpochDuration: u64 = bp_rialto::EPOCH_DURATION_IN_SLOTS as u64;
pub const ExpectedBlockTime: bp_rialto::Moment = bp_rialto::time_units::MILLISECS_PER_BLOCK;
pub const MaxAuthorities: u32 = 10;
}

impl pallet_babe::Config for Runtime {
type EpochDuration = EpochDuration;
type ExpectedBlockTime = ExpectedBlockTime;
type MaxAuthorities = MaxAuthorities;
type MaxAuthorities = ConstU32<10>;

// session module is the trigger
type EpochChangeTrigger = pallet_babe::ExternalTrigger;
Expand All @@ -251,13 +250,13 @@ impl pallet_babe::Config for Runtime {

impl pallet_beefy::Config for Runtime {
type BeefyId = BeefyId;
type MaxAuthorities = MaxAuthorities;
type MaxAuthorities = ConstU32<10>;
type OnNewValidatorSet = MmrLeaf;
}

impl pallet_grandpa::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type MaxAuthorities = MaxAuthorities;
type MaxAuthorities = ConstU32<10>;
type KeyOwnerProofSystem = ();
type KeyOwnerProof =
<Self::KeyOwnerProofSystem as KeyOwnerProofSystem<(KeyTypeId, GrandpaId)>>::Proof;
Expand Down Expand Up @@ -327,10 +326,6 @@ impl pallet_timestamp::Config for Runtime {

parameter_types! {
pub const ExistentialDeposit: bp_rialto::Balance = 500;
// For weight estimation, we assume that the most locks on an individual account will be 50.
// This number may need to be adjusted in the future if this assumption no longer holds true.
pub const MaxLocks: u32 = 50;
pub const MaxReserves: u32 = 50;
}

impl pallet_balances::Config for Runtime {
Expand All @@ -343,15 +338,16 @@ impl pallet_balances::Config for Runtime {
type AccountStore = System;
// TODO: update me (https://github.com/paritytech/parity-bridges-common/issues/78)
type WeightInfo = ();
type MaxLocks = MaxLocks;
type MaxReserves = MaxReserves;
// For weight estimation, we assume that the most locks on an individual account will be 50.
// This number may need to be adjusted in the future if this assumption no longer holds true.
type MaxLocks = ConstU32<50>;
type MaxReserves = ConstU32<50>;
type ReserveIdentifier = [u8; 8];
}

parameter_types! {
pub const TransactionBaseFee: Balance = 0;
pub const TransactionByteFee: Balance = 1;
pub const OperationalFeeMultiplier: u8 = 5;
// values for following parameters are copied from polkadot repo, but it is fine
// not to sync them - we're not going to make Rialto a full copy of one of Polkadot-like chains
pub const TargetBlockFullness: Perquintill = Perquintill::from_percent(25);
Expand All @@ -362,7 +358,7 @@ parameter_types! {

impl pallet_transaction_payment::Config for Runtime {
type OnChargeTransaction = pallet_transaction_payment::CurrencyAdapter<Balances, ()>;
type OperationalFeeMultiplier = OperationalFeeMultiplier;
type OperationalFeeMultiplier = ConstU8<5>;
type WeightToFee = bp_rialto::WeightToFee;
type LengthToFee = bp_rialto::WeightToFee;
type FeeMultiplierUpdate = pallet_transaction_payment::TargetedFeeAdjustment<
Expand Down Expand Up @@ -394,7 +390,7 @@ impl pallet_session::Config for Runtime {
}

impl pallet_authority_discovery::Config for Runtime {
type MaxAuthorities = MaxAuthorities;
type MaxAuthorities = ConstU32<10>;
}

impl pallet_bridge_relayers::Config for Runtime {
Expand All @@ -405,12 +401,6 @@ impl pallet_bridge_relayers::Config for Runtime {
}

parameter_types! {
/// This is a pretty unscientific cap.
///
/// Note that once this is hit the pallet will essentially throttle incoming requests down to one
/// call per block.
pub const MaxRequests: u32 = 50;

/// Number of headers to keep.
///
/// Assuming the worst case of every header being finalized, we will keep headers at least for a
Expand All @@ -426,7 +416,11 @@ parameter_types! {
pub type MillauGrandpaInstance = ();
impl pallet_bridge_grandpa::Config for Runtime {
type BridgedChain = bp_millau::Millau;
type MaxRequests = MaxRequests;
/// This is a pretty unscientific cap.
///
/// Note that once this is hit the pallet will essentially throttle incoming requests down to
/// one call per block.
type MaxRequests = ConstU32<50>;
type HeadersToKeep = HeadersToKeep;
type MaxBridgedAuthorities = MaxAuthoritiesAtMillau;
type MaxBridgedHeaderSize = MaxMillauHeaderSize;
Expand Down
6 changes: 1 addition & 5 deletions bridges/bin/rialto/runtime/src/parachains.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,10 @@ impl parachains_session_info::Config for Runtime {

impl parachains_shared::Config for Runtime {}

parameter_types! {
pub const FirstMessageFactorPercent: u64 = 100;
}

impl parachains_ump::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type UmpSink = ();
type FirstMessageFactorPercent = FirstMessageFactorPercent;
type FirstMessageFactorPercent = frame_support::traits::ConstU64<100>;
type ExecuteOverweightOrigin = EnsureRoot<AccountId>;
type WeightInfo = parachains_ump::TestWeightInfo;
}
Expand Down
8 changes: 2 additions & 6 deletions bridges/bin/rialto/runtime/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use bridge_runtime_common::{
};
use frame_support::{
parameter_types,
traits::{Everything, Nothing},
traits::{ConstU32, Everything, Nothing},
};
use xcm::latest::prelude::*;
use xcm_builder::{
Expand Down Expand Up @@ -104,10 +104,6 @@ pub type XcmRouter = (
XcmBridgeAdapter<ToMillauBridge>,
);

parameter_types! {
pub const MaxAssetsIntoHolding: u32 = 64;
}

/// The barriers one of which must be passed for an XCM message to be executed.
pub type Barrier = (
// Weight that is paid for may be consumed.
Expand Down Expand Up @@ -141,7 +137,7 @@ impl xcm_executor::Config for XcmConfig {
type AssetClaims = XcmPallet;
type SubscriptionService = XcmPallet;
type PalletInstancesInfo = AllPalletsWithSystem;
type MaxAssetsIntoHolding = MaxAssetsIntoHolding;
type MaxAssetsIntoHolding = ConstU32<64>;
type FeeManager = ();
type MessageExporter = ();
type UniversalAliases = Nothing;
Expand Down
5 changes: 2 additions & 3 deletions bridges/modules/beefy/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use crate::{
use bp_beefy::{BeefyValidatorSignatureOf, ChainWithBeefy, Commitment, MmrDataOrHash};
use bp_runtime::{BasicOperatingMode, Chain};
use codec::Encode;
use frame_support::{construct_runtime, parameter_types, weights::Weight};
use frame_support::{construct_runtime, parameter_types, traits::ConstU64, weights::Weight};
use sp_core::{sr25519::Signature, Pair};
use sp_runtime::{
testing::{Header, H256},
Expand Down Expand Up @@ -72,7 +72,6 @@ construct_runtime! {
}

parameter_types! {
pub const BlockHashCount: u64 = 250;
pub const MaximumBlockWeight: Weight = Weight::from_ref_time(1024);
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
Expand All @@ -89,7 +88,7 @@ impl frame_system::Config for TestRuntime {
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type RuntimeEvent = ();
type BlockHashCount = BlockHashCount;
type BlockHashCount = ConstU64<250>;
type Version = ();
type PalletInfo = PalletInfo;
type AccountData = ();
Expand Down
Loading

0 comments on commit 27a7b7d

Please sign in to comment.