Skip to content

Commit

Permalink
set default max outgoing messages to 25 for all channels
Browse files Browse the repository at this point in the history
  • Loading branch information
vedhavyas committed Jan 23, 2025
1 parent 73c12b3 commit 73c7574
Show file tree
Hide file tree
Showing 17 changed files with 57 additions and 49 deletions.
4 changes: 4 additions & 0 deletions Cargo.lock

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

5 changes: 5 additions & 0 deletions crates/subspace-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -650,8 +650,12 @@ parameter_types! {
pub const ChannelInitReservePortion: Perbill = Perbill::from_percent(20);
// TODO update the fee model
pub const ChannelFeeModel: FeeModel<Balance> = 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 {
Expand Down Expand Up @@ -684,6 +688,7 @@ impl pallet_messenger::Config for Runtime {
type ChannelInitReservePortion = ChannelInitReservePortion;
type DomainRegistration = DomainRegistration;
type ChannelFeeModel = ChannelFeeModel;
type MaxOutgoingMessages = MaxOutgoingMessages;
}

impl<C> frame_system::offchain::SendTransactionTypes<C> for Runtime
Expand Down
18 changes: 0 additions & 18 deletions domains/client/domain-operator/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
9 changes: 1 addition & 8 deletions domains/pallets/messenger/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<T>::get(dst_chain_id);
let account = account("account", 0, 0);
T::Currency::set_balance(
Expand All @@ -47,11 +44,7 @@ mod benchmarks {
ChainAllowlist::<T>::put(list);

#[extrinsic_call]
_(
RawOrigin::Signed(account.clone()),
dst_chain_id,
channel_params,
);
_(RawOrigin::Signed(account.clone()), dst_chain_id);

let channel = Channels::<T>::get(dst_chain_id, channel_id).expect("channel should exist");
assert_eq!(channel.state, ChannelState::Initiated);
Expand Down
22 changes: 7 additions & 15 deletions domains/pallets/messenger/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,6 @@ pub(crate) enum CloseChannelBy<AccountId> {
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<T: Config> {
fn messenger_channel() -> FungibleHoldId<T>;
Expand All @@ -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;
Expand Down Expand Up @@ -191,6 +185,8 @@ mod pallet {
type DomainRegistration: DomainRegistration;
/// Channels fee model
type ChannelFeeModel: Get<FeeModel<BalanceOf<Self>>>;
/// Maximum outgoing messages from a given channel
type MaxOutgoingMessages: Get<u32>;
}

/// Pallet messenger used to communicate between chains and other blockchains.
Expand Down Expand Up @@ -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<T>,
dst_chain_id: ChainId,
params: InitiateChannelParams,
) -> DispatchResult {
pub fn initiate_channel(origin: OriginFor<T>, dst_chain_id: ChainId) -> DispatchResult {
let owner = ensure_signed(origin)?;

// reserve channel open fees
Expand All @@ -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(
Expand Down Expand Up @@ -1014,7 +1006,7 @@ mod pallet {
Error::<T>::InvalidChain,
);

// ensure max outgoing messages is atleast 1
// ensure max outgoing messages is at least 1
ensure!(
init_params.max_outgoing_messages >= 1u32,
Error::<T>::InvalidMaxOutgoingMessages
Expand Down
2 changes: 2 additions & 0 deletions domains/pallets/messenger/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Balance> = FeeModel{relay_fee: 1};
pub const MaxOutgoingMessages: u32 = 25;
}

#[derive(
Expand Down Expand Up @@ -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,
Expand Down
11 changes: 3 additions & 8 deletions domains/pallets/messenger/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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::<chain_a::Runtime>::put(list);
assert_ok!(Messenger::initiate_channel(
RuntimeOrigin::signed(USER_ACCOUNT),
chain_id,
params,
));

System::assert_has_event(RuntimeEvent::Messenger(
Expand Down Expand Up @@ -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: <chain_a::Runtime as crate::Config>::ChannelFeeModel::get()
})
)))
Expand Down
2 changes: 2 additions & 0 deletions domains/pallets/transporter/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ parameter_types! {
pub const ChannelInitReservePortion: Perbill = Perbill::from_percent(20);
pub const ChannelFeeModel: FeeModel<Balance> = FeeModel{relay_fee: 1};
pub TransactionWeightFee: Balance = 100_000;
pub const MaxOutgoingMessages: u32 = 25;
}

#[derive(
Expand Down Expand Up @@ -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<Box<dyn EndpointHandler<MessageId>>> {
#[cfg(feature = "runtime-benchmarks")]
Expand Down
1 change: 1 addition & 0 deletions domains/runtime/auto-id/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down
6 changes: 6 additions & 0 deletions domains/runtime/auto-id/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -389,8 +390,12 @@ parameter_types! {
pub const ChannelInitReservePortion: Perbill = Perbill::from_percent(20);
// TODO update the fee model
pub const ChannelFeeModel: FeeModel<Balance> = 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;
Expand All @@ -416,6 +421,7 @@ impl pallet_messenger::Config for Runtime {
type ChannelInitReservePortion = ChannelInitReservePortion;
type DomainRegistration = ();
type ChannelFeeModel = ChannelFeeModel;
type MaxOutgoingMessages = MaxOutgoingMessages;
}

impl<C> frame_system::offchain::SendTransactionTypes<C> for Runtime
Expand Down
1 change: 1 addition & 0 deletions domains/runtime/evm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down
6 changes: 6 additions & 0 deletions domains/runtime/evm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -534,8 +535,12 @@ parameter_types! {
pub const ChannelInitReservePortion: Perbill = Perbill::from_percent(20);
// TODO update the fee model
pub const ChannelFeeModel: FeeModel<Balance> = 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;
Expand All @@ -561,6 +566,7 @@ impl pallet_messenger::Config for Runtime {
type ChannelInitReservePortion = ChannelInitReservePortion;
type DomainRegistration = ();
type ChannelFeeModel = ChannelFeeModel;
type MaxOutgoingMessages = MaxOutgoingMessages;
}

impl<C> frame_system::offchain::SendTransactionTypes<C> for Runtime
Expand Down
1 change: 1 addition & 0 deletions domains/test/runtime/auto-id/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down
6 changes: 6 additions & 0 deletions domains/test/runtime/auto-id/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -388,8 +389,12 @@ parameter_types! {
pub const ChannelInitReservePortion: Perbill = Perbill::from_percent(20);
// TODO update the fee model
pub const ChannelFeeModel: FeeModel<Balance> = 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;
Expand All @@ -415,6 +420,7 @@ impl pallet_messenger::Config for Runtime {
type ChannelInitReservePortion = ChannelInitReservePortion;
type DomainRegistration = ();
type ChannelFeeModel = ChannelFeeModel;
type MaxOutgoingMessages = MaxOutgoingMessages;
}

impl<C> frame_system::offchain::SendTransactionTypes<C> for Runtime
Expand Down
1 change: 1 addition & 0 deletions domains/test/runtime/evm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down
Loading

0 comments on commit 73c7574

Please sign in to comment.