Skip to content

Commit 704e42f

Browse files
committed
change total issuance during migration to resolve epsilon issue
1 parent 9004a01 commit 704e42f

File tree

1 file changed

+30
-6
lines changed

1 file changed

+30
-6
lines changed

pallets/subtensor/src/migrations/migrate_dissolve_sn73.rs

+30-6
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,18 @@ pub fn migrate_dissolve_sn73<T: Config>() -> Weight {
3636
weight = weight.saturating_add(T::DbWeight::get().reads(1));
3737
log::debug!("Subnet TAO: {}", subnet_tao);
3838

39+
// Adjust total stake and total issuance
40+
TotalStake::<T>::mutate(|total| {
41+
*total = total.saturating_sub(subnet_tao.saturating_to_num::<u64>());
42+
});
43+
TotalIssuance::<T>::mutate(|total| {
44+
*total = total.saturating_sub(subnet_tao.saturating_to_num::<u64>());
45+
});
46+
weight = weight.saturating_add(T::DbWeight::get().reads_writes(2, 2));
47+
48+
// Record for total issuance tracking
49+
let mut total_swapped: u64 = 0;
50+
3951
let mut total_alpha: I96F32 = I96F32::from_num(0);
4052
// Iterate over every hotkey and sum up the total alpha
4153
let mut hotkeys_to_remove: Vec<T::AccountId> = Vec::new();
@@ -96,6 +108,7 @@ pub fn migrate_dissolve_sn73<T: Config>() -> Weight {
96108

97109
if as_tao > 0 {
98110
Pallet::<T>::add_balance_to_coldkey_account(&coldkey, as_tao);
111+
total_swapped = total_swapped.saturating_add(as_tao);
99112
weight = weight.saturating_add(T::DbWeight::get().reads_writes(1, 1));
100113

101114
// Emit event
@@ -115,6 +128,23 @@ pub fn migrate_dissolve_sn73<T: Config>() -> Weight {
115128
}
116129
}
117130

131+
// Update total issuance
132+
TotalIssuance::<T>::mutate(|v| *v = v.saturating_add(total_swapped));
133+
weight = weight.saturating_add(T::DbWeight::get().reads_writes(1, 1));
134+
135+
// Verify total issuance change is correct
136+
if subnet_tao
137+
.saturating_to_num::<u64>()
138+
.abs_diff(total_swapped)
139+
>= 100_000
140+
{
141+
log::info!(
142+
"Total issuance change is incorrect: {} != {}",
143+
subnet_tao.saturating_to_num::<u64>(),
144+
total_swapped
145+
);
146+
}
147+
118148
// === Clear storage entries ===
119149
// Clear subnet owner and hotkey
120150
SubnetOwner::<T>::remove(this_netuid);
@@ -154,12 +184,6 @@ pub fn migrate_dissolve_sn73<T: Config>() -> Weight {
154184
let clear_results_1 = TaoDividendsPerSubnet::<T>::clear_prefix(this_netuid, u32::MAX, None);
155185
weight = weight.saturating_add(T::DbWeight::get().writes(clear_results_1.unique.into()));
156186

157-
// Adjust total stake
158-
TotalStake::<T>::mutate(|total| {
159-
*total = total.saturating_sub(subnet_tao.saturating_to_num::<u64>());
160-
});
161-
weight = weight.saturating_add(T::DbWeight::get().reads_writes(1, 1));
162-
163187
// Clear subnet volume
164188
SubnetVolume::<T>::remove(this_netuid);
165189
weight = weight.saturating_add(T::DbWeight::get().writes(1));

0 commit comments

Comments
 (0)