11use super :: * ;
2- use sp_std:: collections:: { btree_map:: BTreeMap , btree_set:: BTreeSet } ;
3-
4- use subtensor_swap_interface:: SwapHandler ;
52
63pub 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 ) ;
0 commit comments