Skip to content

Commit

Permalink
Make xcm config index friendly (#3113)
Browse files Browse the repository at this point in the history
* Barrier with TrailingSetTopic

* Wrap XcmRouter with WithUniqueTopic

* Fix tests
  • Loading branch information
yrong authored Jan 6, 2025
1 parent 74e484b commit aa523e4
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 35 deletions.
10 changes: 5 additions & 5 deletions runtime/moonbase/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ use xcm_builder::{
EnsureXcmOrigin, FungibleAdapter as XcmCurrencyAdapter, FungiblesAdapter, HashedDescription,
NoChecking, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative,
SiblingParachainConvertsVia, SignedAccountKey20AsNative, SovereignSignedViaLocation,
TakeWeightCredit, WeightInfoBounds, WithComputedOrigin,
TakeWeightCredit, TrailingSetTopicAsId, WeightInfoBounds, WithComputedOrigin, WithUniqueTopic,
};

use parachains_common::message_queue::{NarrowOriginToSibling, ParaIdToSibling};
Expand Down Expand Up @@ -207,7 +207,7 @@ pub type XcmWeigher = WeightInfoBounds<
MaxInstructions,
>;

pub type XcmBarrier = (
pub type XcmBarrier = TrailingSetTopicAsId<(
// Weight that is paid for may be consumed.
TakeWeightCredit,
// Expected responses are OK.
Expand All @@ -222,7 +222,7 @@ pub type XcmBarrier = (
UniversalLocation,
ConstU32<8>,
>,
);
)>;

parameter_types! {
/// Xcm fees will go to the treasury account
Expand Down Expand Up @@ -317,12 +317,12 @@ pub type LocalOriginToLocation = SignedToAccountId20<RuntimeOrigin, AccountId, R

/// The means for routing XCM messages which are not for local execution into the right message
/// queues.
pub type XcmRouter = (
pub type XcmRouter = WithUniqueTopic<(
// Two routers - use UMP to communicate with the relay chain:
cumulus_primitives_utility::ParentAsUmp<ParachainSystem, PolkadotXcm, ()>,
// ..and XCMP to communicate with the sibling chains.
XcmpQueue,
);
)>;

type XcmExecutor = pallet_erc20_xcm_bridge::XcmExecutorWrapper<
XcmExecutorConfig,
Expand Down
12 changes: 6 additions & 6 deletions runtime/moonbase/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1526,7 +1526,7 @@ fn xtokens_precompiles_transfer() {
(AccountId::from(ALICE), 2_000 * UNIT),
(AccountId::from(BOB), 1_000 * UNIT),
])
.with_safe_xcm_version(2)
.with_safe_xcm_version(3)
.build()
.execute_with(|| {
let xtokens_precompile_address = H160::from_low_u64_be(2052);
Expand Down Expand Up @@ -1624,7 +1624,7 @@ fn xtokens_precompiles_transfer_multiasset() {
(AccountId::from(ALICE), 2_000 * UNIT),
(AccountId::from(BOB), 1_000 * UNIT),
])
.with_safe_xcm_version(2)
.with_safe_xcm_version(3)
.build()
.execute_with(|| {
let xtokens_precompile_address = H160::from_low_u64_be(2052);
Expand Down Expand Up @@ -1710,7 +1710,7 @@ fn xtokens_precompiles_transfer_native() {
(AccountId::from(ALICE), 2_000 * UNIT),
(AccountId::from(BOB), 1_000 * UNIT),
])
.with_safe_xcm_version(2)
.with_safe_xcm_version(3)
.build()
.execute_with(|| {
let xtokens_precompile_address = H160::from_low_u64_be(2052);
Expand Down Expand Up @@ -2255,7 +2255,7 @@ fn transact_through_signed_precompile_works_v1() {
(AccountId::from(ALICE), 2_000 * UNIT),
(AccountId::from(BOB), 1_000 * UNIT),
])
.with_safe_xcm_version(2)
.with_safe_xcm_version(3)
.build()
.execute_with(|| {
// Destination
Expand Down Expand Up @@ -2307,7 +2307,7 @@ fn transact_through_signed_precompile_works_v2() {
(AccountId::from(ALICE), 2_000 * UNIT),
(AccountId::from(BOB), 1_000 * UNIT),
])
.with_safe_xcm_version(2)
.with_safe_xcm_version(3)
.build()
.execute_with(|| {
// Destination
Expand Down Expand Up @@ -2347,7 +2347,7 @@ fn transact_through_signed_cannot_send_to_local_chain() {
(AccountId::from(ALICE), 2_000 * UNIT),
(AccountId::from(BOB), 1_000 * UNIT),
])
.with_safe_xcm_version(2)
.with_safe_xcm_version(3)
.build()
.execute_with(|| {
// Destination
Expand Down
10 changes: 5 additions & 5 deletions runtime/moonbeam/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ use xcm_builder::{
EnsureXcmOrigin, FungibleAdapter as XcmCurrencyAdapter, FungiblesAdapter, HashedDescription,
NoChecking, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative,
SiblingParachainConvertsVia, SignedAccountKey20AsNative, SovereignSignedViaLocation,
TakeWeightCredit, WeightInfoBounds, WithComputedOrigin,
TakeWeightCredit, TrailingSetTopicAsId, WeightInfoBounds, WithComputedOrigin, WithUniqueTopic,
};

use parachains_common::message_queue::{NarrowOriginToSibling, ParaIdToSibling};
Expand Down Expand Up @@ -197,7 +197,7 @@ pub type XcmWeigher = WeightInfoBounds<
MaxInstructions,
>;

pub type XcmBarrier = (
pub type XcmBarrier = TrailingSetTopicAsId<(
// Weight that is paid for may be consumed.
TakeWeightCredit,
// Expected responses are OK.
Expand All @@ -212,7 +212,7 @@ pub type XcmBarrier = (
UniversalLocation,
ConstU32<8>,
>,
);
)>;

parameter_types! {
/// Xcm fees will go to the treasury account
Expand Down Expand Up @@ -312,12 +312,12 @@ pub type LocalOriginToLocation = SignedToAccountId20<RuntimeOrigin, AccountId, R

/// The means for routing XCM messages which are not for local execution into the right message
/// queues.
pub type XcmRouter = (
pub type XcmRouter = WithUniqueTopic<(
// Two routers - use UMP to communicate with the relay chain:
cumulus_primitives_utility::ParentAsUmp<ParachainSystem, PolkadotXcm, ()>,
// ..and XCMP to communicate with the sibling chains.
XcmpQueue,
);
)>;

impl pallet_xcm::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
Expand Down
16 changes: 8 additions & 8 deletions runtime/moonbeam/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1660,7 +1660,7 @@ fn root_can_change_default_xcm_vers() {
// Root sets the defaultXcm
assert_ok!(PolkadotXcm::force_default_xcm_version(
root_origin(),
Some(2)
Some(3)
));

// Now transferring does not fail
Expand Down Expand Up @@ -1935,7 +1935,7 @@ fn xtokens_precompile_transfer() {
(AccountId::from(ALICE), 2_000 * GLMR),
(AccountId::from(BOB), 1_000 * GLMR),
])
.with_safe_xcm_version(2)
.with_safe_xcm_version(3)
.build()
.execute_with(|| {
let xtokens_precompile_address = H160::from_low_u64_be(2052);
Expand Down Expand Up @@ -1995,7 +1995,7 @@ fn xtokens_precompile_transfer_multiasset() {
(AccountId::from(ALICE), 2_000 * GLMR),
(AccountId::from(BOB), 1_000 * GLMR),
])
.with_safe_xcm_version(2)
.with_safe_xcm_version(3)
.build()
.execute_with(|| {
let xtokens_precompile_address = H160::from_low_u64_be(2052);
Expand Down Expand Up @@ -2041,7 +2041,7 @@ fn make_sure_glmr_can_be_transferred_precompile() {
NimbusId::from_slice(&ALICE_NIMBUS).unwrap(),
AccountId::from(ALICE),
)])
.with_safe_xcm_version(2)
.with_safe_xcm_version(3)
.build()
.execute_with(|| {
assert_ok!(PolkadotXcm::transfer_assets(
Expand Down Expand Up @@ -2080,7 +2080,7 @@ fn make_sure_glmr_can_be_transferred() {
NimbusId::from_slice(&ALICE_NIMBUS).unwrap(),
AccountId::from(ALICE),
)])
.with_safe_xcm_version(2)
.with_safe_xcm_version(3)
.build()
.execute_with(|| {
let dest = Location {
Expand Down Expand Up @@ -2158,7 +2158,7 @@ fn transact_through_signed_precompile_works_v2() {
(AccountId::from(ALICE), 2_000 * GLMR),
(AccountId::from(BOB), 1_000 * GLMR),
])
.with_safe_xcm_version(2)
.with_safe_xcm_version(3)
.build()
.execute_with(|| {
// Destination
Expand Down Expand Up @@ -2198,7 +2198,7 @@ fn transact_through_signed_cannot_send_to_local_chain() {
(AccountId::from(ALICE), 2_000 * GLMR),
(AccountId::from(BOB), 1_000 * GLMR),
])
.with_safe_xcm_version(2)
.with_safe_xcm_version(3)
.build()
.execute_with(|| {
// Destination
Expand Down Expand Up @@ -2329,7 +2329,7 @@ fn call_xtokens_with_fee() {
(AccountId::from(ALICE), 2_000 * GLMR),
(AccountId::from(BOB), 1_000 * GLMR),
])
.with_safe_xcm_version(2)
.with_safe_xcm_version(3)
.with_xcm_assets(vec![XcmAssetInitialization {
asset_type: AssetType::Xcm(xcm::v3::Location::parent()),
metadata: AssetRegistrarMetadata {
Expand Down
10 changes: 5 additions & 5 deletions runtime/moonriver/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ use xcm_builder::{
EnsureXcmOrigin, FungibleAdapter as XcmCurrencyAdapter, FungiblesAdapter, HashedDescription,
NoChecking, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative,
SiblingParachainConvertsVia, SignedAccountKey20AsNative, SovereignSignedViaLocation,
TakeWeightCredit, WeightInfoBounds, WithComputedOrigin,
TakeWeightCredit, TrailingSetTopicAsId, WeightInfoBounds, WithComputedOrigin, WithUniqueTopic,
};

use parachains_common::message_queue::{NarrowOriginToSibling, ParaIdToSibling};
Expand Down Expand Up @@ -205,7 +205,7 @@ pub type XcmWeigher = WeightInfoBounds<
MaxInstructions,
>;

pub type XcmBarrier = (
pub type XcmBarrier = TrailingSetTopicAsId<(
// Weight that is paid for may be consumed.
TakeWeightCredit,
// Expected responses are OK.
Expand All @@ -220,7 +220,7 @@ pub type XcmBarrier = (
UniversalLocation,
ConstU32<8>,
>,
);
)>;

parameter_types! {
/// Xcm fees will go to the treasury account
Expand Down Expand Up @@ -320,12 +320,12 @@ pub type LocalOriginToLocation = SignedToAccountId20<RuntimeOrigin, AccountId, R

/// The means for routing XCM messages which are not for local execution into the right message
/// queues.
pub type XcmRouter = (
pub type XcmRouter = WithUniqueTopic<(
// Two routers - use UMP to communicate with the relay chain:
cumulus_primitives_utility::ParentAsUmp<ParachainSystem, PolkadotXcm, ()>,
// ..and XCMP to communicate with the sibling chains.
XcmpQueue,
);
)>;

impl pallet_xcm::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
Expand Down
12 changes: 6 additions & 6 deletions runtime/moonriver/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1645,7 +1645,7 @@ fn root_can_change_default_xcm_vers() {
// Root sets the defaultXcm
assert_ok!(PolkadotXcm::force_default_xcm_version(
root_origin(),
Some(2)
Some(3)
));

// Now transferring does not fail
Expand Down Expand Up @@ -1910,7 +1910,7 @@ fn xtokens_precompiles_transfer() {
(AccountId::from(ALICE), 2_000 * MOVR),
(AccountId::from(BOB), 1_000 * MOVR),
])
.with_safe_xcm_version(2)
.with_safe_xcm_version(3)
.build()
.execute_with(|| {
let xtokens_precompile_address = H160::from_low_u64_be(2052);
Expand Down Expand Up @@ -1970,7 +1970,7 @@ fn xtokens_precompiles_transfer_multiasset() {
(AccountId::from(ALICE), 2_000 * MOVR),
(AccountId::from(BOB), 1_000 * MOVR),
])
.with_safe_xcm_version(2)
.with_safe_xcm_version(3)
.build()
.execute_with(|| {
let xtokens_precompile_address = H160::from_low_u64_be(2052);
Expand Down Expand Up @@ -2142,7 +2142,7 @@ fn transact_through_signed_precompile_works_v2() {
(AccountId::from(ALICE), 2_000 * MOVR),
(AccountId::from(BOB), 1_000 * MOVR),
])
.with_safe_xcm_version(2)
.with_safe_xcm_version(3)
.build()
.execute_with(|| {
// Destination
Expand Down Expand Up @@ -2182,7 +2182,7 @@ fn transact_through_signed_cannot_send_to_local_chain() {
(AccountId::from(ALICE), 2_000 * MOVR),
(AccountId::from(BOB), 1_000 * MOVR),
])
.with_safe_xcm_version(2)
.with_safe_xcm_version(3)
.build()
.execute_with(|| {
// Destination
Expand Down Expand Up @@ -2225,7 +2225,7 @@ fn call_xtokens_with_fee() {
(AccountId::from(ALICE), 2_000 * MOVR),
(AccountId::from(BOB), 1_000 * MOVR),
])
.with_safe_xcm_version(2)
.with_safe_xcm_version(3)
.with_xcm_assets(vec![XcmAssetInitialization {
asset_type: AssetType::Xcm(xcm::v3::Location::parent()),
metadata: AssetRegistrarMetadata {
Expand Down

0 comments on commit aa523e4

Please sign in to comment.