mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-07 00:18:03 +00:00
3dece311be
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>
233 lines
7.0 KiB
Rust
233 lines
7.0 KiB
Rust
// Copyright (C) Parity Technologies (UK) Ltd.
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
use super::*;
|
|
use crate as xcmp_queue;
|
|
use core::marker::PhantomData;
|
|
use cumulus_pallet_parachain_system::AnyRelayNumber;
|
|
use cumulus_primitives_core::{IsSystem, ParaId};
|
|
use frame_support::{
|
|
parameter_types,
|
|
traits::{ConstU32, Everything, Nothing, OriginTrait},
|
|
};
|
|
use frame_system::EnsureRoot;
|
|
use sp_core::H256;
|
|
use sp_runtime::{
|
|
traits::{BlakeTwo256, IdentityLookup},
|
|
BuildStorage,
|
|
};
|
|
use xcm::prelude::*;
|
|
use xcm_builder::{CurrencyAdapter, FixedWeightBounds, IsConcrete, NativeAsset, ParentIsPreset};
|
|
use xcm_executor::traits::ConvertOrigin;
|
|
|
|
type Block = frame_system::mocking::MockBlock<Test>;
|
|
|
|
// Configure a mock runtime to test the pallet.
|
|
frame_support::construct_runtime!(
|
|
pub enum Test
|
|
{
|
|
System: frame_system::{Pallet, Call, Config<T>, Storage, Event<T>},
|
|
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
|
|
ParachainSystem: cumulus_pallet_parachain_system::{
|
|
Pallet, Call, Config<T>, Storage, Inherent, Event<T>, ValidateUnsigned,
|
|
},
|
|
XcmpQueue: xcmp_queue::{Pallet, Call, Storage, Event<T>},
|
|
}
|
|
);
|
|
|
|
parameter_types! {
|
|
pub const BlockHashCount: u64 = 250;
|
|
pub const SS58Prefix: u8 = 42;
|
|
}
|
|
|
|
type AccountId = u64;
|
|
|
|
impl frame_system::Config for Test {
|
|
type BaseCallFilter = Everything;
|
|
type BlockWeights = ();
|
|
type BlockLength = ();
|
|
type DbWeight = ();
|
|
type RuntimeOrigin = RuntimeOrigin;
|
|
type RuntimeCall = RuntimeCall;
|
|
type Nonce = u64;
|
|
type Hash = H256;
|
|
type Hashing = BlakeTwo256;
|
|
type AccountId = AccountId;
|
|
type Lookup = IdentityLookup<Self::AccountId>;
|
|
type Block = Block;
|
|
type RuntimeEvent = RuntimeEvent;
|
|
type BlockHashCount = BlockHashCount;
|
|
type Version = ();
|
|
type PalletInfo = PalletInfo;
|
|
type AccountData = pallet_balances::AccountData<u64>;
|
|
type OnNewAccount = ();
|
|
type OnKilledAccount = ();
|
|
type SystemWeightInfo = ();
|
|
type SS58Prefix = SS58Prefix;
|
|
type OnSetCode = cumulus_pallet_parachain_system::ParachainSetCode<Test>;
|
|
type MaxConsumers = frame_support::traits::ConstU32<16>;
|
|
}
|
|
|
|
parameter_types! {
|
|
pub const ExistentialDeposit: u64 = 5;
|
|
pub const MaxReserves: u32 = 50;
|
|
}
|
|
|
|
pub type Balance = u64;
|
|
|
|
impl pallet_balances::Config for Test {
|
|
type Balance = Balance;
|
|
type RuntimeEvent = RuntimeEvent;
|
|
type DustRemoval = ();
|
|
type ExistentialDeposit = ExistentialDeposit;
|
|
type AccountStore = System;
|
|
type WeightInfo = ();
|
|
type MaxLocks = ();
|
|
type MaxReserves = MaxReserves;
|
|
type ReserveIdentifier = [u8; 8];
|
|
type RuntimeHoldReason = RuntimeHoldReason;
|
|
type FreezeIdentifier = ();
|
|
type MaxHolds = ConstU32<0>;
|
|
type MaxFreezes = ConstU32<0>;
|
|
}
|
|
|
|
impl cumulus_pallet_parachain_system::Config for Test {
|
|
type RuntimeEvent = RuntimeEvent;
|
|
type OnSystemEvent = ();
|
|
type SelfParaId = ();
|
|
type OutboundXcmpMessageSource = XcmpQueue;
|
|
type DmpMessageHandler = ();
|
|
type ReservedDmpWeight = ();
|
|
type XcmpMessageHandler = XcmpQueue;
|
|
type ReservedXcmpWeight = ();
|
|
type CheckAssociatedRelayNumber = AnyRelayNumber;
|
|
type ConsensusHook = cumulus_pallet_parachain_system::consensus_hook::ExpectParentIncluded;
|
|
}
|
|
|
|
parameter_types! {
|
|
pub const RelayChain: MultiLocation = MultiLocation::parent();
|
|
pub UniversalLocation: InteriorMultiLocation = X1(Parachain(1u32));
|
|
pub UnitWeightCost: Weight = Weight::from_parts(1_000_000, 1024);
|
|
pub const MaxInstructions: u32 = 100;
|
|
pub const MaxAssetsIntoHolding: u32 = 64;
|
|
}
|
|
|
|
/// Means for transacting assets on this chain.
|
|
pub type LocalAssetTransactor = CurrencyAdapter<
|
|
// Use this currency:
|
|
Balances,
|
|
// Use this currency when it is a fungible asset matching the given location or name:
|
|
IsConcrete<RelayChain>,
|
|
// Do a simple punn to convert an AccountId32 MultiLocation into a native chain account ID:
|
|
LocationToAccountId,
|
|
// Our chain's account ID type (we can't get away without mentioning it explicitly):
|
|
AccountId,
|
|
// We don't track any teleports.
|
|
(),
|
|
>;
|
|
|
|
pub type LocationToAccountId = (ParentIsPreset<AccountId>,);
|
|
|
|
pub struct XcmConfig;
|
|
impl xcm_executor::Config for XcmConfig {
|
|
type RuntimeCall = RuntimeCall;
|
|
type XcmSender = XcmRouter;
|
|
// How to withdraw and deposit an asset.
|
|
type AssetTransactor = LocalAssetTransactor;
|
|
type OriginConverter = ();
|
|
type IsReserve = NativeAsset;
|
|
type IsTeleporter = NativeAsset;
|
|
type UniversalLocation = UniversalLocation;
|
|
type Barrier = ();
|
|
type Weigher = FixedWeightBounds<UnitWeightCost, RuntimeCall, MaxInstructions>;
|
|
type Trader = ();
|
|
type ResponseHandler = ();
|
|
type AssetTrap = ();
|
|
type AssetClaims = ();
|
|
type SubscriptionService = ();
|
|
type PalletInstancesInfo = AllPalletsWithSystem;
|
|
type MaxAssetsIntoHolding = MaxAssetsIntoHolding;
|
|
type AssetLocker = ();
|
|
type AssetExchanger = ();
|
|
type FeeManager = ();
|
|
type MessageExporter = ();
|
|
type UniversalAliases = Nothing;
|
|
type CallDispatcher = RuntimeCall;
|
|
type SafeCallFilter = Everything;
|
|
type Aliasers = Nothing;
|
|
}
|
|
|
|
pub type XcmRouter = (
|
|
// XCMP to communicate with the sibling chains.
|
|
XcmpQueue,
|
|
);
|
|
|
|
pub struct SystemParachainAsSuperuser<RuntimeOrigin>(PhantomData<RuntimeOrigin>);
|
|
impl<RuntimeOrigin: OriginTrait> ConvertOrigin<RuntimeOrigin>
|
|
for SystemParachainAsSuperuser<RuntimeOrigin>
|
|
{
|
|
fn convert_origin(
|
|
origin: impl Into<MultiLocation>,
|
|
kind: OriginKind,
|
|
) -> Result<RuntimeOrigin, MultiLocation> {
|
|
let origin = origin.into();
|
|
if kind == OriginKind::Superuser &&
|
|
matches!(
|
|
origin,
|
|
MultiLocation {
|
|
parents: 1,
|
|
interior: X1(Parachain(id)),
|
|
} if ParaId::from(id).is_system(),
|
|
) {
|
|
Ok(RuntimeOrigin::root())
|
|
} else {
|
|
Err(origin)
|
|
}
|
|
}
|
|
}
|
|
|
|
parameter_types! {
|
|
/// The asset ID for the asset that we use to pay for message delivery fees.
|
|
pub FeeAssetId: AssetId = Concrete(RelayChain::get());
|
|
/// The base fee for the message delivery fees.
|
|
pub const BaseDeliveryFee: Balance = 300_000_000;
|
|
/// The fee per byte
|
|
pub const ByteFee: Balance = 1_000_000;
|
|
}
|
|
|
|
pub type PriceForSiblingParachainDelivery = polkadot_runtime_common::xcm_sender::ExponentialPrice<
|
|
FeeAssetId,
|
|
BaseDeliveryFee,
|
|
ByteFee,
|
|
XcmpQueue,
|
|
>;
|
|
|
|
impl Config for Test {
|
|
type RuntimeEvent = RuntimeEvent;
|
|
type XcmExecutor = xcm_executor::XcmExecutor<XcmConfig>;
|
|
type ChannelInfo = ParachainSystem;
|
|
type VersionWrapper = ();
|
|
type ExecuteOverweightOrigin = EnsureRoot<AccountId>;
|
|
type ControllerOrigin = EnsureRoot<AccountId>;
|
|
type ControllerOriginConverter = SystemParachainAsSuperuser<RuntimeOrigin>;
|
|
type WeightInfo = ();
|
|
type PriceForSiblingDelivery = PriceForSiblingParachainDelivery;
|
|
}
|
|
|
|
pub fn new_test_ext() -> sp_io::TestExternalities {
|
|
let t = frame_system::GenesisConfig::<Test>::default().build_storage().unwrap();
|
|
t.into()
|
|
}
|