This repository has been archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
XCM: Properly set the pricing for the DMP router #6843
Merged
Merged
Changes from 18 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 d489025
Publicize price types
KiChjang 39f90fe
Use FixedU128 instead of Percent
KiChjang 824f045
Add sp-arithmetic as a dependency for rococo runtime
KiChjang f4e0d66
Add sp-arithmetic as a dependency to all runtimes
KiChjang 7a49275
Remove duplicate import
KiChjang 59d6693
Add missing import
KiChjang 500b42f
Fix tests
KiChjang 633430c
Create an appropriate QueueDownwardMessageError variant
KiChjang 7f27521
Recalculate delivery fee factor based on past queue sizes
KiChjang 2fe3547
Remove unused error variant
KiChjang 3f6ea59
Fixes
KiChjang c36de96
Fixes
KiChjang 7e3d876
Remove unused imports
KiChjang c5a622d
Rewrite fee factor update mechanism
KiChjang c83126b
Remove unused imports
KiChjang 85141d2
Merge remote-tracking branch 'origin/master' into kckyeung/xcm-sender…
KiChjang 8c7c9f9
Fixes
KiChjang 395a70b
Update runtime/parachains/src/dmp.rs
KiChjang a938c9c
Make DeliveryFeeFactor be a StorageMap keyed on ParaIds
KiChjang 56a018d
Fixes
KiChjang 758ff41
merge master
vstam1 838b9b5
introduce limit for fee increase on dmp queue
vstam1 1a2bcd6
add message_size based fee factor to increment_fee_factor
vstam1 3546698
change message_size fee rate to correct value
vstam1 da90e35
fix div by 0 error
vstam1 9eefb51
bind limit to variable
vstam1 5310ce1
merge master
vstam1 7086ec1
fix message_size_factor and add DeliveryFeeFactor test
vstam1 f2f0427
add test for ExponentialPrice implementation
vstam1 e1fa338
make test formula based
vstam1 303d7d5
make delivery fee factor test formula based
vstam1 8588ce9
add max value test for DeliveryFeeFactor and move limit to config
vstam1 7f6cfdf
change threshold back to dynamic value and fix tests
vstam1 759277c
fmt
vstam1 a6a7fd9
suggested changes and fmt
vstam1 0a2a6e7
merge master
vstam1 d92d990
small stylistic change
vstam1 aafbb68
merge master
vstam1 d0c5de1
fmt
vstam1 ea42774
change to tokenlocation
vstam1 1732846
small fixes
vstam1 56fe04d
fmt
vstam1 2f7acd1
remove sp_arithmetic dependency
vstam1 8b4877a
Merge branch 'master' into kckyeung/xcm-sender-price
vstam1 a7e5ded
Update runtime/parachains/src/dmp.rs
vstam1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,10 @@ use crate::{ | |
}; | ||
use frame_support::pallet_prelude::*; | ||
use primitives::{DownwardMessage, Hash, Id as ParaId, InboundDownwardMessage}; | ||
use sp_runtime::traits::{BlakeTwo256, Hash as HashT, SaturatedConversion}; | ||
use sp_runtime::{ | ||
traits::{BlakeTwo256, Hash as HashT, SaturatedConversion}, | ||
FixedU128, Saturating, | ||
}; | ||
use sp_std::{fmt, prelude::*}; | ||
use xcm::latest::SendError; | ||
|
||
|
@@ -30,6 +33,7 @@ pub use pallet::*; | |
mod tests; | ||
|
||
pub const MAX_MESSAGE_QUEUE_SIZE: usize = 1024; | ||
pub const MULTIPLICATIVE_FEE_FACTOR: FixedU128 = FixedU128::from_rational(101, 100); // 1.01 | ||
vstam1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/// An error sending a downward message. | ||
#[cfg_attr(test, derive(Debug))] | ||
|
@@ -102,8 +106,15 @@ pub mod pallet { | |
pub(crate) type DownwardMessageQueueHeads<T: Config> = | ||
StorageMap<_, Twox64Concat, ParaId, Hash, ValueQuery>; | ||
|
||
#[pallet::call] | ||
impl<T: Config> Pallet<T> {} | ||
frame_support::parameter_types! { | ||
vstam1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
pub InitialFactor: FixedU128 = FixedU128::from_u32(1); | ||
} | ||
|
||
/// The number to multiply the base delivery fee by. | ||
#[pallet::storage] | ||
#[pallet::getter(fn delivery_fee_factor)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. getters are being deprecated: please don't add more :D |
||
pub(crate) type DeliveryFeeFactor<T: Config> = | ||
ggwpez marked this conversation as resolved.
Show resolved
Hide resolved
|
||
StorageValue<_, FixedU128, ValueQuery, InitialFactor>; | ||
} | ||
|
||
/// Routines and getters related to downward message passing. | ||
|
@@ -143,18 +154,14 @@ impl<T: Config> Pallet<T> { | |
/// `queue_downward_message` with the same parameters will be successful. | ||
pub fn can_queue_downward_message( | ||
config: &HostConfiguration<T::BlockNumber>, | ||
para: &ParaId, | ||
_: &ParaId, | ||
msg: &DownwardMessage, | ||
) -> Result<(), QueueDownwardMessageError> { | ||
let serialized_len = msg.len() as u32; | ||
if serialized_len > config.max_downward_message_size { | ||
return Err(QueueDownwardMessageError::ExceedsMaxMessageSize) | ||
} | ||
|
||
if DownwardMessageQueues::<T>::decode_len(para).unwrap_or(0) > MAX_MESSAGE_QUEUE_SIZE { | ||
return Err(QueueDownwardMessageError::ExceedsMaxMessageSize) | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
|
@@ -176,10 +183,6 @@ impl<T: Config> Pallet<T> { | |
return Err(QueueDownwardMessageError::ExceedsMaxMessageSize) | ||
} | ||
|
||
if DownwardMessageQueues::<T>::decode_len(para).unwrap_or(0) > MAX_MESSAGE_QUEUE_SIZE { | ||
return Err(QueueDownwardMessageError::ExceedsMaxMessageSize) | ||
} | ||
|
||
let inbound = | ||
InboundDownwardMessage { msg, sent_at: <frame_system::Pallet<T>>::block_number() }; | ||
|
||
|
@@ -190,10 +193,15 @@ impl<T: Config> Pallet<T> { | |
*head = new_head; | ||
}); | ||
|
||
DownwardMessageQueues::<T>::mutate(para, |v| { | ||
let q_len = DownwardMessageQueues::<T>::mutate(para, |v| { | ||
v.push(inbound); | ||
v.len() | ||
}); | ||
|
||
if q_len > MAX_MESSAGE_QUEUE_SIZE { | ||
Self::increment_fee_factor(); | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
|
@@ -219,7 +227,7 @@ impl<T: Config> Pallet<T> { | |
|
||
/// Prunes the specified number of messages from the downward message queue of the given para. | ||
pub(crate) fn prune_dmq(para: ParaId, processed_downward_messages: u32) -> Weight { | ||
DownwardMessageQueues::<T>::mutate(para, |q| { | ||
let q_len = DownwardMessageQueues::<T>::mutate(para, |q| { | ||
let processed_downward_messages = processed_downward_messages as usize; | ||
if processed_downward_messages > q.len() { | ||
// reaching this branch is unexpected due to the constraint established by | ||
|
@@ -228,7 +236,11 @@ impl<T: Config> Pallet<T> { | |
} else { | ||
*q = q.split_off(processed_downward_messages); | ||
} | ||
q.len() | ||
}); | ||
if q_len <= MAX_MESSAGE_QUEUE_SIZE { | ||
Self::decrement_fee_factor(); | ||
gilescope marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
T::DbWeight::get().reads_writes(1, 1) | ||
} | ||
|
||
|
@@ -254,4 +266,26 @@ impl<T: Config> Pallet<T> { | |
pub(crate) fn dmq_contents(recipient: ParaId) -> Vec<InboundDownwardMessage<T::BlockNumber>> { | ||
DownwardMessageQueues::<T>::get(&recipient) | ||
} | ||
|
||
/// Raise the delivery fee factor by a multiplicative factor and stores the resulting value. | ||
/// | ||
/// Returns the new delivery fee factor after the increment. | ||
pub(crate) fn increment_fee_factor() -> FixedU128 { | ||
<DeliveryFeeFactor<T>>::mutate(|f| { | ||
*f = f.saturating_mul(MULTIPLICATIVE_FEE_FACTOR); | ||
*f | ||
}) | ||
} | ||
|
||
/// Reduce the delivery fee factor by a multiplicative factor and stores the resulting value. | ||
/// | ||
/// Does not reduce the fee factor below the initial value, which is currently set as 1. | ||
/// | ||
/// Returns the new delivery fee factor after the decrement. | ||
pub(crate) fn decrement_fee_factor() -> FixedU128 { | ||
<DeliveryFeeFactor<T>>::mutate(|f| { | ||
*f = InitialFactor::get().min(*f / MULTIPLICATIVE_FEE_FACTOR); | ||
KiChjang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
*f | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ sp-io = { git = "https://github.com/paritytech/substrate", branch = "master", de | |
sp-mmr-primitives = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } | ||
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } | ||
sp-staking = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } | ||
sp-arithmetic = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same? |
||
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } | ||
sp-session = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } | ||
sp-version = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } | ||
|
@@ -112,6 +113,7 @@ std = [ | |
"parity-scale-codec/std", | ||
"scale-info/std", | ||
"inherents/std", | ||
"sp-arithmetic/std", | ||
"sp-core/std", | ||
"sp-api/std", | ||
"tx-pool-api/std", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this could be all refactored to use default parts in the future, no?