Skip to content
This repository has been archived by the owner on Mar 30, 2023. It is now read-only.

Commit

Permalink
Companion for paritytech/cumulus#697 XCM v3
Browse files Browse the repository at this point in the history
  • Loading branch information
Guantong committed Mar 2, 2023
1 parent c92e180 commit 4140e16
Show file tree
Hide file tree
Showing 9 changed files with 185 additions and 52 deletions.
17 changes: 8 additions & 9 deletions runtime/common/src/xcm_configs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ where
{
fn should_execute<RuntimeCall>(
origin: &MultiLocation,
message: &mut Xcm<RuntimeCall>,
max_weight: XcmWeight,
weight_credit: &mut XcmWeight,
message: &mut [Instruction<RuntimeCall>],
max_weight: Weight,
weight_credit: &mut Weight,
) -> Result<(), ()> {
Deny::should_execute(origin, message, max_weight, weight_credit)?;
Allow::should_execute(origin, message, max_weight, weight_credit)
Expand All @@ -84,12 +84,11 @@ pub struct DenyReserveTransferToRelayChain;
impl ShouldExecute for DenyReserveTransferToRelayChain {
fn should_execute<RuntimeCall>(
origin: &MultiLocation,

message: &mut Xcm<RuntimeCall>,
_max_weight: XcmWeight,
_weight_credit: &mut XcmWeight,
message: &mut [Instruction<RuntimeCall>],
_max_weight: Weight,
_weight_credit: &mut Weight,
) -> Result<(), ()> {
if message.0.iter().any(|inst| {
if message.iter().any(|inst| {
matches!(
inst,
InitiateReserveWithdraw {
Expand All @@ -108,7 +107,7 @@ impl ShouldExecute for DenyReserveTransferToRelayChain {
// An unexpected reserve transfer has arrived from the Relay Chain. Generally, `IsReserve`
// should not allow this, but we just log it here.
if matches!(origin, MultiLocation { parents: 1, interior: Here })
&& message.0.iter().any(|inst| matches!(inst, ReserveAssetDeposited { .. }))
&& message.iter().any(|inst| matches!(inst, ReserveAssetDeposited { .. }))
{
log::warn!(
target: "xcm::barriers",
Expand Down
57 changes: 44 additions & 13 deletions runtime/crab/src/pallets/polkadot_xcm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub type LocalAssetTransactor = xcm_builder::CurrencyAdapter<
>;

frame_support::parameter_types! {
pub const RelayNetwork: xcm::latest::prelude::NetworkId = xcm::latest::prelude::NetworkId::Kusama;
pub const RelayNetwork: Option<xcm::latest::prelude::NetworkId> = Some(xcm::latest::NetworkId::Kusama);
pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into();
}
/// Type for specifying how a `MultiLocation` can be converted into an `AccountId`. This is used
Expand Down Expand Up @@ -77,27 +77,36 @@ pub type Barrier = darwinia_common_runtime::xcm_configs::DenyThenTry<
darwinia_common_runtime::xcm_configs::DenyReserveTransferToRelayChain,
(
xcm_builder::TakeWeightCredit,
xcm_builder::AllowTopLevelPaidExecutionFrom<frame_support::traits::Everything>,
// Parent and its exec plurality get free execution
xcm_builder::AllowUnpaidExecutionFrom<
darwinia_common_runtime::xcm_configs::ParentOrParentsExecutivePlurality,
WithComputedOrigin<
(
xcm_builder::AllowTopLevelPaidExecutionFrom<frame_support::traits::Everything>,
// Parent and its exec plurality get free execution
xcm_builder::AllowUnpaidExecutionFrom<
darwinia_common_runtime::xcm_configs::ParentOrParentsExecutivePlurality,
>,
// Subscriptions for version tracking are OK.
xcm_builder::AllowSubscriptionsFrom<
darwinia_common_runtime::xcm_configs::ParentOrSiblings,
>,
),
UniversalLocation,
ConstU32<8>,
>,
// Expected responses are OK.
xcm_builder::AllowKnownQueryResponses<PolkadotXcm>,
// Subscriptions for version tracking are OK.
xcm_builder::AllowSubscriptionsFrom<darwinia_common_runtime::xcm_configs::ParentOrSiblings>,
),
>;

frame_support::parameter_types! {
pub const MaxAssetsIntoHolding: u32 = 64;
pub const MaxInstructions: u32 = 100;
pub AnchoringSelfReserve: xcm::latest::prelude::MultiLocation = xcm::latest::prelude::MultiLocation::new(
0,
xcm::latest::prelude::X1(xcm::latest::prelude::PalletInstance(<Balances as frame_support::traits::PalletInfoAccess>::index() as u8))
);
pub UniversalLocation: xcm::latest::prelude::InteriorMultiLocation = xcm::latest::prelude::Parachain(ParachainInfo::parachain_id().into()).into();
// One XCM operation is 1_000_000_000 weight - almost certainly a conservative estimate.
pub Ancestry: xcm::latest::prelude::MultiLocation = xcm::latest::prelude::Parachain(ParachainInfo::parachain_id().into()).into();
pub UnitWeightCost: u64 = 1_000_000_000;
pub UnitWeightCost: Weight = Weight::from_parts(1_000_000_000, 64 * 1024);
}

pub struct ToTreasury;
Expand All @@ -122,17 +131,23 @@ impl xcm_builder::TakeRevenue for ToTreasury {
pub struct XcmExecutorConfig;
impl xcm_executor::Config for XcmExecutorConfig {
type AssetClaims = PolkadotXcm;
type AssetExchanger = ();
type AssetLocker = ();
// How to withdraw and deposit an asset.
type AssetTransactor = LocalAssetTransactor;
type AssetTrap = PolkadotXcm;
type Barrier = Barrier;
type CallDispatcher = RuntimeCall;
type FeeManager = ();
type IsReserve = xcm_builder::NativeAsset;
type IsTeleporter = ();
// Teleporting is disabled.
type LocationInverter = xcm_builder::LocationInverter<Ancestry>;
type MaxAssetsIntoHolding = MaxAssetsIntoHolding;
type MessageExporter = ();
type OriginConverter = XcmOriginToTransactDispatchOrigin;
type PalletInstancesInfo = AllPalletsWithSystem;
type ResponseHandler = PolkadotXcm;
type RuntimeCall = RuntimeCall;
type SafeCallFilter = Everything;
type SubscriptionService = PolkadotXcm;
type Trader = xcm_configs::LocalAssetTrader<
frame_support::weights::ConstantMultiplier<
Expand All @@ -145,6 +160,9 @@ impl xcm_executor::Config for XcmExecutorConfig {
DealWithFees<Runtime>,
ToTreasury,
>;
type UniversalAliases = Nothing;
// Teleporting is disabled.
type UniversalLocation = UniversalLocation;
type Weigher = xcm_builder::FixedWeightBounds<UnitWeightCost, RuntimeCall, MaxInstructions>;
type XcmSender = XcmRouter;
}
Expand All @@ -156,21 +174,34 @@ pub type LocalOriginToLocation =
/// queues.
pub type XcmRouter = (
// Two routers - use UMP to communicate with the relay chain:
cumulus_primitives_utility::ParentAsUmp<ParachainSystem, PolkadotXcm>,
cumulus_primitives_utility::ParentAsUmp<ParachainSystem, PolkadotXcm, ()>,
// ..and XCMP to communicate with the sibling chains.
XcmpQueue,
);

#[cfg(feature = "runtime-benchmarks")]
parameter_types! {
pub ReachableDest: Option<MultiLocation> = Some(Parent.into());
}

impl pallet_xcm::Config for Runtime {
// ^ Override for AdvertisedXcmVersion default
type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion;
type Currency = Balances;
type CurrencyMatcher = ();
type ExecuteXcmOrigin = xcm_builder::EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
type LocationInverter = xcm_builder::LocationInverter<Ancestry>;
type MaxLockers = ConstU32<8>;
#[cfg(feature = "runtime-benchmarks")]
type ReachableDest = ReachableDest;
type RuntimeCall = RuntimeCall;
type RuntimeEvent = RuntimeEvent;
type RuntimeOrigin = RuntimeOrigin;
type SendXcmOrigin = xcm_builder::EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
type SovereignAccountOf = LocationToAccountId;
type TrustedLockers = ();
type UniversalLocation = UniversalLocation;
type Weigher = xcm_builder::FixedWeightBounds<UnitWeightCost, RuntimeCall, MaxInstructions>;
type WeightInfo = pallet_xcm::TestWeightInfo;
type XcmExecuteFilter = frame_support::traits::Everything;
type XcmExecutor = xcm_executor::XcmExecutor<XcmExecutorConfig>;
type XcmReserveTransferFilter = frame_support::traits::Everything;
Expand Down
1 change: 1 addition & 0 deletions runtime/crab/src/pallets/xcmp_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ impl cumulus_pallet_xcmp_queue::Config for Runtime {
type VersionWrapper = ();
type WeightInfo = weights::cumulus_pallet_xcmp_queue::WeightInfo<Self>;
type XcmExecutor = xcm_executor::XcmExecutor<XcmExecutorConfig>;
type PriceForSiblingDelivery = ();
}
53 changes: 43 additions & 10 deletions runtime/darwinia/src/pallets/polkadot_xcm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub type LocalAssetTransactor = xcm_builder::CurrencyAdapter<
>;

frame_support::parameter_types! {
pub const RelayNetwork: xcm::latest::prelude::NetworkId = xcm::latest::prelude::NetworkId::Polkadot;
pub const RelayNetwork: Option<xcm::latest::prelude::NetworkId> = Some(xcm::latest::NetworkId::Polkadot);
pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into();
}
/// Type for specifying how a `MultiLocation` can be converted into an `AccountId`. This is used
Expand Down Expand Up @@ -77,10 +77,20 @@ pub type Barrier = darwinia_common_runtime::xcm_configs::DenyThenTry<
darwinia_common_runtime::xcm_configs::DenyReserveTransferToRelayChain,
(
xcm_builder::TakeWeightCredit,
xcm_builder::AllowTopLevelPaidExecutionFrom<frame_support::traits::Everything>,
// Parent and its exec plurality get free execution
xcm_builder::AllowUnpaidExecutionFrom<
darwinia_common_runtime::xcm_configs::ParentOrParentsExecutivePlurality,
WithComputedOrigin<
(
xcm_builder::AllowTopLevelPaidExecutionFrom<frame_support::traits::Everything>,
// Parent and its exec plurality get free execution
xcm_builder::AllowUnpaidExecutionFrom<
darwinia_common_runtime::xcm_configs::ParentOrParentsExecutivePlurality,
>,
// Subscriptions for version tracking are OK.
xcm_builder::AllowSubscriptionsFrom<
darwinia_common_runtime::xcm_configs::ParentOrSiblings,
>,
),
UniversalLocation,
ConstU32<8>,
>,
// Expected responses are OK.
xcm_builder::AllowKnownQueryResponses<PolkadotXcm>,
Expand All @@ -90,14 +100,15 @@ pub type Barrier = darwinia_common_runtime::xcm_configs::DenyThenTry<
>;

frame_support::parameter_types! {
pub const MaxAssetsIntoHolding: u32 = 64;
pub const MaxInstructions: u32 = 100;
pub AnchoringSelfReserve: xcm::latest::prelude::MultiLocation = xcm::latest::prelude::MultiLocation::new(
0,
xcm::latest::prelude::X1(xcm::latest::prelude::PalletInstance(<Balances as frame_support::traits::PalletInfoAccess>::index() as u8))
);
pub UniversalLocation: xcm::latest::prelude::InteriorMultiLocation = xcm::latest::prelude::Parachain(ParachainInfo::parachain_id().into()).into();
// One XCM operation is 1_000_000_000 weight - almost certainly a conservative estimate.
pub Ancestry: xcm::latest::prelude::MultiLocation = xcm::latest::prelude::Parachain(ParachainInfo::parachain_id().into()).into();
pub UnitWeightCost: u64 = 1_000_000_000;
pub UnitWeightCost: Weight = Weight::from_parts(1_000_000_000, 64 * 1024);
}

pub struct ToTreasury;
Expand Down Expand Up @@ -129,7 +140,7 @@ impl xcm_executor::Config for XcmExecutorConfig {
type IsReserve = xcm_builder::NativeAsset;
type IsTeleporter = ();
// Teleporting is disabled.
type LocationInverter = xcm_builder::LocationInverter<Ancestry>;
type UniversalLocation = UniversalLocation;
type OriginConverter = XcmOriginToTransactDispatchOrigin;
type ResponseHandler = PolkadotXcm;
type RuntimeCall = RuntimeCall;
Expand All @@ -147,6 +158,15 @@ impl xcm_executor::Config for XcmExecutorConfig {
>;
type Weigher = xcm_builder::FixedWeightBounds<UnitWeightCost, RuntimeCall, MaxInstructions>;
type XcmSender = XcmRouter;
type PalletInstancesInfo = AllPalletsWithSystem;
type MaxAssetsIntoHolding = MaxAssetsIntoHolding;
type AssetLocker = ();
type AssetExchanger = ();
type FeeManager = ();
type MessageExporter = ();
type UniversalAliases = Nothing;
type CallDispatcher = RuntimeCall;
type SafeCallFilter = Everything;
}

/// No local origins on this chain are allowed to dispatch XCM sends/executions.
Expand All @@ -156,16 +176,21 @@ pub type LocalOriginToLocation =
/// queues.
pub type XcmRouter = (
// Two routers - use UMP to communicate with the relay chain:
cumulus_primitives_utility::ParentAsUmp<ParachainSystem, PolkadotXcm>,
cumulus_primitives_utility::ParentAsUmp<ParachainSystem, PolkadotXcm, ()>,
// ..and XCMP to communicate with the sibling chains.
XcmpQueue,
);

#[cfg(feature = "runtime-benchmarks")]
parameter_types! {
pub ReachableDest: Option<MultiLocation> = Some(Parent.into());
}

impl pallet_xcm::Config for Runtime {
// ^ Override for AdvertisedXcmVersion default
type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion;
type ExecuteXcmOrigin = xcm_builder::EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
type LocationInverter = xcm_builder::LocationInverter<Ancestry>;
type UniversalLocation = UniversalLocation;
type RuntimeCall = RuntimeCall;
type RuntimeEvent = RuntimeEvent;
type RuntimeOrigin = RuntimeOrigin;
Expand All @@ -178,6 +203,14 @@ impl pallet_xcm::Config for Runtime {
type XcmTeleportFilter = frame_support::traits::Nothing;

const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;
type Currency = Balances;
type CurrencyMatcher = ();
type TrustedLockers = ();
type SovereignAccountOf = LocationToAccountId;
type MaxLockers = ConstU32<8>;
type WeightInfo = pallet_xcm::TestWeightInfo;
#[cfg(feature = "runtime-benchmarks")]
type ReachableDest = ReachableDest;
}

impl cumulus_pallet_xcm::Config for Runtime {
Expand Down
1 change: 1 addition & 0 deletions runtime/darwinia/src/pallets/xcmp_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ impl cumulus_pallet_xcmp_queue::Config for Runtime {
type VersionWrapper = ();
type WeightInfo = weights::cumulus_pallet_xcmp_queue::WeightInfo<Self>;
type XcmExecutor = xcm_executor::XcmExecutor<XcmExecutorConfig>;
type PriceForSiblingDelivery = ();
}
Loading

0 comments on commit 4140e16

Please sign in to comment.