Skip to content

Commit 73c7574

Browse files
committed
set default max outgoing messages to 25 for all channels
1 parent 73c12b3 commit 73c7574

File tree

17 files changed

+57
-49
lines changed

17 files changed

+57
-49
lines changed

Cargo.lock

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/subspace-runtime/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,8 +650,12 @@ parameter_types! {
650650
pub const ChannelInitReservePortion: Perbill = Perbill::from_percent(20);
651651
// TODO update the fee model
652652
pub const ChannelFeeModel: FeeModel<Balance> = FeeModel{relay_fee: SSC};
653+
pub const MaxOutgoingMessages: u32 = 25;
653654
}
654655

656+
// ensure the max outgoing messages is not 0.
657+
const_assert!(MaxOutgoingMessages::get() >= 1);
658+
655659
pub struct DomainRegistration;
656660
impl sp_messenger::DomainRegistration for DomainRegistration {
657661
fn is_domain_registered(domain_id: DomainId) -> bool {
@@ -684,6 +688,7 @@ impl pallet_messenger::Config for Runtime {
684688
type ChannelInitReservePortion = ChannelInitReservePortion;
685689
type DomainRegistration = DomainRegistration;
686690
type ChannelFeeModel = ChannelFeeModel;
691+
type MaxOutgoingMessages = MaxOutgoingMessages;
687692
}
688693

689694
impl<C> frame_system::offchain::SendTransactionTypes<C> for Runtime

domains/client/domain-operator/src/tests.rs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3784,9 +3784,6 @@ async fn test_domain_sudo_calls() {
37843784
.construct_and_send_extrinsic(evm_domain_test_runtime::RuntimeCall::Messenger(
37853785
pallet_messenger::Call::initiate_channel {
37863786
dst_chain_id: ChainId::Consensus,
3787-
params: pallet_messenger::InitiateChannelParams {
3788-
max_outgoing_messages: 100,
3789-
},
37903787
},
37913788
))
37923789
.await
@@ -3927,9 +3924,6 @@ async fn test_xdm_between_consensus_and_domain_should_work() {
39273924
.construct_and_send_extrinsic(evm_domain_test_runtime::RuntimeCall::Messenger(
39283925
pallet_messenger::Call::initiate_channel {
39293926
dst_chain_id: ChainId::Consensus,
3930-
params: pallet_messenger::InitiateChannelParams {
3931-
max_outgoing_messages: 100,
3932-
},
39333927
},
39343928
))
39353929
.await
@@ -4140,9 +4134,6 @@ async fn test_xdm_between_domains_should_work() {
41404134
bob.construct_and_send_extrinsic(auto_id_domain_test_runtime::RuntimeCall::Messenger(
41414135
pallet_messenger::Call::initiate_channel {
41424136
dst_chain_id: ChainId::Domain(EVM_DOMAIN_ID),
4143-
params: pallet_messenger::InitiateChannelParams {
4144-
max_outgoing_messages: 100,
4145-
},
41464137
},
41474138
))
41484139
.await
@@ -4294,9 +4285,6 @@ async fn test_unordered_cross_domains_message_should_work() {
42944285
.construct_and_send_extrinsic(evm_domain_test_runtime::RuntimeCall::Messenger(
42954286
pallet_messenger::Call::initiate_channel {
42964287
dst_chain_id: ChainId::Consensus,
4297-
params: pallet_messenger::InitiateChannelParams {
4298-
max_outgoing_messages: 100,
4299-
},
43004288
},
43014289
))
43024290
.await
@@ -5430,9 +5418,6 @@ async fn test_xdm_false_invalid_fraud_proof() {
54305418
.construct_and_send_extrinsic(evm_domain_test_runtime::RuntimeCall::Messenger(
54315419
pallet_messenger::Call::initiate_channel {
54325420
dst_chain_id: ChainId::Consensus,
5433-
params: pallet_messenger::InitiateChannelParams {
5434-
max_outgoing_messages: 100,
5435-
},
54365421
},
54375422
))
54385423
.await
@@ -5628,9 +5613,6 @@ async fn test_stale_fork_xdm_true_invalid_fraud_proof() {
56285613
.construct_and_send_extrinsic(evm_domain_test_runtime::RuntimeCall::Messenger(
56295614
pallet_messenger::Call::initiate_channel {
56305615
dst_chain_id: ChainId::Consensus,
5631-
params: pallet_messenger::InitiateChannelParams {
5632-
max_outgoing_messages: 100,
5633-
},
56345616
},
56355617
))
56365618
.await

domains/pallets/messenger/src/benchmarking.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@ mod benchmarks {
3333
fn initiate_channel() {
3434
let dst_chain_id: ChainId = u32::MAX.into();
3535
assert_ne!(T::SelfChainId::get(), dst_chain_id);
36-
let channel_params = InitiateChannelParams {
37-
max_outgoing_messages: 100,
38-
};
3936
let channel_id = NextChannelId::<T>::get(dst_chain_id);
4037
let account = account("account", 0, 0);
4138
T::Currency::set_balance(
@@ -47,11 +44,7 @@ mod benchmarks {
4744
ChainAllowlist::<T>::put(list);
4845

4946
#[extrinsic_call]
50-
_(
51-
RawOrigin::Signed(account.clone()),
52-
dst_chain_id,
53-
channel_params,
54-
);
47+
_(RawOrigin::Signed(account.clone()), dst_chain_id);
5548

5649
let channel = Channels::<T>::get(dst_chain_id, channel_id).expect("channel should exist");
5750
assert_eq!(channel.state, ChannelState::Initiated);

domains/pallets/messenger/src/lib.rs

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,6 @@ pub(crate) enum CloseChannelBy<AccountId> {
9898
Sudo,
9999
}
100100

101-
/// Parameters for a new channel between two chains.
102-
#[derive(Default, Debug, Encode, Decode, Clone, Eq, PartialEq, TypeInfo, Copy)]
103-
pub struct InitiateChannelParams {
104-
pub max_outgoing_messages: u32,
105-
}
106-
107101
/// Hold identifier trait for messenger specific balance holds
108102
pub trait HoldIdentifier<T: Config> {
109103
fn messenger_channel() -> FungibleHoldId<T>;
@@ -114,8 +108,8 @@ mod pallet {
114108
use crate::weights::WeightInfo;
115109
use crate::{
116110
BalanceOf, ChainAllowlistUpdate, Channel, ChannelId, ChannelState, CloseChannelBy,
117-
FeeModel, HoldIdentifier, InitiateChannelParams, Nonce, OutboxMessageResult, StateRootOf,
118-
ValidatedRelayMessage, U256,
111+
FeeModel, HoldIdentifier, Nonce, OutboxMessageResult, StateRootOf, ValidatedRelayMessage,
112+
U256,
119113
};
120114
#[cfg(not(feature = "std"))]
121115
use alloc::boxed::Box;
@@ -191,6 +185,8 @@ mod pallet {
191185
type DomainRegistration: DomainRegistration;
192186
/// Channels fee model
193187
type ChannelFeeModel: Get<FeeModel<BalanceOf<Self>>>;
188+
/// Maximum outgoing messages from a given channel
189+
type MaxOutgoingMessages: Get<u32>;
194190
}
195191

196192
/// Pallet messenger used to communicate between chains and other blockchains.
@@ -559,11 +555,7 @@ mod pallet {
559555
/// Channel is set to initiated and do not accept or receive any messages.
560556
#[pallet::call_index(0)]
561557
#[pallet::weight(T::WeightInfo::initiate_channel())]
562-
pub fn initiate_channel(
563-
origin: OriginFor<T>,
564-
dst_chain_id: ChainId,
565-
params: InitiateChannelParams,
566-
) -> DispatchResult {
558+
pub fn initiate_channel(origin: OriginFor<T>, dst_chain_id: ChainId) -> DispatchResult {
567559
let owner = ensure_signed(origin)?;
568560

569561
// reserve channel open fees
@@ -580,7 +572,7 @@ mod pallet {
580572

581573
// initiate the channel config
582574
let channel_open_params = ChannelOpenParams {
583-
max_outgoing_messages: params.max_outgoing_messages,
575+
max_outgoing_messages: T::MaxOutgoingMessages::get(),
584576
fee_model: T::ChannelFeeModel::get(),
585577
};
586578
let channel_id = Self::do_init_channel(
@@ -1014,7 +1006,7 @@ mod pallet {
10141006
Error::<T>::InvalidChain,
10151007
);
10161008

1017-
// ensure max outgoing messages is atleast 1
1009+
// ensure max outgoing messages is at least 1
10181010
ensure!(
10191011
init_params.max_outgoing_messages >= 1u32,
10201012
Error::<T>::InvalidMaxOutgoingMessages

domains/pallets/messenger/src/mock.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ macro_rules! impl_runtime {
6060
pub const ChannelReserveFee: Balance = 10;
6161
pub const ChannelInitReservePortion: Perbill = Perbill::from_percent(20);
6262
pub const ChannelFeeModel: FeeModel<Balance> = FeeModel{relay_fee: 1};
63+
pub const MaxOutgoingMessages: u32 = 25;
6364
}
6465

6566
#[derive(
@@ -102,6 +103,7 @@ macro_rules! impl_runtime {
102103
type HoldIdentifier = MockHoldIdentifer;
103104
type DomainRegistration = DomainRegistration;
104105
type ChannelFeeModel = ChannelFeeModel;
106+
type MaxOutgoingMessages = MaxOutgoingMessages;
105107
/// function to fetch endpoint response handler by Endpoint.
106108
fn get_endpoint_handler(
107109
#[allow(unused_variables)] endpoint: &Endpoint,

domains/pallets/messenger/src/tests.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ use crate::mock::{
99
use crate::pallet::OutboxMessageCount;
1010
use crate::{
1111
ChainAllowlist, ChainAllowlistUpdate, Channel, ChannelId, ChannelState, Channels,
12-
CloseChannelBy, Error, FeeModel, Inbox, InboxResponses, InitiateChannelParams, Nonce, Outbox,
13-
OutboxMessageResult, OutboxResponses, Pallet, U256,
12+
CloseChannelBy, Error, FeeModel, Inbox, InboxResponses, Nonce, Outbox, OutboxMessageResult,
13+
OutboxResponses, Pallet, U256,
1414
};
1515
use frame_support::traits::fungible::Inspect;
1616
use frame_support::traits::tokens::{Fortitude, Preservation};
@@ -32,16 +32,11 @@ use sp_trie::StorageProof;
3232
use std::collections::BTreeSet;
3333

3434
fn create_channel(chain_id: ChainId, channel_id: ChannelId) {
35-
let params = InitiateChannelParams {
36-
max_outgoing_messages: 100,
37-
};
38-
3935
let list = BTreeSet::from([chain_id]);
4036
ChainAllowlist::<chain_a::Runtime>::put(list);
4137
assert_ok!(Messenger::initiate_channel(
4238
RuntimeOrigin::signed(USER_ACCOUNT),
4339
chain_id,
44-
params,
4540
));
4641

4742
System::assert_has_event(RuntimeEvent::Messenger(
@@ -71,7 +66,7 @@ fn create_channel(chain_id: ChainId, channel_id: ChannelId) {
7166
msg.payload,
7267
VersionedPayload::V0(Payload::Protocol(RequestResponse::Request(
7368
ProtocolMessageRequest::ChannelOpen(ChannelOpenParams {
74-
max_outgoing_messages: params.max_outgoing_messages,
69+
max_outgoing_messages: 25,
7570
fee_model: <chain_a::Runtime as crate::Config>::ChannelFeeModel::get()
7671
})
7772
)))

domains/pallets/transporter/src/mock.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ parameter_types! {
5454
pub const ChannelInitReservePortion: Perbill = Perbill::from_percent(20);
5555
pub const ChannelFeeModel: FeeModel<Balance> = FeeModel{relay_fee: 1};
5656
pub TransactionWeightFee: Balance = 100_000;
57+
pub const MaxOutgoingMessages: u32 = 25;
5758
}
5859

5960
#[derive(
@@ -97,6 +98,7 @@ impl pallet_messenger::Config for MockRuntime {
9798
type HoldIdentifier = MockHoldIdentifer;
9899
type DomainRegistration = DomainRegistration;
99100
type ChannelFeeModel = ChannelFeeModel;
101+
type MaxOutgoingMessages = MaxOutgoingMessages;
100102
/// function to fetch endpoint response handler by Endpoint.
101103
fn get_endpoint_handler(_endpoint: &Endpoint) -> Option<Box<dyn EndpointHandler<MessageId>>> {
102104
#[cfg(feature = "runtime-benchmarks")]

domains/runtime/auto-id/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ sp-storage = { default-features = false, git = "https://github.com/subspace/polk
5656
sp-subspace-mmr = { version = "0.1.0", default-features = false, path = "../../../crates/sp-subspace-mmr" }
5757
sp-transaction-pool = { default-features = false, git = "https://github.com/subspace/polkadot-sdk", rev = "94a1a8143a89bbe9f938c1939ff68abc1519a305" }
5858
sp-version = { default-features = false, git = "https://github.com/subspace/polkadot-sdk", rev = "94a1a8143a89bbe9f938c1939ff68abc1519a305" }
59+
static_assertions = "1.1.0"
5960
subspace-core-primitives = { version = "0.1.0", path = "../../../crates/subspace-core-primitives", default-features = false }
6061
subspace-runtime-primitives = { version = "0.1.0", path = "../../../crates/subspace-runtime-primitives", default-features = false }
6162

domains/runtime/auto-id/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ use sp_subspace_mmr::domain_mmr_runtime_interface::{
6666
};
6767
use sp_subspace_mmr::{ConsensusChainMmrLeafProof, MmrLeaf};
6868
use sp_version::RuntimeVersion;
69+
use static_assertions::const_assert;
6970
use subspace_runtime_primitives::{
7071
BlockNumber as ConsensusBlockNumber, Hash as ConsensusBlockHash, Moment,
7172
SlowAdjustingFeeUpdate, SHANNON, SSC,
@@ -389,8 +390,12 @@ parameter_types! {
389390
pub const ChannelInitReservePortion: Perbill = Perbill::from_percent(20);
390391
// TODO update the fee model
391392
pub const ChannelFeeModel: FeeModel<Balance> = FeeModel{relay_fee: SSC};
393+
pub const MaxOutgoingMessages: u32 = 25;
392394
}
393395

396+
// ensure the max outgoing messages is not 0.
397+
const_assert!(MaxOutgoingMessages::get() >= 1);
398+
394399
impl pallet_messenger::Config for Runtime {
395400
type RuntimeEvent = RuntimeEvent;
396401
type SelfChainId = SelfChainId;
@@ -416,6 +421,7 @@ impl pallet_messenger::Config for Runtime {
416421
type ChannelInitReservePortion = ChannelInitReservePortion;
417422
type DomainRegistration = ();
418423
type ChannelFeeModel = ChannelFeeModel;
424+
type MaxOutgoingMessages = MaxOutgoingMessages;
419425
}
420426

421427
impl<C> frame_system::offchain::SendTransactionTypes<C> for Runtime

0 commit comments

Comments
 (0)