diff --git a/pallets/subtensor/src/uids.rs b/pallets/subtensor/src/uids.rs index 5f96c36c2..3bad000af 100644 --- a/pallets/subtensor/src/uids.rs +++ b/pallets/subtensor/src/uids.rs @@ -10,12 +10,23 @@ impl Pallet { } /// Resets the trust, emission, consensus, incentive, dividends of the neuron to default + fn clear_element_at(position: u16) -> impl Fn(&mut Vec) + where + N: From, + { + move |vec: &mut Vec| { + if vec.len() > position as usize { + vec[position as usize] = N::from(0); + }; + } + } + pub fn clear_neuron(netuid: u16, neuron_uid: u16) { - Emission::::mutate(netuid, |v| v[neuron_uid as usize] = 0); - Trust::::mutate(netuid, |v| v[neuron_uid as usize] = 0); - Consensus::::mutate(netuid, |v| v[neuron_uid as usize] = 0); - Incentive::::mutate(netuid, |v| v[neuron_uid as usize] = 0); - Dividends::::mutate(netuid, |v| v[neuron_uid as usize] = 0); + Emission::::mutate(netuid, Self::clear_element_at(neuron_uid)); + Trust::::mutate(netuid, Self::clear_element_at(neuron_uid)); + Consensus::::mutate(netuid, Self::clear_element_at(neuron_uid)); + Incentive::::mutate(netuid, Self::clear_element_at(neuron_uid)); + Dividends::::mutate(netuid, Self::clear_element_at(neuron_uid)); } /// Replace the neuron under this uid.