Skip to content

fix: clear ValidatorTrust/ValidatorPermit on neuron replace#2609

Open
boskodev790 wants to merge 1 commit intoopentensor:mainfrom
boskodev790:fix/replace-neuron-clear-validator-permit-trust
Open

fix: clear ValidatorTrust/ValidatorPermit on neuron replace#2609
boskodev790 wants to merge 1 commit intoopentensor:mainfrom
boskodev790:fix/replace-neuron-clear-validator-permit-trust

Conversation

@boskodev790
Copy link
Copy Markdown

@boskodev790 boskodev790 commented Apr 22, 2026

clear_neuron zeroed the per-UID slot of Emission, Consensus, Incentive, Dividends, StakeWeight, Bonds and Weights, but missed ValidatorTrust and ValidatorPermit. Both are Vec<_>-per-netuid storage that append_neuron initialises on a fresh UID, so when replace_neuron reuses a UID it currently left the old occupant's validator_permit=true flag and validator_trust score in place until the next epoch recomputed the vectors.

Between replacement and the next epoch, RPC surfaces (delegate_info, show_subnet) and on-chain readers (trim_to_max_allowed_uids and the per-mechanism validator aggregation in mechanism.rs) observed stale validator state for the freshly registered neuron.

Same class of stale-inheritance bug PR #755 was introduced to fix; these two fields were missed there.

  • clear_neuron now also zeroes ValidatorTrust[uid] and resets ValidatorPermit[uid] = false, using the same set_element_at idiom already applied to the other vec-per-netuid fields two lines above.
  • Add test_replace_neuron_clears_validator_trust_and_permit mirroring the existing test_replace_neuron_resets_last_update style.

Description

Related Issue(s)

  • Closes #[issue number]

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Other (please describe):

Breaking Change

If this PR introduces a breaking change, please provide a detailed description of the impact and the migration path for existing applications.

Checklist

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have run ./scripts/fix_rust.sh to ensure my code is formatted and linted correctly
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Screenshots (if applicable)

Please include any relevant screenshots or GIFs that demonstrate the changes made.

Additional Notes

Please provide any additional information or context that may be helpful for reviewers.

clear_neuron zeroed the per-UID slot of Emission, Consensus, Incentive,
Dividends, StakeWeight, Bonds and Weights, but missed ValidatorTrust
and ValidatorPermit. Both are Vec<_>-per-netuid storage that
append_neuron initialises on a fresh UID, so when replace_neuron
reuses a UID it currently left the old occupant's validator_permit=true
flag and validator_trust score in place until the next epoch
recomputed the vectors.

Between replacement and the next epoch, RPC surfaces (delegate_info,
show_subnet) and on-chain readers (trim_to_max_allowed_uids and
the per-mechanism validator aggregation in mechanism.rs) observed
stale validator state for the freshly registered neuron.

Same class of stale-inheritance bug PR opentensor#755 was introduced to fix;
these two fields were missed there.

- clear_neuron now also zeroes ValidatorTrust[uid] and resets
  ValidatorPermit[uid] = false, using the same set_element_at idiom
  already applied to the other vec-per-netuid fields two lines above.
- Add test_replace_neuron_clears_validator_trust_and_permit mirroring
  the existing test_replace_neuron_resets_last_update style.
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.

1 participant