Skip to content

Commit

Permalink
add config type for reserve portion taken by protocol when the init c…
Browse files Browse the repository at this point in the history
…hannel is requested to be closed
  • Loading branch information
vedhavyas committed Jun 6, 2024
1 parent e132217 commit bb7e1f6
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 2 deletions.
4 changes: 3 additions & 1 deletion crates/subspace-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ use sp_runtime::traits::{
};
use sp_runtime::transaction_validity::{TransactionSource, TransactionValidity};
use sp_runtime::{
create_runtime_str, generic, AccountId32, ApplyExtrinsicResult, ExtrinsicInclusionMode,
create_runtime_str, generic, AccountId32, ApplyExtrinsicResult, ExtrinsicInclusionMode, Perbill,
};
use sp_std::collections::btree_map::BTreeMap;
use sp_std::marker::PhantomData;
Expand Down Expand Up @@ -507,6 +507,7 @@ impl sp_messenger::StorageKeys for StorageKeys {
parameter_types! {
// TODO: update value
pub const ChannelReserveFee: Balance = 100 * SSC;
pub const ChannelInitReservePortion: Perbill = Perbill::from_percent(20);
}

impl pallet_messenger::Config for Runtime {
Expand All @@ -531,6 +532,7 @@ impl pallet_messenger::Config for Runtime {
type DomainOwner = Domains;
type HoldIdentifier = HoldIdentifier;
type ChannelReserveFee = ChannelReserveFee;
type ChannelInitReservePortion = ChannelInitReservePortion;
}

impl<C> frame_system::offchain::SendTransactionTypes<C> for Runtime
Expand Down
6 changes: 5 additions & 1 deletion domains/pallets/messenger/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ mod pallet {
use sp_messenger::{
InherentError, InherentType, OnXDMRewards, StorageKeys, INHERENT_IDENTIFIER,
};
use sp_runtime::ArithmeticError;
use sp_runtime::{ArithmeticError, Perbill};
use sp_subspace_mmr::MmrProofVerifier;
#[cfg(feature = "std")]
use std::collections::BTreeSet;
Expand Down Expand Up @@ -201,6 +201,10 @@ mod pallet {
/// Channel reserve fee to open a channel.
#[pallet::constant]
type ChannelReserveFee: Get<BalanceOf<Self>>;
/// Portion of Channel reserve taken by the protocol
/// if the channel is in init state and is requested to be closed.
#[pallet::constant]
type ChannelInitReservePortion: Get<Perbill>;
}

/// Pallet messenger used to communicate between chains and other blockchains.
Expand Down
3 changes: 3 additions & 0 deletions domains/pallets/messenger/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ macro_rules! impl_runtime {
use sp_domains::MessengerHoldIdentifier;
use frame_support::traits::VariantCount;
use core::mem;
use sp_runtime::Perbill;

type Block = frame_system::mocking::MockBlock<Runtime>;

Expand All @@ -59,6 +60,7 @@ macro_rules! impl_runtime {
parameter_types! {
pub SelfChainId: ChainId = $chain_id.into();
pub const ChannelReserveFee: Balance = 10;
pub const ChannelInitReservePortion: Perbill = Perbill::from_percent(20);
}

#[derive(
Expand Down Expand Up @@ -90,6 +92,7 @@ macro_rules! impl_runtime {
type StorageKeys = ();
type DomainOwner = ();
type ChannelReserveFee = ChannelReserveFee;
type ChannelInitReservePortion = ChannelInitReservePortion;
type HoldIdentifier = MockHoldIdentifer;
/// function to fetch endpoint response handler by Endpoint.
fn get_endpoint_handler(
Expand Down
2 changes: 2 additions & 0 deletions domains/runtime/auto-id/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ impl pallet_messenger::HoldIdentifier<Runtime> for HoldIdentifier {

parameter_types! {
pub const ChannelReserveFee: Balance = 100 * SSC;
pub const ChannelInitReservePortion: Perbill = Perbill::from_percent(20);
}

impl pallet_messenger::Config for Runtime {
Expand All @@ -411,6 +412,7 @@ impl pallet_messenger::Config for Runtime {
type DomainOwner = ();
type HoldIdentifier = HoldIdentifier;
type ChannelReserveFee = ChannelReserveFee;
type ChannelInitReservePortion = ChannelInitReservePortion;
}

impl<C> frame_system::offchain::SendTransactionTypes<C> for Runtime
Expand Down
2 changes: 2 additions & 0 deletions domains/runtime/evm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,7 @@ impl pallet_messenger::HoldIdentifier<Runtime> for HoldIdentifier {

parameter_types! {
pub const ChannelReserveFee: Balance = 100 * SSC;
pub const ChannelInitReservePortion: Perbill = Perbill::from_percent(20);
}

impl pallet_messenger::Config for Runtime {
Expand All @@ -540,6 +541,7 @@ impl pallet_messenger::Config for Runtime {
type DomainOwner = ();
type HoldIdentifier = HoldIdentifier;
type ChannelReserveFee = ChannelReserveFee;
type ChannelInitReservePortion = ChannelInitReservePortion;
}

impl<C> frame_system::offchain::SendTransactionTypes<C> for Runtime
Expand Down
2 changes: 2 additions & 0 deletions domains/test/runtime/evm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,7 @@ impl pallet_messenger::HoldIdentifier<Runtime> for HoldIdentifier {

parameter_types! {
pub const ChannelReserveFee: Balance = SSC;
pub const ChannelInitReservePortion: Perbill = Perbill::from_percent(20);
}

pub struct StorageKeys;
Expand Down Expand Up @@ -522,6 +523,7 @@ impl pallet_messenger::Config for Runtime {
type DomainOwner = ();
type HoldIdentifier = HoldIdentifier;
type ChannelReserveFee = ChannelReserveFee;
type ChannelInitReservePortion = ChannelInitReservePortion;
}

impl<C> frame_system::offchain::SendTransactionTypes<C> for Runtime
Expand Down
2 changes: 2 additions & 0 deletions test/subspace-test-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,7 @@ impl sp_messenger::StorageKeys for StorageKeys {

parameter_types! {
pub const ChannelReserveFee: Balance = SSC;
pub const ChannelInitReservePortion: Perbill = Perbill::from_percent(20);
}

impl pallet_messenger::Config for Runtime {
Expand All @@ -619,6 +620,7 @@ impl pallet_messenger::Config for Runtime {
type DomainOwner = Domains;
type HoldIdentifier = HoldIdentifier;
type ChannelReserveFee = ChannelReserveFee;
type ChannelInitReservePortion = ChannelInitReservePortion;
}

impl<C> frame_system::offchain::SendTransactionTypes<C> for Runtime
Expand Down

0 comments on commit bb7e1f6

Please sign in to comment.