From 479fb54714cce49b0b53f59695bf99fad6ad3f7a Mon Sep 17 00:00:00 2001 From: talhadaar Date: Wed, 4 Dec 2024 15:26:46 +0500 Subject: [PATCH] fix bug of session rotating twice in parachain staking --- pallets/parachain-staking/src/migrations.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/pallets/parachain-staking/src/migrations.rs b/pallets/parachain-staking/src/migrations.rs index 2a7e1047..6a894b8a 100644 --- a/pallets/parachain-staking/src/migrations.rs +++ b/pallets/parachain-staking/src/migrations.rs @@ -3,7 +3,7 @@ use crate::{ pallet::{Config, Pallet, OLD_STAKING_ID, STAKING_ID}, types::{AccountIdOf, Candidate, OldCandidate}, - CandidatePool, ForceNewRound, + CandidatePool, ForceNewRound, Round, }; use frame_support::{ pallet_prelude::{GetStorageVersion, StorageVersion, ValueQuery}, @@ -94,9 +94,16 @@ mod upgrade { Versions::default() as u16 ); - // force start new session - >::put(true); - weight_writes += 1; + let round = Round::::get(); + let now = >::block_number(); + weight_reads += 2; + // Force new round if round wasn't about to be rotated anyway + if !round.should_update(now) { + // force start new session + >::put(true); + weight_writes += 1; + log::info!("Will force new round for token economy V2."); + } log::info!("V11 Migrating Done."); }