Skip to content

Add min_childkey_take_per_subnet hyperparameter#2734

Open
gztensor wants to merge 12 commits into
devnet-readyfrom
feat/min-ck-take-hyperparam
Open

Add min_childkey_take_per_subnet hyperparameter#2734
gztensor wants to merge 12 commits into
devnet-readyfrom
feat/min-ck-take-hyperparam

Conversation

@gztensor

@gztensor gztensor commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Description

Add a new hyperparameter min_childkey_take_per_subnet for the existing admin util extrinsic with matching name.

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

Introduces a new min_childkey_take_per_subnet field in get_subnet_hyperparams_v3.

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

@gztensor gztensor self-assigned this Jun 9, 2026
@gztensor gztensor added the skip-cargo-audit This PR fails cargo audit but needs to be merged anyway label Jun 9, 2026
@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

🛡️ AI Review — Skeptic (security review)

VERDICT: SAFE

BASELINE scrutiny: author has write permission, established contribution history, no Gittensor allowlist hit, and branch feat/min-ck-take-hyperparam targets devnet-ready.

Static review found a narrow diff limited to hotkey-swap storage read-weight accounting, a focused test expectation update, and a runtime spec_version bump. No .github/ai-review/*, .github/copilot-instructions.md, workflow, build-script, dependency, or lockfile changes are present.

Findings

No findings.

Conclusion

No malicious pattern or security vulnerability was found. The changed runtime path adds weight accounting before existing storage helper calls and does not introduce a new panic path, origin bypass, dependency surface, or build-time execution surface.


🔍 AI Review — Auditor (domain review)

VERDICT: 👍

Gittensor: LIKELY; no allowlist match, but author has write permission and substantial recent subtensor history.

Description discrepancy: the PR body still describes adding min_childkey_take_per_subnet to the V3 subnet hyperparameter surface, while the current diff only adjusts do_swap_hotkey weight accounting/tests and bumps runtime/src/lib.rs spec_version from 424 to 426. This is worth updating in the PR body, but I do not see a blocking domain issue.

Auto-fix: none. git diff --check is clean. I did not run tests because no finding required runtime confirmation.

Findings

No findings.

Prior-comment reconciliation

  • 5216a5a8: addressed — The current diff accrues one read for hotkey_account_exists(new_hotkey) and two additional reads before coldkey_owns_hotkey(&coldkey, new_hotkey), matching the helper storage accesses on the existing-new-hotkey path.

Conclusion

The remaining diff is narrow, accounts for the added new-hotkey ownership reads before the storage helpers run, and keeps a runtime spec bump in place. I did not find a remaining blocking domain issue.

@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

🔄 AI review updated — Skeptic: SAFE Auditor: 👍

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI review — see the sticky summary comment for the verdict and the inline comments below for specific findings.

Comment on lines 49 to 58
// 3. If the new hotkey already exists globally, ensure the coldkey owns it
if Self::hotkey_account_exists(new_hotkey) {
ensure!(
Self::coldkey_owns_hotkey(&coldkey, new_hotkey),
Error::<T>::NonAssociatedColdKey
);
}

// 4. Initialize the weight for this operation
let mut weight = T::DbWeight::get().reads(2);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[HIGH] Account for the new hotkey-owner reads in swap weights

This new check performs extra Owner storage reads before weight is initialized: hotkey_account_exists(new_hotkey) reads once, and when it exists coldkey_owns_hotkey reads again via contains_key plus get. Those reads are not included in the returned post-dispatch weight, and the pre-dispatch weights for swap_hotkey / swap_hotkey_v2 were not updated or rebenchmarked. Since this is a runtime extrinsic, changed storage access must be reflected in weight. Initialize/accrue the dynamic weight before this check or collapse it into a single charged storage access, then update the generated swap_hotkey weight and the hardcoded swap_hotkey_v2 weight.

@github-actions

Copy link
Copy Markdown
Contributor

🔄 AI review updated — Skeptic: SAFE Auditor: 👎

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI review — see the sticky summary comment for the verdict and the inline comments below for specific findings.

Comment on lines 49 to 58
// 3. If the new hotkey already exists globally, ensure the coldkey owns it
if Self::hotkey_account_exists(new_hotkey) {
ensure!(
Self::coldkey_owns_hotkey(&coldkey, new_hotkey),
Error::<T>::NonAssociatedColdKey
);
}

// 4. Initialize the weight for this operation
let mut weight = T::DbWeight::get().reads(2);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[HIGH] Account for the new hotkey-owner reads in swap weights

This new ownership gate performs additional Owner storage reads before weight is initialized. On the successful path where new_hotkey already exists and is owned by the caller, hotkey_account_exists(new_hotkey) reads once and coldkey_owns_hotkey(&coldkey, new_hotkey) reads again via contains_key plus get, but the returned post-dispatch weight still starts at only the two reads for the old-hotkey ownership check. That under-reports the actual runtime work and can over-refund swap_hotkey / swap_hotkey_v2.

Suggested change
// 3. If the new hotkey already exists globally, ensure the coldkey owns it
if Self::hotkey_account_exists(new_hotkey) {
ensure!(
Self::coldkey_owns_hotkey(&coldkey, new_hotkey),
Error::<T>::NonAssociatedColdKey
);
}
// 4. Initialize the weight for this operation
let mut weight = T::DbWeight::get().reads(2);
// 3. Initialize the weight for ownership checks
let mut weight = T::DbWeight::get().reads(2);
// 4. If the new hotkey already exists globally, ensure the coldkey owns it
if Self::hotkey_account_exists(new_hotkey) {
weight.saturating_accrue(T::DbWeight::get().reads(1));
ensure!(
Self::coldkey_owns_hotkey(&coldkey, new_hotkey),
Error::<T>::NonAssociatedColdKey
);
weight.saturating_accrue(T::DbWeight::get().reads(2));
} else {
weight.saturating_accrue(T::DbWeight::get().reads(1));
}

@github-actions

Copy link
Copy Markdown
Contributor

🔄 AI review updated — Skeptic: SAFE Auditor: 👎

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI review — see the sticky summary comment for the verdict and the inline comments below for specific findings.

Comment thread pallets/subtensor/src/swap/swap_hotkey.rs Outdated
@github-actions

Copy link
Copy Markdown
Contributor

🔄 AI review updated — Skeptic: SAFE Auditor: 👎

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown
Contributor

🔄 AI review updated — Skeptic: SAFE Auditor: 👍

@github-actions

Copy link
Copy Markdown
Contributor

🔄 AI review updated — Skeptic: SAFE Auditor: 👍

@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

🔄 AI review updated — Skeptic: SAFE Auditor: 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip-cargo-audit This PR fails cargo audit but needs to be merged anyway

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant