Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

XCM: Properly set the pricing for the DMP router #6843

Merged
merged 46 commits into from
Apr 20, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
145af81
Properly set the pricing for the DMP router
KiChjang Mar 8, 2023
d489025
Publicize price types
KiChjang Mar 8, 2023
39f90fe
Use FixedU128 instead of Percent
KiChjang Mar 9, 2023
824f045
Add sp-arithmetic as a dependency for rococo runtime
KiChjang Mar 9, 2023
f4e0d66
Add sp-arithmetic as a dependency to all runtimes
KiChjang Mar 9, 2023
7a49275
Remove duplicate import
KiChjang Mar 9, 2023
59d6693
Add missing import
KiChjang Mar 9, 2023
500b42f
Fix tests
KiChjang Mar 9, 2023
633430c
Create an appropriate QueueDownwardMessageError variant
KiChjang Mar 10, 2023
7f27521
Recalculate delivery fee factor based on past queue sizes
KiChjang Mar 10, 2023
2fe3547
Remove unused error variant
KiChjang Mar 10, 2023
3f6ea59
Fixes
KiChjang Mar 10, 2023
c36de96
Fixes
KiChjang Mar 10, 2023
7e3d876
Remove unused imports
KiChjang Mar 10, 2023
c5a622d
Rewrite fee factor update mechanism
KiChjang Mar 15, 2023
c83126b
Remove unused imports
KiChjang Mar 15, 2023
85141d2
Merge remote-tracking branch 'origin/master' into kckyeung/xcm-sender…
KiChjang Mar 15, 2023
8c7c9f9
Fixes
KiChjang Mar 15, 2023
395a70b
Update runtime/parachains/src/dmp.rs
KiChjang Mar 16, 2023
a938c9c
Make DeliveryFeeFactor be a StorageMap keyed on ParaIds
KiChjang Mar 21, 2023
56a018d
Fixes
KiChjang Mar 21, 2023
758ff41
merge master
vstam1 Mar 22, 2023
838b9b5
introduce limit for fee increase on dmp queue
vstam1 Mar 22, 2023
1a2bcd6
add message_size based fee factor to increment_fee_factor
vstam1 Mar 23, 2023
3546698
change message_size fee rate to correct value
vstam1 Mar 23, 2023
da90e35
fix div by 0 error
vstam1 Mar 23, 2023
9eefb51
bind limit to variable
vstam1 Mar 23, 2023
5310ce1
merge master
vstam1 Mar 23, 2023
7086ec1
fix message_size_factor and add DeliveryFeeFactor test
vstam1 Mar 24, 2023
f2f0427
add test for ExponentialPrice implementation
vstam1 Mar 27, 2023
e1fa338
make test formula based
vstam1 Mar 27, 2023
303d7d5
make delivery fee factor test formula based
vstam1 Mar 27, 2023
8588ce9
add max value test for DeliveryFeeFactor and move limit to config
vstam1 Mar 28, 2023
7f6cfdf
change threshold back to dynamic value and fix tests
vstam1 Mar 30, 2023
759277c
fmt
vstam1 Mar 30, 2023
a6a7fd9
suggested changes and fmt
vstam1 Mar 31, 2023
0a2a6e7
merge master
vstam1 Mar 31, 2023
d92d990
small stylistic change
vstam1 Apr 3, 2023
aafbb68
merge master
vstam1 Apr 3, 2023
d0c5de1
fmt
vstam1 Apr 3, 2023
ea42774
change to tokenlocation
vstam1 Apr 4, 2023
1732846
small fixes
vstam1 Apr 11, 2023
56fe04d
fmt
vstam1 Apr 11, 2023
2f7acd1
remove sp_arithmetic dependency
vstam1 Apr 14, 2023
8b4877a
Merge branch 'master' into kckyeung/xcm-sender-price
vstam1 Apr 19, 2023
a7e5ded
Update runtime/parachains/src/dmp.rs
vstam1 Apr 20, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions runtime/kusama/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
//! XCM configurations for the Kusama runtime.

use super::{
parachains_origin, AccountId, AllPalletsWithSystem, Balances, CouncilCollective, Fellows,
parachains_origin, AccountId, AllPalletsWithSystem, Balances, CouncilCollective, Dmp, Fellows,
ParaId, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, StakingAdmin, WeightToFee,
XcmPallet,
};
Expand All @@ -26,8 +26,14 @@ use frame_support::{
traits::{Contains, Everything, Nothing},
weights::Weight,
};
use runtime_common::{paras_registrar, xcm_sender, ToAuthor};
use kusama_runtime_constants::currency::CENTS;
use runtime_common::{
paras_registrar,
xcm_sender::{ChildParachainRouter, PriceForParachainDelivery},
ToAuthor,
};
use sp_core::ConstU32;
use sp_runtime::{traits::Saturating, Percent};
use xcm::latest::prelude::*;
use xcm_builder::{
AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses,
Expand Down Expand Up @@ -103,11 +109,22 @@ parameter_types! {
pub const MaxInstructions: u32 = 100;
}

pub struct ExponentialKsmPrice;
impl PriceForParachainDelivery for ExponentialKsmPrice {
fn price_for_parachain_delivery(para: ParaId, _: &Xcm<()>) -> MultiAssets {
let factor = Percent::from_percent(101).saturating_pow(Dmp::dmq_length(para) as usize);
KiChjang marked this conversation as resolved.
Show resolved Hide resolved
let base = CENTS.saturating_mul(3);

let amount = factor * base;
(Here, amount).into()
}
}

/// The XCM router. When we want to send an XCM message, we use this type. It amalgamates all of our
/// individual routers.
pub type XcmRouter = (
// Only one router so far - use DMP to communicate with child parachains.
xcm_sender::ChildParachainRouter<Runtime, XcmPallet, ()>,
ChildParachainRouter<Runtime, XcmPallet, ExponentialKsmPrice>,
);

parameter_types! {
Expand Down
2 changes: 1 addition & 1 deletion runtime/parachains/src/dmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ impl<T: Config> Pallet<T> {
/// Returns the number of pending downward messages addressed to the given para.
///
/// Returns 0 if the para doesn't have an associated downward message queue.
pub(crate) fn dmq_length(para: ParaId) -> u32 {
pub fn dmq_length(para: ParaId) -> u32 {
<Self as Store>::DownwardMessageQueues::decode_len(&para)
.unwrap_or(0)
.saturated_into::<u32>()
Expand Down
23 changes: 20 additions & 3 deletions runtime/polkadot/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,22 @@
//! XCM configuration for Polkadot.

use super::{
parachains_origin, AccountId, AllPalletsWithSystem, Balances, CouncilCollective, ParaId,
parachains_origin, AccountId, AllPalletsWithSystem, Balances, CouncilCollective, Dmp, ParaId,
Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, WeightToFee, XcmPallet,
};
use frame_support::{
match_types, parameter_types,
traits::{Contains, Everything, Nothing},
weights::Weight,
};
use runtime_common::{paras_registrar, xcm_sender, ToAuthor};
use polkadot_runtime_constants::currency::CENTS;
use runtime_common::{
paras_registrar,
xcm_sender::{ChildParachainRouter, PriceForParachainDelivery},
ToAuthor,
};
use sp_core::ConstU32;
use sp_runtime::{traits::Saturating, Percent};
use xcm::latest::prelude::*;
use xcm_builder::{
AccountId32Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom,
Expand Down Expand Up @@ -101,11 +107,22 @@ parameter_types! {
pub const MaxInstructions: u32 = 100;
}

pub struct ExponentialDotPrice;
impl PriceForParachainDelivery for ExponentialDotPrice {
fn price_for_parachain_delivery(para: ParaId, _: &Xcm<()>) -> MultiAssets {
let factor = Percent::from_percent(101).saturating_pow(Dmp::dmq_length(para) as usize);
let base = CENTS.saturating_mul(3);

let amount = factor * base;
(Here, amount).into()
}
}

/// The XCM router. When we want to send an XCM message, we use this type. It amalgamates all of our
/// individual routers.
pub type XcmRouter = (
// Only one router so far - use DMP to communicate with child parachains.
xcm_sender::ChildParachainRouter<Runtime, XcmPallet, ()>,
ChildParachainRouter<Runtime, XcmPallet, ExponentialDotPrice>,
);

parameter_types! {
Expand Down
24 changes: 21 additions & 3 deletions runtime/rococo/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,22 @@
//! XCM configuration for Rococo.

use super::{
parachains_origin, AccountId, AllPalletsWithSystem, Balances, CouncilCollective, ParaId,
parachains_origin, AccountId, AllPalletsWithSystem, Balances, CouncilCollective, Dmp, ParaId,
Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, WeightToFee, XcmPallet,
};
use frame_support::{
match_types, parameter_types,
traits::{Contains, Everything, Nothing},
weights::Weight,
};
use runtime_common::{paras_registrar, xcm_sender, ToAuthor};
use rococo_runtime_constants::currency::CENTS;
use runtime_common::{
paras_registrar,
xcm_sender::{ChildParachainRouter, PriceForParachainDelivery},
ToAuthor,
};
use sp_core::ConstU32;
use sp_runtime::{traits::Saturating, Percent};
use xcm::latest::prelude::*;
use xcm_builder::{
AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses,
Expand Down Expand Up @@ -82,11 +88,23 @@ parameter_types! {
/// The amount of weight an XCM operation takes. This is a safe overestimate.
pub const BaseXcmWeight: Weight = Weight::from_parts(1_000_000_000, 64 * 1024);
}

pub struct ExponentialRocPrice;
impl PriceForParachainDelivery for ExponentialRocPrice {
fn price_for_parachain_delivery(para: ParaId, _: &Xcm<()>) -> MultiAssets {
let factor = Percent::from_percent(101).saturating_pow(Dmp::dmq_length(para) as usize);
let base = CENTS.saturating_mul(3);

let amount = factor * base;
(Here, amount).into()
}
}

/// The XCM router. When we want to send an XCM message, we use this type. It amalgamates all of our
/// individual routers.
pub type XcmRouter = (
// Only one router so far - use DMP to communicate with child parachains.
xcm_sender::ChildParachainRouter<Runtime, XcmPallet, ()>,
ChildParachainRouter<Runtime, XcmPallet, ExponentialRocPrice>,
);

parameter_types! {
Expand Down
23 changes: 20 additions & 3 deletions runtime/westend/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,21 @@
//! XCM configurations for Westend.

use super::{
parachains_origin, weights, AccountId, AllPalletsWithSystem, Balances, ParaId, Runtime,
parachains_origin, weights, AccountId, AllPalletsWithSystem, Balances, Dmp, ParaId, Runtime,
RuntimeCall, RuntimeEvent, RuntimeOrigin, WeightToFee, XcmPallet,
};
use frame_support::{
parameter_types,
traits::{Contains, Everything, Nothing},
};
use runtime_common::{paras_registrar, xcm_sender, ToAuthor};
use runtime_common::{
paras_registrar,
xcm_sender::{ChildParachainRouter, PriceForParachainDelivery},
ToAuthor,
};
use sp_core::ConstU32;
use sp_runtime::{traits::Saturating, Percent};
use westend_runtime_constants::currency::CENTS;
use xcm::latest::prelude::*;
use xcm_builder::{
AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses,
Expand Down Expand Up @@ -68,11 +74,22 @@ type LocalOriginConverter = (
ChildSystemParachainAsSuperuser<ParaId, RuntimeOrigin>,
);

pub struct ExponentialWndPrice;
impl PriceForParachainDelivery for ExponentialWndPrice {
fn price_for_parachain_delivery(para: ParaId, _: &Xcm<()>) -> MultiAssets {
let factor = Percent::from_percent(101).saturating_pow(Dmp::dmq_length(para) as usize);
let base = CENTS.saturating_mul(3);

let amount = factor * base;
(Here, amount).into()
}
}

/// The XCM router. When we want to send an XCM message, we use this type. It amalgamates all of our
/// individual routers.
pub type XcmRouter = (
// Only one router so far - use DMP to communicate with child parachains.
xcm_sender::ChildParachainRouter<Runtime, XcmPallet, ()>,
ChildParachainRouter<Runtime, XcmPallet, ExponentialWndPrice>,
);

parameter_types! {
Expand Down
12 changes: 9 additions & 3 deletions xcm/pallet-xcm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1144,7 +1144,10 @@ impl<T: Config> Pallet<T> {
BuyExecution { fees, weight_limit },
DepositAsset { assets: Wild(AllCounted(max_assets)), beneficiary },
]);
let mut message = Xcm(vec![TransferReserveAsset { assets, dest, xcm }]);
let mut message = Xcm(vec![
SetFeesMode { jit_withdraw: true },
TransferReserveAsset { assets, dest, xcm },
]);
let weight =
T::Weigher::weight(&mut message).map_err(|()| Error::<T>::UnweighableMessage)?;
let hash = message.using_encoded(sp_io::hashing::blake2_256);
Expand Down Expand Up @@ -1201,8 +1204,11 @@ impl<T: Config> Pallet<T> {
BuyExecution { fees, weight_limit },
DepositAsset { assets: Wild(AllCounted(max_assets)), beneficiary },
]);
let mut message =
Xcm(vec![WithdrawAsset(assets), InitiateTeleport { assets: Wild(All), dest, xcm }]);
let mut message = Xcm(vec![
WithdrawAsset(assets),
SetFeesMode { jit_withdraw: true },
vstam1 marked this conversation as resolved.
Show resolved Hide resolved
InitiateTeleport { assets: Wild(All), dest, xcm },
]);
let weight =
T::Weigher::weight(&mut message).map_err(|()| Error::<T>::UnweighableMessage)?;
let hash = message.using_encoded(sp_io::hashing::blake2_256);
Expand Down