diff --git a/pallets/dapp-staking/src/migration.rs b/pallets/dapp-staking/src/migration.rs index 43c1999d36..f782110e2a 100644 --- a/pallets/dapp-staking/src/migration.rs +++ b/pallets/dapp-staking/src/migration.rs @@ -20,7 +20,7 @@ use super::*; use frame_support::{ migrations::{MigrationId, SteppedMigration, SteppedMigrationError}, storage_alias, - traits::UncheckedOnRuntimeUpgrade, + traits::{OnRuntimeUpgrade, UncheckedOnRuntimeUpgrade}, weights::WeightMeter, }; @@ -449,6 +449,7 @@ impl SteppedMigration for LazyMigration { } let mut count = 0u32; + let mut migrated = 0u32; let current_block_number = frame_system::Pallet::::block_number().saturated_into::(); @@ -471,9 +472,13 @@ impl SteppedMigration for LazyMigration { // If there's a next item in the iterator, perform the migration. if let Some((ref last_key, mut ledger)) = iter.next() { + // inc count + count.saturating_inc(); + if ledger.unlocking.is_empty() { // no unlocking for this account, nothing to update - cursor = Some(last_key.clone()); // Return the processed key as the new cursor. + // Return the processed key as the new cursor. + cursor = Some(last_key.clone()); continue; } for chunk in ledger.unlocking.iter_mut() { @@ -487,8 +492,8 @@ impl SteppedMigration for LazyMigration { // Override ledger Ledger::::insert(last_key, ledger); - // inc counter - count.saturating_inc(); + // inc migrated + migrated.saturating_inc(); // Return the processed key as the new cursor. cursor = Some(last_key.clone()) @@ -498,7 +503,25 @@ impl SteppedMigration for LazyMigration { break; } } - log::debug!(target: LOG_TARGET, "migrated {count:?} entries"); + log::info!(target: LOG_TARGET, "🚚 iterated {count} entries, migrated {migrated}"); Ok(cursor) } } + +/// Double the remaining block for next era start +pub struct AdjustEraMigration(PhantomData); + +impl OnRuntimeUpgrade for AdjustEraMigration { + fn on_runtime_upgrade() -> Weight { + log::info!("🚚 migrated to async backing, adjust next era start"); + ActiveProtocolState::::mutate_exists(|maybe| { + if let Some(state) = maybe { + let current_block_number = + frame_system::Pallet::::block_number().saturated_into::(); + let remaining = state.next_era_start.saturating_sub(current_block_number); + state.next_era_start.saturating_accrue(2 * remaining); + } + }); + T::DbWeight::get().reads_writes(1, 1) + } +} diff --git a/pallets/inflation/src/lib.rs b/pallets/inflation/src/lib.rs index 25fa4bd505..c9baf754a0 100644 --- a/pallets/inflation/src/lib.rs +++ b/pallets/inflation/src/lib.rs @@ -126,6 +126,7 @@ pub use weights::WeightInfo; #[cfg(any(feature = "runtime-benchmarks"))] pub mod benchmarking; +pub mod migration; #[cfg(test)] mod mock; #[cfg(test)] diff --git a/pallets/inflation/src/migration.rs b/pallets/inflation/src/migration.rs new file mode 100644 index 0000000000..100b75a169 --- /dev/null +++ b/pallets/inflation/src/migration.rs @@ -0,0 +1,39 @@ +// This file is part of Astar. + +// Copyright (C) Stake Technologies Pte.Ltd. +// SPDX-License-Identifier: GPL-3.0-or-later + +// Astar 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. + +// Astar 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 Astar. If not, see . + +use super::*; +use frame_support::pallet_prelude::Weight; +use frame_support::traits::OnRuntimeUpgrade; + +/// Half block reward for collators and treasury +pub struct AdjustBlockRewardMigration(core::marker::PhantomData); + +impl OnRuntimeUpgrade for AdjustBlockRewardMigration { + fn on_runtime_upgrade() -> Weight { + log::info!("🚚 migrated to async backing, adjust reward per block"); + ActiveInflationConfig::::mutate_exists(|maybe| { + if let Some(config) = maybe { + config.collator_reward_per_block = + config.collator_reward_per_block.saturating_div(2); + config.treasury_reward_per_block = + config.treasury_reward_per_block.saturating_div(2); + } + }); + T::DbWeight::get().reads_writes(1, 1) + } +} diff --git a/runtime/shibuya/src/lib.rs b/runtime/shibuya/src/lib.rs index 0aeeb6e47b..cd05f75113 100644 --- a/runtime/shibuya/src/lib.rs +++ b/runtime/shibuya/src/lib.rs @@ -1646,33 +1646,6 @@ pub type Executive = frame_executive::Executive< Migrations, >; -parameter_types! { - // Threshold amount variation allowed for this migration - 150% - pub const ThresholdVariationPercentage: u32 = 150; - // percentages below are calculated based on a total issuance at the time when dApp staking v3 was launched (147M) - pub const TierThresholds: [TierThreshold; 4] = [ - TierThreshold::DynamicPercentage { - percentage: Perbill::from_parts(20_000), // 0.0020% - minimum_required_percentage: Perbill::from_parts(17_000), // 0.0017% - }, - TierThreshold::DynamicPercentage { - percentage: Perbill::from_parts(13_000), // 0.0013% - minimum_required_percentage: Perbill::from_parts(10_000), // 0.0010% - }, - TierThreshold::DynamicPercentage { - percentage: Perbill::from_parts(5_400), // 0.00054% - minimum_required_percentage: Perbill::from_parts(3_400), // 0.00034% - }, - TierThreshold::FixedPercentage { - required_percentage: Perbill::from_parts(1_400), // 0.00014% - }, - ]; -} - -parameter_types! { - pub const DmpQueuePalletName: &'static str = "DmpQueue"; -} - /// All migrations that will run on the next runtime upgrade. /// /// __NOTE:__ THE ORDER IS IMPORTANT. @@ -1680,17 +1653,8 @@ pub type Migrations = (Unreleased, Permanent); /// Unreleased migrations. Add new ones here: pub type Unreleased = ( - // dApp-staking dyn tier threshold migrations - pallet_dapp_staking::migration::versioned_migrations::V7ToV8< - Runtime, - TierThresholds, - ThresholdVariationPercentage, - >, - frame_support::migrations::RemovePallet< - DmpQueuePalletName, - ::DbWeight, - >, - pallet_contracts::Migration, + pallet_dapp_staking::migration::AdjustEraMigration, + pallet_inflation::migration::AdjustBlockRewardMigration, ); /// Migrations/checks that do not need to be versioned and can run on every upgrade.