subtensor
subtensor copied to clipboard
fix remove_network
Description
Currently, the remove_network function does not properly handle the unstaking of nominators and delegates when a network is removed. This leads to orphaned stakes in neurons. Additionally, there may be existing neurons staked in already dissolved networks that need to be addressed.
We need to update the remove_network function to correctly differentiate between delegates and nominators when returning stakes, and implement a storage migration to handle existing neurons staked in dissolved networks.
Acceptance Criteria
- Update the remove_network function to properly unstake and return funds to both delegates and nominators.
- Implement a storage migration to handle existing neurons staked in dissolved networks.
- Ensure that delegate stakes are returned to the delegate's coldkey.
- Ensure that nominator stakes are returned to the nominator's coldkey.
- Write unit tests to verify the correct behavior of the updated remove_network function.
- Write integration tests to ensure the storage migration works as expected.
Tasks
- [ ] Modify the remove_network function in pallets/subtensor/src/root.rs:
pub fn remove_network(netuid: u16) {
// ... existing code ...
// Unstake nominators and delegates
for (hotkey, coldkey, stake) in <Stake<T> as IterableStorageDoubleMap<T::AccountId, T::AccountId, u64>>::iter() {
if let Some(neuron) = Neurons::<T>::get(&hotkey) {
if neuron.netuid == netuid {
if Self::hotkey_is_delegate(&hotkey) {
let delegate_coldkey = Owner::<T>::get(hotkey.clone());
Self::add_balance_to_coldkey_account(&delegate_coldkey, stake);
} else {
Self::add_balance_to_coldkey_account(&coldkey, stake);
}
<Stake<T>>::remove(hotkey.clone(), coldkey.clone());
}
}
}
}
- [ ] Implement a storage migration to handle existing neurons staked in dissolved networks:
- [ ] Write unit tests for the updated
remove_networkfunction. - [ ] Write integration tests for the storage migration.