diff --git a/Cargo.lock b/Cargo.lock index 24779abeb8..4f608bd685 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1013,6 +1013,7 @@ dependencies = [ "sp-subspace-mmr", "sp-transaction-pool", "sp-version", + "static_assertions", "subspace-core-primitives", "subspace-runtime-primitives", "substrate-wasm-builder", @@ -1061,6 +1062,7 @@ dependencies = [ "sp-subspace-mmr", "sp-transaction-pool", "sp-version", + "static_assertions", "subspace-core-primitives", "subspace-runtime-primitives", "substrate-wasm-builder", @@ -3285,6 +3287,7 @@ dependencies = [ "sp-subspace-mmr", "sp-transaction-pool", "sp-version", + "static_assertions", "subspace-core-primitives", "subspace-runtime-primitives", "substrate-wasm-builder", @@ -3340,6 +3343,7 @@ dependencies = [ "sp-subspace-mmr", "sp-transaction-pool", "sp-version", + "static_assertions", "subspace-core-primitives", "subspace-runtime-primitives", "substrate-wasm-builder", diff --git a/crates/subspace-runtime/src/lib.rs b/crates/subspace-runtime/src/lib.rs index f0ac27b258..0de246f52f 100644 --- a/crates/subspace-runtime/src/lib.rs +++ b/crates/subspace-runtime/src/lib.rs @@ -650,8 +650,12 @@ parameter_types! { pub const ChannelInitReservePortion: Perbill = Perbill::from_percent(20); // TODO update the fee model pub const ChannelFeeModel: FeeModel = FeeModel{relay_fee: SSC}; + pub const MaxOutgoingMessages: u32 = 25; } +// ensure the max outgoing messages is not 0. +const_assert!(MaxOutgoingMessages::get() >= 1); + pub struct DomainRegistration; impl sp_messenger::DomainRegistration for DomainRegistration { fn is_domain_registered(domain_id: DomainId) -> bool { @@ -684,6 +688,7 @@ impl pallet_messenger::Config for Runtime { type ChannelInitReservePortion = ChannelInitReservePortion; type DomainRegistration = DomainRegistration; type ChannelFeeModel = ChannelFeeModel; + type MaxOutgoingMessages = MaxOutgoingMessages; } impl frame_system::offchain::SendTransactionTypes for Runtime diff --git a/domains/client/domain-operator/src/tests.rs b/domains/client/domain-operator/src/tests.rs index d201ac9d8e..7ddc81f156 100644 --- a/domains/client/domain-operator/src/tests.rs +++ b/domains/client/domain-operator/src/tests.rs @@ -3784,9 +3784,6 @@ async fn test_domain_sudo_calls() { .construct_and_send_extrinsic(evm_domain_test_runtime::RuntimeCall::Messenger( pallet_messenger::Call::initiate_channel { dst_chain_id: ChainId::Consensus, - params: pallet_messenger::InitiateChannelParams { - max_outgoing_messages: 100, - }, }, )) .await @@ -3927,9 +3924,6 @@ async fn test_xdm_between_consensus_and_domain_should_work() { .construct_and_send_extrinsic(evm_domain_test_runtime::RuntimeCall::Messenger( pallet_messenger::Call::initiate_channel { dst_chain_id: ChainId::Consensus, - params: pallet_messenger::InitiateChannelParams { - max_outgoing_messages: 100, - }, }, )) .await @@ -4140,9 +4134,6 @@ async fn test_xdm_between_domains_should_work() { bob.construct_and_send_extrinsic(auto_id_domain_test_runtime::RuntimeCall::Messenger( pallet_messenger::Call::initiate_channel { dst_chain_id: ChainId::Domain(EVM_DOMAIN_ID), - params: pallet_messenger::InitiateChannelParams { - max_outgoing_messages: 100, - }, }, )) .await @@ -4294,9 +4285,6 @@ async fn test_unordered_cross_domains_message_should_work() { .construct_and_send_extrinsic(evm_domain_test_runtime::RuntimeCall::Messenger( pallet_messenger::Call::initiate_channel { dst_chain_id: ChainId::Consensus, - params: pallet_messenger::InitiateChannelParams { - max_outgoing_messages: 100, - }, }, )) .await @@ -5430,9 +5418,6 @@ async fn test_xdm_false_invalid_fraud_proof() { .construct_and_send_extrinsic(evm_domain_test_runtime::RuntimeCall::Messenger( pallet_messenger::Call::initiate_channel { dst_chain_id: ChainId::Consensus, - params: pallet_messenger::InitiateChannelParams { - max_outgoing_messages: 100, - }, }, )) .await @@ -5628,9 +5613,6 @@ async fn test_stale_fork_xdm_true_invalid_fraud_proof() { .construct_and_send_extrinsic(evm_domain_test_runtime::RuntimeCall::Messenger( pallet_messenger::Call::initiate_channel { dst_chain_id: ChainId::Consensus, - params: pallet_messenger::InitiateChannelParams { - max_outgoing_messages: 100, - }, }, )) .await diff --git a/domains/pallets/messenger/src/benchmarking.rs b/domains/pallets/messenger/src/benchmarking.rs index 9422459e19..53399a4384 100644 --- a/domains/pallets/messenger/src/benchmarking.rs +++ b/domains/pallets/messenger/src/benchmarking.rs @@ -33,9 +33,6 @@ mod benchmarks { fn initiate_channel() { let dst_chain_id: ChainId = u32::MAX.into(); assert_ne!(T::SelfChainId::get(), dst_chain_id); - let channel_params = InitiateChannelParams { - max_outgoing_messages: 100, - }; let channel_id = NextChannelId::::get(dst_chain_id); let account = account("account", 0, 0); T::Currency::set_balance( @@ -47,11 +44,7 @@ mod benchmarks { ChainAllowlist::::put(list); #[extrinsic_call] - _( - RawOrigin::Signed(account.clone()), - dst_chain_id, - channel_params, - ); + _(RawOrigin::Signed(account.clone()), dst_chain_id); let channel = Channels::::get(dst_chain_id, channel_id).expect("channel should exist"); assert_eq!(channel.state, ChannelState::Initiated); diff --git a/domains/pallets/messenger/src/lib.rs b/domains/pallets/messenger/src/lib.rs index ebc1492c6f..ab36d46b3b 100644 --- a/domains/pallets/messenger/src/lib.rs +++ b/domains/pallets/messenger/src/lib.rs @@ -98,12 +98,6 @@ pub(crate) enum CloseChannelBy { Sudo, } -/// Parameters for a new channel between two chains. -#[derive(Default, Debug, Encode, Decode, Clone, Eq, PartialEq, TypeInfo, Copy)] -pub struct InitiateChannelParams { - pub max_outgoing_messages: u32, -} - /// Hold identifier trait for messenger specific balance holds pub trait HoldIdentifier { fn messenger_channel() -> FungibleHoldId; @@ -114,8 +108,8 @@ mod pallet { use crate::weights::WeightInfo; use crate::{ BalanceOf, ChainAllowlistUpdate, Channel, ChannelId, ChannelState, CloseChannelBy, - FeeModel, HoldIdentifier, InitiateChannelParams, Nonce, OutboxMessageResult, StateRootOf, - ValidatedRelayMessage, U256, + FeeModel, HoldIdentifier, Nonce, OutboxMessageResult, StateRootOf, ValidatedRelayMessage, + U256, }; #[cfg(not(feature = "std"))] use alloc::boxed::Box; @@ -191,6 +185,8 @@ mod pallet { type DomainRegistration: DomainRegistration; /// Channels fee model type ChannelFeeModel: Get>>; + /// Maximum outgoing messages from a given channel + type MaxOutgoingMessages: Get; } /// Pallet messenger used to communicate between chains and other blockchains. @@ -559,11 +555,7 @@ mod pallet { /// Channel is set to initiated and do not accept or receive any messages. #[pallet::call_index(0)] #[pallet::weight(T::WeightInfo::initiate_channel())] - pub fn initiate_channel( - origin: OriginFor, - dst_chain_id: ChainId, - params: InitiateChannelParams, - ) -> DispatchResult { + pub fn initiate_channel(origin: OriginFor, dst_chain_id: ChainId) -> DispatchResult { let owner = ensure_signed(origin)?; // reserve channel open fees @@ -580,7 +572,7 @@ mod pallet { // initiate the channel config let channel_open_params = ChannelOpenParams { - max_outgoing_messages: params.max_outgoing_messages, + max_outgoing_messages: T::MaxOutgoingMessages::get(), fee_model: T::ChannelFeeModel::get(), }; let channel_id = Self::do_init_channel( @@ -1014,7 +1006,7 @@ mod pallet { Error::::InvalidChain, ); - // ensure max outgoing messages is atleast 1 + // ensure max outgoing messages is at least 1 ensure!( init_params.max_outgoing_messages >= 1u32, Error::::InvalidMaxOutgoingMessages diff --git a/domains/pallets/messenger/src/mock.rs b/domains/pallets/messenger/src/mock.rs index d6cd143682..0f82ecb686 100644 --- a/domains/pallets/messenger/src/mock.rs +++ b/domains/pallets/messenger/src/mock.rs @@ -60,6 +60,7 @@ macro_rules! impl_runtime { pub const ChannelReserveFee: Balance = 10; pub const ChannelInitReservePortion: Perbill = Perbill::from_percent(20); pub const ChannelFeeModel: FeeModel = FeeModel{relay_fee: 1}; + pub const MaxOutgoingMessages: u32 = 25; } #[derive( @@ -102,6 +103,7 @@ macro_rules! impl_runtime { type HoldIdentifier = MockHoldIdentifer; type DomainRegistration = DomainRegistration; type ChannelFeeModel = ChannelFeeModel; + type MaxOutgoingMessages = MaxOutgoingMessages; /// function to fetch endpoint response handler by Endpoint. fn get_endpoint_handler( #[allow(unused_variables)] endpoint: &Endpoint, diff --git a/domains/pallets/messenger/src/tests.rs b/domains/pallets/messenger/src/tests.rs index f58ae7a9f0..a60fe44f4f 100644 --- a/domains/pallets/messenger/src/tests.rs +++ b/domains/pallets/messenger/src/tests.rs @@ -9,8 +9,8 @@ use crate::mock::{ use crate::pallet::OutboxMessageCount; use crate::{ ChainAllowlist, ChainAllowlistUpdate, Channel, ChannelId, ChannelState, Channels, - CloseChannelBy, Error, FeeModel, Inbox, InboxResponses, InitiateChannelParams, Nonce, Outbox, - OutboxMessageResult, OutboxResponses, Pallet, U256, + CloseChannelBy, Error, FeeModel, Inbox, InboxResponses, Nonce, Outbox, OutboxMessageResult, + OutboxResponses, Pallet, U256, }; use frame_support::traits::fungible::Inspect; use frame_support::traits::tokens::{Fortitude, Preservation}; @@ -32,16 +32,11 @@ use sp_trie::StorageProof; use std::collections::BTreeSet; fn create_channel(chain_id: ChainId, channel_id: ChannelId) { - let params = InitiateChannelParams { - max_outgoing_messages: 100, - }; - let list = BTreeSet::from([chain_id]); ChainAllowlist::::put(list); assert_ok!(Messenger::initiate_channel( RuntimeOrigin::signed(USER_ACCOUNT), chain_id, - params, )); System::assert_has_event(RuntimeEvent::Messenger( @@ -71,7 +66,7 @@ fn create_channel(chain_id: ChainId, channel_id: ChannelId) { msg.payload, VersionedPayload::V0(Payload::Protocol(RequestResponse::Request( ProtocolMessageRequest::ChannelOpen(ChannelOpenParams { - max_outgoing_messages: params.max_outgoing_messages, + max_outgoing_messages: 25, fee_model: ::ChannelFeeModel::get() }) ))) diff --git a/domains/pallets/transporter/src/mock.rs b/domains/pallets/transporter/src/mock.rs index cf99ce9426..f62e9ba793 100644 --- a/domains/pallets/transporter/src/mock.rs +++ b/domains/pallets/transporter/src/mock.rs @@ -54,6 +54,7 @@ parameter_types! { pub const ChannelInitReservePortion: Perbill = Perbill::from_percent(20); pub const ChannelFeeModel: FeeModel = FeeModel{relay_fee: 1}; pub TransactionWeightFee: Balance = 100_000; + pub const MaxOutgoingMessages: u32 = 25; } #[derive( @@ -97,6 +98,7 @@ impl pallet_messenger::Config for MockRuntime { type HoldIdentifier = MockHoldIdentifer; type DomainRegistration = DomainRegistration; type ChannelFeeModel = ChannelFeeModel; + type MaxOutgoingMessages = MaxOutgoingMessages; /// function to fetch endpoint response handler by Endpoint. fn get_endpoint_handler(_endpoint: &Endpoint) -> Option>> { #[cfg(feature = "runtime-benchmarks")] diff --git a/domains/runtime/auto-id/Cargo.toml b/domains/runtime/auto-id/Cargo.toml index fb46a63690..737692c6e9 100644 --- a/domains/runtime/auto-id/Cargo.toml +++ b/domains/runtime/auto-id/Cargo.toml @@ -56,6 +56,7 @@ sp-storage = { default-features = false, git = "https://github.com/subspace/polk sp-subspace-mmr = { version = "0.1.0", default-features = false, path = "../../../crates/sp-subspace-mmr" } sp-transaction-pool = { default-features = false, git = "https://github.com/subspace/polkadot-sdk", rev = "94a1a8143a89bbe9f938c1939ff68abc1519a305" } sp-version = { default-features = false, git = "https://github.com/subspace/polkadot-sdk", rev = "94a1a8143a89bbe9f938c1939ff68abc1519a305" } +static_assertions = "1.1.0" subspace-core-primitives = { version = "0.1.0", path = "../../../crates/subspace-core-primitives", default-features = false } subspace-runtime-primitives = { version = "0.1.0", path = "../../../crates/subspace-runtime-primitives", default-features = false } diff --git a/domains/runtime/auto-id/src/lib.rs b/domains/runtime/auto-id/src/lib.rs index ade1200f0c..7b390f9be6 100644 --- a/domains/runtime/auto-id/src/lib.rs +++ b/domains/runtime/auto-id/src/lib.rs @@ -66,6 +66,7 @@ use sp_subspace_mmr::domain_mmr_runtime_interface::{ }; use sp_subspace_mmr::{ConsensusChainMmrLeafProof, MmrLeaf}; use sp_version::RuntimeVersion; +use static_assertions::const_assert; use subspace_runtime_primitives::{ BlockNumber as ConsensusBlockNumber, Hash as ConsensusBlockHash, Moment, SlowAdjustingFeeUpdate, SHANNON, SSC, @@ -389,8 +390,12 @@ parameter_types! { pub const ChannelInitReservePortion: Perbill = Perbill::from_percent(20); // TODO update the fee model pub const ChannelFeeModel: FeeModel = FeeModel{relay_fee: SSC}; + pub const MaxOutgoingMessages: u32 = 25; } +// ensure the max outgoing messages is not 0. +const_assert!(MaxOutgoingMessages::get() >= 1); + impl pallet_messenger::Config for Runtime { type RuntimeEvent = RuntimeEvent; type SelfChainId = SelfChainId; @@ -416,6 +421,7 @@ impl pallet_messenger::Config for Runtime { type ChannelInitReservePortion = ChannelInitReservePortion; type DomainRegistration = (); type ChannelFeeModel = ChannelFeeModel; + type MaxOutgoingMessages = MaxOutgoingMessages; } impl frame_system::offchain::SendTransactionTypes for Runtime diff --git a/domains/runtime/evm/Cargo.toml b/domains/runtime/evm/Cargo.toml index 6fecb2f63f..b1826a280a 100644 --- a/domains/runtime/evm/Cargo.toml +++ b/domains/runtime/evm/Cargo.toml @@ -66,6 +66,7 @@ sp-storage = { default-features = false, git = "https://github.com/subspace/polk sp-subspace-mmr = { version = "0.1.0", default-features = false, path = "../../../crates/sp-subspace-mmr" } sp-transaction-pool = { default-features = false, git = "https://github.com/subspace/polkadot-sdk", rev = "94a1a8143a89bbe9f938c1939ff68abc1519a305" } sp-version = { default-features = false, git = "https://github.com/subspace/polkadot-sdk", rev = "94a1a8143a89bbe9f938c1939ff68abc1519a305" } +static_assertions = "1.1.0" subspace-core-primitives = { version = "0.1.0", path = "../../../crates/subspace-core-primitives", default-features = false } subspace-runtime-primitives = { version = "0.1.0", path = "../../../crates/subspace-runtime-primitives", default-features = false } diff --git a/domains/runtime/evm/src/lib.rs b/domains/runtime/evm/src/lib.rs index 965573b918..ec5dc5ea81 100644 --- a/domains/runtime/evm/src/lib.rs +++ b/domains/runtime/evm/src/lib.rs @@ -84,6 +84,7 @@ use sp_subspace_mmr::domain_mmr_runtime_interface::{ }; use sp_subspace_mmr::{ConsensusChainMmrLeafProof, MmrLeaf}; use sp_version::RuntimeVersion; +use static_assertions::const_assert; use subspace_runtime_primitives::{ BlockNumber as ConsensusBlockNumber, Hash as ConsensusBlockHash, Moment, SlowAdjustingFeeUpdate, SHANNON, SSC, @@ -534,8 +535,12 @@ parameter_types! { pub const ChannelInitReservePortion: Perbill = Perbill::from_percent(20); // TODO update the fee model pub const ChannelFeeModel: FeeModel = FeeModel{relay_fee: SSC}; + pub const MaxOutgoingMessages: u32 = 25; } +// ensure the max outgoing messages is not 0. +const_assert!(MaxOutgoingMessages::get() >= 1); + impl pallet_messenger::Config for Runtime { type RuntimeEvent = RuntimeEvent; type SelfChainId = SelfChainId; @@ -561,6 +566,7 @@ impl pallet_messenger::Config for Runtime { type ChannelInitReservePortion = ChannelInitReservePortion; type DomainRegistration = (); type ChannelFeeModel = ChannelFeeModel; + type MaxOutgoingMessages = MaxOutgoingMessages; } impl frame_system::offchain::SendTransactionTypes for Runtime diff --git a/domains/test/runtime/auto-id/Cargo.toml b/domains/test/runtime/auto-id/Cargo.toml index a69eed2e75..ec75b680f4 100644 --- a/domains/test/runtime/auto-id/Cargo.toml +++ b/domains/test/runtime/auto-id/Cargo.toml @@ -56,6 +56,7 @@ sp-storage = { default-features = false, git = "https://github.com/subspace/polk sp-subspace-mmr = { version = "0.1.0", default-features = false, path = "../../../../crates/sp-subspace-mmr" } sp-transaction-pool = { default-features = false, git = "https://github.com/subspace/polkadot-sdk", rev = "94a1a8143a89bbe9f938c1939ff68abc1519a305" } sp-version = { default-features = false, git = "https://github.com/subspace/polkadot-sdk", rev = "94a1a8143a89bbe9f938c1939ff68abc1519a305" } +static_assertions = "1.1.0" subspace-core-primitives = { version = "0.1.0", path = "../../../../crates/subspace-core-primitives", default-features = false } subspace-runtime-primitives = { version = "0.1.0", path = "../../../../crates/subspace-runtime-primitives", default-features = false } diff --git a/domains/test/runtime/auto-id/src/lib.rs b/domains/test/runtime/auto-id/src/lib.rs index ca1d80a13d..369e1e18ec 100644 --- a/domains/test/runtime/auto-id/src/lib.rs +++ b/domains/test/runtime/auto-id/src/lib.rs @@ -66,6 +66,7 @@ use sp_subspace_mmr::domain_mmr_runtime_interface::{ }; use sp_subspace_mmr::{ConsensusChainMmrLeafProof, MmrLeaf}; use sp_version::RuntimeVersion; +use static_assertions::const_assert; use subspace_runtime_primitives::{ BlockNumber as ConsensusBlockNumber, Hash as ConsensusBlockHash, Moment, SlowAdjustingFeeUpdate, SSC, @@ -388,8 +389,12 @@ parameter_types! { pub const ChannelInitReservePortion: Perbill = Perbill::from_percent(20); // TODO update the fee model pub const ChannelFeeModel: FeeModel = FeeModel{relay_fee: SSC}; + pub const MaxOutgoingMessages: u32 = 25; } +// ensure the max outgoing messages is not 0. +const_assert!(MaxOutgoingMessages::get() >= 1); + impl pallet_messenger::Config for Runtime { type RuntimeEvent = RuntimeEvent; type SelfChainId = SelfChainId; @@ -415,6 +420,7 @@ impl pallet_messenger::Config for Runtime { type ChannelInitReservePortion = ChannelInitReservePortion; type DomainRegistration = (); type ChannelFeeModel = ChannelFeeModel; + type MaxOutgoingMessages = MaxOutgoingMessages; } impl frame_system::offchain::SendTransactionTypes for Runtime diff --git a/domains/test/runtime/evm/Cargo.toml b/domains/test/runtime/evm/Cargo.toml index 2f26410460..485cda416f 100644 --- a/domains/test/runtime/evm/Cargo.toml +++ b/domains/test/runtime/evm/Cargo.toml @@ -63,6 +63,7 @@ sp-std = { default-features = false, git = "https://github.com/subspace/polkadot sp-subspace-mmr = { version = "0.1.0", default-features = false, path = "../../../../crates/sp-subspace-mmr" } sp-transaction-pool = { default-features = false, git = "https://github.com/subspace/polkadot-sdk", rev = "94a1a8143a89bbe9f938c1939ff68abc1519a305" } sp-version = { default-features = false, git = "https://github.com/subspace/polkadot-sdk", rev = "94a1a8143a89bbe9f938c1939ff68abc1519a305" } +static_assertions = "1.1.0" subspace-core-primitives = { version = "0.1.0", path = "../../../../crates/subspace-core-primitives", default-features = false } subspace-runtime-primitives = { version = "0.1.0", path = "../../../../crates/subspace-runtime-primitives", default-features = false } diff --git a/domains/test/runtime/evm/src/lib.rs b/domains/test/runtime/evm/src/lib.rs index a46ad36a43..020a5fc8d3 100644 --- a/domains/test/runtime/evm/src/lib.rs +++ b/domains/test/runtime/evm/src/lib.rs @@ -84,6 +84,7 @@ use sp_subspace_mmr::domain_mmr_runtime_interface::{ }; use sp_subspace_mmr::{ConsensusChainMmrLeafProof, MmrLeaf}; use sp_version::RuntimeVersion; +use static_assertions::const_assert; use subspace_runtime_primitives::{ BlockNumber as ConsensusBlockNumber, Hash as ConsensusBlockHash, Moment, SHANNON, SSC, }; @@ -498,8 +499,12 @@ parameter_types! { pub const ChannelReserveFee: Balance = SSC; pub const ChannelInitReservePortion: Perbill = Perbill::from_percent(20); pub const ChannelFeeModel: FeeModel = FeeModel{relay_fee: SSC}; + pub const MaxOutgoingMessages: u32 = 25; } +// ensure the max outgoing messages is not 0. +const_assert!(MaxOutgoingMessages::get() >= 1); + pub struct StorageKeys; impl sp_messenger::StorageKeys for StorageKeys { @@ -547,6 +552,7 @@ impl pallet_messenger::Config for Runtime { type ChannelInitReservePortion = ChannelInitReservePortion; type DomainRegistration = (); type ChannelFeeModel = ChannelFeeModel; + type MaxOutgoingMessages = MaxOutgoingMessages; } impl frame_system::offchain::SendTransactionTypes for Runtime diff --git a/test/subspace-test-runtime/src/lib.rs b/test/subspace-test-runtime/src/lib.rs index db14548917..2cad894248 100644 --- a/test/subspace-test-runtime/src/lib.rs +++ b/test/subspace-test-runtime/src/lib.rs @@ -595,8 +595,12 @@ parameter_types! { pub const ChannelReserveFee: Balance = SSC; pub const ChannelInitReservePortion: Perbill = Perbill::from_percent(20); pub const ChannelFeeModel: FeeModel = FeeModel{relay_fee: SSC}; + pub const MaxOutgoingMessages: u32 = 25; } +// ensure the max outgoing messages is not 0. +const_assert!(MaxOutgoingMessages::get() >= 1); + pub struct OnXDMRewards; impl sp_messenger::OnXDMRewards for OnXDMRewards { @@ -640,6 +644,7 @@ impl pallet_messenger::Config for Runtime { type ChannelInitReservePortion = ChannelInitReservePortion; type DomainRegistration = DomainRegistration; type ChannelFeeModel = ChannelFeeModel; + type MaxOutgoingMessages = MaxOutgoingMessages; } impl frame_system::offchain::SendTransactionTypes for Runtime