From 623435424a54e2bbfa7a7ac7b7d596aa5a504357 Mon Sep 17 00:00:00 2001 From: MrPai <1164934857@qq.com> Date: Tue, 14 Nov 2023 09:32:19 +0800 Subject: [PATCH] Fix: xcm notification error (#1950) --- Cargo.lock | 2 ++ runtime/common/Cargo.toml | 2 ++ runtime/common/src/lib.rs | 37 +++++++++++++++++++++++++++++++++++++ runtime/heiko/src/lib.rs | 12 ++++++------ runtime/kerria/src/lib.rs | 12 ++++++------ runtime/parallel/src/lib.rs | 12 ++++++------ runtime/vanilla/src/lib.rs | 12 ++++++------ 7 files changed, 65 insertions(+), 24 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ac4969b9e..b63d754b0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10525,6 +10525,8 @@ dependencies = [ "sp-core", "sp-runtime", "sp-std", + "xcm", + "xcm-executor", ] [[package]] diff --git a/runtime/common/Cargo.toml b/runtime/common/Cargo.toml index a134afd37..e59845333 100644 --- a/runtime/common/Cargo.toml +++ b/runtime/common/Cargo.toml @@ -26,6 +26,8 @@ pallet-timestamp = { workspace = true } # Polkadot dependencies polkadot-runtime-common = { workspace = true } +xcm = { workspace = true } +xcm-executor = { workspace = true } # Frontier dependencies fp-rpc = { workspace = true } diff --git a/runtime/common/src/lib.rs b/runtime/common/src/lib.rs index 6c0057417..f0d917e4c 100644 --- a/runtime/common/src/lib.rs +++ b/runtime/common/src/lib.rs @@ -8,3 +8,40 @@ pub use fp_rpc; pub use fp_self_contained; pub use pallet_evm_precompile_assets_erc20::AddressToAssetId; pub use pallet_evm_precompile_balances_erc20::Erc20Metadata; + +use frame_support::log; +use sp_std::{marker::PhantomData, result::Result}; +use xcm::latest::{ + Instruction::{self, *}, + MultiLocation, Weight, +}; +use xcm_executor::traits::{OnResponse, ShouldExecute}; + +/// TODO: Belowing code can be removed once upgrade to polkadot-v1.0.0 +/// Copy from polkadot-v0.9.38 +/// Polakdot-v1.0.0 have made changes of ShouldExecute +pub struct AllowKnownQueryResponses(PhantomData); +impl ShouldExecute for AllowKnownQueryResponses { + fn should_execute( + origin: &MultiLocation, + instructions: &mut [Instruction], + _max_weight: Weight, + _weight_credit: &mut Weight, + ) -> Result<(), ()> { + log::trace!( + target: "xcm::barriers", + "Parallel AllowKnownQueryResponses origin: {:?}, instructions: {:?}, max_weight: {:?}, weight_credit: {:?}", + origin, instructions, _max_weight, _weight_credit, + ); + // ignore other instructions + // ensure!(instructions.len() == 1, ()); + match instructions.first() { + Some(QueryResponse { + query_id, querier, .. + }) if ResponseHandler::expecting_response(origin, *query_id, querier.as_ref()) => { + Ok(()) + } + _ => Err(()), + } + } +} diff --git a/runtime/heiko/src/lib.rs b/runtime/heiko/src/lib.rs index fe9bcbad0..332290e6b 100644 --- a/runtime/heiko/src/lib.rs +++ b/runtime/heiko/src/lib.rs @@ -71,11 +71,11 @@ use sp_version::NativeVersion; use sp_version::RuntimeVersion; use xcm::latest::prelude::*; use xcm_builder::{ - AccountId32Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom, - AllowTopLevelPaidExecutionFrom, ConvertedConcreteId, EnsureXcmOrigin, FixedWeightBounds, - FungiblesAdapter, NoChecking, ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, - SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative, - SignedToAccountId32, SovereignSignedViaLocation, TakeRevenue, TakeWeightCredit, + AccountId32Aliases, AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom, + ConvertedConcreteId, EnsureXcmOrigin, FixedWeightBounds, FungiblesAdapter, NoChecking, + ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, + SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32, + SovereignSignedViaLocation, TakeRevenue, TakeWeightCredit, }; use xcm_executor::{traits::JustTry, Config, XcmExecutor}; @@ -116,7 +116,7 @@ use runtime_common::{ constants::{currency, fee, time}, fp_rpc, fp_self_contained, precompiles::{ParallelPrecompiles, ASSET_PRECOMPILE_ADDRESS_PREFIX}, - AddressToAssetId, Erc20Metadata, + AddressToAssetId, AllowKnownQueryResponses, Erc20Metadata, }; use currency::*; diff --git a/runtime/kerria/src/lib.rs b/runtime/kerria/src/lib.rs index b0f7fb599..2d44a6dc8 100644 --- a/runtime/kerria/src/lib.rs +++ b/runtime/kerria/src/lib.rs @@ -73,11 +73,11 @@ use sp_version::NativeVersion; use sp_version::RuntimeVersion; use xcm::latest::prelude::*; use xcm_builder::{ - AccountId32Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom, - AllowTopLevelPaidExecutionFrom, ConvertedConcreteId, EnsureXcmOrigin, FixedWeightBounds, - FungiblesAdapter, NoChecking, ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, - SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative, - SignedToAccountId32, SovereignSignedViaLocation, TakeRevenue, TakeWeightCredit, + AccountId32Aliases, AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom, + ConvertedConcreteId, EnsureXcmOrigin, FixedWeightBounds, FungiblesAdapter, NoChecking, + ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, + SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32, + SovereignSignedViaLocation, TakeRevenue, TakeWeightCredit, }; use xcm_executor::{traits::JustTry, Config, XcmExecutor}; @@ -116,7 +116,7 @@ use runtime_common::{ constants::{currency, fee, time}, fp_rpc, fp_self_contained, precompiles::{ParallelPrecompiles, ASSET_PRECOMPILE_ADDRESS_PREFIX}, - AddressToAssetId, Erc20Metadata, + AddressToAssetId, AllowKnownQueryResponses, Erc20Metadata, }; use currency::*; diff --git a/runtime/parallel/src/lib.rs b/runtime/parallel/src/lib.rs index e6ee35646..c56638add 100644 --- a/runtime/parallel/src/lib.rs +++ b/runtime/parallel/src/lib.rs @@ -74,11 +74,11 @@ use sp_version::NativeVersion; use sp_version::RuntimeVersion; use xcm::latest::prelude::*; use xcm_builder::{ - AccountId32Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom, - AllowTopLevelPaidExecutionFrom, ConvertedConcreteId, EnsureXcmOrigin, FixedWeightBounds, - FungiblesAdapter, NoChecking, ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, - SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative, - SignedToAccountId32, SovereignSignedViaLocation, TakeRevenue, TakeWeightCredit, + AccountId32Aliases, AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom, + ConvertedConcreteId, EnsureXcmOrigin, FixedWeightBounds, FungiblesAdapter, NoChecking, + ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, + SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32, + SovereignSignedViaLocation, TakeRevenue, TakeWeightCredit, }; use xcm_executor::{traits::JustTry, Config, XcmExecutor}; @@ -116,7 +116,7 @@ use runtime_common::{ constants::{currency, fee, time}, fp_rpc, fp_self_contained, precompiles::{ParallelPrecompiles, ASSET_PRECOMPILE_ADDRESS_PREFIX}, - AddressToAssetId, Erc20Metadata, + AddressToAssetId, AllowKnownQueryResponses, Erc20Metadata, }; use currency::*; diff --git a/runtime/vanilla/src/lib.rs b/runtime/vanilla/src/lib.rs index 0d234fe5a..8600cf054 100644 --- a/runtime/vanilla/src/lib.rs +++ b/runtime/vanilla/src/lib.rs @@ -69,11 +69,11 @@ use sp_version::NativeVersion; use sp_version::RuntimeVersion; use xcm::latest::prelude::*; use xcm_builder::{ - AccountId32Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom, - AllowTopLevelPaidExecutionFrom, ConvertedConcreteId, EnsureXcmOrigin, FixedWeightBounds, - FungiblesAdapter, NoChecking, ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, - SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative, - SignedToAccountId32, SovereignSignedViaLocation, TakeRevenue, TakeWeightCredit, + AccountId32Aliases, AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom, + ConvertedConcreteId, EnsureXcmOrigin, FixedWeightBounds, FungiblesAdapter, NoChecking, + ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, + SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32, + SovereignSignedViaLocation, TakeRevenue, TakeWeightCredit, }; use xcm_executor::{traits::JustTry, Config, XcmExecutor}; @@ -116,7 +116,7 @@ use runtime_common::{ constants::{currency, fee, time}, fp_rpc, fp_self_contained, precompiles::{ParallelPrecompiles, ASSET_PRECOMPILE_ADDRESS_PREFIX}, - AddressToAssetId, Erc20Metadata, + AddressToAssetId, AllowKnownQueryResponses, Erc20Metadata, }; use currency::*;