Skip to content
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions pallets/dapp-staking/src/benchmarking/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@

use super::{Pallet as DappStaking, *};

use astar_primitives::{
dapp_staking::FIXED_NUMBER_OF_TIER_SLOTS,
Balance,
};
use astar_primitives::{dapp_staking::FIXED_NUMBER_OF_TIER_SLOTS, Balance};

use frame_system::Pallet as System;
use sp_arithmetic::Permill;
Expand Down
125 changes: 63 additions & 62 deletions pallets/dapp-staking/src/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ pub mod versioned_migrations {
use super::*;

/// Migration V11 to V12:
/// - Prune old `PeriodEnd` entries for periods 0..=6
/// - Prune old `PeriodEnd` entries up to the given `PruneMaxPeriod` (inclusive)
/// - Migrate `StaticTierParams` to remove `slot_number_args` and `DynamicPercentage`
pub type V11ToV12<T> = frame_support::migrations::VersionedMigration<
pub type V11ToV12<T, PruneMaxPeriod> = frame_support::migrations::VersionedMigration<
11,
12,
v12::VersionMigrateV11ToV12<T>,
v12::VersionMigrateV11ToV12<T, PruneMaxPeriod>,
Pallet<T>,
<T as frame_system::Config>::DbWeight,
>;
Expand All @@ -47,13 +47,12 @@ pub mod versioned_migrations {
mod v12 {
use super::*;

/// Maximum period number to prune (inclusive).
const PRUNE_MAX_PERIOD: PeriodNumber = 6;

/// Old `TierThreshold` enum that includes the removed `DynamicPercentage` variant.
#[derive(Encode, Decode, Clone)]
pub enum OldTierThreshold {
FixedPercentage { required_percentage: Perbill },
FixedPercentage {
required_percentage: Perbill,
},
DynamicPercentage {
percentage: Perbill,
minimum_required_percentage: Perbill,
Expand All @@ -71,19 +70,19 @@ mod v12 {
pub tier_rank_multipliers: BoundedVec<u32, NT>,
}

#[frame_support::storage_alias]
pub type OldStaticTierParams<T: Config> =
StorageValue<Pallet<T>, OldTierParameters<<T as Config>::NumberOfTiers>, OptionQuery>;
pub struct VersionMigrateV11ToV12<T, PruneMaxPeriod>(PhantomData<(T, PruneMaxPeriod)>);

pub struct VersionMigrateV11ToV12<T>(PhantomData<T>);

impl<T: Config> UncheckedOnRuntimeUpgrade for VersionMigrateV11ToV12<T> {
impl<T: Config, PruneMaxPeriod: Get<PeriodNumber>> UncheckedOnRuntimeUpgrade
for VersionMigrateV11ToV12<T, PruneMaxPeriod>
{
fn on_runtime_upgrade() -> Weight {
let mut reads: u64 = 0;
let mut writes: u64 = 0;

// 1. Prune old PeriodEnd entries for periods 0..=6
for period in 0..=PRUNE_MAX_PERIOD {
let prune_max_period = PruneMaxPeriod::get();

// 1. Prune old PeriodEnd entries up to the configured max period
for period in 0..=prune_max_period {
reads += 1;
if PeriodEnd::<T>::take(period).is_some() {
writes += 1;
Expand All @@ -97,56 +96,56 @@ mod v12 {

// 2. Migrate StaticTierParams to new shape (remove slot_number_args, convert DynamicPercentage)
reads += 1;
if let Some(old_params) = OldStaticTierParams::<T>::get() {
let new_tier_thresholds: Vec<TierThreshold> = old_params
.tier_thresholds
.iter()
.map(|t| match t {
OldTierThreshold::FixedPercentage {
required_percentage,
} => TierThreshold::FixedPercentage {
required_percentage: *required_percentage,
},
OldTierThreshold::DynamicPercentage { percentage, .. } => {
TierThreshold::FixedPercentage {
required_percentage: *percentage,
}
}
})
.collect();

let new_params = TierParameters::<T::NumberOfTiers> {
reward_portion: old_params.reward_portion,
slot_distribution: old_params.slot_distribution,
tier_thresholds: BoundedVec::truncate_from(new_tier_thresholds),
tier_rank_multipliers: old_params.tier_rank_multipliers,
};

if new_params.is_valid() {
StaticTierParams::<T>::put(new_params);
writes += 1;
log::info!(target: LOG_TARGET, "StaticTierParams migrated to v12 successfully");
} else {
log::error!(
target: LOG_TARGET,
"New TierParameters validation failed during v12 migration. Enabling maintenance mode."
);
ActiveProtocolState::<T>::mutate(|state| {
state.maintenance = true;
});
reads += 1;
writes += 1;
}
let result = StaticTierParams::<T>::translate::<OldTierParameters<T::NumberOfTiers>, _>(
|maybe_old_params| match maybe_old_params {
Some(old_params) => {
let new_tier_thresholds: Vec<TierThreshold> = old_params
.tier_thresholds
.iter()
.map(|t| match t {
OldTierThreshold::FixedPercentage {
required_percentage,
} => TierThreshold::FixedPercentage {
required_percentage: *required_percentage,
},
OldTierThreshold::DynamicPercentage { percentage, .. } => {
TierThreshold::FixedPercentage {
required_percentage: *percentage,
}
}
})
.collect();

Some(TierParameters {
reward_portion: old_params.reward_portion,
slot_distribution: old_params.slot_distribution,
tier_thresholds: BoundedVec::truncate_from(new_tier_thresholds),
tier_rank_multipliers: old_params.tier_rank_multipliers,
})
}
None => None,
},
);

if result.is_err() {
log::error!(
target: LOG_TARGET,
"Failed to translate StaticTierParams from old type to new v12 type. \
Enabling maintenance mode."
);
ActiveProtocolState::<T>::mutate(|state| {
state.maintenance = true;
});
reads += 1;
writes += 1;
} else {
log::warn!(
writes += 1;
log::info!(
target: LOG_TARGET,
"No StaticTierParams found during v12 migration (raw storage empty or decode failed)."
"StaticTierParams migrated to v12 successfully"
);
}

// 3. Clean up raw storage for old StaticTierParams key (same key, already overwritten above)
// No additional action needed since StaticTierParams::put already overwrites.

T::DbWeight::get().reads_writes(reads, writes)
}

Expand All @@ -158,6 +157,8 @@ mod v12 {

#[cfg(feature = "try-runtime")]
fn post_upgrade(_data: Vec<u8>) -> Result<(), TryRuntimeError> {
let prune_max_period = PruneMaxPeriod::get();

// Verify storage version
ensure!(
Pallet::<T>::on_chain_storage_version() == StorageVersion::new(12),
Expand All @@ -171,8 +172,8 @@ mod v12 {
"StaticTierParams invalid after migration"
);

// Verify PeriodEnd entries for periods 0..=6 are removed
for period in 0..=PRUNE_MAX_PERIOD {
// Verify PeriodEnd entries for pruned periods are removed
for period in 0..=prune_max_period {
ensure!(
PeriodEnd::<T>::get(period).is_none(),
"PeriodEnd entry should be removed for pruned period"
Expand Down
5 changes: 1 addition & 4 deletions runtime/astar/src/genesis_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@
// along with Astar. If not, see <http://www.gnu.org/licenses/>.

use crate::*;
use astar_primitives::{
evm::EVM_REVERT_CODE, genesis::GenesisAccount,
parachain::ASTAR_ID,
};
use astar_primitives::{evm::EVM_REVERT_CODE, genesis::GenesisAccount, parachain::ASTAR_ID};

/// Provides the JSON representation of predefined genesis config for given `id`.
pub fn get_preset(id: &sp_genesis_builder::PresetId) -> Option<Vec<u8>> {
Expand Down
6 changes: 5 additions & 1 deletion runtime/astar/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1695,6 +1695,7 @@ pub type Executive = frame_executive::Executive<
>;

parameter_types! {
pub const DappStakingPruneMaxPeriod: u32 = 6;
pub const PriceAggregatorPalletStr: &'static str = "PriceAggregator";
pub const OraclePalletStr: &'static str = "Oracle";
pub const OracleMembershipPalletStr: &'static str = "OracleMembership";
Expand All @@ -1707,7 +1708,10 @@ pub type Migrations = (Unreleased, Permanent);

/// Unreleased migrations. Add new ones here:
pub type Unreleased = (
pallet_dapp_staking::migration::versioned_migrations::V11ToV12<Runtime>,
pallet_dapp_staking::migration::versioned_migrations::V11ToV12<
Runtime,
DappStakingPruneMaxPeriod,
>,
frame_support::migrations::RemovePallet<PriceAggregatorPalletStr, RocksDbWeight>,
frame_support::migrations::RemovePallet<OraclePalletStr, RocksDbWeight>,
frame_support::migrations::RemovePallet<OracleMembershipPalletStr, RocksDbWeight>,
Expand Down
18 changes: 9 additions & 9 deletions runtime/astar/src/weights/block_weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// along with Astar. If not, see <http://www.gnu.org/licenses/>.

//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0
//! DATE: 2025-12-19 (Y/M/D)
//! DATE: 2026-03-23 (Y/M/D)
//! HOSTNAME: `gh-runner-01-ovh`, CPU: `Intel(R) Xeon(R) E-2236 CPU @ 3.40GHz`
//!
//! SHORT-NAME: `block`, LONG-NAME: `BlockExecution`, RUNTIME: `astar`
Expand All @@ -43,17 +43,17 @@ parameter_types! {
/// Calculated by multiplying the *Average* with `1.0` and adding `0`.
///
/// Stats nanoseconds:
/// Min, Max: 708_212, 844_044
/// Average: 761_989
/// Median: 754_226
/// Std-Dev: 30284.39
/// Min, Max: 615_206, 724_092
/// Average: 654_801
/// Median: 656_156
/// Std-Dev: 29311.54
///
/// Percentiles nanoseconds:
/// 99th: 844_044
/// 95th: 817_447
/// 75th: 758_024
/// 99th: 724_092
/// 95th: 721_515
/// 75th: 659_926
pub const BlockExecutionWeight: Weight =
Weight::from_parts(WEIGHT_REF_TIME_PER_NANOS.saturating_mul(761_989), 6_281);
Weight::from_parts(WEIGHT_REF_TIME_PER_NANOS.saturating_mul(654_801), 6_010);
}

#[cfg(test)]
Expand Down
18 changes: 9 additions & 9 deletions runtime/astar/src/weights/extrinsic_weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// along with Astar. If not, see <http://www.gnu.org/licenses/>.

//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0
//! DATE: 2025-12-19 (Y/M/D)
//! DATE: 2026-03-23 (Y/M/D)
//! HOSTNAME: `gh-runner-01-ovh`, CPU: `Intel(R) Xeon(R) E-2236 CPU @ 3.40GHz`
//!
//! SHORT-NAME: `extrinsic`, LONG-NAME: `ExtrinsicBase`, RUNTIME: `astar`
Expand All @@ -43,17 +43,17 @@ parameter_types! {
/// Calculated by multiplying the *Average* with `1.0` and adding `0`.
///
/// Stats nanoseconds:
/// Min, Max: 99_630, 101_936
/// Average: 100_226
/// Median: 100_119
/// Std-Dev: 477.29
/// Min, Max: 93_438, 96_137
/// Average: 94_252
/// Median: 94_063
/// Std-Dev: 620.6
///
/// Percentiles nanoseconds:
/// 99th: 101_936
/// 95th: 101_138
/// 75th: 100_462
/// 99th: 96_137
/// 95th: 95_682
/// 75th: 94_505
pub const ExtrinsicBaseWeight: Weight =
Weight::from_parts(WEIGHT_REF_TIME_PER_NANOS.saturating_mul(100_226), 166);
Weight::from_parts(WEIGHT_REF_TIME_PER_NANOS.saturating_mul(94_252), 166);
}

#[cfg(test)]
Expand Down
38 changes: 19 additions & 19 deletions runtime/astar/src/weights/frame_system_extensions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
//! Autogenerated weights for `frame_system_extensions`
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0
//! DATE: 2025-12-19, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! DATE: 2026-03-23, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! WORST CASE MAP SIZE: `1000000`
//! HOSTNAME: `gh-runner-01-ovh`, CPU: `Intel(R) Xeon(R) E-2236 CPU @ 3.40GHz`
//! WASM-EXECUTION: `Compiled`, CHAIN: `None`, DB CACHE: 1024
Expand Down Expand Up @@ -56,32 +56,32 @@ impl<T: frame_system::Config> frame_system::ExtensionsWeightInfo for SubstrateWe
// Proof Size summary in bytes:
// Measured: `30`
// Estimated: `0`
// Minimum execution time: 3_945_000 picoseconds.
Weight::from_parts(4_062_000, 0)
// Minimum execution time: 4_836_000 picoseconds.
Weight::from_parts(5_191_000, 0)
.saturating_add(Weight::from_parts(0, 0))
}
fn check_mortality_mortal_transaction() -> Weight {
// Proof Size summary in bytes:
// Measured: `68`
// Estimated: `0`
// Minimum execution time: 7_427_000 picoseconds.
Weight::from_parts(7_656_000, 0)
// Minimum execution time: 8_071_000 picoseconds.
Weight::from_parts(8_554_000, 0)
.saturating_add(Weight::from_parts(0, 0))
}
fn check_mortality_immortal_transaction() -> Weight {
// Proof Size summary in bytes:
// Measured: `68`
// Estimated: `0`
// Minimum execution time: 7_500_000 picoseconds.
Weight::from_parts(7_702_000, 0)
// Minimum execution time: 8_107_000 picoseconds.
Weight::from_parts(8_578_000, 0)
.saturating_add(Weight::from_parts(0, 0))
}
fn check_non_zero_sender() -> Weight {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 569_000 picoseconds.
Weight::from_parts(597_000, 0)
// Minimum execution time: 519_000 picoseconds.
Weight::from_parts(604_000, 0)
.saturating_add(Weight::from_parts(0, 0))
}
/// Storage: `System::Account` (r:1 w:1)
Expand All @@ -90,8 +90,8 @@ impl<T: frame_system::Config> frame_system::ExtensionsWeightInfo for SubstrateWe
// Proof Size summary in bytes:
// Measured: `102`
// Estimated: `3593`
// Minimum execution time: 10_378_000 picoseconds.
Weight::from_parts(10_599_000, 0)
// Minimum execution time: 9_406_000 picoseconds.
Weight::from_parts(9_905_000, 0)
.saturating_add(Weight::from_parts(0, 3593))
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(1))
Expand All @@ -100,32 +100,32 @@ impl<T: frame_system::Config> frame_system::ExtensionsWeightInfo for SubstrateWe
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 452_000 picoseconds.
Weight::from_parts(491_000, 0)
// Minimum execution time: 418_000 picoseconds.
Weight::from_parts(493_000, 0)
.saturating_add(Weight::from_parts(0, 0))
}
fn check_tx_version() -> Weight {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 440_000 picoseconds.
Weight::from_parts(492_000, 0)
// Minimum execution time: 393_000 picoseconds.
Weight::from_parts(482_000, 0)
.saturating_add(Weight::from_parts(0, 0))
}
fn check_weight() -> Weight {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 6_223_000 picoseconds.
Weight::from_parts(6_420_000, 0)
// Minimum execution time: 4_087_000 picoseconds.
Weight::from_parts(4_377_000, 0)
.saturating_add(Weight::from_parts(0, 0))
}
fn weight_reclaim() -> Weight {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 4_050_000 picoseconds.
Weight::from_parts(4_264_000, 0)
// Minimum execution time: 2_376_000 picoseconds.
Weight::from_parts(2_618_000, 0)
.saturating_add(Weight::from_parts(0, 0))
}
}
Loading
Loading