Skip to content

Commit 1380a42

Browse files
authored
Merge pull request #279 from paritytech/bump-collator-staking
Upgrade pallet-collator-staking
2 parents 80255a9 + 60fa058 commit 1380a42

File tree

4 files changed

+37
-5
lines changed

4 files changed

+37
-5
lines changed

Cargo.lock

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ pallet-nfts = { path = "pallets/nfts", default-features = false }
4949
pallet-myth-proxy = { path = "pallets/myth-proxy", default-features = false }
5050

5151
# External pallets
52-
pallet-collator-staking = { git = "https://github.com/blockdeep/pallet-collator-staking.git", tag = "v1.2.2", default-features = false }
52+
pallet-collator-staking = { git = "https://github.com/blockdeep/pallet-collator-staking.git", tag = "v1.2.3", default-features = false }
5353

5454
# Substrate
5555
frame-benchmarking = { git = "https://github.com/paritytech/polkadot-sdk", tag = "polkadot-stable2412-1", default-features = false }

runtime/testnet/src/lib.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ extern crate alloc; // Make the WASM binary available.
66
#[cfg(feature = "std")]
77
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
88

9+
mod migration;
910
mod weights;
1011
pub mod xcm_config;
1112

@@ -135,7 +136,7 @@ impl frame_support::traits::OnRuntimeUpgrade for PrepareForMove {
135136
}
136137

137138
/// Pending migrations to be applied.
138-
pub type Migrations = ();
139+
pub type Migrations = (migration::ResetCollatorStakingRewardsRuntimeMigration,);
139140

140141
/// Executive: handles dispatch to the various modules.
141142
pub type Executive = frame_executive::Executive<
@@ -288,7 +289,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
288289
spec_name: alloc::borrow::Cow::Borrowed("muse"),
289290
impl_name: alloc::borrow::Cow::Borrowed("muse"),
290291
authoring_version: 1,
291-
spec_version: 1023,
292+
spec_version: 1024,
292293
impl_version: 0,
293294
apis: RUNTIME_API_VERSIONS,
294295
transaction_version: 1,

runtime/testnet/src/migration.rs

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//! # ResetCollatorStakingRewardsRuntimeMigration
2+
//!
3+
//! This migration is responsible for resetting the collator staking rewards.
4+
//! It ensures that any polluted state pertaining to `pallet-collator-staking` is cleared
5+
//! from the chain, allowing the new logic in the pallet to take effect without issues.
6+
//!
7+
//! The migration clears all per-session rewards and claimable rewards, ensuring
8+
//! a clean state moving forward. Note this migration must be applied only once.
9+
10+
use crate::Runtime;
11+
use frame_support::{traits::OnRuntimeUpgrade, weights::Weight};
12+
use sp_runtime::RuntimeDebug;
13+
14+
#[derive(RuntimeDebug)]
15+
pub struct ResetCollatorStakingRewardsRuntimeMigration;
16+
17+
impl OnRuntimeUpgrade for ResetCollatorStakingRewardsRuntimeMigration {
18+
fn on_runtime_upgrade() -> Weight {
19+
log::info!("Starting ResetCollatorStakingRewardsRuntimeMigration...");
20+
21+
let iterations =
22+
pallet_collator_staking::PerSessionRewards::<Runtime>::clear(u32::MAX, None).loops
23+
as u64;
24+
pallet_collator_staking::ClaimableRewards::<Runtime>::kill();
25+
26+
log::info!("ResetCollatorStakingRewardsRuntimeMigration completed.");
27+
28+
<Runtime as frame_system::Config>::DbWeight::get()
29+
.reads_writes(iterations, iterations.saturating_add(1))
30+
}
31+
}

0 commit comments

Comments
 (0)