Skip to content

Commit 4197a03

Browse files
committed
make sure to ensure burn reg before writing
1 parent a4c49e3 commit 4197a03

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

pallets/subtensor/src/subnets/registration.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -119,29 +119,29 @@ impl<T: Config> Pallet<T> {
119119
Error::<T>::NotEnoughBalanceToStake
120120
);
121121

122-
// --- 8. Ensure the remove operation from the coldkey is a success.
123-
let actual_burn_amount =
124-
Self::remove_balance_from_coldkey_account(&coldkey, registration_cost)?;
125-
126-
// Tokens are swapped and then burned.
127-
let burned_alpha: u64 = Self::swap_tao_for_alpha(netuid, actual_burn_amount);
128-
SubnetAlphaOut::<T>::mutate(netuid, |total| *total = total.saturating_sub(burned_alpha));
129-
130-
// --- 9. If the network account does not exist we will create it here.
131-
Self::create_account_if_non_existent(&coldkey, &hotkey);
132-
133-
// --- 10. Ensure that the pairing is correct.
122+
// --- 8. Ensure that the pairing is correct.
134123
ensure!(
135124
Self::coldkey_owns_hotkey(&coldkey, &hotkey),
136125
Error::<T>::NonAssociatedColdKey
137126
);
138127

139-
// Possibly there is no neuron slots at all.
128+
// --- 9. Possibly there are no neuron slots at all.
140129
ensure!(
141130
Self::get_max_allowed_uids(netuid) != 0,
142131
Error::<T>::NoNeuronIdAvailable
143132
);
144133

134+
// --- 10. Ensure the remove operation from the coldkey is a success.
135+
let actual_burn_amount =
136+
Self::remove_balance_from_coldkey_account(&coldkey, registration_cost)?;
137+
138+
// Tokens are swapped and then burned.
139+
let burned_alpha: u64 = Self::swap_tao_for_alpha(netuid, actual_burn_amount);
140+
SubnetAlphaOut::<T>::mutate(netuid, |total| *total = total.saturating_sub(burned_alpha));
141+
142+
// --- 11. If the network account does not exist we will create it here.
143+
Self::create_account_if_non_existent(&coldkey, &hotkey);
144+
145145
// Actually perform the registration.
146146
let neuron_uid: u16 = Self::register_neuron(netuid, &hotkey);
147147

0 commit comments

Comments
 (0)