Skip to content

Commit

Permalink
fix: migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
Supremesource committed Nov 26, 2024
1 parent f641913 commit beb4b28
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 41 deletions.
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ try-runtime-upgrade-testnet:

try-runtime-upgrade-mainnet:
cargo build --release --features try-runtime
RUST_BACKTRACE=1; RUST_LOG="${RUST_LOG}"; try-runtime --runtime target/release/wbuild/node-subspace-runtime/node_subspace_runtime.compact.compressed.wasm on-runtime-upgrade --blocktime 8000 live --uri wss://mainnet.api.communeai.net:443
RUST_BACKTRACE=1; RUST_LOG="${RUST_LOG}"; try-runtime --runtime target/release/wbuild/node-subspace-runtime/node_subspace_runtime.compact.compressed.wasm on-runtime-upgrade --blocktime 8000 live --uri wss://api.communeai.net:443

try-runtime-upgrade-devnet:
cargo build --release --features try-runtime
RUST_BACKTRACE=1; RUST_LOG="${RUST_LOG}"; try-runtime --runtime target/release/wbuild/node-subspace-runtime/node_subspace_runtime.compact.compressed.wasm on-runtime-upgrade --blocktime 8000 live --uri wss://devnet-commune-api-node-0.communeai.net:443


run-benchmarking:
cargo build -r --features runtime-benchmarks
Expand Down
51 changes: 11 additions & 40 deletions pallets/subnet_emission/src/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,61 +4,32 @@ use frame_support::{
traits::{OnRuntimeUpgrade, StorageVersion},
};

// pub mod v1 {
// use super::*;

// pub struct MigrateToV1<T>(sp_std::marker::PhantomData<T>);

// impl<T: Config> OnRuntimeUpgrade for MigrateToV1<T> {
// fn on_runtime_upgrade() -> frame_support::weights::Weight {
// let on_chain_version = StorageVersion::get::<Pallet<T>>();
// if on_chain_version != 0 {
// log::info!("Storage v1 already updated");
// return Weight::zero();
// }

// StorageVersion::new(1).put::<Pallet<T>>();

// pallet_subspace::migrations::v15::old_storage::Weights::<T>::iter().for_each(
// |(netuid, uid, values)| {
// log::info!("migrating weights for netuid: {}, uid: {}", netuid, uid);
// Weights::<T>::insert(netuid, uid, values);
// },
// );

// // Just for clarity, (although not explicitly needed)
// let _ =
// pallet_subspace::migrations::v15::old_storage::Weights::<T>::clear(u32::MAX,
// None);

// log::info!("Migrated to v1");

// Weight::zero()
// }
// }
// }

pub mod v1 {
use core::u32;

use super::*;

pub struct MigrateToV1<T>(sp_std::marker::PhantomData<T>);

impl<T: Config> OnRuntimeUpgrade for MigrateToV1<T> {
fn on_runtime_upgrade() -> frame_support::weights::Weight {
let on_chain_version = StorageVersion::get::<Pallet<T>>();
if on_chain_version != 15 {
if on_chain_version != 0 {
log::info!("Storage v1 already updated");
return Weight::zero();
}

StorageVersion::new(16).put::<Pallet<T>>();
StorageVersion::new(1).put::<Pallet<T>>();

let _ = BannedDecryptionNodes::<T>::clear(u32::MAX, None);
let _ = DecryptionNodeBanQueue::<T>::clear(u32::MAX, None);
pallet_subspace::migrations::v15::old_storage::Weights::<T>::iter().for_each(
|(netuid, uid, values)| {
log::info!("migrating weights for netuid: {}, uid: {}", netuid, uid);
Weights::<T>::insert(netuid, uid, values);
},
);

// Just for clarity, (although not explicitly needed)
let _ =
pallet_subspace::migrations::v15::old_storage::Weights::<T>::clear(u32::MAX, None);

log::info!("Migrated to v1");

Weight::zero()
Expand Down

0 comments on commit beb4b28

Please sign in to comment.