Skip to content

Commit 0ff5f9a

Browse files
committed
wip
1 parent dcda87b commit 0ff5f9a

File tree

4 files changed

+67
-1
lines changed

4 files changed

+67
-1
lines changed

pallets/subtensor/src/coinbase/root.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,7 @@ impl<T: Config> Pallet<T> {
527527

528528
// --- 7. Remove incentive mechanism memory.
529529
let _ = Uids::<T>::clear_prefix(netuid, u32::MAX, None);
530+
let keys = Keys::<T>::iter_prefix(netuid).collect::<Vec<_>>();
530531
let _ = Keys::<T>::clear_prefix(netuid, u32::MAX, None);
531532
let _ = Bonds::<T>::clear_prefix(netuid, u32::MAX, None);
532533

@@ -564,6 +565,10 @@ impl<T: Config> Pallet<T> {
564565
ValidatorPermit::<T>::remove(netuid);
565566
ValidatorTrust::<T>::remove(netuid);
566567

568+
for key in keys {
569+
IsNetworkMember::<T>::remove(key, netuid);
570+
}
571+
567572
// --- 11. Erase network parameters.
568573
Tempo::<T>::remove(netuid);
569574
Kappa::<T>::remove(netuid);

pallets/subtensor/src/macros/hooks.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ mod hooks {
7474
// Migrate Commit-Reval 2.0
7575
.saturating_add(migrations::migrate_commit_reveal_v2::migrate_commit_reveal_2::<T>())
7676
// Migrate to RAO
77-
.saturating_add(migrations::migrate_rao::migrate_rao::<T>());
77+
.saturating_add(migrations::migrate_rao::migrate_rao::<T>())
78+
// Fix the IsNetworkMember map to be consistent with other storage maps
79+
.saturating_add(migrations::migrate_fix_is_network_member::migrate_fix_is_network_member::<T>());
7880
weight
7981
}
8082

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
use super::*;
2+
use alloc::string::String;
3+
use frame_support::{traits::Get, weights::Weight};
4+
use log;
5+
6+
pub fn migrate_fix_is_network_member<T: Config>() -> Weight {
7+
let migration_name = b"migrate_fix_is_network_member".to_vec();
8+
9+
// Initialize the weight with one read operation.
10+
let mut weight = T::DbWeight::get().reads(1);
11+
12+
// Check if the migration has already run
13+
if HasMigrationRun::<T>::get(&migration_name) {
14+
log::info!(
15+
"Migration '{:?}' has already run. Skipping.",
16+
migration_name
17+
);
18+
return weight;
19+
}
20+
log::info!(
21+
"Running migration '{}'",
22+
String::from_utf8_lossy(&migration_name)
23+
);
24+
25+
weight = do_fix_is_network_member::<T>(weight);
26+
27+
// Mark the migration as completed
28+
HasMigrationRun::<T>::insert(&migration_name, true);
29+
weight = weight.saturating_add(T::DbWeight::get().writes(1));
30+
31+
log::info!(
32+
"Migration '{:?}' completed. Storage version set to 7.",
33+
String::from_utf8_lossy(&migration_name)
34+
);
35+
36+
// Return the migration weight.
37+
weight
38+
}
39+
40+
fn do_fix_is_network_member<T: Config>(weight: Weight) -> Weight {
41+
// Clear the IsNetworkMember storage
42+
let mut curr = IsNetworkMember::<T>::clear(U32::MAX, None);
43+
weight = weight.saturating_add(T::DbWeight::get().reads_writes(curr.loops, curr.unique));
44+
while curr.maybe_cursor.is_some() {
45+
// Clear until empty
46+
curr = IsNetworkMember::<T>::clear(U32::MAX, curr.maybe_cursor);
47+
weight = weight.saturating_add(T::DbWeight::get().reads_writes(curr.loops, curr.unique));
48+
}
49+
// Repopulate the IsNetworkMember storage using the Keys map
50+
let netuids = Subtensor::<T>::get_all_subnet_netuids();
51+
for netuid in netuids {
52+
for key in Keys::<T>::iter_prefix(netuid) {
53+
IsNetworkMember::<T>::insert(key, netuid, true);
54+
}
55+
}
56+
57+
weight
58+
}

pallets/subtensor/src/migrations/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ pub mod migrate_commit_reveal_v2;
44
pub mod migrate_create_root_network;
55
pub mod migrate_delete_subnet_21;
66
pub mod migrate_delete_subnet_3;
7+
pub mod migrate_fix_is_network_member;
78
pub mod migrate_fix_total_coldkey_stake;
89
pub mod migrate_init_total_issuance;
910
pub mod migrate_populate_owned_hotkeys;

0 commit comments

Comments
 (0)