-
Notifications
You must be signed in to change notification settings - Fork 1.2k
xcm: fix for DenyThenTry Barrier #7169
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
Merged
Merged
Changes from 26 commits
Commits
Show all changes
52 commits
Select commit
Hold shift + click to select a range
faa431a
Fix for DenyThenTry
yrong d0748cf
Apply suggestions from code review
bkontur bf669bb
Rename to DenyExportMessageFrom with comments
yrong 716ccdc
Move DenyExportMessageFrom to bridge-hub-common
yrong 17c9b14
Merge branch 'fix-for-deny-then-try' of https://github.com/yrong/polk…
yrong e10587b
Update comments
yrong d83dadb
Add the prdoc
yrong 0b4c955
Merge branch 'master' into fix-for-deny-then-try
yrong ac810f7
Refactor DenyExecution to be more explicit
yrong 8f0af5b
Update prdoc/pr_7169.prdoc
yrong 67e7991
Merge branch 'master' into fix-for-deny-then-try
yrong ee8de3e
Merge branch 'master' into fix-for-deny-then-try
yrong 2b496e5
Update polkadot/xcm/xcm-executor/src/traits/should_execute.rs
bkontur 81ec7f1
Update polkadot/xcm/xcm-executor/src/traits/should_execute.rs
bkontur 17c4972
Improve tests
yrong 58d7990
Test for DenyReserveTransferToRelayChain
yrong 2258ab1
Merge branch 'fix-for-deny-then-try' of https://github.com/yrong/polk…
yrong dbfe244
Merge branch 'master' into fix-for-deny-then-try
yrong 462c049
Apply suggestions from code review
bkontur 6e578bf
Update polkadot/xcm/xcm-builder/src/tests/barriers.rs
bkontur e4acb39
Update from bkontur running command 'fmt'
8b94963
Move dummy impls to tests
yrong b2f7338
More tests
yrong a8a7ea3
Merge branch 'fix-for-deny-then-try' of https://github.com/yrong/polk…
yrong a78449e
Fix comments
yrong ddba5dc
Apply suggestions from code review
bkontur 66814c9
Update polkadot/xcm/xcm-executor/src/traits/should_execute.rs
bkontur 02912a6
Update cumulus/parachains/runtimes/bridge-hubs/common/tests/tests.rs
bkontur 5d3a5e7
Merge branch 'master' into fix-for-deny-then-try
bkontur 85b06c2
Add comments
yrong dfbafc5
Merge branch 'master' into fix-for-deny-then-try
yrong a842c4d
Fix clippy
yrong c7cd51d
Merge branch 'fix-for-deny-then-try' of https://github.com/yrong/polk…
yrong 551afc1
Update polkadot/xcm/xcm-executor/src/traits/should_execute.rs
yrong cd33044
Update polkadot/xcm/xcm-executor/src/traits/should_execute.rs
yrong 639177b
Update polkadot/xcm/xcm-executor/src/traits/should_execute.rs
yrong 7564e23
Update cumulus/parachains/runtimes/bridge-hubs/common/src/barriers.rs
yrong d9c2f0e
Update cumulus/parachains/runtimes/bridge-hubs/common/src/barriers.rs
yrong a04aae2
Merge branch 'fix-for-deny-then-try' of https://github.com/yrong/polk…
yrong c038e86
Merge branch 'master' into fix-for-deny-then-try
yrong 234a5e7
Merge branch 'master' into fix-for-deny-then-try
franciscoaguirre b39f07e
Update polkadot/xcm/xcm-builder/src/tests/barriers.rs
yrong 110d42e
Update polkadot/xcm/xcm-builder/src/tests/barriers.rs
yrong 8699575
Update cumulus/parachains/runtimes/bridge-hubs/common/src/barriers.rs
yrong 3cd6bf5
Merge branch 'master' into fix-for-deny-then-try
yrong 6b65c81
Change return to Result<(), ProcessMessageError>
yrong 03ff441
Fix tests
yrong 8d61bfb
Merge branch 'master' into fix-for-deny-then-try
yrong c2719f9
Update polkadot/xcm/xcm-executor/src/traits/should_execute.rs
bkontur 83835fc
Merge branch 'master' into fix-for-deny-then-try
bkontur 54dadec
Update polkadot/xcm/xcm-executor/src/traits/should_execute.rs
acatangiu 90153db
Merge branch 'master' into fix-for-deny-then-try
acatangiu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
cumulus/parachains/runtimes/bridge-hubs/common/src/barriers.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| // Copyright (C) Parity Technologies (UK) Ltd. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| use core::{marker::PhantomData, ops::ControlFlow}; | ||
| use cumulus_primitives_core::Weight; | ||
| use frame_support::traits::{Contains, ProcessMessageError}; | ||
| use xcm::prelude::{ExportMessage, Instruction, Location, NetworkId}; | ||
|
|
||
| use xcm_builder::{CreateMatcher, MatchXcm}; | ||
| use xcm_executor::traits::{DenyExecution, Properties}; | ||
|
|
||
| /// Deny execution if the message contains instruction `ExportMessage` with | ||
| /// a. origin is contained in `FromOrigin` (i.e.`FromOrigin::Contains(origin)`) | ||
| /// b. network is contained in `ToGlobalConsensus`, (i.e. `ToGlobalConsensus::contains(network)`) | ||
| pub struct DenyExportMessageFrom<FromOrigin, ToGlobalConsensus>( | ||
| PhantomData<(FromOrigin, ToGlobalConsensus)>, | ||
| ); | ||
|
|
||
| impl<FromOrigin, ToGlobalConsensus> DenyExecution | ||
| for DenyExportMessageFrom<FromOrigin, ToGlobalConsensus> | ||
| where | ||
| FromOrigin: Contains<Location>, | ||
| ToGlobalConsensus: Contains<NetworkId>, | ||
| { | ||
| fn deny_execution<RuntimeCall>( | ||
| origin: &Location, | ||
| message: &mut [Instruction<RuntimeCall>], | ||
| _max_weight: Weight, | ||
| _properties: &mut Properties, | ||
| ) -> Option<ProcessMessageError> { | ||
| match message.matcher().match_next_inst_while( | ||
| |_| true, | ||
| |inst| match inst { | ||
| ExportMessage { network, .. } => | ||
| if ToGlobalConsensus::contains(network) && FromOrigin::contains(origin) { | ||
| return Err(ProcessMessageError::Unsupported) | ||
| } else { | ||
| Ok(ControlFlow::Continue(())) | ||
| }, | ||
yrong marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| _ => Ok(ControlFlow::Continue(())), | ||
| }, | ||
| ) { | ||
| Ok(_) => None, | ||
| Err(error) => Some(error), | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
cumulus/parachains/runtimes/bridge-hubs/common/tests/tests.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| // Copyright (C) Parity Technologies (UK) Ltd. | ||
| // This file is part of Cumulus. | ||
|
|
||
| // Cumulus is free software: you can redistribute it and/or modify | ||
| // it under the terms of the GNU General Public License as published by | ||
| // the Free Software Foundation, either version 3 of the License, or | ||
| // (at your option) any later version. | ||
|
|
||
| // Cumulus is distributed in the hope that it will be useful, | ||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| // GNU General Public License for more details. | ||
|
|
||
| // You should have received a copy of the GNU General Public License | ||
| // along with Cumulus. If not, see <http://www.gnu.org/licenses/>. | ||
|
|
||
| #![cfg(test)] | ||
| use bridge_hub_common::DenyExportMessageFrom; | ||
| use frame_support::{ | ||
| parameter_types, | ||
| traits::{Equals, EverythingBut, ProcessMessageError::Unsupported}, | ||
| }; | ||
| use xcm::prelude::{ | ||
| AliasOrigin, ByGenesis, ExportMessage, Here, Instruction, Location, NetworkId, Parachain, | ||
| Weight, | ||
| }; | ||
| use xcm_executor::traits::{DenyExecution, Properties}; | ||
|
|
||
| #[test] | ||
| fn test_deny_export_message_from() { | ||
| parameter_types! { | ||
| pub Source1: Location = Location::new(1, Parachain(1)); | ||
| pub Source2: Location = Location::new(1, Parachain(2)); | ||
| pub Remote1: NetworkId = ByGenesis([1;32]); | ||
| pub Remote2: NetworkId = ByGenesis([2;32]); | ||
| } | ||
|
|
||
| pub type Denied = DenyExportMessageFrom<EverythingBut<Equals<Source1>>, Equals<Remote1>>; | ||
bkontur marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| let assert_deny_execution = |mut xcm: Vec<Instruction<()>>, origin, expected_result| { | ||
| assert_eq!( | ||
| Denied::deny_execution( | ||
| &origin, | ||
| &mut xcm, | ||
| Weight::zero(), | ||
| &mut Properties { weight_credit: Weight::zero(), message_id: None } | ||
| ), | ||
| expected_result | ||
| ); | ||
| }; | ||
|
|
||
| // No `ExportMessage` should pass | ||
bkontur marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| assert_deny_execution(vec![AliasOrigin(Here.into())], Source1::get(), None); | ||
|
|
||
| // `ExportMessage` from source1 and remote1 should pass | ||
acatangiu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| assert_deny_execution( | ||
| vec![ExportMessage { network: Remote1::get(), destination: Here, xcm: Default::default() }], | ||
| Source1::get(), | ||
| None, | ||
| ); | ||
|
|
||
| // `ExportMessage` from source1 and remote2 should pass | ||
| assert_deny_execution( | ||
| vec![ExportMessage { network: Remote2::get(), destination: Here, xcm: Default::default() }], | ||
| Source1::get(), | ||
| None, | ||
| ); | ||
|
|
||
| // `ExportMessage` from source2 and remote2 should pass | ||
| assert_deny_execution( | ||
| vec![ExportMessage { network: Remote2::get(), destination: Here, xcm: Default::default() }], | ||
| Source2::get(), | ||
| None, | ||
| ); | ||
|
|
||
| // `ExportMessage` from source2 and remote1 should be banned | ||
| assert_deny_execution( | ||
| vec![ExportMessage { network: Remote1::get(), destination: Here, xcm: Default::default() }], | ||
| Source2::get(), | ||
| Some(Unsupported), | ||
| ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.