Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename OnDemandAssignmentProvider to OnDemand on Kusama #417

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Asset Hubs: setup auto incremented asset id to 50_000_000 for trust backed assets ([polkadot-fellows/runtimes#414](https://github.com/polkadot-fellows/runtimes/pull/414)).
- Upgrade dependencies to the [[email protected]](https://github.com/paritytech/polkadot-sdk/releases/tag/polkadot-v1.13.0) release ([polkadot-fellows/runtimes#332](https://github.com/polkadot-fellows/runtimes/pull/332)).
- Filter `interlace` calls on the Polkadot Coretime Chain until the Relay chain implementation is more mature ([polkadot-fellows/runtimes#438](https://github.com/polkadot-fellows/runtimes/pull/438)).
- Kusama, pallet OnDemandAssignmentProvider: renamed to OnDemand ([polkadot-fellows/runtimes#417](https://github.com/polkadot-fellows/runtimes/pull/417))

#### From [#322](https://github.com/polkadot-fellows/runtimes/pull/322):

Expand Down
71 changes: 69 additions & 2 deletions relay/kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1727,7 +1727,7 @@ construct_runtime! {
ParaSessionInfo: parachains_session_info = 61,
ParasDisputes: parachains_disputes = 62,
ParasSlashing: parachains_slashing = 63,
OnDemandAssignmentProvider: parachains_assigner_on_demand = 64,
OnDemand: parachains_assigner_on_demand = 64,
CoretimeAssignmentProvider: parachains_assigner_coretime = 65,

// Parachain Onboarding Pallets. Start indices at 70 to leave room.
Expand Down Expand Up @@ -1795,13 +1795,80 @@ pub type Migrations = (migrations::Unreleased, migrations::Permanent);
#[allow(deprecated, missing_docs)]
pub mod migrations {
use super::*;
#[cfg(feature = "try-runtime")]
use frame_support::storage::PrefixIterator;
use frame_support::{
migration::move_pallet,
traits::{GetStorageVersion, OnRuntimeUpgrade, PalletInfoAccess},
};
#[cfg(feature = "try-runtime")]
use sp_io::hashing::twox_128;

// Migrate storage for pallet rename `OnDemandAssignmentProvider` -> `OnDemand`.
pub struct OnDemandRename;
impl OnDemandRename {
const OLD_PALLET_NAME: &'static str = "OnDemandAssignmentProvider";
}
impl OnRuntimeUpgrade for OnDemandRename {
#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<Vec<u8>, sp_runtime::TryRuntimeError> {
let old_pallet_prefix = twox_128(Self::OLD_PALLET_NAME.as_bytes());
let iter = PrefixIterator::<_>::new(
old_pallet_prefix.to_vec(),
old_pallet_prefix.to_vec(),
|k, v| Ok((k.to_vec(), v.to_vec())),
);

let mut count = 0;
for (k, v) in iter {
log::trace!(target: "runtime", "Found storage keys before running OnDemandRename: {:x?}", k);
count += 1;
}

log::trace!(target: "runtime", "Before running OnDemandRename: {} keys found for prefix {:x?}", count, old_pallet_prefix);

Ok(Vec::new())
}

fn on_runtime_upgrade() -> Weight {
// todo: version check

log::info!(target: "runtime", "Applying OnDemandRename");

let new_pallet = <OnDemand as PalletInfoAccess>::name();
move_pallet(Self::OLD_PALLET_NAME.as_bytes(), new_pallet.as_bytes());
<Runtime as frame_system::Config>::DbWeight::get().reads_writes(0, 0) //todo: set proper weights
}

#[cfg(feature = "try-runtime")]
fn post_upgrade(_state: Vec<u8>) -> Result<(), sp_runtime::TryRuntimeError> {
let old_pallet_prefix = twox_128(Self::OLD_PALLET_NAME.as_bytes());
let count = PrefixIterator::<_>::new(
old_pallet_prefix.to_vec(),
old_pallet_prefix.to_vec(),
|_, _| Ok(()),
)
.count();

log::trace!(target: "runtime", "After running OnDemandRename: {} old keys found", count);

if count == 0 {
Ok(())
} else {
Err(sp_runtime::TryRuntimeError::Other(
"OnDemandRename failed - keys with the old prefix still exist",
))
}
}
}

/// Unreleased migrations. Add new ones here:
pub type Unreleased = (
parachains_configuration::migration::v12::MigrateToV12<Runtime>,
pallet_staking::migrations::v15::MigrateV14ToV15<Runtime>,
parachains_inclusion::migration::MigrateToV1<Runtime>,
parachains_assigner_on_demand::migration::MigrateV0ToV1<Runtime>,
OnDemandRename,
);

/// Migrations/checks that do not need to be versioned and can run on every update.
Expand Down Expand Up @@ -1840,7 +1907,7 @@ mod benches {
[runtime_parachains::initializer, Initializer]
[runtime_parachains::paras_inherent, ParaInherent]
[runtime_parachains::paras, Paras]
[runtime_parachains::assigner_on_demand, OnDemandAssignmentProvider]
[runtime_parachains::assigner_on_demand, OnDemand]
[runtime_parachains::coretime, Coretime]
// Substrate
[pallet_balances, Native]
Expand Down
Loading