This repository was archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 370
Support overweight messages in XCMP queue #799
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
5168cf5
Support overweight messages in XCMP queue
KiChjang b4fd7d7
Add storage migration logic to XCMP queue pallet
KiChjang b38016c
Check whether required weight is larger than max individual weight first
KiChjang c723fc3
cargo fmt
KiChjang 1538a5b
Add some unit tests
KiChjang cf4d4ca
Merge branch 'master' into kckyeung/xcmp-overweight
KiChjang 40c33b7
Remove review question comment
KiChjang 6d72b3b
Update pallets/xcmp-queue/src/lib.rs
gavofyork 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 2021 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/>. | ||
|
|
||
| //! A module that is responsible for migration of storage. | ||
|
|
||
| use crate::{Config, Pallet, Store}; | ||
| use frame_support::{pallet_prelude::*, traits::StorageVersion, weights::Weight}; | ||
|
|
||
| /// The current storage version. | ||
| pub const STORAGE_VERSION: StorageVersion = StorageVersion::new(1); | ||
|
|
||
| /// Migrates the pallet storage to the most recent version, checking and setting the | ||
| /// `StorageVersion`. | ||
| pub fn migrate_to_latest<T: Config>() -> Weight { | ||
| let mut weight = 0; | ||
|
|
||
| if StorageVersion::get::<Pallet<T>>() == 0 { | ||
| weight += migrate_to_v1::<T>(); | ||
| StorageVersion::new(1).put::<Pallet<T>>(); | ||
| } | ||
|
|
||
| weight | ||
| } | ||
|
|
||
| mod v0 { | ||
| use super::*; | ||
| use codec::{Decode, Encode}; | ||
|
|
||
| #[derive(Encode, Decode, Debug)] | ||
| pub struct QueueConfigData { | ||
| pub suspend_threshold: u32, | ||
| pub drop_threshold: u32, | ||
| pub resume_threshold: u32, | ||
| pub threshold_weight: Weight, | ||
| pub weight_restrict_decay: Weight, | ||
| } | ||
|
|
||
| impl Default for QueueConfigData { | ||
| fn default() -> Self { | ||
| QueueConfigData { | ||
| suspend_threshold: 2, | ||
| drop_threshold: 5, | ||
| resume_threshold: 1, | ||
| threshold_weight: 100_000, | ||
| weight_restrict_decay: 2, | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// Migrates `QueueConfigData` from v0 (without the `xcmp_max_individual_weight` field) to v1 (with | ||
| /// max individual weight). | ||
| /// Uses the `Default` implementation of `QueueConfigData` to choose a value for | ||
| /// `xcmp_max_individual_weight`. | ||
| /// | ||
| /// NOTE: Only use this function if you know what you're doing. Default to using | ||
| /// `migrate_to_latest`. | ||
| pub fn migrate_to_v1<T: Config>() -> Weight { | ||
| let translate = |pre: v0::QueueConfigData| -> super::QueueConfigData { | ||
| super::QueueConfigData { | ||
| suspend_threshold: pre.suspend_threshold, | ||
| drop_threshold: pre.drop_threshold, | ||
| resume_threshold: pre.resume_threshold, | ||
| threshold_weight: pre.threshold_weight, | ||
| weight_restrict_decay: pre.weight_restrict_decay, | ||
| xcmp_max_individual_weight: super::QueueConfigData::default() | ||
| .xcmp_max_individual_weight, | ||
| } | ||
| }; | ||
|
Comment on lines
+71
to
+82
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it make sense to parameterize the migration function to take a
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added an issue: #801 |
||
|
|
||
| if let Err(_) = <Pallet<T> as Store>::QueueConfig::translate(|pre| pre.map(translate)) { | ||
| log::error!( | ||
| target: super::LOG_TARGET, | ||
| "unexpected error when performing translation of the QueueConfig type during storage upgrade to v1" | ||
| ); | ||
| } | ||
|
|
||
| T::DbWeight::get().reads_writes(1, 1) | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
| use crate::mock::{new_test_ext, Test}; | ||
|
|
||
| #[test] | ||
| fn test_migration_to_v1() { | ||
| let v0 = v0::QueueConfigData { | ||
| suspend_threshold: 5, | ||
| drop_threshold: 12, | ||
| resume_threshold: 3, | ||
| threshold_weight: 333_333, | ||
| weight_restrict_decay: 1, | ||
| }; | ||
|
|
||
| new_test_ext().execute_with(|| { | ||
| // Put the v0 version in the state | ||
| frame_support::storage::unhashed::put_raw( | ||
| &crate::QueueConfig::<Test>::hashed_key(), | ||
| &v0.encode(), | ||
| ); | ||
|
|
||
| migrate_to_v1::<Test>(); | ||
|
|
||
| let v1 = crate::QueueConfig::<Test>::get(); | ||
|
|
||
| assert_eq!(v0.suspend_threshold, v1.suspend_threshold); | ||
| assert_eq!(v0.drop_threshold, v1.drop_threshold); | ||
| assert_eq!(v0.resume_threshold, v1.resume_threshold); | ||
| assert_eq!(v0.threshold_weight, v1.threshold_weight); | ||
| assert_eq!(v0.weight_restrict_decay, v1.weight_restrict_decay); | ||
| assert_eq!(v1.xcmp_max_individual_weight, 20_000_000_000); | ||
| }); | ||
| } | ||
| } | ||
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.