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

Remove redundant XCMs from dry run's forwarded xcms #5913

Merged
merged 17 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
0a74c6e
fix(parachain-system): not include messages if empty
franciscoaguirre Oct 3, 2024
4ba9883
fix: exporters already add their message to xcmp-queue
franciscoaguirre Oct 3, 2024
b9755bf
doc: prdoc
franciscoaguirre Oct 3, 2024
4594acb
Merge branch 'master' into xcm-dry-run-redundant-forwarded-xcms
franciscoaguirre Oct 3, 2024
08dad22
test(bridge-hub-westend-integration-tests): add dry run test
franciscoaguirre Oct 4, 2024
196d265
Merge branch 'master' into xcm-dry-run-redundant-forwarded-xcms
franciscoaguirre Oct 4, 2024
5914f23
test(bridge-hub-rococo-integration-tests): add same test as in westend
franciscoaguirre Oct 4, 2024
84e60a0
test(emulated-integration-tests-common): refactor rococo and westend …
franciscoaguirre Oct 4, 2024
72d1a00
Merge branch 'master' into xcm-dry-run-redundant-forwarded-xcms
franciscoaguirre Oct 4, 2024
aab1b1d
doc: update prdoc
franciscoaguirre Oct 4, 2024
4cddc77
doc: add a note of why some impls are empty
franciscoaguirre Oct 4, 2024
250c987
".git/.scripts/commands/fmt/fmt.sh"
Oct 4, 2024
ddc07f3
Merge branch 'master' into xcm-dry-run-redundant-forwarded-xcms
franciscoaguirre Oct 4, 2024
5fab2ab
Merge branch 'master' into xcm-dry-run-redundant-forwarded-xcms
franciscoaguirre Oct 7, 2024
e22a72b
Merge branch 'master' into xcm-dry-run-redundant-forwarded-xcms
franciscoaguirre Oct 9, 2024
081cede
Merge branch 'master' into xcm-dry-run-redundant-forwarded-xcms
franciscoaguirre Oct 10, 2024
3367dd0
fix(pallet-xcm-bridge-hub-router): update test
franciscoaguirre Oct 10, 2024
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
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions bridges/modules/xcm-bridge-hub-router/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ pub mod pallet {
type DestinationVersion: GetVersion;

/// Actual message sender (`HRMP` or `DMP`) to the sibling bridge hub location.
type ToBridgeHubSender: SendXcm + InspectMessageQueues;
type ToBridgeHubSender: SendXcm;
/// Local XCM channel manager.
type LocalXcmChannelManager: XcmChannelStatusProvider;

Expand Down Expand Up @@ -408,12 +408,12 @@ impl<T: Config<I>, I: 'static> SendXcm for Pallet<T, I> {
}

impl<T: Config<I>, I: 'static> InspectMessageQueues for Pallet<T, I> {
fn clear_messages() {
ViaBridgeHubExporter::<T, I>::clear_messages()
}
fn clear_messages() {}

/// This router needs to implement `InspectMessageQueues` but doesn't have to
/// return any messages, since it just reuses the `XcmpQueue` router.
fn get_messages() -> Vec<(VersionedLocation, Vec<VersionedXcm<()>>)> {
ViaBridgeHubExporter::<T, I>::get_messages()
Vec::new()
serban300 marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down
6 changes: 5 additions & 1 deletion cumulus/pallets/parachain-system/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1627,7 +1627,11 @@ impl<T: Config> InspectMessageQueues for Pallet<T> {
.map(|encoded_message| VersionedXcm::<()>::decode(&mut &encoded_message[..]).unwrap())
.collect();

vec![(VersionedLocation::V4(Parent.into()), messages)]
if messages.is_empty() {
vec![]
} else {
vec![(VersionedLocation::from(Location::parent()), messages)]
}
}
}

Expand Down
48 changes: 48 additions & 0 deletions cumulus/parachains/integration-tests/emulated/common/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,3 +403,51 @@ macro_rules! test_chain_can_claim_assets {
}
};
}

#[macro_export]
macro_rules! test_dry_run_transfer_across_pk_bridge {
( $sender_asset_hub:ty, $sender_bridge_hub:ty, $destination:expr ) => {
$crate::macros::paste::paste! {
use frame_support::{dispatch::RawOrigin, traits::fungible};
use sp_runtime::AccountId32;
use xcm::prelude::*;
use xcm_runtime_apis::dry_run::runtime_decl_for_dry_run_api::DryRunApiV1;

let who = AccountId32::new([1u8; 32]);
let transfer_amount = 10_000_000_000_000u128;
let initial_balance = transfer_amount * 10;

// Bridge setup.
$sender_asset_hub::force_xcm_version($destination, XCM_VERSION);
open_bridge_between_asset_hub_rococo_and_asset_hub_westend();

<$sender_asset_hub as TestExt>::execute_with(|| {
type Runtime = <$sender_asset_hub as Chain>::Runtime;
type RuntimeCall = <$sender_asset_hub as Chain>::RuntimeCall;
type OriginCaller = <$sender_asset_hub as Chain>::OriginCaller;
type Balances = <$sender_asset_hub as [<$sender_asset_hub Pallet>]>::Balances;

// Give some initial funds.
<Balances as fungible::Mutate<_>>::set_balance(&who, initial_balance);

let call = RuntimeCall::PolkadotXcm(pallet_xcm::Call::transfer_assets {
dest: Box::new(VersionedLocation::from($destination)),
beneficiary: Box::new(VersionedLocation::from(Junction::AccountId32 {
id: who.clone().into(),
network: None,
})),
assets: Box::new(VersionedAssets::from(vec![
(Parent, transfer_amount).into(),
])),
fee_asset_item: 0,
weight_limit: Unlimited,
});
let result = Runtime::dry_run_call(OriginCaller::system(RawOrigin::Signed(who)), call).unwrap();
// We assert the dry run succeeds and sends only one message to the local bridge hub.
assert!(result.execution_result.is_ok());
assert_eq!(result.forwarded_xcms.len(), 1);
assert_eq!(result.forwarded_xcms[0].0, VersionedLocation::from(Location::new(1, [Parachain($sender_bridge_hub::para_id().into())])));
});
}
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ sp-runtime = { workspace = true }
xcm = { workspace = true }
pallet-xcm = { workspace = true }
xcm-executor = { workspace = true }
xcm-runtime-apis = { workspace = true }

# Bridges
pallet-bridge-messages = { workspace = true }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ mod imports {
pub use emulated_integration_tests_common::{
accounts::ALICE,
impls::Inspect,
test_parachain_is_trusted_teleporter, test_parachain_is_trusted_teleporter_for_relay,
test_relay_is_trusted_teleporter,
test_dry_run_transfer_across_pk_bridge, test_parachain_is_trusted_teleporter,
test_parachain_is_trusted_teleporter_for_relay, test_relay_is_trusted_teleporter,
xcm_emulator::{
assert_expected_events, bx, Chain, Parachain as Para, RelayChain as Relay, TestExt,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -534,3 +534,12 @@ fn send_back_wnds_from_penpal_rococo_through_asset_hub_rococo_to_asset_hub_weste
assert!(receiver_wnds_after > receiver_wnds_before);
assert!(receiver_wnds_after <= receiver_wnds_before + amount);
}

#[test]
fn dry_run_transfer_to_westend_sends_xcm_to_bridge_hub() {
test_dry_run_transfer_across_pk_bridge!(
AssetHubRococo,
BridgeHubRococo,
asset_hub_westend_location()
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ sp-runtime = { workspace = true }
xcm = { workspace = true }
pallet-xcm = { workspace = true }
xcm-executor = { workspace = true }
xcm-runtime-apis = { workspace = true }

# Bridges
pallet-bridge-messages = { workspace = true }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ mod imports {
pub use emulated_integration_tests_common::{
accounts::ALICE,
impls::Inspect,
test_parachain_is_trusted_teleporter, test_parachain_is_trusted_teleporter_for_relay,
test_relay_is_trusted_teleporter,
test_dry_run_transfer_across_pk_bridge, test_parachain_is_trusted_teleporter,
test_parachain_is_trusted_teleporter_for_relay, test_relay_is_trusted_teleporter,
xcm_emulator::{
assert_expected_events, bx, Chain, Parachain as Para, RelayChain as Relay, TestExt,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -554,3 +554,12 @@ fn send_back_rocs_from_penpal_westend_through_asset_hub_westend_to_asset_hub_roc
assert!(receiver_rocs_after > receiver_rocs_before);
assert!(receiver_rocs_after <= receiver_rocs_before + amount);
}

#[test]
fn dry_run_transfer_to_rococo_sends_xcm_to_bridge_hub() {
test_dry_run_transfer_across_pk_bridge!(
AssetHubWestend,
BridgeHubWestend,
asset_hub_rococo_location()
);
}
10 changes: 5 additions & 5 deletions polkadot/xcm/xcm-builder/src/universal_exports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,15 +337,15 @@ impl<Bridges: ExporterFor, Router: SendXcm, UniversalLocation: Get<InteriorLocat
}
}

impl<Bridges, Router: InspectMessageQueues, UniversalLocation> InspectMessageQueues
impl<Bridges, Router, UniversalLocation> InspectMessageQueues
for SovereignPaidRemoteExporter<Bridges, Router, UniversalLocation>
{
fn clear_messages() {
Router::clear_messages()
}
fn clear_messages() {}

/// This router needs to implement `InspectMessageQueues` but doesn't have to
/// return any messages, since it just reuses the `XcmpQueue` router.
fn get_messages() -> Vec<(VersionedLocation, Vec<VersionedXcm<()>>)> {
Router::get_messages()
Vec::new()
}
}

Expand Down
20 changes: 20 additions & 0 deletions prdoc/pr_5913.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0
# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json

title: Remove redundant XCMs from dry run's forwarded xcms

doc:
- audience: Runtime User
description: |
The DryRunApi was returning the same message repeated multiple times in the
`forwarded_xcms` field. This is no longer the case.

crates:
- name: pallet-xcm-bridge-hub-router
bump: patch
- name: cumulus-pallet-parachain-system
bump: patch
- name: staging-xcm-builder
bump: patch
- name: emulated-integration-tests-common
bump: minor
Loading