Skip to content

Commit

Permalink
rebase fix
Browse files Browse the repository at this point in the history
  • Loading branch information
andreea-popescu-reef committed Sep 15, 2024
1 parent 149b9d2 commit 6575d97
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 20 deletions.
24 changes: 9 additions & 15 deletions pallets/subtensor/src/subnets/uids.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,20 @@ impl<T: Config> Pallet<T> {
SubnetworkN::<T>::get(netuid)
}

/// Returns a callback that sets the element at the given position to zero, doing nothing if the
/// position is out of bounds
fn clear_element_at<N>(position: u16) -> impl Fn(&mut Vec<N>)
where
N: From<u8>,
{
move |vec: &mut Vec<N>| {
if let Some(element) = vec.get_mut(position as usize) {
*element = N::from(0);
}
/// Sets value for the element at the given position if it exists.
pub fn set_element_at<N>(vec: &mut [N], position: usize, value: N) {
if let Some(element) = vec.get_mut(position) {
*element = value;
}
}

/// Resets the trust, emission, consensus, incentive, dividends of the neuron to default
pub fn clear_neuron(netuid: u16, neuron_uid: u16) {
Emission::<T>::mutate(netuid, Self::clear_element_at(neuron_uid));
Trust::<T>::mutate(netuid, Self::clear_element_at(neuron_uid));
Consensus::<T>::mutate(netuid, Self::clear_element_at(neuron_uid));
Incentive::<T>::mutate(netuid, Self::clear_element_at(neuron_uid));
Dividends::<T>::mutate(netuid, Self::clear_element_at(neuron_uid));
Emission::<T>::mutate(netuid, |v| Self::set_element_at(v, neuron_uid.into(), 0));
Trust::<T>::mutate(netuid, |v| Self::set_element_at(v, neuron_uid.into(), 0));
Consensus::<T>::mutate(netuid, |v| Self::set_element_at(v, neuron_uid.into(), 0));
Incentive::<T>::mutate(netuid, |v| Self::set_element_at(v, neuron_uid.into(), 0));
Dividends::<T>::mutate(netuid, |v| Self::set_element_at(v, neuron_uid.into(), 0));
}

/// Replace the neuron under this uid.
Expand Down
20 changes: 15 additions & 5 deletions pallets/subtensor/tests/uids.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,21 @@ fn test_replace_neuron() {
let neuron_uid = neuron_uid.unwrap();

// set non-default values
Trust::<Test>::mutate(netuid, |v| v[neuron_uid as usize] = 5u16);
Emission::<Test>::mutate(netuid, |v| v[neuron_uid as usize] = 5u64);
Consensus::<Test>::mutate(netuid, |v| v[neuron_uid as usize] = 5u16);
Incentive::<Test>::mutate(netuid, |v| v[neuron_uid as usize] = 5u16);
Dividends::<Test>::mutate(netuid, |v| v[neuron_uid as usize] = 5u16);
Trust::<Test>::mutate(netuid, |v| {
SubtensorModule::set_element_at(v, neuron_uid as usize, 5u16)
});
Emission::<Test>::mutate(netuid, |v| {
SubtensorModule::set_element_at(v, neuron_uid as usize, 5u64)
});
Consensus::<Test>::mutate(netuid, |v| {
SubtensorModule::set_element_at(v, neuron_uid as usize, 5u16)
});
Incentive::<Test>::mutate(netuid, |v| {
SubtensorModule::set_element_at(v, neuron_uid as usize, 5u16)
});
Dividends::<Test>::mutate(netuid, |v| {
SubtensorModule::set_element_at(v, neuron_uid as usize, 5u16)
});

// serve axon mock address
let ip: u128 = 1676056785;
Expand Down

0 comments on commit 6575d97

Please sign in to comment.