Skip to content
Merged
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
2 changes: 2 additions & 0 deletions pallets/subtensor/src/macros/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,5 +262,7 @@ mod errors {
UidMapCouldNotBeCleared,
/// Trimming would exceed the max immune neurons percentage
TrimmingWouldExceedMaxImmunePercentage,
/// Violating the rules of Childkey-Parentkey consistency
ChildParentInconsistency,
}
}
2 changes: 2 additions & 0 deletions pallets/subtensor/src/macros/hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ mod hooks {
.saturating_add(migrations::migrate_subnet_locked::migrate_restore_subnet_locked::<T>())
// Migrate subnet burn cost to 2500
.saturating_add(migrations::migrate_network_lock_cost_2500::migrate_network_lock_cost_2500::<T>())
// Cleanup child/parent keys
.saturating_add(migrations::migrate_fix_childkeys::migrate_fix_childkeys::<T>())
// Migrate AutoStakeDestinationColdkeys
.saturating_add(migrations::migrate_auto_stake_destination::migrate_auto_stake_destination::<T>());
weight
Expand Down
40 changes: 40 additions & 0 deletions pallets/subtensor/src/migrations/migrate_fix_childkeys.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
use super::*;
use alloc::string::String;

pub fn migrate_fix_childkeys<T: Config>() -> Weight {
let migration_name = b"migrate_fix_childkeys".to_vec();
let mut weight = T::DbWeight::get().reads(1);

if HasMigrationRun::<T>::get(&migration_name) {
log::info!(
"Migration '{:?}' has already run. Skipping.",
String::from_utf8_lossy(&migration_name)
);
return weight;
}

log::info!(
"Running migration '{}'",
String::from_utf8_lossy(&migration_name)
);

////////////////////////////////////////////////////////
// Actual migration

Pallet::<T>::clean_zero_childkey_vectors(&mut weight);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you consider iterating through the child and parent key maps once and passing collected values into the substeps?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but after clean_zero_childkey_vectors the number of keys in both maps is significantly reduced, so it is not worth the added complexity. Also, we've done heavier migrations in the past, so this one will pass.

Pallet::<T>::clean_zero_parentkey_vectors(&mut weight);
Pallet::<T>::clean_self_loops(&mut weight);
Pallet::<T>::repair_child_parent_consistency(&mut weight);

////////////////////////////////////////////////////////

HasMigrationRun::<T>::insert(&migration_name, true);
weight = weight.saturating_add(T::DbWeight::get().writes(1));

log::info!(
target: "runtime",
"Migration '{}' completed successfully.",
String::from_utf8_lossy(&migration_name)
);
weight
}
1 change: 1 addition & 0 deletions pallets/subtensor/src/migrations/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub mod migrate_crv3_v2_to_timelocked;
pub mod migrate_delete_subnet_21;
pub mod migrate_delete_subnet_3;
pub mod migrate_disable_commit_reveal;
pub mod migrate_fix_childkeys;
pub mod migrate_fix_is_network_member;
pub mod migrate_fix_root_subnet_tao;
pub mod migrate_fix_root_tao_and_alpha_in;
Expand Down
Loading
Loading