diff --git a/pallet/account-migration/Cargo.toml b/pallet/account-migration/Cargo.toml index 9b4273974..9a8b9aa02 100644 --- a/pallet/account-migration/Cargo.toml +++ b/pallet/account-migration/Cargo.toml @@ -9,7 +9,7 @@ version.workspace = true [dependencies] # crates.io array-bytes = { workspace = true } -codec = { workspace = true, package = "parity-scale-codec" } +codec = { workspace = true } scale-info = { workspace = true } # darwinia diff --git a/pallet/asset-limit/Cargo.toml b/pallet/asset-limit/Cargo.toml index ddc19d225..2f6cb2284 100644 --- a/pallet/asset-limit/Cargo.toml +++ b/pallet/asset-limit/Cargo.toml @@ -8,7 +8,7 @@ version.workspace = true [dependencies] # crates.io -codec = { workspace = true, package = "parity-scale-codec" } +codec = { workspace = true } scale-info = { workspace = true } # moonbeam diff --git a/pallet/deposit/Cargo.toml b/pallet/deposit/Cargo.toml index 1f2b2cdf1..97b929656 100644 --- a/pallet/deposit/Cargo.toml +++ b/pallet/deposit/Cargo.toml @@ -8,7 +8,7 @@ version.workspace = true [dependencies] # crates.io -codec = { workspace = true, package = "parity-scale-codec" } +codec = { workspace = true } ethabi = { workspace = true } log = { workspace = true } scale-info = { workspace = true } diff --git a/pallet/ethtx-forwarder/Cargo.toml b/pallet/ethtx-forwarder/Cargo.toml index 45b7b4b8c..debd2b5d7 100644 --- a/pallet/ethtx-forwarder/Cargo.toml +++ b/pallet/ethtx-forwarder/Cargo.toml @@ -8,7 +8,7 @@ version.workspace = true [dependencies] # crates.io -codec = { workspace = true, package = "parity-scale-codec" } +codec = { workspace = true } ethabi = { workspace = true } ethereum = { workspace = true } log = { workspace = true } diff --git a/pallet/staking/Cargo.toml b/pallet/staking/Cargo.toml index 4e05913fe..e8a248fb7 100644 --- a/pallet/staking/Cargo.toml +++ b/pallet/staking/Cargo.toml @@ -8,7 +8,7 @@ version.workspace = true [dependencies] # crates.io -codec = { workspace = true, package = "parity-scale-codec" } +codec = { workspace = true } ethabi = { workspace = true } log = { workspace = true } scale-info = { workspace = true } diff --git a/pallet/staking/src/lib.rs b/pallet/staking/src/lib.rs index 1dcd9b505..b322234ac 100644 --- a/pallet/staking/src/lib.rs +++ b/pallet/staking/src/lib.rs @@ -82,7 +82,7 @@ macro_rules! call_on_exposure { } }}; (<$s:ident<$t:ident>>$($f:tt)*) => {{ - let s = <$crate::ExposureCacheStates<$t>>::get(); + let s = <$crate::CacheStates<$t>>::get(); $crate::call_on_exposure!(s, <$s<$t>>$($f)*) }}; @@ -103,7 +103,7 @@ macro_rules! call_on_cache { } }}; (<$s:ident<$t:ident>>$($f:tt)*) => {{ - let s = <$crate::CollatorsCacheState<$t>>::get(); + let s = <$crate::CacheStates<$t>>::get(); $crate::call_on_cache!(s, <$s<$t>>$($f)*) }}; @@ -215,7 +215,7 @@ pub mod pallet { #[pallet::getter(fn collator_of)] pub type Collators = StorageMap<_, Twox64Concat, T::AccountId, Perbill>; - /// Exposure cache states. + /// Collator/Exposure cache states. /// /// To avoid extra DB RWs during new session, such as: /// ```nocompile @@ -239,15 +239,11 @@ pub mod pallet { /// ``` #[pallet::storage] #[pallet::getter(fn exposure_cache_states)] - pub type ExposureCacheStates = StorageValue< - _, - (CacheState, CacheState, CacheState), - ValueQuery, - ExposureCacheStatesDefault, - >; - /// Default value for [`ExposureCacheStates`]. + pub type CacheStates = + StorageValue<_, (CacheState, CacheState, CacheState), ValueQuery, CacheStatesDefault>; + /// Default value for [`CacheStates`]. #[pallet::type_value] - pub fn ExposureCacheStatesDefault() -> (CacheState, CacheState, CacheState) { + pub fn CacheStatesDefault() -> (CacheState, CacheState, CacheState) { (CacheState::Previous, CacheState::Current, CacheState::Next) } @@ -334,42 +330,6 @@ pub mod pallet { #[pallet::getter(fn migration_start_point)] pub type MigrationStartPoint = StorageValue<_, Moment, ValueQuery>; - /// Collator cache state. - /// - /// To avoid extra DB RWs during new session, such as: - /// ```nocompile - /// previous = current; - /// current = next; - /// next = elect(); - /// ``` - /// - /// Now, with data: - /// ```nocompile - /// cache1 == previous; - /// cache2 == current; - /// cache3 == next; - /// ``` - /// Just need to shift the marker and write the storage map once: - /// ```nocompile - /// mark(cache3, current); - /// mark(cache2, previous); - /// mark(cache1, next); - /// cache1 = elect(); - /// ``` - #[pallet::storage] - #[pallet::getter(fn collator_cache_state)] - pub type CollatorsCacheState = StorageValue< - _, - (CacheState, CacheState, CacheState), - ValueQuery, - CollatorCacheStateDefault, - >; - /// Default value for [`CollatorsCacheState`]. - #[pallet::type_value] - pub fn CollatorCacheStateDefault() -> (CacheState, CacheState, CacheState) { - (CacheState::Previous, CacheState::Current, CacheState::Next) - } - // TODO: use `BoundedVec`. /// Exposure cache 0. #[pallet::storage] @@ -789,8 +749,6 @@ pub mod pallet { for n_exposure in c_exposure.nominators { let n_payout = Perbill::from_rational(n_exposure.vote, c_exposure.vote) * n_payout; - dbg!(n_payout); - if collator == n_exposure.who { // If the collator nominated themselves. @@ -873,13 +831,9 @@ pub mod pallet { /// loop { mutate(2, 0, 1) } /// ``` pub fn shift_cache_states() { - let (s0, s1, s2) = >::get(); - - >::put((s2, s0, s1)); - - let (s0, s1, s2) = >::get(); + let (s0, s1, s2) = >::get(); - >::put((s2, s0, s1)); + >::put((s2, s0, s1)); } /// Elect the new collators. @@ -912,7 +866,7 @@ pub mod pallet { collators.sort_by(|(_, a), (_, b)| b.cmp(a)); - let cache_states = >::get(); + let cache_states = >::get(); collators .into_iter() diff --git a/pallet/staking/src/tests.rs b/pallet/staking/src/tests.rs index 756cd6324..59ed4af91 100644 --- a/pallet/staking/src/tests.rs +++ b/pallet/staking/src/tests.rs @@ -30,7 +30,7 @@ fn exposure_cache_states_should_work() { ExtBuilder::default().build().execute_with(|| { #[allow(deprecated)] { - >::kill(); + >::kill(); >::remove_all(None); >::remove_all(None); >::remove_all(None); @@ -56,7 +56,7 @@ fn exposure_cache_states_should_work() { assert!(call_on_exposure!(>::get(AccountId(1)).is_none()).unwrap()); assert!(call_on_exposure!(>::get(AccountId(2)).is_some()).unwrap()); assert_eq!( - >::get(), + >::get(), (CacheState::Previous, CacheState::Current, CacheState::Next) ); @@ -72,7 +72,7 @@ fn exposure_cache_states_should_work() { assert!(call_on_exposure!(>::get(AccountId(1)).is_none()).unwrap()); assert!(call_on_exposure!(>::get(AccountId(2)).is_none()).unwrap()); assert_eq!( - >::get(), + >::get(), (CacheState::Next, CacheState::Previous, CacheState::Current) ); @@ -88,7 +88,7 @@ fn exposure_cache_states_should_work() { assert!(call_on_exposure!(>::get(AccountId(1)).is_some()).unwrap()); assert!(call_on_exposure!(>::get(AccountId(2)).is_none()).unwrap()); assert_eq!( - >::get(), + >::get(), (CacheState::Current, CacheState::Next, CacheState::Previous) ); @@ -104,7 +104,7 @@ fn exposure_cache_states_should_work() { assert!(call_on_exposure!(>::get(AccountId(1)).is_none()).unwrap()); assert!(call_on_exposure!(>::get(AccountId(2)).is_some()).unwrap()); assert_eq!( - >::get(), + >::get(), (CacheState::Previous, CacheState::Current, CacheState::Next) ); }); @@ -864,19 +864,7 @@ fn hybrid_payout_should_work() { payout(); assert_eq!( - [ - 1_000 * UNIT, - 1_000 * UNIT, - 1_000 * UNIT, - 1_000 * UNIT, - 1_000 * UNIT, - 1_000 * UNIT, - 1_000 * UNIT, - 1_000 * UNIT, - 1_000 * UNIT, - 1_000 * UNIT, - ] - .as_slice(), + [1_000 * UNIT; 10].as_slice(), collators .into_iter() .map(Balances::free_balance) diff --git a/pallet/staking/traits/Cargo.toml b/pallet/staking/traits/Cargo.toml index e1cd88ffd..3e49557a2 100644 --- a/pallet/staking/traits/Cargo.toml +++ b/pallet/staking/traits/Cargo.toml @@ -8,7 +8,7 @@ version.workspace = true [dependencies] # crates.io -codec = { workspace = true, package = "parity-scale-codec" } +codec = { workspace = true } scale-info = { workspace = true } # polkadot-sdk diff --git a/precompile/assets/Cargo.toml b/precompile/assets/Cargo.toml index a567dabf5..4e5e4c329 100644 --- a/precompile/assets/Cargo.toml +++ b/precompile/assets/Cargo.toml @@ -24,7 +24,7 @@ sp-std = { workspace = true } [dev-dependencies] # crates.io -codec = { workspace = true, package = "parity-scale-codec" } +codec = { workspace = true } scale-info = { workspace = true, features = ["std"] } sha3 = { workspace = true } diff --git a/precompile/deposit/Cargo.toml b/precompile/deposit/Cargo.toml index 1791bdbe0..f478498f1 100644 --- a/precompile/deposit/Cargo.toml +++ b/precompile/deposit/Cargo.toml @@ -26,7 +26,7 @@ sp-std = { workspace = true } [dev-dependencies] # crates.io -codec = { workspace = true, package = "parity-scale-codec", features = ["std"] } +codec = { workspace = true, features = ["std"] } scale-info = { workspace = true, features = ["std"] } # moonbeam diff --git a/precompile/staking/Cargo.toml b/precompile/staking/Cargo.toml index 1efd76332..fc1d2c781 100644 --- a/precompile/staking/Cargo.toml +++ b/precompile/staking/Cargo.toml @@ -26,7 +26,7 @@ sp-std = { workspace = true } [dev-dependencies] # crates.io -codec = { workspace = true, package = "parity-scale-codec", features = ["std"] } +codec = { workspace = true, features = ["std"] } scale-info = { workspace = true, features = ["std"] } # darwinia diff --git a/precompile/state-storage/Cargo.toml b/precompile/state-storage/Cargo.toml index d49379ee4..eab420fd0 100644 --- a/precompile/state-storage/Cargo.toml +++ b/precompile/state-storage/Cargo.toml @@ -20,7 +20,7 @@ sp-std = { workspace = true } [dev-dependencies] # crates.io -codec = { workspace = true, package = "parity-scale-codec", features = ["std"] } +codec = { workspace = true, features = ["std"] } scale-info = { workspace = true, features = ["std"] } # moonbeam diff --git a/runtime/common/Cargo.toml b/runtime/common/Cargo.toml index f475d989e..981b81375 100644 --- a/runtime/common/Cargo.toml +++ b/runtime/common/Cargo.toml @@ -8,7 +8,7 @@ version.workspace = true [dependencies] # crates.io -codec = { workspace = true, package = "parity-scale-codec" } +codec = { workspace = true } log = { workspace = true } scale-info = { workspace = true } smallvec = { version = "1.10" } diff --git a/runtime/crab/Cargo.toml b/runtime/crab/Cargo.toml index f0b95255a..f18a67bba 100644 --- a/runtime/crab/Cargo.toml +++ b/runtime/crab/Cargo.toml @@ -12,7 +12,7 @@ substrate-wasm-builder = { workspace = true, optional = true } [dependencies] # crates.io -codec = { workspace = true, package = "parity-scale-codec" } +codec = { workspace = true } log = { workspace = true } scale-info = { workspace = true } strum = { workspace = true, features = ["derive"] } diff --git a/runtime/crab/src/migration.rs b/runtime/crab/src/migration.rs index f36834591..51935f86e 100644 --- a/runtime/crab/src/migration.rs +++ b/runtime/crab/src/migration.rs @@ -45,6 +45,16 @@ impl frame_support::traits::OnRuntimeUpgrade for CustomOnRuntimeUpgrade { } fn migrate() -> frame_support::weights::Weight { - frame_support::weights::Weight::zero() - // ::DbWeight::get().reads_writes(10, 10) + // 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); + } + + // frame_support::weights::Weight::zero() + ::DbWeight::get().reads_writes(1, 1) } diff --git a/runtime/darwinia/Cargo.toml b/runtime/darwinia/Cargo.toml index 8468aab32..f8f0f8d59 100644 --- a/runtime/darwinia/Cargo.toml +++ b/runtime/darwinia/Cargo.toml @@ -12,7 +12,7 @@ substrate-wasm-builder = { workspace = true, optional = true } [dependencies] # crates.io -codec = { workspace = true, package = "parity-scale-codec" } +codec = { workspace = true } log = { workspace = true } scale-info = { workspace = true } strum = { workspace = true, features = ["derive"] } diff --git a/runtime/darwinia/src/migration.rs b/runtime/darwinia/src/migration.rs index 29ced7b78..53a7a98d5 100644 --- a/runtime/darwinia/src/migration.rs +++ b/runtime/darwinia/src/migration.rs @@ -53,6 +53,16 @@ fn migrate() -> frame_support::weights::Weight { 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); + } + // frame_support::weights::Weight::zero() - ::DbWeight::get().reads_writes(0, 100) + ::DbWeight::get().reads_writes(1, 101) } diff --git a/runtime/koi/Cargo.toml b/runtime/koi/Cargo.toml index ec3f6beb3..c4cf7a1e4 100644 --- a/runtime/koi/Cargo.toml +++ b/runtime/koi/Cargo.toml @@ -13,7 +13,7 @@ substrate-wasm-builder = { workspace = true, optional = true } [dependencies] # crates.io array-bytes = { workspace = true } -codec = { workspace = true, package = "parity-scale-codec" } +codec = { workspace = true } log = { workspace = true } scale-info = { workspace = true } strum = { workspace = true, features = ["derive"] } diff --git a/runtime/koi/src/migration.rs b/runtime/koi/src/migration.rs index 5047bc277..743e5e352 100644 --- a/runtime/koi/src/migration.rs +++ b/runtime/koi/src/migration.rs @@ -45,6 +45,19 @@ impl frame_support::traits::OnRuntimeUpgrade for CustomOnRuntimeUpgrade { } fn migrate() -> frame_support::weights::Weight { - frame_support::weights::Weight::zero() - // ::DbWeight::get().reads_writes(0, 1) + 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); + } + + // frame_support::weights::Weight::zero() + ::DbWeight::get().reads_writes(1, 2) }