From c798cdbf7bf35fe0f13c0e28012862fbe3d22ffd Mon Sep 17 00:00:00 2001 From: linning Date: Wed, 25 Sep 2024 17:58:10 +0800 Subject: [PATCH] Merge all HoldIdentifier into one Signed-off-by: linning --- crates/pallet-domains/src/staking_epoch.rs | 2 +- crates/pallet-domains/src/tests.rs | 32 ++++++-------- crates/sp-domains/src/lib.rs | 19 -------- crates/subspace-runtime-primitives/src/lib.rs | 11 +++++ crates/subspace-runtime/src/lib.rs | 43 ++++++++----------- domains/pallets/messenger/src/mock.rs | 12 +++--- domains/pallets/transporter/src/mock.rs | 11 +++-- domains/primitives/runtime/src/lib.rs | 1 + domains/runtime/auto-id/src/lib.rs | 30 +++++-------- domains/runtime/evm/src/lib.rs | 30 +++++-------- domains/test/runtime/auto-id/src/lib.rs | 29 +++++-------- domains/test/runtime/evm/src/lib.rs | 25 +++++------ test/subspace-test-runtime/src/lib.rs | 39 ++++++++--------- 13 files changed, 117 insertions(+), 167 deletions(-) diff --git a/crates/pallet-domains/src/staking_epoch.rs b/crates/pallet-domains/src/staking_epoch.rs index 1f9b1af660..09db7bd79e 100644 --- a/crates/pallet-domains/src/staking_epoch.rs +++ b/crates/pallet-domains/src/staking_epoch.rs @@ -660,7 +660,7 @@ mod tests { assert_ok!(do_unlock_nominator::(operator_id, operator_account)); - let hold_id = crate::tests::HoldIdentifier::staking_staked(); + let hold_id = crate::tests::HoldIdentifierWrapper::staking_staked(); for (nominator_id, mut expected_usable_balance) in expected_usable_balances { expected_usable_balance += minimum_free_balance; assert_eq!(Deposits::::get(operator_id, nominator_id), None); diff --git a/crates/pallet-domains/src/tests.rs b/crates/pallet-domains/src/tests.rs index a616b92f36..ecf6bd5490 100644 --- a/crates/pallet-domains/src/tests.rs +++ b/crates/pallet-domains/src/tests.rs @@ -11,6 +11,7 @@ use crate::{ RuntimeRegistry, ScheduledRuntimeUpgrades, }; use codec::{Decode, Encode, MaxEncodedLen}; +use core::mem; use domain_runtime_primitives::opaque::Header as DomainHeader; use domain_runtime_primitives::BlockNumber as DomainBlockNumber; use frame_support::dispatch::{DispatchInfo, RawOrigin}; @@ -26,9 +27,9 @@ use sp_core::{Get, H256, U256}; use sp_domains::merkle_tree::MerkleTree; use sp_domains::storage::RawGenesis; use sp_domains::{ - BundleHeader, ChainId, DomainId, DomainsHoldIdentifier, ExecutionReceipt, InboxedBundle, - OpaqueBundle, OperatorAllowList, OperatorId, OperatorPair, ProofOfElection, RuntimeId, - RuntimeType, SealedBundleHeader, + BundleHeader, ChainId, DomainId, ExecutionReceipt, InboxedBundle, OpaqueBundle, + OperatorAllowList, OperatorId, OperatorPair, ProofOfElection, RuntimeId, RuntimeType, + SealedBundleHeader, }; use sp_domains_fraud_proof::fraud_proof::FraudProof; use sp_runtime::traits::{ @@ -38,7 +39,7 @@ use sp_runtime::transaction_validity::TransactionValidityError; use sp_runtime::{BuildStorage, OpaqueExtrinsic, Saturating}; use sp_version::RuntimeVersion; use subspace_core_primitives::U256 as P256; -use subspace_runtime_primitives::{Moment, StorageFee, SSC}; +use subspace_runtime_primitives::{HoldIdentifier, Moment, StorageFee, SSC}; type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; type Block = frame_system::mocking::MockBlock; @@ -100,29 +101,24 @@ impl Get for ConfirmationDepthK { #[derive( PartialEq, Eq, Clone, Encode, Decode, TypeInfo, MaxEncodedLen, Ord, PartialOrd, Copy, Debug, )] -pub enum HoldIdentifier { - Domains(DomainsHoldIdentifier), -} +pub struct HoldIdentifierWrapper(HoldIdentifier); -impl pallet_domains::HoldIdentifier for HoldIdentifier { +impl pallet_domains::HoldIdentifier for HoldIdentifierWrapper { fn staking_staked() -> FungibleHoldId { - Self::Domains(DomainsHoldIdentifier::Staking) + Self(HoldIdentifier::DomainStaking) } fn domain_instantiation_id() -> FungibleHoldId { - Self::Domains(DomainsHoldIdentifier::DomainInstantiation) + Self(HoldIdentifier::DomainInstantiation) } fn storage_fund_withdrawal() -> Self { - Self::Domains(DomainsHoldIdentifier::StorageFund) + Self(HoldIdentifier::DomainStorageFund) } } -impl VariantCount for HoldIdentifier { - // TODO: HACK this is not the actual variant count but it is required see - // https://github.com/autonomys/subspace/issues/2674 for more details. It - // will be resolved as https://github.com/paritytech/polkadot-sdk/issues/4033. - const VARIANT_COUNT: u32 = 10; +impl VariantCount for HoldIdentifierWrapper { + const VARIANT_COUNT: u32 = mem::variant_count::() as u32; } parameter_types! { @@ -134,7 +130,7 @@ impl pallet_balances::Config for Test { type Balance = Balance; type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; - type RuntimeHoldReason = HoldIdentifier; + type RuntimeHoldReason = HoldIdentifierWrapper; type DustRemoval = (); } @@ -248,7 +244,7 @@ impl pallet_domains::Config for Test { type ConfirmationDepthK = ConfirmationDepthK; type DomainRuntimeUpgradeDelay = DomainRuntimeUpgradeDelay; type Currency = Balances; - type HoldIdentifier = HoldIdentifier; + type HoldIdentifier = HoldIdentifierWrapper; type WeightInfo = pallet_domains::weights::SubstrateWeight; type InitialDomainTxRange = InitialDomainTxRange; type DomainTxRangeAdjustmentInterval = DomainTxRangeAdjustmentInterval; diff --git a/crates/sp-domains/src/lib.rs b/crates/sp-domains/src/lib.rs index 76706bc2bc..1214e799ec 100644 --- a/crates/sp-domains/src/lib.rs +++ b/crates/sp-domains/src/lib.rs @@ -951,25 +951,6 @@ pub type OperatorId = u64; /// Channel identity. pub type ChannelId = sp_core::U256; -/// Messenger specific hold identifier -#[derive( - PartialEq, Eq, Clone, Encode, Decode, TypeInfo, MaxEncodedLen, Ord, PartialOrd, Copy, Debug, -)] -pub enum MessengerHoldIdentifier { - /// Holds the current reserved balance for channel opening - Channel, -} - -/// Domains specific Identifier for Balances holds. -#[derive( - PartialEq, Eq, Clone, Encode, Decode, TypeInfo, MaxEncodedLen, Ord, PartialOrd, Copy, Debug, -)] -pub enum DomainsHoldIdentifier { - Staking, - DomainInstantiation, - StorageFund, -} - /// Domains specific digest item. #[derive(PartialEq, Eq, Clone, Encode, Decode, TypeInfo)] pub enum DomainDigestItem { diff --git a/crates/subspace-runtime-primitives/src/lib.rs b/crates/subspace-runtime-primitives/src/lib.rs index 984d79a83b..647a97c088 100644 --- a/crates/subspace-runtime-primitives/src/lib.rs +++ b/crates/subspace-runtime-primitives/src/lib.rs @@ -243,6 +243,17 @@ impl Default for BlockTransactionByteFee for HoldIdentifier { +impl pallet_domains::HoldIdentifier for HoldIdentifierWrapper { fn staking_staked() -> Self { - Self::Domains(DomainsHoldIdentifier::Staking) + Self(HoldIdentifier::DomainStaking) } fn domain_instantiation_id() -> Self { - Self::Domains(DomainsHoldIdentifier::DomainInstantiation) + Self(HoldIdentifier::DomainInstantiation) } fn storage_fund_withdrawal() -> Self { - Self::Domains(DomainsHoldIdentifier::StorageFund) + Self(HoldIdentifier::DomainStorageFund) } } -impl pallet_messenger::HoldIdentifier for HoldIdentifier { +impl pallet_messenger::HoldIdentifier for HoldIdentifierWrapper { fn messenger_channel() -> Self { - Self::Messenger(MessengerHoldIdentifier::Channel) + Self(HoldIdentifier::MessengerChannel) } } -impl VariantCount for HoldIdentifier { - const VARIANT_COUNT: u32 = 1 - + mem::variant_count::() as u32 - + mem::variant_count::() as u32; +impl VariantCount for HoldIdentifierWrapper { + const VARIANT_COUNT: u32 = mem::variant_count::() as u32; } impl pallet_balances::Config for Runtime { @@ -375,7 +370,7 @@ impl pallet_balances::Config for Runtime { type WeightInfo = pallet_balances::weights::SubstrateWeight; type FreezeIdentifier = (); type MaxFreezes = (); - type RuntimeHoldReason = HoldIdentifier; + type RuntimeHoldReason = HoldIdentifierWrapper; } parameter_types! { @@ -465,7 +460,7 @@ impl pallet_collective::Config for Runtime { parameter_types! { pub PreimageBaseDeposit: Balance = 100 * SSC; pub PreimageByteDeposit: Balance = SSC; - pub const PreImageHoldReason: HoldIdentifier = HoldIdentifier::Preimage; + pub const PreImageHoldReason: HoldIdentifierWrapper = HoldIdentifierWrapper(HoldIdentifier::Preimage); } impl pallet_preimage::Config for Runtime { @@ -695,7 +690,7 @@ impl pallet_messenger::Config for Runtime { type MmrProofVerifier = MmrProofVerifier; type StorageKeys = StorageKeys; type DomainOwner = Domains; - type HoldIdentifier = HoldIdentifier; + type HoldIdentifier = HoldIdentifierWrapper; type ChannelReserveFee = ChannelReserveFee; type ChannelInitReservePortion = ChannelInitReservePortion; type DomainRegistration = DomainRegistration; @@ -818,7 +813,7 @@ impl pallet_domains::Config for Runtime { type ConfirmationDepthK = ConfirmationDepthK; type DomainRuntimeUpgradeDelay = DomainRuntimeUpgradeDelay; type Currency = Balances; - type HoldIdentifier = HoldIdentifier; + type HoldIdentifier = HoldIdentifierWrapper; type WeightInfo = pallet_domains::weights::SubstrateWeight; type InitialDomainTxRange = InitialDomainTxRange; type DomainTxRangeAdjustmentInterval = DomainTxRangeAdjustmentInterval; diff --git a/domains/pallets/messenger/src/mock.rs b/domains/pallets/messenger/src/mock.rs index 3fffde6974..d6cd143682 100644 --- a/domains/pallets/messenger/src/mock.rs +++ b/domains/pallets/messenger/src/mock.rs @@ -21,7 +21,7 @@ macro_rules! impl_runtime { use crate::mock::MockEndpoint; use crate::mock::{AccountId, Balance, MessageId, TestExternalities}; use codec::{Decode, Encode}; - use domain_runtime_primitives::{MultiAccountId, TryConvertBack}; + use domain_runtime_primitives::{MultiAccountId, TryConvertBack, HoldIdentifier}; #[cfg(not(feature = "runtime-benchmarks"))] use frame_support::pallet_prelude::*; use frame_support::{derive_impl, parameter_types}; @@ -31,10 +31,8 @@ macro_rules! impl_runtime { use sp_messenger::messages::{ChainId, FeeModel}; use sp_runtime::traits::Convert; use sp_runtime::BuildStorage; - use crate::HoldIdentifier; use scale_info::TypeInfo; use codec::MaxEncodedLen; - use sp_domains::MessengerHoldIdentifier; use frame_support::traits::VariantCount; use core::mem; use sp_runtime::Perbill; @@ -68,16 +66,16 @@ macro_rules! impl_runtime { PartialEq, Eq, Clone, Encode, Decode, TypeInfo, MaxEncodedLen, Ord, PartialOrd, Copy, Debug, )] pub enum MockHoldIdentifer { - Messenger(MessengerHoldIdentifier) + Messenger(HoldIdentifier) } impl VariantCount for MockHoldIdentifer { - const VARIANT_COUNT: u32 = mem::variant_count::() as u32; + const VARIANT_COUNT: u32 = mem::variant_count::() as u32; } - impl HoldIdentifier<$runtime> for MockHoldIdentifer { + impl crate::HoldIdentifier<$runtime> for MockHoldIdentifer { fn messenger_channel() -> Self { - MockHoldIdentifer::Messenger(MessengerHoldIdentifier::Channel) + MockHoldIdentifer::Messenger(HoldIdentifier::MessengerChannel) } } diff --git a/domains/pallets/transporter/src/mock.rs b/domains/pallets/transporter/src/mock.rs index a9d193bd2e..cf99ce9426 100644 --- a/domains/pallets/transporter/src/mock.rs +++ b/domains/pallets/transporter/src/mock.rs @@ -1,14 +1,13 @@ use crate as pallet_transporter; use crate::{Config, TryConvertBack}; use codec::{Decode, Encode}; -use domain_runtime_primitives::MultiAccountId; +use domain_runtime_primitives::{HoldIdentifier, MultiAccountId}; use frame_support::pallet_prelude::{MaxEncodedLen, TypeInfo}; use frame_support::traits::VariantCount; use frame_support::{derive_impl, parameter_types}; use pallet_balances::AccountData; -use pallet_messenger::HoldIdentifier; use sp_core::U256; -use sp_domains::{DomainId, MessengerHoldIdentifier}; +use sp_domains::DomainId; use sp_messenger::endpoint::{Endpoint, EndpointHandler, EndpointId, EndpointRequest, Sender}; use sp_messenger::messages::{ChainId, FeeModel, MessageId}; use sp_runtime::traits::{Convert, IdentityLookup}; @@ -61,7 +60,7 @@ parameter_types! { PartialEq, Eq, Clone, Encode, Decode, TypeInfo, MaxEncodedLen, Ord, PartialOrd, Copy, Debug, )] pub enum MockHoldIdentifer { - Messenger(MessengerHoldIdentifier), + Messenger(HoldIdentifier), } impl VariantCount for MockHoldIdentifer { @@ -76,9 +75,9 @@ impl sp_messenger::DomainRegistration for DomainRegistration { } } -impl HoldIdentifier for MockHoldIdentifer { +impl pallet_messenger::HoldIdentifier for MockHoldIdentifer { fn messenger_channel() -> Self { - MockHoldIdentifer::Messenger(MessengerHoldIdentifier::Channel) + MockHoldIdentifer::Messenger(HoldIdentifier::MessengerChannel) } } diff --git a/domains/primitives/runtime/src/lib.rs b/domains/primitives/runtime/src/lib.rs index 02cb53e935..cff7e01485 100644 --- a/domains/primitives/runtime/src/lib.rs +++ b/domains/primitives/runtime/src/lib.rs @@ -37,6 +37,7 @@ use sp_runtime::transaction_validity::TransactionValidityError; use sp_runtime::{MultiAddress, MultiSignature, Perbill}; use sp_weights::constants::WEIGHT_REF_TIME_PER_SECOND; use sp_weights::Weight; +pub use subspace_runtime_primitives::HoldIdentifier; use subspace_runtime_primitives::{MAX_BLOCK_LENGTH, SHANNON, SLOT_PROBABILITY}; /// Alias to 512-bit hash when used in the context of a transaction signature on the chain. diff --git a/domains/runtime/auto-id/src/lib.rs b/domains/runtime/auto-id/src/lib.rs index 851620c96a..4cfde5ace7 100644 --- a/domains/runtime/auto-id/src/lib.rs +++ b/domains/runtime/auto-id/src/lib.rs @@ -13,14 +13,15 @@ extern crate alloc; #[cfg(not(feature = "std"))] use alloc::format; use codec::{Decode, Encode, MaxEncodedLen}; +use core::mem; use domain_runtime_primitives::opaque::Header; pub use domain_runtime_primitives::{ block_weights, maximum_block_length, opaque, Balance, BlockNumber, Hash, Nonce, EXISTENTIAL_DEPOSIT, }; use domain_runtime_primitives::{ - AccountId, Address, CheckExtrinsicsValidityError, DecodeExtrinsicError, Signature, - ERR_BALANCE_OVERFLOW, SLOT_DURATION, + AccountId, Address, CheckExtrinsicsValidityError, DecodeExtrinsicError, HoldIdentifier, + Signature, ERR_BALANCE_OVERFLOW, SLOT_DURATION, }; use frame_support::dispatch::{DispatchClass, DispatchInfo, GetDispatchInfo}; use frame_support::genesis_builder_helper::{build_state, get_preset}; @@ -39,7 +40,7 @@ use pallet_transporter::EndpointHandler; use sp_api::impl_runtime_apis; use sp_core::crypto::KeyTypeId; use sp_core::{Get, OpaqueMetadata}; -use sp_domains::{ChannelId, DomainAllowlistUpdates, DomainId, MessengerHoldIdentifier, Transfers}; +use sp_domains::{ChannelId, DomainAllowlistUpdates, DomainId, Transfers}; use sp_messenger::endpoint::{Endpoint, EndpointHandler as EndpointHandlerT, EndpointId}; use sp_messenger::messages::{ BlockMessagesWithStorageKey, ChainId, CrossDomainMessage, FeeModel, MessageId, MessageKey, @@ -227,7 +228,7 @@ impl pallet_balances::Config for Runtime { type ReserveIdentifier = [u8; 8]; type FreezeIdentifier = (); type MaxFreezes = (); - type RuntimeHoldReason = HoldIdentifier; + type RuntimeHoldReason = HoldIdentifierWrapper; } parameter_types! { @@ -374,24 +375,15 @@ impl sp_messenger::StorageKeys for StorageKeys { #[derive( PartialEq, Eq, Clone, Encode, Decode, TypeInfo, MaxEncodedLen, Ord, PartialOrd, Copy, Debug, )] -pub enum HoldIdentifier { - Messenger(MessengerHoldIdentifier), -} +pub struct HoldIdentifierWrapper(HoldIdentifier); -impl VariantCount for HoldIdentifier { - // TODO: revist this value, it is used as the max number of hold an account can - // create. Currently, opening an XDM channel will create 1 hold, so this value - // also used as the limit of how many channel an account can open. - // - // TODO: HACK this is not the actual variant count but it is required see - // https://github.com/autonomys/subspace/issues/2674 for more details. It - // will be resolved as https://github.com/paritytech/polkadot-sdk/issues/4033. - const VARIANT_COUNT: u32 = 100; +impl VariantCount for HoldIdentifierWrapper { + const VARIANT_COUNT: u32 = mem::variant_count::() as u32; } -impl pallet_messenger::HoldIdentifier for HoldIdentifier { +impl pallet_messenger::HoldIdentifier for HoldIdentifierWrapper { fn messenger_channel() -> Self { - Self::Messenger(MessengerHoldIdentifier::Channel) + Self(HoldIdentifier::MessengerChannel) } } @@ -422,7 +414,7 @@ impl pallet_messenger::Config for Runtime { type MmrProofVerifier = MmrProofVerifier; type StorageKeys = StorageKeys; type DomainOwner = (); - type HoldIdentifier = HoldIdentifier; + type HoldIdentifier = HoldIdentifierWrapper; type ChannelReserveFee = ChannelReserveFee; type ChannelInitReservePortion = ChannelInitReservePortion; type DomainRegistration = (); diff --git a/domains/runtime/evm/src/lib.rs b/domains/runtime/evm/src/lib.rs index b4add6da33..7242a2ed6b 100644 --- a/domains/runtime/evm/src/lib.rs +++ b/domains/runtime/evm/src/lib.rs @@ -15,14 +15,15 @@ extern crate alloc; #[cfg(not(feature = "std"))] use alloc::format; use codec::{Decode, Encode, MaxEncodedLen}; +use core::mem; use domain_runtime_primitives::opaque::Header; pub use domain_runtime_primitives::{ block_weights, maximum_block_length, maximum_domain_block_weight, opaque, Balance, BlockNumber, Hash, Nonce, EXISTENTIAL_DEPOSIT, }; use domain_runtime_primitives::{ - CheckExtrinsicsValidityError, DecodeExtrinsicError, ERR_BALANCE_OVERFLOW, ERR_NONCE_OVERFLOW, - SLOT_DURATION, + CheckExtrinsicsValidityError, DecodeExtrinsicError, HoldIdentifier, ERR_BALANCE_OVERFLOW, + ERR_NONCE_OVERFLOW, SLOT_DURATION, }; use fp_account::EthereumSignature; use fp_self_contained::{CheckedSignature, SelfContainedCall}; @@ -52,7 +53,7 @@ use pallet_transporter::EndpointHandler; use sp_api::impl_runtime_apis; use sp_core::crypto::KeyTypeId; use sp_core::{Get, OpaqueMetadata, H160, H256, U256}; -use sp_domains::{ChannelId, DomainAllowlistUpdates, DomainId, MessengerHoldIdentifier, Transfers}; +use sp_domains::{ChannelId, DomainAllowlistUpdates, DomainId, Transfers}; use sp_messenger::endpoint::{Endpoint, EndpointHandler as EndpointHandlerT, EndpointId}; use sp_messenger::messages::{ BlockMessagesWithStorageKey, ChainId, CrossDomainMessage, FeeModel, MessageId, MessageKey, @@ -359,7 +360,7 @@ impl pallet_balances::Config for Runtime { type ReserveIdentifier = [u8; 8]; type FreezeIdentifier = (); type MaxFreezes = (); - type RuntimeHoldReason = HoldIdentifier; + type RuntimeHoldReason = HoldIdentifierWrapper; } parameter_types! { @@ -503,24 +504,15 @@ impl sp_messenger::StorageKeys for StorageKeys { #[derive( PartialEq, Eq, Clone, Encode, Decode, TypeInfo, MaxEncodedLen, Ord, PartialOrd, Copy, Debug, )] -pub enum HoldIdentifier { - Messenger(MessengerHoldIdentifier), -} +pub struct HoldIdentifierWrapper(HoldIdentifier); -impl VariantCount for HoldIdentifier { - // TODO: revist this value, it is used as the max number of hold an account can - // create. Currently, opening an XDM channel will create 1 hold, so this value - // also used as the limit of how many channel an account can open. - // - // TODO: HACK this is not the actual variant count but it is required see - // https://github.com/autonomys/subspace/issues/2674 for more details. It - // will be resolved as https://github.com/paritytech/polkadot-sdk/issues/4033. - const VARIANT_COUNT: u32 = 100; +impl VariantCount for HoldIdentifierWrapper { + const VARIANT_COUNT: u32 = mem::variant_count::() as u32; } -impl pallet_messenger::HoldIdentifier for HoldIdentifier { +impl pallet_messenger::HoldIdentifier for HoldIdentifierWrapper { fn messenger_channel() -> Self { - Self::Messenger(MessengerHoldIdentifier::Channel) + Self(HoldIdentifier::MessengerChannel) } } @@ -551,7 +543,7 @@ impl pallet_messenger::Config for Runtime { type MmrProofVerifier = MmrProofVerifier; type StorageKeys = StorageKeys; type DomainOwner = (); - type HoldIdentifier = HoldIdentifier; + type HoldIdentifier = HoldIdentifierWrapper; type ChannelReserveFee = ChannelReserveFee; type ChannelInitReservePortion = ChannelInitReservePortion; type DomainRegistration = (); diff --git a/domains/test/runtime/auto-id/src/lib.rs b/domains/test/runtime/auto-id/src/lib.rs index 0969b000d0..d549d9c1b5 100644 --- a/domains/test/runtime/auto-id/src/lib.rs +++ b/domains/test/runtime/auto-id/src/lib.rs @@ -13,13 +13,15 @@ extern crate alloc; #[cfg(not(feature = "std"))] use alloc::format; use codec::{Decode, Encode, MaxEncodedLen}; +use core::mem; use domain_runtime_primitives::opaque::Header; pub use domain_runtime_primitives::{ block_weights, maximum_block_length, opaque, AccountId, Address, Balance, BlockNumber, Hash, Nonce, Signature, EXISTENTIAL_DEPOSIT, }; use domain_runtime_primitives::{ - CheckExtrinsicsValidityError, DecodeExtrinsicError, ERR_BALANCE_OVERFLOW, SLOT_DURATION, + CheckExtrinsicsValidityError, DecodeExtrinsicError, HoldIdentifier, ERR_BALANCE_OVERFLOW, + SLOT_DURATION, }; use frame_support::dispatch::{DispatchClass, DispatchInfo, GetDispatchInfo}; use frame_support::genesis_builder_helper::{build_state, get_preset}; @@ -38,7 +40,7 @@ use pallet_transporter::EndpointHandler; use sp_api::impl_runtime_apis; use sp_core::crypto::KeyTypeId; use sp_core::{Get, OpaqueMetadata}; -use sp_domains::{ChannelId, DomainAllowlistUpdates, DomainId, MessengerHoldIdentifier, Transfers}; +use sp_domains::{ChannelId, DomainAllowlistUpdates, DomainId, Transfers}; use sp_messenger::endpoint::{Endpoint, EndpointHandler as EndpointHandlerT, EndpointId}; use sp_messenger::messages::{ BlockMessagesWithStorageKey, ChainId, CrossDomainMessage, FeeModel, MessageId, MessageKey, @@ -226,7 +228,7 @@ impl pallet_balances::Config for Runtime { type ReserveIdentifier = [u8; 8]; type FreezeIdentifier = (); type MaxFreezes = (); - type RuntimeHoldReason = HoldIdentifier; + type RuntimeHoldReason = HoldIdentifierWrapper; } parameter_types! { @@ -372,24 +374,15 @@ impl sp_messenger::StorageKeys for StorageKeys { #[derive( PartialEq, Eq, Clone, Encode, Decode, TypeInfo, MaxEncodedLen, Ord, PartialOrd, Copy, Debug, )] -pub enum HoldIdentifier { - Messenger(MessengerHoldIdentifier), -} +pub struct HoldIdentifierWrapper(HoldIdentifier); -impl VariantCount for HoldIdentifier { - // TODO: revist this value, it is used as the max number of hold an account can - // create. Currently, opening an XDM channel will create 1 hold, so this value - // also used as the limit of how many channel an account can open. - // - // TODO: HACK this is not the actual variant count but it is required see - // https://github.com/autonomys/subspace/issues/2674 for more details. It - // will be resolved as https://github.com/paritytech/polkadot-sdk/issues/4033. - const VARIANT_COUNT: u32 = 100; +impl VariantCount for HoldIdentifierWrapper { + const VARIANT_COUNT: u32 = mem::variant_count::() as u32; } -impl pallet_messenger::HoldIdentifier for HoldIdentifier { +impl pallet_messenger::HoldIdentifier for HoldIdentifierWrapper { fn messenger_channel() -> Self { - Self::Messenger(MessengerHoldIdentifier::Channel) + Self(HoldIdentifier::MessengerChannel) } } @@ -420,7 +413,7 @@ impl pallet_messenger::Config for Runtime { type MmrProofVerifier = MmrProofVerifier; type StorageKeys = StorageKeys; type DomainOwner = (); - type HoldIdentifier = HoldIdentifier; + type HoldIdentifier = HoldIdentifierWrapper; type ChannelReserveFee = ChannelReserveFee; type ChannelInitReservePortion = ChannelInitReservePortion; type DomainRegistration = (); diff --git a/domains/test/runtime/evm/src/lib.rs b/domains/test/runtime/evm/src/lib.rs index e5c9057ae1..cd3aaf4a9f 100644 --- a/domains/test/runtime/evm/src/lib.rs +++ b/domains/test/runtime/evm/src/lib.rs @@ -15,13 +15,15 @@ extern crate alloc; #[cfg(not(feature = "std"))] use alloc::format; use codec::{Decode, Encode, MaxEncodedLen}; +use core::mem; pub use domain_runtime_primitives::opaque::Header; use domain_runtime_primitives::{ block_weights, maximum_block_length, maximum_domain_block_weight, ERR_BALANCE_OVERFLOW, ERR_NONCE_OVERFLOW, EXISTENTIAL_DEPOSIT, SLOT_DURATION, }; pub use domain_runtime_primitives::{ - opaque, Balance, BlockNumber, CheckExtrinsicsValidityError, DecodeExtrinsicError, Hash, Nonce, + opaque, Balance, BlockNumber, CheckExtrinsicsValidityError, DecodeExtrinsicError, Hash, + HoldIdentifier, Nonce, }; use fp_account::EthereumSignature; use fp_self_contained::{CheckedSignature, SelfContainedCall}; @@ -50,7 +52,7 @@ use pallet_transporter::EndpointHandler; use sp_api::impl_runtime_apis; use sp_core::crypto::KeyTypeId; use sp_core::{Get, OpaqueMetadata, H160, H256, U256}; -use sp_domains::{DomainAllowlistUpdates, DomainId, MessengerHoldIdentifier, Transfers}; +use sp_domains::{DomainAllowlistUpdates, DomainId, Transfers}; use sp_messenger::endpoint::{Endpoint, EndpointHandler as EndpointHandlerT, EndpointId}; use sp_messenger::messages::{ BlockMessagesWithStorageKey, ChainId, ChannelId, CrossDomainMessage, FeeModel, MessageId, @@ -348,7 +350,7 @@ impl pallet_balances::Config for Runtime { type ReserveIdentifier = [u8; 8]; type FreezeIdentifier = (); type MaxFreezes = (); - type RuntimeHoldReason = HoldIdentifier; + type RuntimeHoldReason = HoldIdentifierWrapper; } parameter_types! { @@ -467,20 +469,15 @@ impl sp_subspace_mmr::MmrProofVerifier, Hash> for MmrP #[derive( PartialEq, Eq, Clone, Encode, Decode, TypeInfo, MaxEncodedLen, Ord, PartialOrd, Copy, Debug, )] -pub enum HoldIdentifier { - Messenger(MessengerHoldIdentifier), -} +pub struct HoldIdentifierWrapper(HoldIdentifier); -impl VariantCount for HoldIdentifier { - // TODO: HACK this is not the actual variant count but it is required see - // https://github.com/autonomys/subspace/issues/2674 for more details. It - // will be resolved as https://github.com/paritytech/polkadot-sdk/issues/4033. - const VARIANT_COUNT: u32 = 10; +impl VariantCount for HoldIdentifierWrapper { + const VARIANT_COUNT: u32 = mem::variant_count::() as u32; } -impl pallet_messenger::HoldIdentifier for HoldIdentifier { +impl pallet_messenger::HoldIdentifier for HoldIdentifierWrapper { fn messenger_channel() -> Self { - Self::Messenger(MessengerHoldIdentifier::Channel) + Self(HoldIdentifier::MessengerChannel) } } @@ -532,7 +529,7 @@ impl pallet_messenger::Config for Runtime { type MmrProofVerifier = MmrProofVerifier; type StorageKeys = StorageKeys; type DomainOwner = (); - type HoldIdentifier = HoldIdentifier; + type HoldIdentifier = HoldIdentifierWrapper; type ChannelReserveFee = ChannelReserveFee; type ChannelInitReservePortion = ChannelInitReservePortion; type DomainRegistration = (); diff --git a/test/subspace-test-runtime/src/lib.rs b/test/subspace-test-runtime/src/lib.rs index 35b1d29df6..01b3eccf96 100644 --- a/test/subspace-test-runtime/src/lib.rs +++ b/test/subspace-test-runtime/src/lib.rs @@ -59,9 +59,9 @@ use sp_core::crypto::{ByteArray, KeyTypeId}; use sp_core::{OpaqueMetadata, H256}; use sp_domains::bundle_producer_election::BundleProducerElectionParams; use sp_domains::{ - DomainAllowlistUpdates, DomainId, DomainInstanceData, DomainsHoldIdentifier, - ExecutionReceiptFor, MessengerHoldIdentifier, OpaqueBundle, OpaqueBundles, OperatorId, - OperatorPublicKey, DOMAIN_STORAGE_FEE_MULTIPLIER, INITIAL_DOMAIN_TX_RANGE, + DomainAllowlistUpdates, DomainId, DomainInstanceData, ExecutionReceiptFor, OpaqueBundle, + OpaqueBundles, OperatorId, OperatorPublicKey, DOMAIN_STORAGE_FEE_MULTIPLIER, + INITIAL_DOMAIN_TX_RANGE, }; use sp_domains_fraud_proof::fraud_proof::FraudProof; use sp_domains_fraud_proof::storage_proof::{ @@ -98,8 +98,8 @@ use subspace_core_primitives::{ SolutionRange, U256, }; use subspace_runtime_primitives::{ - AccountId, Balance, BlockNumber, FindBlockRewardAddress, Hash, Moment, Nonce, Signature, - MIN_REPLICATION_FACTOR, + AccountId, Balance, BlockNumber, FindBlockRewardAddress, Hash, HoldIdentifier, Moment, Nonce, + Signature, MIN_REPLICATION_FACTOR, }; sp_runtime::impl_opaque_keys! { @@ -330,35 +330,30 @@ impl pallet_timestamp::Config for Runtime { #[derive( PartialEq, Eq, Clone, Encode, Decode, TypeInfo, MaxEncodedLen, Ord, PartialOrd, Copy, Debug, )] -pub enum HoldIdentifier { - Domains(DomainsHoldIdentifier), - Messenger(MessengerHoldIdentifier), -} +pub struct HoldIdentifierWrapper(HoldIdentifier); -impl pallet_domains::HoldIdentifier for HoldIdentifier { +impl pallet_domains::HoldIdentifier for HoldIdentifierWrapper { fn staking_staked() -> Self { - Self::Domains(DomainsHoldIdentifier::Staking) + Self(HoldIdentifier::DomainStaking) } fn domain_instantiation_id() -> Self { - Self::Domains(DomainsHoldIdentifier::DomainInstantiation) + Self(HoldIdentifier::DomainInstantiation) } fn storage_fund_withdrawal() -> Self { - Self::Domains(DomainsHoldIdentifier::StorageFund) + Self(HoldIdentifier::DomainStorageFund) } } -impl pallet_messenger::HoldIdentifier for HoldIdentifier { +impl pallet_messenger::HoldIdentifier for HoldIdentifierWrapper { fn messenger_channel() -> Self { - Self::Messenger(MessengerHoldIdentifier::Channel) + Self(HoldIdentifier::MessengerChannel) } } -impl VariantCount for HoldIdentifier { - const VARIANT_COUNT: u32 = 1 - + mem::variant_count::() as u32 - + mem::variant_count::() as u32; +impl VariantCount for HoldIdentifierWrapper { + const VARIANT_COUNT: u32 = mem::variant_count::() as u32; } impl pallet_balances::Config for Runtime { @@ -377,7 +372,7 @@ impl pallet_balances::Config for Runtime { type WeightInfo = pallet_balances::weights::SubstrateWeight; type FreezeIdentifier = (); type MaxFreezes = (); - type RuntimeHoldReason = HoldIdentifier; + type RuntimeHoldReason = HoldIdentifierWrapper; } pub struct CreditSupply; @@ -635,7 +630,7 @@ impl pallet_messenger::Config for Runtime { type MmrProofVerifier = MmrProofVerifier; type StorageKeys = StorageKeys; type DomainOwner = Domains; - type HoldIdentifier = HoldIdentifier; + type HoldIdentifier = HoldIdentifierWrapper; type ChannelReserveFee = ChannelReserveFee; type ChannelInitReservePortion = ChannelInitReservePortion; type DomainRegistration = DomainRegistration; @@ -748,7 +743,7 @@ impl pallet_domains::Config for Runtime { type ConfirmationDepthK = ConfirmationDepthK; type DomainRuntimeUpgradeDelay = DomainRuntimeUpgradeDelay; type Currency = Balances; - type HoldIdentifier = HoldIdentifier; + type HoldIdentifier = HoldIdentifierWrapper; type WeightInfo = pallet_domains::weights::SubstrateWeight; type InitialDomainTxRange = InitialDomainTxRange; type DomainTxRangeAdjustmentInterval = DomainTxRangeAdjustmentInterval;