mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 10:31:03 +00:00
Move XCM runtime configurations into their own files (#4644)
* Move XCM runtime configurations into their own files * Update copyright year * Fix compilation errors * Import XCM types in westend runtime unit tests
This commit is contained in:
@@ -33,9 +33,9 @@ use primitives::{
|
||||
v2::SessionInfo,
|
||||
};
|
||||
use runtime_common::{
|
||||
auctions, claims, crowdloan, impls::DealWithFees, paras_registrar, slots, xcm_sender,
|
||||
BlockHashCount, BlockLength, BlockWeights, CurrencyToVote, OffchainSolutionLengthLimit,
|
||||
OffchainSolutionWeightLimit, RocksDbWeight, SlowAdjustingFeeUpdate, ToAuthor,
|
||||
auctions, claims, crowdloan, impls::DealWithFees, paras_registrar, slots, BlockHashCount,
|
||||
BlockLength, BlockWeights, CurrencyToVote, OffchainSolutionLengthLimit,
|
||||
OffchainSolutionWeightLimit, RocksDbWeight, SlowAdjustingFeeUpdate,
|
||||
};
|
||||
use sp_core::u32_trait::{_1, _2, _3, _5};
|
||||
use sp_std::{cmp::Ordering, collections::btree_map::BTreeMap, prelude::*};
|
||||
@@ -52,10 +52,10 @@ use runtime_parachains::{
|
||||
use authority_discovery_primitives::AuthorityId as AuthorityDiscoveryId;
|
||||
use beefy_primitives::crypto::AuthorityId as BeefyId;
|
||||
use frame_support::{
|
||||
construct_runtime, match_type, parameter_types,
|
||||
construct_runtime, parameter_types,
|
||||
traits::{
|
||||
Contains, EnsureOneOf, Everything, InstanceFilter, KeyOwnerProofSystem, LockIdentifier,
|
||||
Nothing, OnRuntimeUpgrade, PrivilegeCmp,
|
||||
Contains, EnsureOneOf, InstanceFilter, KeyOwnerProofSystem, LockIdentifier,
|
||||
OnRuntimeUpgrade, PrivilegeCmp,
|
||||
},
|
||||
weights::Weight,
|
||||
PalletId, RuntimeDebug,
|
||||
@@ -82,16 +82,6 @@ use sp_staking::SessionIndex;
|
||||
use sp_version::NativeVersion;
|
||||
use sp_version::RuntimeVersion;
|
||||
use static_assertions::const_assert;
|
||||
use xcm::latest::prelude::*;
|
||||
use xcm_builder::{
|
||||
AccountId32Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom,
|
||||
AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, BackingToPlurality,
|
||||
ChildParachainAsNative, ChildParachainConvertsVia, ChildSystemParachainAsSuperuser,
|
||||
CurrencyAdapter as XcmCurrencyAdapter, FixedWeightBounds, IsChildSystemParachain, IsConcrete,
|
||||
LocationInverter, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation,
|
||||
TakeWeightCredit, UsingComponents,
|
||||
};
|
||||
use xcm_executor::XcmExecutor;
|
||||
|
||||
pub use pallet_balances::Call as BalancesCall;
|
||||
pub use pallet_election_provider_multi_phase::Call as EPMCall;
|
||||
@@ -110,6 +100,9 @@ mod weights;
|
||||
// Voter bag threshold definitions.
|
||||
mod bag_thresholds;
|
||||
|
||||
// XCM configurations.
|
||||
mod xcm_config;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
@@ -1210,7 +1203,8 @@ parameter_types! {
|
||||
|
||||
impl parachains_ump::Config for Runtime {
|
||||
type Event = Event;
|
||||
type UmpSink = crate::parachains_ump::XcmSink<XcmExecutor<XcmConfig>, Runtime>;
|
||||
type UmpSink =
|
||||
crate::parachains_ump::XcmSink<xcm_executor::XcmExecutor<xcm_config::XcmConfig>, Runtime>;
|
||||
type FirstMessageFactorPercent = FirstMessageFactorPercent;
|
||||
type ExecuteOverweightOrigin = EnsureRoot<AccountId>;
|
||||
}
|
||||
@@ -1316,156 +1310,6 @@ impl auctions::Config for Runtime {
|
||||
type WeightInfo = weights::runtime_common_auctions::WeightInfo<Runtime>;
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
/// The location of the KSM token, from the context of this chain. Since this token is native to this
|
||||
/// chain, we make it synonymous with it and thus it is the `Here` location, which means "equivalent to
|
||||
/// the context".
|
||||
pub const KsmLocation: MultiLocation = Here.into();
|
||||
/// The Kusama network ID. This is named.
|
||||
pub const KusamaNetwork: NetworkId = NetworkId::Kusama;
|
||||
/// Our XCM location ancestry - i.e. what, if anything, `Parent` means evaluated in our context. Since
|
||||
/// Kusama is a top-level relay-chain, there is no ancestry.
|
||||
pub const Ancestry: MultiLocation = Here.into();
|
||||
/// The check account, which holds any native assets that have been teleported out and not back in (yet).
|
||||
pub CheckAccount: AccountId = XcmPallet::check_account();
|
||||
}
|
||||
|
||||
/// The canonical means of converting a `MultiLocation` into an `AccountId`, used when we want to determine
|
||||
/// the sovereign account controlled by a location.
|
||||
pub type SovereignAccountOf = (
|
||||
// We can convert a child parachain using the standard `AccountId` conversion.
|
||||
ChildParachainConvertsVia<ParaId, AccountId>,
|
||||
// We can directly alias an `AccountId32` into a local account.
|
||||
AccountId32Aliases<KusamaNetwork, AccountId>,
|
||||
);
|
||||
|
||||
/// Our asset transactor. This is what allows us to interest with the runtime facilities from the point of
|
||||
/// view of XCM-only concepts like `MultiLocation` and `MultiAsset`.
|
||||
///
|
||||
/// Ours is only aware of the Balances pallet, which is mapped to `KsmLocation`.
|
||||
pub type LocalAssetTransactor = XcmCurrencyAdapter<
|
||||
// Use this currency:
|
||||
Balances,
|
||||
// Use this currency when it is a fungible asset matching the given location or name:
|
||||
IsConcrete<KsmLocation>,
|
||||
// We can convert the MultiLocations with our converter above:
|
||||
SovereignAccountOf,
|
||||
// Our chain's account ID type (we can't get away without mentioning it explicitly):
|
||||
AccountId,
|
||||
// We track our teleports in/out to keep total issuance correct.
|
||||
CheckAccount,
|
||||
>;
|
||||
|
||||
/// The means that we convert an the XCM message origin location into a local dispatch origin.
|
||||
type LocalOriginConverter = (
|
||||
// A `Signed` origin of the sovereign account that the original location controls.
|
||||
SovereignSignedViaLocation<SovereignAccountOf, Origin>,
|
||||
// A child parachain, natively expressed, has the `Parachain` origin.
|
||||
ChildParachainAsNative<parachains_origin::Origin, Origin>,
|
||||
// The AccountId32 location type can be expressed natively as a `Signed` origin.
|
||||
SignedAccountId32AsNative<KusamaNetwork, Origin>,
|
||||
// A system child parachain, expressed as a Superuser, converts to the `Root` origin.
|
||||
ChildSystemParachainAsSuperuser<ParaId, Origin>,
|
||||
);
|
||||
|
||||
parameter_types! {
|
||||
/// The amount of weight an XCM operation takes. This is a safe overestimate.
|
||||
pub const BaseXcmWeight: Weight = 1_000_000_000;
|
||||
/// Maximum number of instructions in a single XCM fragment. A sanity check against weight
|
||||
/// calculations getting too crazy.
|
||||
pub const MaxInstructions: u32 = 100;
|
||||
}
|
||||
|
||||
/// 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>,
|
||||
);
|
||||
|
||||
parameter_types! {
|
||||
pub const Kusama: MultiAssetFilter = Wild(AllOf { fun: WildFungible, id: Concrete(KsmLocation::get()) });
|
||||
pub const KusamaForStatemine: (MultiAssetFilter, MultiLocation) = (Kusama::get(), Parachain(1000).into());
|
||||
pub const KusamaForEncointer: (MultiAssetFilter, MultiLocation) = (Kusama::get(), Parachain(1001).into());
|
||||
}
|
||||
pub type TrustedTeleporters =
|
||||
(xcm_builder::Case<KusamaForStatemine>, xcm_builder::Case<KusamaForEncointer>);
|
||||
|
||||
match_type! {
|
||||
pub type OnlyParachains: impl Contains<MultiLocation> = {
|
||||
MultiLocation { parents: 0, interior: X1(Parachain(_)) }
|
||||
};
|
||||
}
|
||||
|
||||
/// The barriers one of which must be passed for an XCM message to be executed.
|
||||
pub type Barrier = (
|
||||
// Weight that is paid for may be consumed.
|
||||
TakeWeightCredit,
|
||||
// If the message is one that immediately attemps to pay for execution, then allow it.
|
||||
AllowTopLevelPaidExecutionFrom<Everything>,
|
||||
// Messages coming from system parachains need not pay for execution.
|
||||
AllowUnpaidExecutionFrom<IsChildSystemParachain<ParaId>>,
|
||||
// Expected responses are OK.
|
||||
AllowKnownQueryResponses<XcmPallet>,
|
||||
// Subscriptions for version tracking are OK.
|
||||
AllowSubscriptionsFrom<OnlyParachains>,
|
||||
);
|
||||
|
||||
pub struct XcmConfig;
|
||||
impl xcm_executor::Config for XcmConfig {
|
||||
type Call = Call;
|
||||
type XcmSender = XcmRouter;
|
||||
type AssetTransactor = LocalAssetTransactor;
|
||||
type OriginConverter = LocalOriginConverter;
|
||||
type IsReserve = ();
|
||||
type IsTeleporter = TrustedTeleporters;
|
||||
type LocationInverter = LocationInverter<Ancestry>;
|
||||
type Barrier = Barrier;
|
||||
type Weigher = FixedWeightBounds<BaseXcmWeight, Call, MaxInstructions>;
|
||||
// The weight trader piggybacks on the existing transaction-fee conversion logic.
|
||||
type Trader = UsingComponents<WeightToFee, KsmLocation, AccountId, Balances, ToAuthor<Runtime>>;
|
||||
type ResponseHandler = XcmPallet;
|
||||
type AssetTrap = XcmPallet;
|
||||
type AssetClaims = XcmPallet;
|
||||
type SubscriptionService = XcmPallet;
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
pub const CouncilBodyId: BodyId = BodyId::Executive;
|
||||
}
|
||||
|
||||
/// Type to convert an `Origin` type value into a `MultiLocation` value which represents an interior location
|
||||
/// of this chain.
|
||||
pub type LocalOriginToLocation = (
|
||||
// We allow an origin from the Collective pallet to be used in XCM as a corresponding Plurality of the
|
||||
// `Unit` body.
|
||||
BackingToPlurality<
|
||||
Origin,
|
||||
pallet_collective::Origin<Runtime, CouncilCollective>,
|
||||
CouncilBodyId,
|
||||
>,
|
||||
// And a usual Signed origin to be used in XCM as a corresponding AccountId32
|
||||
SignedToAccountId32<Origin, AccountId, KusamaNetwork>,
|
||||
);
|
||||
impl pallet_xcm::Config for Runtime {
|
||||
type Event = Event;
|
||||
type SendXcmOrigin = xcm_builder::EnsureXcmOrigin<Origin, LocalOriginToLocation>;
|
||||
type XcmRouter = XcmRouter;
|
||||
// Anyone can execute XCM messages locally...
|
||||
type ExecuteXcmOrigin = xcm_builder::EnsureXcmOrigin<Origin, LocalOriginToLocation>;
|
||||
// ...but they must match our filter, which rejects all.
|
||||
type XcmExecuteFilter = Nothing;
|
||||
type XcmExecutor = XcmExecutor<XcmConfig>;
|
||||
type XcmTeleportFilter = Everything;
|
||||
type XcmReserveTransferFilter = Everything;
|
||||
type Weigher = FixedWeightBounds<BaseXcmWeight, Call, MaxInstructions>;
|
||||
type LocationInverter = LocationInverter<Ancestry>;
|
||||
type Origin = Origin;
|
||||
type Call = Call;
|
||||
const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;
|
||||
type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion;
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
pub IgnoredIssuance: Balance = Treasury::pot();
|
||||
pub const QueueCount: u32 = 300;
|
||||
|
||||
Reference in New Issue
Block a user