Skip to content

refactor: remove unnecessary clone and fix collect element type in do_reset_bonds#2605

Open
greatjourney589 wants to merge 11 commits intoopentensor:devnet-readyfrom
greatjourney589:refactor/bonds-reset-clean-collect
Open

refactor: remove unnecessary clone and fix collect element type in do_reset_bonds#2605
greatjourney589 wants to merge 11 commits intoopentensor:devnet-readyfrom
greatjourney589:refactor/bonds-reset-clean-collect

Conversation

@greatjourney589
Copy link
Copy Markdown

Description

Remove an unnecessary .clone() and fix the collected element type in do_reset_bonds.
When filtering bond entries for a deregistered hotkey, the original code cloned bonds_vec before iterating (wasteful — .iter() borrows in place) and collected into Vec<&(u16, u16)> instead of Vec<(u16, u16)>. The reference type happened to compile via SCALE's EncodeLike blanket impl but does not match the Bonds storage type. Adding .copied() between .filter() and .collect() fixes the element type and makes the clone unnecessary.

Related Issue(s)

  • N/A

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

N/A

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)

N/A

Additional Notes

The two unit tests added in tests/epoch.rs cover:

  1. test_do_reset_bonds_removes_target_uid_from_all_bond_vecs - verifies the deregistered uid is removed from every other neuron's bond vec while unrelated entries are preserved.
  2. test_do_reset_bonds_noop_when_disabled - verifies the early-return path when bonds_reset is disabled leaves storage unchanged.

@greatjourney589
Copy link
Copy Markdown
Author

@open-junius Would appreciate your review on this PR. Fixed 2 minor but real issues.

@open-junius
Copy link
Copy Markdown
Contributor

need to run cargo fmt.

@greatjourney589
Copy link
Copy Markdown
Author

need to run cargo fmt.

Am I supposed to run it locally and push again?

@greatjourney589
Copy link
Copy Markdown
Author

@open-junius Ran cargo fmt and push again. Request your review. Thanks.

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.

4 participants