mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-03 19:17:26 +00:00
Introduce XcmFeesToAccount fee manager (#1234)
Combination of paritytech/polkadot#7005, its addon PR paritytech/polkadot#7585 and its companion paritytech/cumulus#2433. This PR introduces a new XcmFeesToAccount struct which implements the `FeeManager` trait, and assigns this struct as the `FeeManager` in the XCM config for all runtimes. The struct simply deposits all fees handled by the XCM executor to a specified account. In all runtimes, the specified account is configured as the treasury account. XCM __delivery__ fees are now being introduced (unless the root origin is sending a message to a system parachain on behalf of the originating chain). # Note for reviewers Most file changes are tests that had to be modified to account for the new fees. Main changes are in: - cumulus/pallets/xcmp-queue/src/lib.rs <- To make it track the delivery fees exponential factor - polkadot/xcm/xcm-builder/src/fee_handling.rs <- Added. Has the FeeManager implementation - All runtime xcm_config files <- To add the FeeManager to the XCM configuration # Important note After this change, instructions that create and send a new XCM (Query*, Report*, ExportMessage, InitiateReserveWithdraw, InitiateTeleport, DepositReserveAsset, TransferReserveAsset, LockAsset and RequestUnlock) will require the corresponding origin account in the origin register to pay for transport delivery fees, and the onward message will fail to be sent if the origin account does not have the required amount. This delivery fee is on top of what we already collect as tx fees in pallet-xcm and XCM BuyExecution fees! Wallet UIs that want to expose the new delivery fee can do so using the formula: ``` delivery_fee_factor * (base_fee + encoded_msg_len * per_byte_fee) ``` where the delivery fee factor can be obtained from the corresponding pallet based on which transport you are using (UMP, HRMP or bridges), the base fee is a constant, the encoded message length from the message itself and the per byte fee is the same as the configured per byte fee for txs (i.e. `TransactionByteFee`). --------- Co-authored-by: Branislav Kontur <bkontur@gmail.com> Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com> Co-authored-by: Giles Cope <gilescope@gmail.com> Co-authored-by: command-bot <> Co-authored-by: Francisco Aguirre <franciscoaguirreperez@gmail.com> Co-authored-by: Liam Aharon <liam.aharon@hotmail.com> Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
This commit is contained in:
@@ -324,13 +324,14 @@ fn xcmp_queue_consumes_dest_and_msg_on_ok_validate() {
|
||||
let dest = (Parent, X1(Parachain(5555)));
|
||||
let mut dest_wrapper = Some(dest.into());
|
||||
let mut msg_wrapper = Some(message.clone());
|
||||
assert!(<XcmpQueue as SendXcm>::validate(&mut dest_wrapper, &mut msg_wrapper).is_ok());
|
||||
|
||||
// check wrapper were consumed
|
||||
assert_eq!(None, dest_wrapper.take());
|
||||
assert_eq!(None, msg_wrapper.take());
|
||||
|
||||
new_test_ext().execute_with(|| {
|
||||
assert!(<XcmpQueue as SendXcm>::validate(&mut dest_wrapper, &mut msg_wrapper).is_ok());
|
||||
|
||||
// check wrapper were consumed
|
||||
assert_eq!(None, dest_wrapper.take());
|
||||
assert_eq!(None, msg_wrapper.take());
|
||||
|
||||
// another try with router chain with asserting sender
|
||||
assert_eq!(
|
||||
Err(SendError::Transport("NoChannel")),
|
||||
@@ -370,3 +371,74 @@ fn xcmp_queue_send_xcm_works() {
|
||||
.any(|(para_id, _)| para_id == &sibling_para_id));
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn verify_fee_factor_increase_and_decrease() {
|
||||
use cumulus_primitives_core::AbridgedHrmpChannel;
|
||||
use sp_runtime::FixedU128;
|
||||
|
||||
let sibling_para_id = ParaId::from(12345);
|
||||
let destination = (Parent, Parachain(sibling_para_id.into())).into();
|
||||
let xcm = Xcm(vec![ClearOrigin; 100]);
|
||||
let versioned_xcm = VersionedXcm::from(xcm.clone());
|
||||
let mut xcmp_message = XcmpMessageFormat::ConcatenatedVersionedXcm.encode();
|
||||
xcmp_message.extend(versioned_xcm.encode());
|
||||
|
||||
new_test_ext().execute_with(|| {
|
||||
let initial = InitialFactor::get();
|
||||
assert_eq!(DeliveryFeeFactor::<Test>::get(sibling_para_id), initial);
|
||||
|
||||
// Open channel so messages can actually be sent
|
||||
ParachainSystem::open_custom_outbound_hrmp_channel_for_benchmarks_or_tests(
|
||||
sibling_para_id,
|
||||
AbridgedHrmpChannel {
|
||||
max_capacity: 10,
|
||||
max_total_size: 1000,
|
||||
max_message_size: 104,
|
||||
msg_count: 0,
|
||||
total_size: 0,
|
||||
mqc_head: None,
|
||||
},
|
||||
);
|
||||
|
||||
// Fee factor is only increased in `send_fragment`, which is called by `send_xcm`.
|
||||
// When queue is not congested, fee factor doesn't change.
|
||||
assert_ok!(send_xcm::<XcmpQueue>(destination, xcm.clone())); // Size 104
|
||||
assert_ok!(send_xcm::<XcmpQueue>(destination, xcm.clone())); // Size 208
|
||||
assert_ok!(send_xcm::<XcmpQueue>(destination, xcm.clone())); // Size 312
|
||||
assert_ok!(send_xcm::<XcmpQueue>(destination, xcm.clone())); // Size 416
|
||||
assert_eq!(DeliveryFeeFactor::<Test>::get(sibling_para_id), initial);
|
||||
|
||||
// Sending the message right now is cheap
|
||||
let (_, delivery_fees) = validate_send::<XcmpQueue>(destination, xcm.clone())
|
||||
.expect("message can be sent; qed");
|
||||
let Fungible(delivery_fee_amount) = delivery_fees.inner()[0].fun else { unreachable!("asset is fungible; qed"); };
|
||||
assert_eq!(delivery_fee_amount, 402_000_000);
|
||||
|
||||
let smaller_xcm = Xcm(vec![ClearOrigin; 30]);
|
||||
|
||||
// When we get to half of `max_total_size`, because `THRESHOLD_FACTOR` is 2,
|
||||
// then the fee factor starts to increase.
|
||||
assert_ok!(send_xcm::<XcmpQueue>(destination, xcm.clone())); // Size 520
|
||||
assert_eq!(DeliveryFeeFactor::<Test>::get(sibling_para_id), FixedU128::from_float(1.05));
|
||||
|
||||
for _ in 0..12 { // We finish at size 929
|
||||
assert_ok!(send_xcm::<XcmpQueue>(destination, smaller_xcm.clone()));
|
||||
}
|
||||
assert!(DeliveryFeeFactor::<Test>::get(sibling_para_id) > FixedU128::from_float(1.88));
|
||||
|
||||
// Sending the message right now is expensive
|
||||
let (_, delivery_fees) = validate_send::<XcmpQueue>(destination, xcm.clone())
|
||||
.expect("message can be sent; qed");
|
||||
let Fungible(delivery_fee_amount) = delivery_fees.inner()[0].fun else { unreachable!("asset is fungible; qed"); };
|
||||
assert_eq!(delivery_fee_amount, 758_030_955);
|
||||
|
||||
// Fee factor only decreases in `take_outbound_messages`
|
||||
for _ in 0..5 { // We take 5 100 byte pages
|
||||
XcmpQueue::take_outbound_messages(1);
|
||||
}
|
||||
assert!(DeliveryFeeFactor::<Test>::get(sibling_para_id) < FixedU128::from_float(1.72));
|
||||
XcmpQueue::take_outbound_messages(1);
|
||||
assert!(DeliveryFeeFactor::<Test>::get(sibling_para_id) < FixedU128::from_float(1.63));
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user