Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add defaults for pallet-xcm #1959

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions polkadot/xcm/pallet-xcm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ std = [
"xcm-executor/std",
"xcm-runtime-apis/std",
"xcm/std",
"xcm-builder/std",
]
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
Expand Down
121 changes: 103 additions & 18 deletions polkadot/xcm/pallet-xcm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,34 +210,40 @@ pub mod pallet {
pub type BalanceOf<T> =
<<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;

#[pallet::config]
#[pallet::config(with_default)]
/// The module configuration trait.
pub trait Config: frame_system::Config {
/// The overarching event type.
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;

/// A lockable currency.
// TODO: We should really use a trait which can handle multiple currencies.
#[pallet::no_default]
/// A lockable currency.
type Currency: LockableCurrency<Self::AccountId, Moment = BlockNumberFor<Self>>;

/// The `Asset` matcher for `Currency`.
#[pallet::no_default_bounds]
type CurrencyMatcher: MatchesFungible<BalanceOf<Self>>;

// TODO: Would love to add a default for this, but I need access to `RuntimeOrigin`
// from the derive_impl
#[pallet::no_default_bounds]
/// Required origin for sending XCM messages. If successful, it resolves to `Location`
/// which exists as an interior location within this chain's XCM context.
type SendXcmOrigin: EnsureOrigin<<Self as SysConfig>::RuntimeOrigin, Success = Location>;

#[pallet::no_default]
/// The type used to actually dispatch an XCM to its destination.
type XcmRouter: SendXcm;

#[pallet::no_default]
/// Required origin for executing XCM messages, including the teleport functionality. If
/// successful, then it resolves to `Location` which exists as an interior location
/// within this chain's XCM context.
type ExecuteXcmOrigin: EnsureOrigin<<Self as SysConfig>::RuntimeOrigin, Success = Location>;

#[pallet::no_default_bounds]
/// Our XCM filter which messages to be executed using `XcmExecutor` must pass.
type XcmExecuteFilter: Contains<(Location, Xcm<<Self as Config>::RuntimeCall>)>;

#[pallet::no_default]
/// Something to execute an XCM message.
type XcmExecutor: ExecuteXcm<<Self as Config>::RuntimeCall> + XcmAssetTransfers;

Expand All @@ -248,36 +254,29 @@ pub mod pallet {
/// must pass.
type XcmReserveTransferFilter: Contains<(Location, Vec<Asset>)>;

#[pallet::no_default]
/// Means of measuring the weight consumed by an XCM message locally.
type Weigher: WeightBounds<<Self as Config>::RuntimeCall>;

#[pallet::no_default]
/// This chain's Universal Location.
type UniversalLocation: Get<InteriorLocation>;

/// The runtime `Origin` type.
type RuntimeOrigin: From<Origin> + From<<Self as SysConfig>::RuntimeOrigin>;

/// The runtime `Call` type.
type RuntimeCall: Parameter
+ GetDispatchInfo
+ Dispatchable<
RuntimeOrigin = <Self as Config>::RuntimeOrigin,
PostInfo = PostDispatchInfo,
>;

const VERSION_DISCOVERY_QUEUE_SIZE: u32;

/// The latest supported version that we advertise. Generally just set it to
/// `pallet_xcm::CurrentXcmVersion`.
/// The latest supported version that we advertise.
/// Its default is `pallet_xcm::CurrentXcmVersion`.
type AdvertisedXcmVersion: Get<XcmVersion>;

#[pallet::no_default]
/// The origin that is allowed to call privileged operations on the XCM pallet
type AdminOrigin: EnsureOrigin<<Self as SysConfig>::RuntimeOrigin>;

/// The assets which we consider a given origin is trusted if they claim to have placed a
/// lock.
type TrustedLockers: ContainsPair<Location, Asset>;

#[pallet::no_default]
/// How to get an `AccountId` value from a `Location`, useful for handling asset locks.
type SovereignAccountOf: ConvertLocation<Self::AccountId>;

Expand All @@ -292,6 +291,92 @@ pub mod pallet {

/// Weight information for extrinsics in this pallet.
type WeightInfo: WeightInfo;

/// The overarching event type.
#[pallet::no_default_bounds]
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;

/// The runtime `Origin` type.
#[pallet::no_default_bounds]
type RuntimeOrigin: From<Origin> + From<<Self as SysConfig>::RuntimeOrigin>;

/// The runtime `Call` type.
#[pallet::no_default_bounds]
type RuntimeCall: Parameter
+ GetDispatchInfo
+ Dispatchable<
RuntimeOrigin = <Self as Config>::RuntimeOrigin,
PostInfo = PostDispatchInfo,
>;
}

/// Default implementations of [`DefaultConfig`], which can be used to implement [`Config`]
pub mod config_preludes {
use super::*;
use frame_support::{
derive_impl, register_default_impl,
traits::{Everything, ConstU32, Equals},
};
use xcm_builder::{
IsConcrete,
LocationWithAssetFilters,
};

pub struct TestDefaultConfig<RuntimeOrigin, AccountId>(core::marker::PhantomData<(RuntimeOrigin, AccountId)>);

#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig, no_aggregated_types)]
impl<RuntimeOrigin, AccountId> frame_system::DefaultConfig for TestDefaultConfig<RuntimeOrigin, AccountId> {}

// TODO: These make sense for an actual runtime, not for a test one maybe
parameter_types! {
/// We hold a native token locally, in `Here`
pub TokenLocation: Location = Here.into_location();
/// We don't allow any assets to be teleported
pub AllowedAssetsToTeleport: Vec<AssetFilter> = vec![];
/// We only allow reserve asset depositing the native token
pub AllowedAssetsToReserveTransfer: Vec<AssetFilter> = vec![
Wild(AllOf { fun: WildFungible, id: AssetId(TokenLocation::get()) }),
];
pub AnyNetwork: Option<NetworkId> = None;
}

#[register_default_impl(TestDefaultConfig)]
impl<RuntimeOrigin, AccountId> DefaultConfig for TestDefaultConfig<RuntimeOrigin, AccountId> {
// This default config only handles the native token
type CurrencyMatcher = IsConcrete<TokenLocation>;

type SendXcmOrigin = xcm_builder::EnsureXcmOrigin<RuntimeOrigin, xcm_builder::SignedToAccountId32<RuntimeOrigin, AccountId, AnyNetwork>>;

// We don't filter any specific message
type XcmExecuteFilter = Everything;

type XcmTeleportFilter = LocationWithAssetFilters<
Equals<TokenLocation>,
AllowedAssetsToTeleport,
>;
type XcmReserveTransferFilter = LocationWithAssetFilters<
Equals<TokenLocation>,
AllowedAssetsToReserveTransfer,
>;

// Use latest version by default
type AdvertisedXcmVersion = CurrentXcmVersion;
const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;

type TrustedLockers = ();
type MaxLockers = ConstU32<0>;
type MaxRemoteLockConsumers = ConstU32<0>;
type RemoteLockConsumerIdentifier = ();

type WeightInfo = TestWeightInfo;

#[inject_runtime_type]
type RuntimeEvent = ();
#[inject_runtime_type]
type RuntimeOrigin = ();
#[inject_runtime_type]
type RuntimeCall = ();
}
}

impl<T: Config> ExecuteControllerWeightInfo for Pallet<T> {
Expand Down
14 changes: 1 addition & 13 deletions polkadot/xcm/pallet-xcm/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -532,30 +532,18 @@ impl Contains<(Location, Vec<Asset>)> for XcmTeleportFiltered {
}
}

#[derive_impl(pallet_xcm::config_preludes::TestDefaultConfig<RuntimeOrigin, AccountId> as pallet_xcm::DefaultConfig)]
impl pallet_xcm::Config for Test {
type RuntimeEvent = RuntimeEvent;
type SendXcmOrigin = xcm_builder::EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
type XcmRouter = XcmRouter;
type ExecuteXcmOrigin = xcm_builder::EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
type XcmExecuteFilter = Everything;
type XcmExecutor = XcmExecutor<XcmConfig>;
type XcmTeleportFilter = EverythingBut<XcmTeleportFiltered>;
type XcmReserveTransferFilter = Everything;
type Weigher = FixedWeightBounds<BaseXcmWeight, RuntimeCall, MaxInstructions>;
type UniversalLocation = UniversalLocation;
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;
type AdvertisedXcmVersion = AdvertisedXcmVersion;
type AdminOrigin = EnsureRoot<AccountId>;
type TrustedLockers = ();
type SovereignAccountOf = AccountId32Aliases<(), AccountId32>;
type Currency = Balances;
type CurrencyMatcher = IsConcrete<RelayLocation>;
type MaxLockers = frame_support::traits::ConstU32<8>;
type MaxRemoteLockConsumers = frame_support::traits::ConstU32<0>;
type RemoteLockConsumerIdentifier = ();
type WeightInfo = TestWeightInfo;
}

impl origin::Config for Test {}
Expand Down
Loading