Skip to content

Commit cf157c5

Browse files
authored
Merge pull request #2116 from opentensor/fix/child-parent-setting
Refactor childkeys/parentkeys, add migration to clean state
2 parents be43bed + 1b9eb7d commit cf157c5

File tree

9 files changed

+918
-140
lines changed

9 files changed

+918
-140
lines changed

pallets/subtensor/src/macros/errors.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,5 +262,7 @@ mod errors {
262262
UidMapCouldNotBeCleared,
263263
/// Trimming would exceed the max immune neurons percentage
264264
TrimmingWouldExceedMaxImmunePercentage,
265+
/// Violating the rules of Childkey-Parentkey consistency
266+
ChildParentInconsistency,
265267
}
266268
}

pallets/subtensor/src/macros/hooks.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ mod hooks {
150150
.saturating_add(migrations::migrate_subnet_locked::migrate_restore_subnet_locked::<T>())
151151
// Migrate subnet burn cost to 2500
152152
.saturating_add(migrations::migrate_network_lock_cost_2500::migrate_network_lock_cost_2500::<T>())
153+
// Cleanup child/parent keys
154+
.saturating_add(migrations::migrate_fix_childkeys::migrate_fix_childkeys::<T>())
153155
// Migrate AutoStakeDestinationColdkeys
154156
.saturating_add(migrations::migrate_auto_stake_destination::migrate_auto_stake_destination::<T>());
155157
weight
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
use super::*;
2+
use alloc::string::String;
3+
4+
pub fn migrate_fix_childkeys<T: Config>() -> Weight {
5+
let migration_name = b"migrate_fix_childkeys".to_vec();
6+
let mut weight = T::DbWeight::get().reads(1);
7+
8+
if HasMigrationRun::<T>::get(&migration_name) {
9+
log::info!(
10+
"Migration '{:?}' has already run. Skipping.",
11+
String::from_utf8_lossy(&migration_name)
12+
);
13+
return weight;
14+
}
15+
16+
log::info!(
17+
"Running migration '{}'",
18+
String::from_utf8_lossy(&migration_name)
19+
);
20+
21+
////////////////////////////////////////////////////////
22+
// Actual migration
23+
24+
Pallet::<T>::clean_zero_childkey_vectors(&mut weight);
25+
Pallet::<T>::clean_zero_parentkey_vectors(&mut weight);
26+
Pallet::<T>::clean_self_loops(&mut weight);
27+
Pallet::<T>::repair_child_parent_consistency(&mut weight);
28+
29+
////////////////////////////////////////////////////////
30+
31+
HasMigrationRun::<T>::insert(&migration_name, true);
32+
weight = weight.saturating_add(T::DbWeight::get().writes(1));
33+
34+
log::info!(
35+
target: "runtime",
36+
"Migration '{}' completed successfully.",
37+
String::from_utf8_lossy(&migration_name)
38+
);
39+
weight
40+
}

pallets/subtensor/src/migrations/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ pub mod migrate_crv3_v2_to_timelocked;
1515
pub mod migrate_delete_subnet_21;
1616
pub mod migrate_delete_subnet_3;
1717
pub mod migrate_disable_commit_reveal;
18+
pub mod migrate_fix_childkeys;
1819
pub mod migrate_fix_is_network_member;
1920
pub mod migrate_fix_root_subnet_tao;
2021
pub mod migrate_fix_root_tao_and_alpha_in;

0 commit comments

Comments
 (0)