mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 05:51:02 +00:00
Fix a few migration issues with 2D weights (#1755)
* Give a max proof size to DMP individual weight processing during migration * Fix a few migration issues with 2D weights * Update substrate * Fixes * cargo fmt * Re-add v1 migration * Set DEFAULT_POV_SIZE to 64 KB * Use Weight::from_parts * Update Polkadot * Fixes
This commit is contained in:
Generated
+355
-355
File diff suppressed because it is too large
Load Diff
@@ -38,6 +38,8 @@ use xcm::{
|
|||||||
VersionedXcm, MAX_XCM_DECODE_DEPTH,
|
VersionedXcm, MAX_XCM_DECODE_DEPTH,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const DEFAULT_POV_SIZE: u64 = 64 * 1024; // 64 KB
|
||||||
|
|
||||||
#[derive(Copy, Clone, Eq, PartialEq, Encode, Decode, RuntimeDebug, TypeInfo)]
|
#[derive(Copy, Clone, Eq, PartialEq, Encode, Decode, RuntimeDebug, TypeInfo)]
|
||||||
pub struct ConfigData {
|
pub struct ConfigData {
|
||||||
/// The maximum amount of weight any individual message may consume. Messages above this weight
|
/// The maximum amount of weight any individual message may consume. Messages above this weight
|
||||||
@@ -49,7 +51,10 @@ pub struct ConfigData {
|
|||||||
impl Default for ConfigData {
|
impl Default for ConfigData {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
max_individual: 10u64 * WEIGHT_PER_MILLIS, // 10 ms of execution time maximum by default
|
max_individual: Weight::from_parts(
|
||||||
|
10u64 * WEIGHT_PER_MILLIS.ref_time(), // 10 ms of execution time maximum by default
|
||||||
|
DEFAULT_POV_SIZE, // 64 KB of proof size by default
|
||||||
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
//! A module that is responsible for migration of storage.
|
//! A module that is responsible for migration of storage.
|
||||||
|
|
||||||
use crate::{Config, Pallet, Store};
|
use crate::{Config, Pallet, Store, DEFAULT_POV_SIZE};
|
||||||
use frame_support::{
|
use frame_support::{
|
||||||
pallet_prelude::*,
|
pallet_prelude::*,
|
||||||
traits::StorageVersion,
|
traits::StorageVersion,
|
||||||
@@ -63,7 +63,9 @@ mod v0 {
|
|||||||
/// `migrate_to_latest`.
|
/// `migrate_to_latest`.
|
||||||
pub fn migrate_to_v1<T: Config>() -> Weight {
|
pub fn migrate_to_v1<T: Config>() -> Weight {
|
||||||
let translate = |pre: v0::ConfigData| -> super::ConfigData {
|
let translate = |pre: v0::ConfigData| -> super::ConfigData {
|
||||||
super::ConfigData { max_individual: Weight::from_ref_time(pre.max_individual) }
|
super::ConfigData {
|
||||||
|
max_individual: Weight::from_parts(pre.max_individual, DEFAULT_POV_SIZE),
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Err(_) = <Pallet<T> as Store>::Configuration::translate(|pre| pre.map(translate)) {
|
if let Err(_) = <Pallet<T> as Store>::Configuration::translate(|pre| pre.map(translate)) {
|
||||||
@@ -96,6 +98,7 @@ mod tests {
|
|||||||
let v1 = crate::Configuration::<Test>::get();
|
let v1 = crate::Configuration::<Test>::get();
|
||||||
|
|
||||||
assert_eq!(v0.max_individual, v1.max_individual.ref_time());
|
assert_eq!(v0.max_individual, v1.max_individual.ref_time());
|
||||||
|
assert_eq!(v1.max_individual.proof_size(), DEFAULT_POV_SIZE);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -141,6 +141,7 @@ pub mod pallet {
|
|||||||
|
|
||||||
#[pallet::pallet]
|
#[pallet::pallet]
|
||||||
#[pallet::storage_version(migration::STORAGE_VERSION)]
|
#[pallet::storage_version(migration::STORAGE_VERSION)]
|
||||||
|
#[pallet::generate_store(pub(super) trait Store)]
|
||||||
#[pallet::without_storage_info]
|
#[pallet::without_storage_info]
|
||||||
pub struct Pallet<T>(_);
|
pub struct Pallet<T>(_);
|
||||||
|
|
||||||
|
|||||||
@@ -14,18 +14,18 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>.
|
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use crate::{Config, Pallet};
|
use crate::{Config, Pallet, Store};
|
||||||
use frame_support::{
|
use frame_support::{
|
||||||
traits::{Get, StorageVersion},
|
traits::{Get, StorageVersion},
|
||||||
weights::Weight,
|
weights::Weight,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// The current storage version.
|
/// The current storage version.
|
||||||
pub const STORAGE_VERSION: StorageVersion = StorageVersion::new(1);
|
pub const STORAGE_VERSION: StorageVersion = StorageVersion::new(2);
|
||||||
|
|
||||||
/// Call this during the next runtime upgrade for this module.
|
/// Call this during the next runtime upgrade for this module.
|
||||||
pub fn on_runtime_upgrade<T: Config>() -> Weight {
|
pub fn on_runtime_upgrade<T: Config>() -> Weight {
|
||||||
let mut weight: Weight = Weight::zero();
|
let mut weight: Weight = T::DbWeight::get().reads(2);
|
||||||
|
|
||||||
if StorageVersion::get::<Pallet<T>>() == 0 {
|
if StorageVersion::get::<Pallet<T>>() == 0 {
|
||||||
weight = weight
|
weight = weight
|
||||||
@@ -34,9 +34,46 @@ pub fn on_runtime_upgrade<T: Config>() -> Weight {
|
|||||||
StorageVersion::new(1).put::<Pallet<T>>();
|
StorageVersion::new(1).put::<Pallet<T>>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if StorageVersion::get::<Pallet<T>>() == 1 {
|
||||||
|
weight = weight
|
||||||
|
.saturating_add(v2::migrate::<T>())
|
||||||
|
.saturating_add(T::DbWeight::get().writes(1));
|
||||||
|
STORAGE_VERSION.put::<Pallet<T>>();
|
||||||
|
}
|
||||||
|
|
||||||
weight
|
weight
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// V2: Migrate to 2D weights for ReservedXcmpWeightOverride and ReservedDmpWeightOverride.
|
||||||
|
mod v2 {
|
||||||
|
use super::*;
|
||||||
|
const DEFAULT_POV_SIZE: u64 = 64 * 1024; // 64 KB
|
||||||
|
|
||||||
|
pub fn migrate<T: Config>() -> Weight {
|
||||||
|
let translate = |pre: u64| -> Weight { Weight::from_parts(pre, DEFAULT_POV_SIZE) };
|
||||||
|
|
||||||
|
if <Pallet<T> as Store>::ReservedXcmpWeightOverride::translate(|pre| pre.map(translate))
|
||||||
|
.is_err()
|
||||||
|
{
|
||||||
|
log::error!(
|
||||||
|
target: "parachain_system",
|
||||||
|
"unexpected error when performing translation of the ReservedXcmpWeightOverride type during storage upgrade to v2"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if <Pallet<T> as Store>::ReservedDmpWeightOverride::translate(|pre| pre.map(translate))
|
||||||
|
.is_err()
|
||||||
|
{
|
||||||
|
log::error!(
|
||||||
|
target: "parachain_system",
|
||||||
|
"unexpected error when performing translation of the ReservedDmpWeightOverride type during storage upgrade to v2"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
T::DbWeight::get().reads_writes(2, 2)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// V1: `LastUpgrade` block number is removed from the storage since the upgrade
|
/// V1: `LastUpgrade` block number is removed from the storage since the upgrade
|
||||||
/// mechanism now uses signals instead of block offsets.
|
/// mechanism now uses signals instead of block offsets.
|
||||||
mod v1 {
|
mod v1 {
|
||||||
|
|||||||
@@ -66,6 +66,7 @@ pub use pallet::*;
|
|||||||
pub type OverweightIndex = u64;
|
pub type OverweightIndex = u64;
|
||||||
|
|
||||||
const LOG_TARGET: &str = "xcmp_queue";
|
const LOG_TARGET: &str = "xcmp_queue";
|
||||||
|
const DEFAULT_POV_SIZE: u64 = 64 * 1024; // 64 KB
|
||||||
|
|
||||||
#[frame_support::pallet]
|
#[frame_support::pallet]
|
||||||
pub mod pallet {
|
pub mod pallet {
|
||||||
@@ -462,7 +463,10 @@ impl Default for QueueConfigData {
|
|||||||
resume_threshold: 1,
|
resume_threshold: 1,
|
||||||
threshold_weight: Weight::from_ref_time(100_000),
|
threshold_weight: Weight::from_ref_time(100_000),
|
||||||
weight_restrict_decay: Weight::from_ref_time(2),
|
weight_restrict_decay: Weight::from_ref_time(2),
|
||||||
xcmp_max_individual_weight: 20u64 * WEIGHT_PER_MILLIS,
|
xcmp_max_individual_weight: Weight::from_parts(
|
||||||
|
20u64 * WEIGHT_PER_MILLIS.ref_time(),
|
||||||
|
DEFAULT_POV_SIZE,
|
||||||
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
//! A module that is responsible for migration of storage.
|
//! A module that is responsible for migration of storage.
|
||||||
|
|
||||||
use crate::{Config, Pallet, Store};
|
use crate::{Config, Pallet, Store, DEFAULT_POV_SIZE};
|
||||||
use frame_support::{
|
use frame_support::{
|
||||||
pallet_prelude::*,
|
pallet_prelude::*,
|
||||||
traits::StorageVersion,
|
traits::StorageVersion,
|
||||||
@@ -81,7 +81,10 @@ pub fn migrate_to_v2<T: Config>() -> Weight {
|
|||||||
resume_threshold: pre.resume_threshold,
|
resume_threshold: pre.resume_threshold,
|
||||||
threshold_weight: Weight::from_ref_time(pre.threshold_weight),
|
threshold_weight: Weight::from_ref_time(pre.threshold_weight),
|
||||||
weight_restrict_decay: Weight::from_ref_time(pre.weight_restrict_decay),
|
weight_restrict_decay: Weight::from_ref_time(pre.weight_restrict_decay),
|
||||||
xcmp_max_individual_weight: Weight::from_ref_time(pre.xcmp_max_individual_weight),
|
xcmp_max_individual_weight: Weight::from_parts(
|
||||||
|
pre.xcmp_max_individual_weight,
|
||||||
|
DEFAULT_POV_SIZE,
|
||||||
|
),
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -218,7 +218,10 @@ fn update_weight_restrict_decay_works() {
|
|||||||
fn update_xcmp_max_individual_weight() {
|
fn update_xcmp_max_individual_weight() {
|
||||||
new_test_ext().execute_with(|| {
|
new_test_ext().execute_with(|| {
|
||||||
let data: QueueConfigData = <QueueConfig<Test>>::get();
|
let data: QueueConfigData = <QueueConfig<Test>>::get();
|
||||||
assert_eq!(data.xcmp_max_individual_weight, 20u64 * WEIGHT_PER_MILLIS);
|
assert_eq!(
|
||||||
|
data.xcmp_max_individual_weight,
|
||||||
|
Weight::from_parts(20u64 * WEIGHT_PER_MILLIS.ref_time(), DEFAULT_POV_SIZE),
|
||||||
|
);
|
||||||
assert_ok!(XcmpQueue::update_xcmp_max_individual_weight(
|
assert_ok!(XcmpQueue::update_xcmp_max_individual_weight(
|
||||||
RuntimeOrigin::root(),
|
RuntimeOrigin::root(),
|
||||||
30u64 * WEIGHT_PER_MILLIS.ref_time()
|
30u64 * WEIGHT_PER_MILLIS.ref_time()
|
||||||
|
|||||||
Reference in New Issue
Block a user