Skip to content

Commit 7a40853

Browse files
committed
only reset the pending em
1 parent 6053ed5 commit 7a40853

File tree

2 files changed

+8
-84
lines changed

2 files changed

+8
-84
lines changed

pallets/subtensor/src/migrations/migrate_reset_unactive_sn.rs

Lines changed: 2 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
use super::*;
2-
use sp_std::collections::{btree_map::BTreeMap, btree_set::BTreeSet};
3-
4-
use subtensor_swap_interface::SwapHandler;
52

63
pub fn get_unactive_sn_netuids<T: Config>(
74
pool_initial_alpha: AlphaCurrency,
@@ -51,37 +48,6 @@ pub fn migrate_reset_unactive_sn<T: Config>() -> Weight {
5148
let (unactive_netuids, w) = get_unactive_sn_netuids::<T>(pool_initial_alpha);
5249
weight = weight.saturating_add(w);
5350

54-
// Collect the hotkeys to remove for each subnet
55-
let mut to_remove_alpha_hotkeys: BTreeMap<NetUid, Vec<T::AccountId>> = BTreeMap::new();
56-
let mut to_remove_alpha_coldkeys: BTreeMap<NetUid, Vec<(T::AccountId, T::AccountId)>> =
57-
BTreeMap::new();
58-
let mut all_hotkeys_set = BTreeSet::new();
59-
for (hotkey, netuid_i, _) in TotalHotkeyAlpha::<T>::iter() {
60-
weight = weight.saturating_add(T::DbWeight::get().reads(1));
61-
if unactive_netuids.contains(&netuid_i) {
62-
// Only for unactive subnets
63-
to_remove_alpha_hotkeys
64-
.entry(netuid_i)
65-
.or_insert(Vec::new())
66-
.push(hotkey.clone());
67-
all_hotkeys_set.insert(hotkey);
68-
}
69-
}
70-
71-
// Collect the coldkeys to remove for each subnet
72-
for hotkey in all_hotkeys_set.iter() {
73-
for ((coldkey, netuid_i), _) in Alpha::<T>::iter_prefix((&hotkey,)) {
74-
weight = weight.saturating_add(T::DbWeight::get().reads(1));
75-
if unactive_netuids.contains(&netuid_i) {
76-
// Only for unactive subnets
77-
to_remove_alpha_coldkeys
78-
.entry(netuid_i)
79-
.or_insert(Vec::new())
80-
.push((hotkey.clone(), coldkey));
81-
}
82-
}
83-
}
84-
8551
for netuid in unactive_netuids.iter() {
8652
// Reset the subnet as it shouldn't have any emissions
8753
PendingServerEmission::<T>::remove(*netuid);
@@ -92,55 +58,11 @@ pub fn migrate_reset_unactive_sn<T: Config>() -> Weight {
9258
SubnetAlphaInEmission::<T>::remove(*netuid);
9359
SubnetAlphaOutEmission::<T>::remove(*netuid);
9460
weight = weight.saturating_add(T::DbWeight::get().writes(7));
95-
96-
// Reset v3 pool
97-
let burned_tao = match T::SwapInterface::clear_protocol_liquidity(*netuid) {
98-
Ok((_tao, fee_tao, _alpha, _fee_alpha)) => fee_tao,
99-
Err(e) => {
100-
log::error!("Failed to clear protocol liquidity for netuid {netuid:?}: {e:?}");
101-
TaoCurrency::ZERO
102-
}
103-
};
104-
Pallet::<T>::recycle_tao(burned_tao);
105-
// might be based on ticks but this is a rough estimate
106-
weight = weight.saturating_add(T::DbWeight::get().reads_writes(6, 14));
107-
108-
// Recycle already emitted TAO
109-
// or mint 1 TAO to the pool
110-
let subnet_tao = SubnetTAO::<T>::get(*netuid);
111-
if subnet_tao > pool_initial_tao {
112-
let tao_to_recycle = subnet_tao.saturating_sub(pool_initial_tao);
113-
Pallet::<T>::recycle_tao(tao_to_recycle);
114-
TotalStake::<T>::mutate(|total| {
115-
*total = total.saturating_sub(tao_to_recycle);
116-
});
117-
SubnetTAO::<T>::mutate(*netuid, |amount| {
118-
*amount = amount.saturating_sub(tao_to_recycle);
119-
});
120-
weight = weight.saturating_add(T::DbWeight::get().reads_writes(3, 3));
121-
} else if subnet_tao < pool_initial_tao {
122-
let tao_to_add = pool_initial_tao.saturating_sub(subnet_tao);
123-
TotalStake::<T>::mutate(|total| {
124-
*total = total.saturating_add(tao_to_add);
125-
});
126-
SubnetTAO::<T>::mutate(*netuid, |amount| {
127-
*amount = amount.saturating_add(tao_to_add);
128-
});
129-
TotalIssuance::<T>::mutate(|total| {
130-
*total = total.saturating_add(tao_to_add);
131-
});
132-
weight = weight.saturating_add(T::DbWeight::get().reads_writes(3, 3));
133-
}
134-
135-
// Reset pool alpha
136-
SubnetAlphaIn::<T>::insert(*netuid, pool_initial_alpha);
137-
// Reset volume
138-
SubnetVolume::<T>::insert(*netuid, 0u128);
139-
weight = weight.saturating_add(T::DbWeight::get().writes(4));
14061
}
14162

14263
// Run total issuance migration
143-
crate::migrations::migrate_init_total_issuance::migrate_init_total_issuance::<T>();
64+
let ti_w = crate::migrations::migrate_init_total_issuance::migrate_init_total_issuance::<T>();
65+
weight = weight.saturating_add(ti_w);
14466

14567
// Mark Migration as Completed
14668
HasMigrationRun::<T>::insert(&migration_name, true);

pallets/subtensor/src/tests/migration.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2577,10 +2577,12 @@ fn test_migrate_reset_unactive_sn() {
25772577
RAORecycledForRegistration::<Test>::get(netuid),
25782578
actual_tao_lock_amount_less_pool_tao
25792579
);
2580-
assert!(!pallet_subtensor_swap::AlphaSqrtPrice::<Test>::contains_key(*netuid));
2580+
assert!(pallet_subtensor_swap::AlphaSqrtPrice::<Test>::contains_key(
2581+
*netuid
2582+
));
25812583
assert_eq!(PendingOwnerCut::<Test>::get(netuid), AlphaCurrency::ZERO);
2582-
assert_eq!(SubnetTAO::<Test>::get(netuid), initial_tao);
2583-
assert_eq!(SubnetAlphaIn::<Test>::get(netuid), initial_alpha);
2584+
assert_ne!(SubnetTAO::<Test>::get(netuid), initial_tao);
2585+
assert_ne!(SubnetAlphaIn::<Test>::get(netuid), initial_alpha);
25842586
assert_ne!(SubnetAlphaOut::<Test>::get(netuid), AlphaCurrency::ZERO);
25852587
assert_eq!(SubnetTaoInEmission::<Test>::get(netuid), TaoCurrency::ZERO);
25862588
assert_eq!(
@@ -2591,7 +2593,7 @@ fn test_migrate_reset_unactive_sn() {
25912593
SubnetAlphaOutEmission::<Test>::get(netuid),
25922594
AlphaCurrency::ZERO
25932595
);
2594-
assert_eq!(SubnetVolume::<Test>::get(netuid), 0u128);
2596+
assert_ne!(SubnetVolume::<Test>::get(netuid), 0u128);
25952597
for hotkey in 0..10 {
25962598
let hk = U256::from(hotkey);
25972599
assert_ne!(

0 commit comments

Comments
 (0)