-
Notifications
You must be signed in to change notification settings - Fork 139
[AHM] Add Asset Hub CallFilter #670
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 all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
be0b07f
[AHM] Add Asset Hub CallFilter
ggwpez b2fce79
fmt
ggwpez 34f1046
Tests
ggwpez ea6caf3
fix
ggwpez 5e8fab2
Merge branch 'dev-asset-hub-migration' into oty-ahm-ah-callfilter
ggwpez cf60609
fix
ggwpez 9aa42b7
Fix
ggwpez 1b40af6
Merge remote-tracking branch 'origin/dev-asset-hub-migration' into ot…
ggwpez e7b9498
fix merge
ggwpez 22959eb
Add Stage checks
ggwpez e3493bd
fmt
ggwpez d670ef4
Fix westend
ggwpez 3159216
fmt
ggwpez e3ef511
fix Filter
ggwpez 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
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
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,128 @@ | ||
| // Copyright (C) Parity Technologies (UK) Ltd. | ||
| // This file is part of Polkadot. | ||
|
|
||
| // Polkadot 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. | ||
|
|
||
| // Polkadot 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 Polkadot. If not, see <http://www.gnu.org/licenses/>. | ||
|
|
||
| //! Asset Hub Migration tests. | ||
|
|
||
| use crate::porting_prelude::*; | ||
|
|
||
| use asset_hub_polkadot_runtime::{ | ||
| AhMigrator, Block, BuildStorage, Runtime as T, RuntimeCall, RuntimeOrigin, System, | ||
| }; | ||
| use cumulus_primitives_core::AggregateMessageOrigin; | ||
| use frame_support::{sp_runtime::traits::Dispatchable, traits::Contains}; | ||
| use pallet_ah_migrator::*; | ||
| use polkadot_primitives::Id as ParaId; | ||
| use remote_externalities::{Builder, Mode, OfflineConfig, RemoteExternalities}; | ||
| use sp_runtime::AccountId32; | ||
|
|
||
| /// Check that the call filtering mechanism works. | ||
| #[test] | ||
| #[cfg(not(feature = "ahm-westend"))] // FIXME make work on Westend | ||
| fn call_filter_works() { | ||
| let mut t: sp_io::TestExternalities = | ||
| frame_system::GenesisConfig::<T>::default().build_storage().unwrap().into(); | ||
|
|
||
| // MQ calls are never filtered: | ||
| let mq_call = RuntimeCall::MessageQueue(pallet_message_queue::Call::<T>::reap_page { | ||
| message_origin: AggregateMessageOrigin::Here, | ||
| page_index: 0, | ||
| }); | ||
| // Balances calls are filtered during the migration: | ||
| let balances_call = RuntimeCall::Balances(pallet_balances::Call::<T>::transfer_all { | ||
| dest: AccountId32::from([0; 32]).into(), | ||
| keep_alive: false, | ||
| }); | ||
| // Indices calls are filtered during and after the migration: | ||
| let indices_call = RuntimeCall::Indices(pallet_indices::Call::<T>::claim { index: 0 }); | ||
|
|
||
| let is_allowed = |call: &RuntimeCall| Pallet::<T>::contains(call); | ||
|
|
||
| // Try the BaseCallFilter | ||
| t.execute_with(|| { | ||
| // Before the migration starts | ||
| { | ||
| AhMigrationStage::<T>::put(MigrationStage::Pending); | ||
|
|
||
| assert!(is_allowed(&mq_call)); | ||
| assert!(is_allowed(&balances_call)); | ||
| assert!(is_allowed(&indices_call)); | ||
| } | ||
|
|
||
| // During the migration | ||
| { | ||
| AhMigrationStage::<T>::put(MigrationStage::DataMigrationOngoing); | ||
|
|
||
| assert!(is_allowed(&mq_call)); | ||
| assert!(!is_allowed(&balances_call)); | ||
| assert!(!is_allowed(&indices_call)); | ||
| } | ||
|
|
||
| // After the migration | ||
| { | ||
| AhMigrationStage::<T>::put(MigrationStage::MigrationDone); | ||
|
|
||
| assert!(is_allowed(&mq_call)); | ||
| assert!(is_allowed(&balances_call)); | ||
| assert!(is_allowed(&indices_call)); | ||
| } | ||
| }); | ||
|
|
||
| // Try to actually dispatch the calls | ||
| t.execute_with(|| { | ||
| let _ = | ||
| <pallet_balances::Pallet<T> as frame_support::traits::Currency<_>>::deposit_creating( | ||
| &AccountId32::from([0; 32]), | ||
| u64::MAX.into(), | ||
| ); | ||
|
|
||
| // Before the migration starts | ||
| { | ||
| AhMigrationStage::<T>::put(MigrationStage::Pending); | ||
|
|
||
| assert!(!is_forbidden(&mq_call)); | ||
| assert!(!is_forbidden(&balances_call)); | ||
| assert!(!is_forbidden(&indices_call)); | ||
| } | ||
|
|
||
| // During the migration | ||
| { | ||
| AhMigrationStage::<T>::put(MigrationStage::DataMigrationOngoing); | ||
|
|
||
| assert!(!is_forbidden(&mq_call)); | ||
| assert!(is_forbidden(&balances_call)); | ||
| assert!(is_forbidden(&indices_call)); | ||
| } | ||
|
|
||
| // After the migration | ||
| { | ||
| AhMigrationStage::<T>::put(MigrationStage::MigrationDone); | ||
|
|
||
| assert!(!is_forbidden(&mq_call)); | ||
| assert!(!is_forbidden(&balances_call)); | ||
| assert!(!is_forbidden(&indices_call)); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| /// Whether a call is forbidden by the call filter. | ||
| fn is_forbidden(call: &RuntimeCall) -> bool { | ||
| let Err(err) = call.clone().dispatch(RuntimeOrigin::signed(AccountId32::from([0; 32]))) else { | ||
| return false; | ||
| }; | ||
|
|
||
| let filtered_err: sp_runtime::DispatchError = frame_system::Error::<T>::CallFiltered.into(); | ||
| err.error == filtered_err | ||
| } |
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
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,71 @@ | ||
| // Copyright (C) Parity Technologies (UK) Ltd. | ||
| // This file is part of Polkadot. | ||
|
|
||
| // Polkadot 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. | ||
|
|
||
| // Polkadot 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 Polkadot. If not, see <http://www.gnu.org/licenses/>. | ||
|
|
||
| //! Generic checks for Relay and AH. | ||
|
|
||
| use crate::porting_prelude::*; | ||
|
|
||
| use frame_support::{ | ||
| pallet_prelude::*, | ||
| traits::{Currency, Defensive}, | ||
| }; | ||
| use frame_system::pallet_prelude::*; | ||
| use pallet_ah_migrator::types::AhMigrationCheck; | ||
| use pallet_rc_migrator::types::{RcMigrationCheck, ToPolkadotSs58}; | ||
| use sp_runtime::{ | ||
| traits::{Dispatchable, TryConvert}, | ||
| AccountId32, | ||
| }; | ||
| use std::{collections::BTreeMap, str::FromStr}; | ||
|
|
||
| pub struct SanityChecks; | ||
|
|
||
| impl RcMigrationCheck for SanityChecks { | ||
| type RcPrePayload = (); | ||
|
|
||
| fn pre_check() -> Self::RcPrePayload { | ||
| assert!( | ||
| pallet_rc_migrator::RcMigrationStage::<RcRuntime>::get() == | ||
| pallet_rc_migrator::MigrationStage::Scheduled { block_number: 0 } | ||
| ); | ||
| } | ||
|
|
||
| fn post_check(_: Self::RcPrePayload) { | ||
| assert!( | ||
| pallet_rc_migrator::RcMigrationStage::<RcRuntime>::get() == | ||
| pallet_rc_migrator::MigrationStage::MigrationDone | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| impl AhMigrationCheck for SanityChecks { | ||
| type RcPrePayload = (); | ||
| type AhPrePayload = (); | ||
|
|
||
| fn pre_check(_: Self::RcPrePayload) -> Self::AhPrePayload { | ||
| assert!( | ||
| pallet_ah_migrator::AhMigrationStage::<AhRuntime>::get() == | ||
| pallet_ah_migrator::MigrationStage::Pending | ||
| ); | ||
| } | ||
|
|
||
| fn post_check(rc_pre_payload: Self::RcPrePayload, _: Self::AhPrePayload) { | ||
| assert!( | ||
| pallet_ah_migrator::AhMigrationStage::<AhRuntime>::get() == | ||
| pallet_ah_migrator::MigrationStage::MigrationDone | ||
| ); | ||
| } | ||
| } |
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
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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@muharem i disabled this by default since it ran very slowly for me.