fix: clear Active/ValidatorTrust/ValidatorPermit on neuron replace#2609
fix: clear Active/ValidatorTrust/ValidatorPermit on neuron replace#2609boskodev790 wants to merge 1 commit into
Conversation
|
Fix looks correct — mirrors the existing One adjacent observation while reading through the per-netuid storage definitions:
Is |
clear_neuron zeroed the per-UID slot of Emission, Consensus, Incentive, Dividends, StakeWeight, Bonds and Weights, but missed Active, ValidatorTrust, and ValidatorPermit. All three are Vec<_>-per-netuid storage (Active and ValidatorPermit are Vec<bool> via EmptyBoolVec; ValidatorTrust is Vec<u16> via EmptyU16Vec) that append_neuron initialises on a fresh UID, so when replace_neuron reuses a UID it currently left the old occupant's active=true flag, 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/active state for the freshly registered neuron. Same class of stale-inheritance bug PR opentensor#755 was introduced to fix; these three fields were missed there. - clear_neuron now also zeroes ValidatorTrust[uid] and resets ValidatorPermit[uid] = false and Active[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 and test_replace_neuron_clears_active mirroring the existing test_replace_neuron_resets_last_update style. Co-authored-by: Cursor <cursoragent@cursor.com>
1938dc9 to
e57f6f0
Compare
|
Thanks for the careful read, @RUNECTZ33 — the observation is right on the money.
I've folded the
On Let me know if the expanded scope still looks good. — Bosko |
|
Expanded scope looks correct to me. Pulled
Agreed on the LGTM on the expanded scope. |
clear_neuron zeroed the per-UID slot of Emission, Consensus, Incentive, Dividends, StakeWeight, Bonds and Weights, but missed Active, ValidatorTrust, and ValidatorPermit. All three are Vec<_>-per-netuid storage (Active and ValidatorPermit are Vec via EmptyBoolVec; ValidatorTrust is Vec) that append_neuron initialises on a fresh UID, so when replace_neuron reuses a UID it currently left the old occupant's active=true flag, 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/active state for the freshly registered neuron.
Same class of stale-inheritance bug PR #755 was introduced to fix; these three fields were missed there.
Description
Related Issue(s)
Type of Change
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
./scripts/fix_rust.shto ensure my code is formatted and linted correctlyScreenshots (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.