From 0ac29941d5b19f572b0cc430240d1d9dac46b426 Mon Sep 17 00:00:00 2001 From: Juan Ignacio Rios <54085674+JuaniRios@users.noreply.github.com> Date: Mon, 24 Jun 2024 16:34:40 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20Accept=20trailing=20topics=20on?= =?UTF-8?q?=20xcm=20barrier=20(#335)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## What? - Make messages with a trailing `SetTopic` pass the barriers ## Why? - This is a convention used by parachains. Any query we send will be responded with the response + topic, and currently our barriers don't expect that ## How? - The wrapper checks if at the end there is a `SetTopic`, and if so removes it and sets the topic of the executor ## Testing? No tests ## Anything Else? Discussion on the SDK repo: https://github.com/paritytech/polkadot-sdk/issues/4868 --- runtimes/polimec/src/xcm_config.rs | 88 ++++++++++-------------------- 1 file changed, 30 insertions(+), 58 deletions(-) diff --git a/runtimes/polimec/src/xcm_config.rs b/runtimes/polimec/src/xcm_config.rs index f39503b81..a2581a8a9 100644 --- a/runtimes/polimec/src/xcm_config.rs +++ b/runtimes/polimec/src/xcm_config.rs @@ -34,12 +34,12 @@ use polkadot_parachain_primitives::primitives::Sibling; use sp_runtime::traits::MaybeEquivalence; use xcm::latest::prelude::*; use xcm_builder::{ - AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom, - CreateMatcher, DenyReserveTransferToRelayChain, DenyThenTry, EnsureXcmOrigin, FixedRateOfFungible, - FixedWeightBounds, FungibleAdapter, FungiblesAdapter, IsConcrete, MatchXcm, MatchedConvertedConcreteId, - MintLocation, NoChecking, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, + AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses, AllowSubscriptionsFrom, + AllowTopLevelPaidExecutionFrom, CreateMatcher, DenyReserveTransferToRelayChain, DenyThenTry, EnsureXcmOrigin, + FixedRateOfFungible, FixedWeightBounds, FungibleAdapter, FungiblesAdapter, IsConcrete, MatchXcm, + MatchedConvertedConcreteId, MintLocation, NoChecking, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, - TakeWeightCredit, UsingComponents, WithComputedOrigin, + TakeWeightCredit, TrailingSetTopicAsId, UsingComponents, WithComputedOrigin, }; const DOT_ASSET_ID: AssetId = Concrete(RelayLocation::get()); @@ -226,59 +226,31 @@ match_types! { MultiLocation { parents: 1, interior: X1(Parachain(_)) } }; } -use polimec_xcm_executor::polimec_traits::OnResponse; -/// Allows only messages if the generic `ResponseHandler` expects them via `expecting_response`. -pub struct AllowKnownQueryResponses(PhantomData); -impl ShouldExecute for AllowKnownQueryResponses { - fn should_execute( - origin: &MultiLocation, - instructions: &mut [Instruction], - _max_weight: Weight, - _properties: &mut Properties, - ) -> Result<(), ProcessMessageError> { - log::trace!( - target: "xcm::barriers", - "AllowKnownQueryResponses origin: {:?}, instructions: {:?}, max_weight: {:?}, properties: {:?}", - origin, instructions, _max_weight, _properties, - ); - instructions - .matcher() - .assert_remaining_insts(2)? - .match_next_inst(|inst| match inst { - QueryResponse { query_id, querier, .. } - if ResponseHandler::expecting_response(origin, *query_id, querier.as_ref()) => - Ok(()), - _ => Err(ProcessMessageError::BadFormat), - })? - .match_next_inst(|inst| match inst { - SetTopic { .. } => Ok(()), - _ => Err(ProcessMessageError::BadFormat), - })?; - Ok(()) - } -} -pub type Barrier = DenyThenTry< - DenyReserveTransferToRelayChain, - ( - TakeWeightCredit, - // Expected responses are OK. - AllowKnownQueryResponses, - // Allow XCMs with some computed origins to pass through. - WithComputedOrigin< - ( - // HRMP notifications from relay get free pass - AllowHrmpNotifications, - // If the message is one that immediately attemps to pay for execution, then allow it. - AllowTopLevelPaidExecutionFrom, - // Common Good Assets parachain, parent and its exec plurality get free execution - AllowExplicitUnpaidExecutionFrom<(CommonGoodAssetsParachain, ParentOrParentsExecutivePlurality)>, - // Subscriptions for version tracking are OK. - AllowSubscriptionsFrom, - ), - UniversalLocation, - ConstU32<8>, - >, - ), + +pub type Barrier = TrailingSetTopicAsId< + DenyThenTry< + DenyReserveTransferToRelayChain, + ( + TakeWeightCredit, + // Expected responses are OK. + AllowKnownQueryResponses, + // Allow XCMs with some computed origins to pass through. + WithComputedOrigin< + ( + // HRMP notifications from relay get free pass + AllowHrmpNotifications, + // If the message is one that immediately attemps to pay for execution, then allow it. + AllowTopLevelPaidExecutionFrom, + // Common Good Assets parachain, parent and its exec plurality get free execution + AllowExplicitUnpaidExecutionFrom<(CommonGoodAssetsParachain, ParentOrParentsExecutivePlurality)>, + // Subscriptions for version tracking are OK. + AllowSubscriptionsFrom, + ), + UniversalLocation, + ConstU32<8>, + >, + ), + >, >; /// Trusted reserve locations for reserve assets. For now we only trust the AssetHub parachain