Skip to content

Commit e13e14b

Browse files
authored
Release koi-6653 (#1574)
* Release `koi-6653` * Fixes
1 parent d9dd210 commit e13e14b

File tree

11 files changed

+63
-69
lines changed

11 files changed

+63
-69
lines changed

pallet/staking/src/lib.rs

Lines changed: 22 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ macro_rules! call_on_exposure {
7575
(_, $crate::CacheState::$s, _) => Ok(<$crate::ExposureCache1<$t>>$($f)*),
7676
(_, _, $crate::CacheState::$s) => Ok(<$crate::ExposureCache2<$t>>$($f)*),
7777
_ => {
78-
log::error!("[pallet::staking] exposure cache states must be correct; qed");
78+
log::error!("exposure cache states must be correct; qed");
7979

8080
Err("[pallet::staking] exposure cache states must be correct; qed")
8181
},
@@ -96,7 +96,7 @@ macro_rules! call_on_cache {
9696
(_, $crate::CacheState::$s, _) => Ok(<$crate::CollatorsCache1<$t>>$($f)*),
9797
(_, _, $crate::CacheState::$s) => Ok(<$crate::CollatorsCache2<$t>>$($f)*),
9898
_ => {
99-
log::error!("[pallet::staking] collators cache states must be correct; qed");
99+
log::error!("collators cache states must be correct; qed");
100100

101101
Err("[pallet::staking] collators cache states must be correct; qed")
102102
},
@@ -183,8 +183,6 @@ pub mod pallet {
183183
Payout { who: T::AccountId, amount: Balance },
184184
/// Unable to pay the staker's reward.
185185
Unpaid { who: T::AccountId, amount: Balance },
186-
/// A new collator set has been elected.
187-
Elected { collators: Vec<T::AccountId> },
188186
}
189187

190188
#[pallet::error]
@@ -780,43 +778,24 @@ pub mod pallet {
780778

781779
let bn = <frame_system::Pallet<T>>::block_number();
782780

783-
log::info!(
784-
"[pallet::staking] assembling new collators for new session {index} at #{bn:?}",
785-
);
781+
log::info!("assembling new collators for new session {index} at #{bn:?}",);
786782

787783
let (n1, n2) = Self::elect_ns();
788-
let cs_from_contract = Self::try_elect(n1, Self::elect_from_contract);
789-
let cs_from_pallet = Self::try_elect(n2, Self::elect);
790-
791-
if n1 != cs_from_contract.len() as u32 || n2 != cs_from_pallet.len() as u32 {
792-
log::error!(
793-
"[pallet::staking] collator count mismatch; \
794-
expected collator count from contract: {n1}, from pallet: {n2}, \
795-
actual collator count from contract: {}, from pallet: {}",
796-
cs_from_contract.len(),
797-
cs_from_pallet.len(),
798-
);
799-
800-
return None;
801-
}
784+
let cs_from_contract = Self::elect_from_contract(n1)?;
785+
let cs_from_pallet = Self::elect(n2)?;
786+
787+
log::info!("collators from contract {cs_from_contract:?}");
788+
log::info!("collators from pallet {cs_from_pallet:?}");
802789

803790
let cs = [cs_from_contract, cs_from_pallet].concat();
804791

805792
if cs.is_empty() {
806-
// This error log is acceptable when testing with `genesis_collator = false`.
807-
log::error!(
808-
"[pallet::staking] fail to elect collators for new session {index} at #{bn:?}"
809-
);
810-
811793
// Impossible case.
812794
//
813795
// But if there is an issue, retain the old collators; do not alter the session
814796
// collators if any error occurs to prevent the chain from stalling.
815797
None
816798
} else {
817-
// ? if we really need this event.
818-
Self::deposit_event(Event::Elected { collators: cs.clone() });
819-
820799
Some(cs)
821800
}
822801
}
@@ -889,28 +868,22 @@ pub mod pallet {
889868
pub fn elect_ns() -> (u32, u32) {
890869
let n = <CollatorCount<T>>::get();
891870
let n1 = Self::migration_progress() * n;
871+
let n2 = n - n1;
872+
873+
log::info!("election ns {n1} + {n2}");
892874

893-
(n1, n - n1)
875+
(n1, n2)
894876
}
895877

896878
fn migration_progress() -> Perbill {
897879
const TOTAL: Moment = 30 * 2 * DAY_IN_MILLIS;
898880

899881
let start = <MigrationStartPoint<T>>::get();
882+
let prog = Perbill::from_rational(now::<T>() - start, TOTAL);
900883

901-
Perbill::from_rational(now::<T>() - start, TOTAL)
902-
}
884+
log::info!("migration progress {prog:?}");
903885

904-
fn try_elect<F, R>(n: u32, elect: F) -> R
905-
where
906-
F: FnOnce(u32) -> Option<R>,
907-
R: Default,
908-
{
909-
if n > 0 {
910-
elect(n).unwrap_or_default()
911-
} else {
912-
Default::default()
913-
}
886+
prog
914887
}
915888

916889
fn elect_from_contract(n: u32) -> Option<Vec<T::AccountId>> {
@@ -940,7 +913,13 @@ pub mod pallet {
940913
fn start_session(_: u32) {}
941914

942915
fn new_session(index: u32) -> Option<Vec<T::AccountId>> {
943-
Self::prepare_new_session(index)
916+
let maybe_collators = Self::prepare_new_session(index);
917+
918+
if maybe_collators.is_some() {
919+
log::error!("fail to elect collators for session {index}");
920+
}
921+
922+
maybe_collators
944923
}
945924
}
946925
}

runtime/crab/src/migration.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,19 @@ fn migrate() -> frame_support::weights::Weight {
5252
b"ExposureCacheStates",
5353
&[],
5454
) {
55-
let _ = migration::put_storage_value(b"DarwinaStaking", b"CacheStates", &[], s);
55+
migration::put_storage_value(b"DarwinaStaking", b"CacheStates", &[], s);
56+
}
57+
58+
if let Ok(owner) =
59+
array_bytes::hex_n_into::<_, AccountId, 20>("0x7FAcDaFB282028E4B3264fB08cd633A9142514df")
60+
{
61+
let _ = <pallet_assets::Pallet<Runtime>>::transfer_ownership(
62+
RuntimeOrigin::signed(ROOT),
63+
codec::Compact(AssetIds::CKton as AssetId),
64+
owner,
65+
);
5666
}
5767

5868
// frame_support::weights::Weight::zero()
59-
<Runtime as frame_system::Config>::DbWeight::get().reads_writes(1, 1)
69+
<Runtime as frame_system::Config>::DbWeight::get().reads_writes(3, 3)
6070
}

runtime/crab/src/pallets/session.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ sp_runtime::impl_opaque_keys! {
2525
}
2626
}
2727

28-
fast_runtime_or_not!(PERIOD, BlockNumber, 5 * MINUTES, 6 * HOURS);
28+
darwinia_common_runtime::fast_runtime_or_not!(PERIOD, BlockNumber, 5 * MINUTES, 6 * HOURS);
2929

3030
type Offset = ConstU32<0>;
3131
type Period = ConstU32<{ PERIOD }>;

runtime/crab/src/pallets/staking.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use crate::*;
2121
// polkadot-sdk
2222
use frame_support::traits::Currency;
2323

24-
fast_runtime_or_not!(DURATION, BlockNumber, 5 * MINUTES, 14 * DAYS);
24+
darwinia_common_runtime::fast_runtime_or_not!(DURATION, BlockNumber, 5 * MINUTES, 14 * DAYS);
2525

2626
pub enum RingStaking {}
2727
impl darwinia_staking::Stake for RingStaking {

runtime/darwinia/src/migration.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,19 @@ fn migrate() -> frame_support::weights::Weight {
6060
b"ExposureCacheStates",
6161
&[],
6262
) {
63-
let _ = migration::put_storage_value(b"DarwinaStaking", b"CacheStates", &[], s);
63+
migration::put_storage_value(b"DarwinaStaking", b"CacheStates", &[], s);
64+
}
65+
66+
if let Ok(owner) =
67+
array_bytes::hex_n_into::<_, AccountId, 20>("0x7FAcDaFB282028E4B3264fB08cd633A9142514df")
68+
{
69+
let _ = <pallet_assets::Pallet<Runtime>>::transfer_ownership(
70+
RuntimeOrigin::signed(ROOT),
71+
codec::Compact(AssetIds::Kton as AssetId),
72+
owner,
73+
);
6474
}
6575

6676
// frame_support::weights::Weight::zero()
67-
<Runtime as frame_system::Config>::DbWeight::get().reads_writes(1, 101)
77+
<Runtime as frame_system::Config>::DbWeight::get().reads_writes(3, 103)
6878
}

runtime/darwinia/src/pallets/session.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ sp_runtime::impl_opaque_keys! {
2525
}
2626
}
2727

28-
fast_runtime_or_not!(PERIOD, BlockNumber, 5 * MINUTES, 6 * HOURS);
28+
darwinia_common_runtime::fast_runtime_or_not!(PERIOD, BlockNumber, 5 * MINUTES, 6 * HOURS);
2929

3030
type Offset = ConstU32<0>;
3131
type Period = ConstU32<{ PERIOD }>;

runtime/darwinia/src/pallets/staking.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use crate::*;
2121
// polkadot-sdk
2222
use frame_support::traits::Currency;
2323

24-
fast_runtime_or_not!(DURATION, BlockNumber, 5 * MINUTES, 14 * DAYS);
24+
darwinia_common_runtime::fast_runtime_or_not!(DURATION, BlockNumber, 5 * MINUTES, 14 * DAYS);
2525

2626
pub enum RingStaking {}
2727
impl darwinia_staking::Stake for RingStaking {

runtime/koi/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ pub const VERSION: sp_version::RuntimeVersion = sp_version::RuntimeVersion {
8080
spec_name: sp_runtime::create_runtime_str!("Darwinia Koi"),
8181
impl_name: sp_runtime::create_runtime_str!("DarwiniaOfficialRust"),
8282
authoring_version: 0,
83-
spec_version: 6_6_5_2,
83+
spec_version: 6_6_5_3,
8484
impl_version: 0,
8585
apis: RUNTIME_API_VERSIONS,
8686
transaction_version: 0,

runtime/koi/src/migration.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,16 @@ impl frame_support::traits::OnRuntimeUpgrade for CustomOnRuntimeUpgrade {
4545
}
4646

4747
fn migrate() -> frame_support::weights::Weight {
48-
let _ =
49-
migration::clear_storage_prefix(b"DarwinaStaking", b"CollatorCacheState", &[], None, None);
50-
51-
// dawinia
52-
use darwinia_staking::CacheState;
53-
if let Some(s) = migration::get_storage_value::<(CacheState, CacheState, CacheState)>(
54-
b"DarwinaStaking",
55-
b"ExposureCacheStates",
56-
&[],
57-
) {
58-
let _ = migration::put_storage_value(b"DarwinaStaking", b"CacheStates", &[], s);
48+
if let Ok(owner) =
49+
array_bytes::hex_n_into::<_, AccountId, 20>("0x7FAcDaFB282028E4B3264fB08cd633A9142514df")
50+
{
51+
let _ = <pallet_assets::Pallet<Runtime>>::transfer_ownership(
52+
RuntimeOrigin::signed(ROOT),
53+
codec::Compact(AssetIds::KKton as AssetId),
54+
owner,
55+
);
5956
}
6057

6158
// frame_support::weights::Weight::zero()
62-
<Runtime as frame_system::Config>::DbWeight::get().reads_writes(1, 2)
59+
<Runtime as frame_system::Config>::DbWeight::get().reads_writes(2, 2)
6360
}

runtime/koi/src/pallets/governance.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ pub use pallet_collective::Instance1 as TechnicalCollective;
2727

2828
pub(super) use crate::*;
2929

30-
fast_runtime_or_not!(TIME_1, BlockNumber, 2 * MINUTES, 10 * MINUTES);
31-
fast_runtime_or_not!(TIME_2, BlockNumber, 5 * MINUTES, 20 * MINUTES);
30+
darwinia_common_runtime::fast_runtime_or_not!(TIME_1, BlockNumber, 2 * MINUTES, 10 * MINUTES);
31+
darwinia_common_runtime::fast_runtime_or_not!(TIME_2, BlockNumber, 5 * MINUTES, 20 * MINUTES);
3232

3333
type Time1 = ConstU32<TIME_1>;
3434
type Time2 = ConstU32<TIME_2>;

runtime/koi/src/pallets/session.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,8 @@ sp_runtime::impl_opaque_keys! {
2525
}
2626
}
2727

28-
fast_runtime_or_not!(PERIOD, BlockNumber, 5 * MINUTES, 6 * HOURS);
29-
3028
type Offset = ConstU32<0>;
31-
type Period = ConstU32<{ PERIOD }>;
29+
type Period = ConstU32<{ 5 * MINUTES }>;
3230

3331
impl pallet_session::Config for Runtime {
3432
type Keys = SessionKeys;

0 commit comments

Comments
 (0)