From e13e14b3036532727ba48a382d63702098b6e826 Mon Sep 17 00:00:00 2001 From: Xavier Lau Date: Fri, 23 Aug 2024 15:53:08 +0800 Subject: [PATCH] Release `koi-6653` (#1574) * Release `koi-6653` * Fixes --- pallet/staking/src/lib.rs | 65 +++++++++---------------- runtime/crab/src/migration.rs | 14 +++++- runtime/crab/src/pallets/session.rs | 2 +- runtime/crab/src/pallets/staking.rs | 2 +- runtime/darwinia/src/migration.rs | 14 +++++- runtime/darwinia/src/pallets/session.rs | 2 +- runtime/darwinia/src/pallets/staking.rs | 2 +- runtime/koi/src/lib.rs | 2 +- runtime/koi/src/migration.rs | 21 ++++---- runtime/koi/src/pallets/governance.rs | 4 +- runtime/koi/src/pallets/session.rs | 4 +- 11 files changed, 63 insertions(+), 69 deletions(-) diff --git a/pallet/staking/src/lib.rs b/pallet/staking/src/lib.rs index b322234ac..1ec3e81dc 100644 --- a/pallet/staking/src/lib.rs +++ b/pallet/staking/src/lib.rs @@ -75,7 +75,7 @@ macro_rules! call_on_exposure { (_, $crate::CacheState::$s, _) => Ok(<$crate::ExposureCache1<$t>>$($f)*), (_, _, $crate::CacheState::$s) => Ok(<$crate::ExposureCache2<$t>>$($f)*), _ => { - log::error!("[pallet::staking] exposure cache states must be correct; qed"); + log::error!("exposure cache states must be correct; qed"); Err("[pallet::staking] exposure cache states must be correct; qed") }, @@ -96,7 +96,7 @@ macro_rules! call_on_cache { (_, $crate::CacheState::$s, _) => Ok(<$crate::CollatorsCache1<$t>>$($f)*), (_, _, $crate::CacheState::$s) => Ok(<$crate::CollatorsCache2<$t>>$($f)*), _ => { - log::error!("[pallet::staking] collators cache states must be correct; qed"); + log::error!("collators cache states must be correct; qed"); Err("[pallet::staking] collators cache states must be correct; qed") }, @@ -183,8 +183,6 @@ pub mod pallet { Payout { who: T::AccountId, amount: Balance }, /// Unable to pay the staker's reward. Unpaid { who: T::AccountId, amount: Balance }, - /// A new collator set has been elected. - Elected { collators: Vec }, } #[pallet::error] @@ -780,43 +778,24 @@ pub mod pallet { let bn = >::block_number(); - log::info!( - "[pallet::staking] assembling new collators for new session {index} at #{bn:?}", - ); + log::info!("assembling new collators for new session {index} at #{bn:?}",); let (n1, n2) = Self::elect_ns(); - let cs_from_contract = Self::try_elect(n1, Self::elect_from_contract); - let cs_from_pallet = Self::try_elect(n2, Self::elect); - - if n1 != cs_from_contract.len() as u32 || n2 != cs_from_pallet.len() as u32 { - log::error!( - "[pallet::staking] collator count mismatch; \ - expected collator count from contract: {n1}, from pallet: {n2}, \ - actual collator count from contract: {}, from pallet: {}", - cs_from_contract.len(), - cs_from_pallet.len(), - ); - - return None; - } + let cs_from_contract = Self::elect_from_contract(n1)?; + let cs_from_pallet = Self::elect(n2)?; + + log::info!("collators from contract {cs_from_contract:?}"); + log::info!("collators from pallet {cs_from_pallet:?}"); let cs = [cs_from_contract, cs_from_pallet].concat(); if cs.is_empty() { - // This error log is acceptable when testing with `genesis_collator = false`. - log::error!( - "[pallet::staking] fail to elect collators for new session {index} at #{bn:?}" - ); - // Impossible case. // // But if there is an issue, retain the old collators; do not alter the session // collators if any error occurs to prevent the chain from stalling. None } else { - // ? if we really need this event. - Self::deposit_event(Event::Elected { collators: cs.clone() }); - Some(cs) } } @@ -889,28 +868,22 @@ pub mod pallet { pub fn elect_ns() -> (u32, u32) { let n = >::get(); let n1 = Self::migration_progress() * n; + let n2 = n - n1; + + log::info!("election ns {n1} + {n2}"); - (n1, n - n1) + (n1, n2) } fn migration_progress() -> Perbill { const TOTAL: Moment = 30 * 2 * DAY_IN_MILLIS; let start = >::get(); + let prog = Perbill::from_rational(now::() - start, TOTAL); - Perbill::from_rational(now::() - start, TOTAL) - } + log::info!("migration progress {prog:?}"); - fn try_elect(n: u32, elect: F) -> R - where - F: FnOnce(u32) -> Option, - R: Default, - { - if n > 0 { - elect(n).unwrap_or_default() - } else { - Default::default() - } + prog } fn elect_from_contract(n: u32) -> Option> { @@ -940,7 +913,13 @@ pub mod pallet { fn start_session(_: u32) {} fn new_session(index: u32) -> Option> { - Self::prepare_new_session(index) + let maybe_collators = Self::prepare_new_session(index); + + if maybe_collators.is_some() { + log::error!("fail to elect collators for session {index}"); + } + + maybe_collators } } } diff --git a/runtime/crab/src/migration.rs b/runtime/crab/src/migration.rs index 51935f86e..31dd6c38a 100644 --- a/runtime/crab/src/migration.rs +++ b/runtime/crab/src/migration.rs @@ -52,9 +52,19 @@ fn migrate() -> frame_support::weights::Weight { b"ExposureCacheStates", &[], ) { - let _ = migration::put_storage_value(b"DarwinaStaking", b"CacheStates", &[], s); + migration::put_storage_value(b"DarwinaStaking", b"CacheStates", &[], s); + } + + if let Ok(owner) = + array_bytes::hex_n_into::<_, AccountId, 20>("0x7FAcDaFB282028E4B3264fB08cd633A9142514df") + { + let _ = >::transfer_ownership( + RuntimeOrigin::signed(ROOT), + codec::Compact(AssetIds::CKton as AssetId), + owner, + ); } // frame_support::weights::Weight::zero() - ::DbWeight::get().reads_writes(1, 1) + ::DbWeight::get().reads_writes(3, 3) } diff --git a/runtime/crab/src/pallets/session.rs b/runtime/crab/src/pallets/session.rs index c5b764597..526a7eb8b 100644 --- a/runtime/crab/src/pallets/session.rs +++ b/runtime/crab/src/pallets/session.rs @@ -25,7 +25,7 @@ sp_runtime::impl_opaque_keys! { } } -fast_runtime_or_not!(PERIOD, BlockNumber, 5 * MINUTES, 6 * HOURS); +darwinia_common_runtime::fast_runtime_or_not!(PERIOD, BlockNumber, 5 * MINUTES, 6 * HOURS); type Offset = ConstU32<0>; type Period = ConstU32<{ PERIOD }>; diff --git a/runtime/crab/src/pallets/staking.rs b/runtime/crab/src/pallets/staking.rs index 87568aca1..a8bf1f698 100644 --- a/runtime/crab/src/pallets/staking.rs +++ b/runtime/crab/src/pallets/staking.rs @@ -21,7 +21,7 @@ use crate::*; // polkadot-sdk use frame_support::traits::Currency; -fast_runtime_or_not!(DURATION, BlockNumber, 5 * MINUTES, 14 * DAYS); +darwinia_common_runtime::fast_runtime_or_not!(DURATION, BlockNumber, 5 * MINUTES, 14 * DAYS); pub enum RingStaking {} impl darwinia_staking::Stake for RingStaking { diff --git a/runtime/darwinia/src/migration.rs b/runtime/darwinia/src/migration.rs index 53a7a98d5..ce08cf436 100644 --- a/runtime/darwinia/src/migration.rs +++ b/runtime/darwinia/src/migration.rs @@ -60,9 +60,19 @@ fn migrate() -> frame_support::weights::Weight { b"ExposureCacheStates", &[], ) { - let _ = migration::put_storage_value(b"DarwinaStaking", b"CacheStates", &[], s); + migration::put_storage_value(b"DarwinaStaking", b"CacheStates", &[], s); + } + + if let Ok(owner) = + array_bytes::hex_n_into::<_, AccountId, 20>("0x7FAcDaFB282028E4B3264fB08cd633A9142514df") + { + let _ = >::transfer_ownership( + RuntimeOrigin::signed(ROOT), + codec::Compact(AssetIds::Kton as AssetId), + owner, + ); } // frame_support::weights::Weight::zero() - ::DbWeight::get().reads_writes(1, 101) + ::DbWeight::get().reads_writes(3, 103) } diff --git a/runtime/darwinia/src/pallets/session.rs b/runtime/darwinia/src/pallets/session.rs index c5b764597..526a7eb8b 100644 --- a/runtime/darwinia/src/pallets/session.rs +++ b/runtime/darwinia/src/pallets/session.rs @@ -25,7 +25,7 @@ sp_runtime::impl_opaque_keys! { } } -fast_runtime_or_not!(PERIOD, BlockNumber, 5 * MINUTES, 6 * HOURS); +darwinia_common_runtime::fast_runtime_or_not!(PERIOD, BlockNumber, 5 * MINUTES, 6 * HOURS); type Offset = ConstU32<0>; type Period = ConstU32<{ PERIOD }>; diff --git a/runtime/darwinia/src/pallets/staking.rs b/runtime/darwinia/src/pallets/staking.rs index 191bbdbc7..ef0d0f84f 100644 --- a/runtime/darwinia/src/pallets/staking.rs +++ b/runtime/darwinia/src/pallets/staking.rs @@ -21,7 +21,7 @@ use crate::*; // polkadot-sdk use frame_support::traits::Currency; -fast_runtime_or_not!(DURATION, BlockNumber, 5 * MINUTES, 14 * DAYS); +darwinia_common_runtime::fast_runtime_or_not!(DURATION, BlockNumber, 5 * MINUTES, 14 * DAYS); pub enum RingStaking {} impl darwinia_staking::Stake for RingStaking { diff --git a/runtime/koi/src/lib.rs b/runtime/koi/src/lib.rs index eed603a83..f9758ff5a 100644 --- a/runtime/koi/src/lib.rs +++ b/runtime/koi/src/lib.rs @@ -80,7 +80,7 @@ pub const VERSION: sp_version::RuntimeVersion = sp_version::RuntimeVersion { spec_name: sp_runtime::create_runtime_str!("Darwinia Koi"), impl_name: sp_runtime::create_runtime_str!("DarwiniaOfficialRust"), authoring_version: 0, - spec_version: 6_6_5_2, + spec_version: 6_6_5_3, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 0, diff --git a/runtime/koi/src/migration.rs b/runtime/koi/src/migration.rs index 743e5e352..1ff9e93d5 100644 --- a/runtime/koi/src/migration.rs +++ b/runtime/koi/src/migration.rs @@ -45,19 +45,16 @@ impl frame_support::traits::OnRuntimeUpgrade for CustomOnRuntimeUpgrade { } fn migrate() -> frame_support::weights::Weight { - let _ = - migration::clear_storage_prefix(b"DarwinaStaking", b"CollatorCacheState", &[], None, None); - - // dawinia - use darwinia_staking::CacheState; - if let Some(s) = migration::get_storage_value::<(CacheState, CacheState, CacheState)>( - b"DarwinaStaking", - b"ExposureCacheStates", - &[], - ) { - let _ = migration::put_storage_value(b"DarwinaStaking", b"CacheStates", &[], s); + if let Ok(owner) = + array_bytes::hex_n_into::<_, AccountId, 20>("0x7FAcDaFB282028E4B3264fB08cd633A9142514df") + { + let _ = >::transfer_ownership( + RuntimeOrigin::signed(ROOT), + codec::Compact(AssetIds::KKton as AssetId), + owner, + ); } // frame_support::weights::Weight::zero() - ::DbWeight::get().reads_writes(1, 2) + ::DbWeight::get().reads_writes(2, 2) } diff --git a/runtime/koi/src/pallets/governance.rs b/runtime/koi/src/pallets/governance.rs index 84a203797..689e16e3f 100644 --- a/runtime/koi/src/pallets/governance.rs +++ b/runtime/koi/src/pallets/governance.rs @@ -27,8 +27,8 @@ pub use pallet_collective::Instance1 as TechnicalCollective; pub(super) use crate::*; -fast_runtime_or_not!(TIME_1, BlockNumber, 2 * MINUTES, 10 * MINUTES); -fast_runtime_or_not!(TIME_2, BlockNumber, 5 * MINUTES, 20 * MINUTES); +darwinia_common_runtime::fast_runtime_or_not!(TIME_1, BlockNumber, 2 * MINUTES, 10 * MINUTES); +darwinia_common_runtime::fast_runtime_or_not!(TIME_2, BlockNumber, 5 * MINUTES, 20 * MINUTES); type Time1 = ConstU32; type Time2 = ConstU32; diff --git a/runtime/koi/src/pallets/session.rs b/runtime/koi/src/pallets/session.rs index c5b764597..d9d4d5518 100644 --- a/runtime/koi/src/pallets/session.rs +++ b/runtime/koi/src/pallets/session.rs @@ -25,10 +25,8 @@ sp_runtime::impl_opaque_keys! { } } -fast_runtime_or_not!(PERIOD, BlockNumber, 5 * MINUTES, 6 * HOURS); - type Offset = ConstU32<0>; -type Period = ConstU32<{ PERIOD }>; +type Period = ConstU32<{ 5 * MINUTES }>; impl pallet_session::Config for Runtime { type Keys = SessionKeys;