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

Clear other messages before dry-run to get only the ones produced during #5581

Merged
merged 16 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 4 additions & 0 deletions bridges/modules/xcm-bridge-hub-router/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,10 @@ 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 get_messages() -> Vec<(VersionedLocation, Vec<VersionedXcm<()>>)> {
ViaBridgeHubExporter::<T, I>::get_messages()
}
Expand Down
4 changes: 4 additions & 0 deletions bridges/modules/xcm-bridge-hub-router/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ impl SendXcm for TestToBridgeHubSender {
}

impl InspectMessageQueues for TestToBridgeHubSender {
fn clear_messages() {
SENT_XCM.with(|q| *q.borrow_mut().clear());
}

fn get_messages() -> Vec<(VersionedLocation, Vec<VersionedXcm<()>>)> {
SENT_XCM.with(|q| {
(*q.borrow())
Expand Down
4 changes: 4 additions & 0 deletions bridges/modules/xcm-bridge-hub/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,10 @@ impl SendXcm for TestExportXcmWithXcmOverBridge {
}
}
impl InspectMessageQueues for TestExportXcmWithXcmOverBridge {
fn clear_messages() {
todo!()
}

fn get_messages() -> Vec<(VersionedLocation, Vec<VersionedXcm<()>>)> {
todo!()
}
Expand Down
4 changes: 4 additions & 0 deletions cumulus/pallets/parachain-system/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1540,6 +1540,10 @@ impl<T: Config> UpwardMessageSender for Pallet<T> {
}

impl<T: Config> InspectMessageQueues for Pallet<T> {
fn clear_messages() {
PendingUpwardMessages::<T>::kill();
}

fn get_messages() -> Vec<(VersionedLocation, Vec<VersionedXcm<()>>)> {
use xcm::prelude::*;

Expand Down
8 changes: 7 additions & 1 deletion cumulus/pallets/xcmp-queue/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ use frame_support::{
defensive, defensive_assert,
traits::{Defensive, EnqueueMessage, EnsureOrigin, Get, QueueFootprint, QueuePausedQuery},
weights::{Weight, WeightMeter},
BoundedVec,
BoundedVec, StoragePrefixedMap,
};
use pallet_message_queue::OnQueueChanged;
use polkadot_runtime_common::xcm_sender::PriceForMessageDelivery;
Expand Down Expand Up @@ -1008,6 +1008,12 @@ impl<T: Config> SendXcm for Pallet<T> {
}

impl<T: Config> InspectMessageQueues for Pallet<T> {
fn clear_messages() {
let prefix = OutboundXcmpMessages::<T>::final_prefix();
// Best effort.
let _ = frame_support::storage::unhashed::clear_prefix(&prefix, None, None);
}

fn get_messages() -> Vec<(VersionedLocation, Vec<VersionedXcm<()>>)> {
use xcm::prelude::*;

Expand Down
4 changes: 4 additions & 0 deletions cumulus/primitives/utility/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ where
impl<T: UpwardMessageSender + InspectMessageQueues, W, P> InspectMessageQueues
for ParentAsUmp<T, W, P>
{
fn clear_messages() {
T::clear_messages();
}

fn get_messages() -> Vec<(VersionedLocation, Vec<VersionedXcm<()>>)> {
T::get_messages()
}
Expand Down
8 changes: 7 additions & 1 deletion polkadot/runtime/common/src/xcm_sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use alloc::vec::Vec;
use codec::{Decode, Encode};
use core::marker::PhantomData;
use frame_support::traits::Get;
use frame_support::{traits::Get, StoragePrefixedMap};
use frame_system::pallet_prelude::BlockNumberFor;
use polkadot_primitives::Id as ParaId;
use polkadot_runtime_parachains::{
Expand Down Expand Up @@ -141,6 +141,12 @@ where
}

impl<T: dmp::Config, W, P> InspectMessageQueues for ChildParachainRouter<T, W, P> {
fn clear_messages() {
let prefix = dmp::DownwardMessageQueues::<T>::final_prefix();
// Best effort.
let _ = frame_support::storage::unhashed::clear_prefix(&prefix, None, None);
franciscoaguirre marked this conversation as resolved.
Show resolved Hide resolved
}

fn get_messages() -> Vec<(VersionedLocation, Vec<VersionedXcm<()>>)> {
dmp::DownwardMessageQueues::<T>::iter()
.map(|(para_id, messages)| {
Expand Down
2 changes: 2 additions & 0 deletions polkadot/xcm/pallet-xcm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2457,10 +2457,12 @@ impl<T: Config> Pallet<T> {
<RuntimeCall as Dispatchable>::RuntimeOrigin: From<OriginCaller>,
{
crate::Pallet::<Runtime>::set_record_xcm(true);
Router::clear_messages(); // Clear other messages in queues.
frame_system::Pallet::<Runtime>::reset_events(); // To make sure we only record events from current call.
franciscoaguirre marked this conversation as resolved.
Show resolved Hide resolved
let result = call.dispatch(origin.into());
crate::Pallet::<Runtime>::set_record_xcm(false);
let local_xcm = crate::Pallet::<Runtime>::recorded_xcm();
// Should only get messages from this call since we cleared previous ones.
let forwarded_xcms = Router::get_messages();
let events: Vec<<Runtime as frame_system::Config>::RuntimeEvent> =
frame_system::Pallet::<Runtime>::read_events_no_consensus()
Expand Down
12 changes: 12 additions & 0 deletions polkadot/xcm/xcm-builder/src/routing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ impl<Inner: SendXcm> SendXcm for WithUniqueTopic<Inner> {
}
}
impl<Inner: InspectMessageQueues> InspectMessageQueues for WithUniqueTopic<Inner> {
fn clear_messages() {
Inner::clear_messages()
}

fn get_messages() -> Vec<(VersionedLocation, Vec<VersionedXcm<()>>)> {
Inner::get_messages()
}
Expand Down Expand Up @@ -149,12 +153,20 @@ impl EnsureDelivery for Tuple {
/// Inspects messages in queues.
/// Meant to be used in runtime APIs, not in runtimes.
pub trait InspectMessageQueues {
/// Clear the queues, so `Self::get_messages()` can return only the desired events.
franciscoaguirre marked this conversation as resolved.
Show resolved Hide resolved
fn clear_messages();
/// Get queued messages and their destinations.
fn get_messages() -> Vec<(VersionedLocation, Vec<VersionedXcm<()>>)>;
}

#[impl_trait_for_tuples::impl_for_tuples(30)]
impl InspectMessageQueues for Tuple {
fn clear_messages() {
for_tuples!( #(
Tuple::clear_messages();
)* );
}

fn get_messages() -> Vec<(VersionedLocation, Vec<VersionedXcm<()>>)> {
let mut messages = Vec::new();

Expand Down
4 changes: 4 additions & 0 deletions polkadot/xcm/xcm-builder/src/universal_exports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,10 @@ impl<Bridges: ExporterFor, Router: SendXcm, UniversalLocation: Get<InteriorLocat
impl<Bridges, Router: InspectMessageQueues, UniversalLocation> InspectMessageQueues
for SovereignPaidRemoteExporter<Bridges, Router, UniversalLocation>
{
fn clear_messages() {
Router::clear_messages()
}

fn get_messages() -> Vec<(VersionedLocation, Vec<VersionedXcm<()>>)> {
Router::get_messages()
}
Expand Down
Loading