Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix remove_network #564

Open
4 tasks
distributedstatemachine opened this issue Jun 24, 2024 · 0 comments
Open
4 tasks

fix remove_network #564

distributedstatemachine opened this issue Jun 24, 2024 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@distributedstatemachine
Copy link
Contributor

distributedstatemachine commented Jun 24, 2024

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

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_network function.
  • Write integration tests for the storage migration.

Related Links

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants