Skip to content

Commit

Permalink
migration code
Browse files Browse the repository at this point in the history
  • Loading branch information
girazoki committed Jan 29, 2025
1 parent 145aa8d commit 4f51dc6
Showing 3 changed files with 50 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions chains/orchestrator-paras/runtime/common/Cargo.toml
Original file line number Diff line number Diff line change
@@ -22,6 +22,7 @@ scale-info = { workspace = true, features = [ "derive" ] }
pallet-configuration = { workspace = true }
pallet-data-preservers = { workspace = true }
pallet-external-validators = { workspace = true }
pallet-external-validator-slashes = { workspace = true }
pallet-foreign-asset-creator = { workspace = true }
pallet-invulnerables = { workspace = true }
pallet-pooled-staking = { workspace = true }
@@ -50,6 +51,7 @@ staging-xcm = { workspace = true }

sp-core = { workspace = true }
sp-runtime = { workspace = true }
sp-staking = { workspace = true }
sp-std = { workspace = true }

# Cumulus
@@ -70,6 +72,7 @@ std = [
"pallet-beefy-mmr/std",
"pallet-configuration/std",
"pallet-data-preservers/std",
"pallet-external-validator-slashes/std",
"pallet-external-validators/std",
"pallet-foreign-asset-creator/std",
"pallet-invulnerables/std",
@@ -84,6 +87,7 @@ std = [
"scale-info/std",
"sp-core/std",
"sp-runtime/std",
"sp-staking/std",
"sp-std/std",
"staging-xcm/std",
]
@@ -97,6 +101,7 @@ runtime-benchmarks = [
"pallet-beefy-mmr/runtime-benchmarks",
"pallet-configuration/runtime-benchmarks",
"pallet-data-preservers/runtime-benchmarks",
"pallet-external-validator-slashes/runtime-benchmarks",
"pallet-external-validators/runtime-benchmarks",
"pallet-foreign-asset-creator/runtime-benchmarks",
"pallet-invulnerables/runtime-benchmarks",
43 changes: 43 additions & 0 deletions chains/orchestrator-paras/runtime/common/src/migrations.rs
Original file line number Diff line number Diff line change
@@ -1024,6 +1024,45 @@ impl<T> MigrateMMRLeafPallet<T> {
}
}

pub struct BondedErasTimestampMigration<Runtime>(pub PhantomData<Runtime>);

impl<Runtime> Migration for BondedErasTimestampMigration<Runtime>
where
Runtime: pallet_external_validator_slashes::Config,
{
fn friendly_name(&self) -> &str {
"TM_ExternalValidatorSlashesBondedErasTimestampMigration"
}

fn migrate(&self, _available_weight: Weight) -> Weight {
use frame_support::pallet_prelude::*;

let bonded_eras: Vec<(sp_staking::EraIndex, sp_staking::SessionIndex)> =
frame_support::storage::unhashed::get(
&pallet_external_validator_slashes::BondedEras::<Runtime>::hashed_key(),
)
.unwrap_or_default();
let new_eras = bonded_eras
.iter()
.map(|(era, session)| (*era, *session, 0u64))
.collect();
pallet_external_validator_slashes::BondedEras::<Runtime>::set(new_eras);

// One db read and one db write per element, plus the on-chain storage
Runtime::DbWeight::get().reads_writes(1, 1)
}

#[cfg(feature = "try-runtime")]
fn pre_upgrade(&self) -> Result<Vec<u8>, sp_runtime::DispatchError> {
Ok(vec![])
}

#[cfg(feature = "try-runtime")]
fn post_upgrade(&self, _state: Vec<u8>) -> Result<(), sp_runtime::DispatchError> {
Ok(())
}
}

pub struct DancelightMigrations<Runtime>(PhantomData<Runtime>);

impl<Runtime> GetMigrations for DancelightMigrations<Runtime>
@@ -1034,18 +1073,22 @@ where
Runtime: pallet_session::Config<
ValidatorId = <Runtime as pallet_external_validators::Config>::ValidatorId,
>,
Runtime: pallet_external_validator_slashes::Config,
{
fn get_migrations() -> Vec<Box<dyn Migration>> {
let migrate_mmr_leaf_pallet = MigrateMMRLeafPallet::<Runtime>(Default::default());
let migrate_external_validators =
ExternalValidatorsInitialMigration::<Runtime>(Default::default());
let migrate_config_full_rotation_mode =
MigrateConfigurationAddFullRotationMode::<Runtime>(Default::default());

let external_validator_slashes_bonded_eras_timestamp = BondedErasTimestampMigration::<Runtime>(Default::default());

vec![
Box::new(migrate_mmr_leaf_pallet),
Box::new(migrate_external_validators),
Box::new(migrate_config_full_rotation_mode),
Box::new(external_validator_slashes_bonded_eras_timestamp),
]
}
}

0 comments on commit 4f51dc6

Please sign in to comment.