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

reset neuron data on dereg #755

Open
wants to merge 1 commit into
base: devnet-ready
Choose a base branch
from

Conversation

andreea-popescu-reef
Copy link
Contributor

reviving: #522

Description

On neuron registration the trust, emission, consensus, incentive, dividends values as well as axon info associated with the assigned neuron_uid are inherited from the previous neuron. Thus for the first few blocks after registration these values will be wrong, then reset to zero and then get populated with the correct values for the newly registered neuron. This change resets these values on neuron registration.

@distributedstatemachine distributedstatemachine changed the base branch from main to devnet-ready August 27, 2024 12:55
@distributedstatemachine
Copy link
Collaborator

@andreea-popescu-reef also changed the base against devnet-ready , so you need to resolve conflicts , or fork off devnet-ready

}

/// Resets the trust, emission, consensus, incentive, dividends of the neuron to default
pub fn clear_neuron(netuid: u16, neuron_uid: u16) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we optimise this by reducing the number of storage / writes , and number of function calls ?

pub fn clear_neuron(netuid: u16, neuron_uid: u16) {
    let neuron_index: usize = neuron_uid.into();
    let default_value = 0;

    for storage in &mut [
        &mut Emission::<T>::get(netuid),
        &mut Trust::<T>::get(netuid),
        &mut Consensus::<T>::get(netuid),
        &mut Incentive::<T>::get(netuid),
        &mut Dividends::<T>::get(netuid),
    ] {
        set_element_at(storage, neuron_index, default_value);
    }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that does not quite work as the vectors have different int types

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's the same number of calls to the set_element_at. is there much difference between get vs mutate calls? aren't they compiled to similar things?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

anyway made the change

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reverted - that does not work

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we not just clear the netuid prefix? Or is that the same runtime?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it does not modify the vector - &mut Emission::::get(netuid) just gives back the value & StorageMap does not have a way to get a mut ref to the value

@andreea-popescu-reef
Copy link
Contributor Author

rebased this pr

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants