From 48169228cfd9126e1f8e3191cb5f7c9658c2ed9f Mon Sep 17 00:00:00 2001 From: hqwangningbo <2536935847@qq.com> Date: Mon, 4 Dec 2023 10:24:45 +0800 Subject: [PATCH] Fix bifrost-polkadot barrier --- runtime/bifrost-polkadot/src/lib.rs | 2 +- runtime/bifrost-polkadot/src/xcm_config.rs | 29 ++++++++++++++++++++-- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/runtime/bifrost-polkadot/src/lib.rs b/runtime/bifrost-polkadot/src/lib.rs index f96a1e433..fff38616f 100644 --- a/runtime/bifrost-polkadot/src/lib.rs +++ b/runtime/bifrost-polkadot/src/lib.rs @@ -130,7 +130,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("bifrost_polkadot"), impl_name: create_runtime_str!("bifrost_polkadot"), authoring_version: 0, - spec_version: 987, + spec_version: 988, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 1, diff --git a/runtime/bifrost-polkadot/src/xcm_config.rs b/runtime/bifrost-polkadot/src/xcm_config.rs index 809744930..7f59128bf 100644 --- a/runtime/bifrost-polkadot/src/xcm_config.rs +++ b/runtime/bifrost-polkadot/src/xcm_config.rs @@ -306,7 +306,32 @@ impl> ShouldExecute for AllowTopLevelPaidExecutionDes } } -pub type Barrier = ( +/// Sets the message ID to `t` using a `SetTopic(t)` in the last position if present. +/// +/// Requires some inner barrier to pass on the rest of the message. +pub struct TrailingSetTopicAsId(PhantomData); +impl ShouldExecute for TrailingSetTopicAsId { + fn should_execute( + origin: &MultiLocation, + instructions: &mut [Instruction], + max_weight: Weight, + weight_credit: &mut Weight, + ) -> Result<(), ProcessMessageError> { + log::trace!( + target: "xcm::barriers", + "TrailingSetTopicAsId origin: {:?}, instructions: {:?}, max_weight: {:?}", + origin, instructions, max_weight, + ); + let until = if let Some(SetTopic(_)) = instructions.last() { + instructions.len() - 1 + } else { + instructions.len() + }; + InnerBarrier::should_execute(&origin, &mut instructions[..until], max_weight, weight_credit) + } +} + +pub type Barrier = TrailingSetTopicAsId<( // Weight that is paid for may be consumed. TakeWeightCredit, // Expected responses are OK. @@ -317,7 +342,7 @@ pub type Barrier = ( AllowSubscriptionsFrom, // Barrier allowing a top level paid message with DescendOrigin instruction AllowTopLevelPaidExecutionDescendOriginFirst, -); +)>; pub type BifrostAssetTransactor = MultiCurrencyAdapter< Currencies,