Skip to content

Handle swap errors in chain buys#2753

Open
gztensor wants to merge 8 commits into
devnet-readyfrom
fix/handle-chain-buy-swap-failures
Open

Handle swap errors in chain buys#2753
gztensor wants to merge 8 commits into
devnet-readyfrom
fix/handle-chain-buy-swap-failures

Conversation

@gztensor

Copy link
Copy Markdown
Contributor

Description

Chain buys may result in swap errors, in which case the TAO will be withdrawn from the subnet account and returned to the total imbalance.

Related Issue(s)

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):

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 12, 2026
@gztensor gztensor added the skip-cargo-audit This PR fails cargo audit but needs to be merged anyway label Jun 12, 2026
@github-actions

github-actions Bot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

🛡️ AI Review — Skeptic (security review)

VERDICT: SAFE

BASELINE scrutiny: gztensor has repo write permission, established contribution history, no trusted Gittensor allowlist hit; branch fix/handle-chain-buy-swap-failures -> devnet-ready.

Static review only. The diff does not modify .github/ai-review/*, .github/copilot-instructions.md, dependencies, lockfiles, or build scripts. The runtime/pallet changes are limited to refunding failed chain-buy TAO deposits through the existing credit/recycle accounting path, handling ED dust in Subtensor TotalIssuance, updating tests, and bumping spec_version.

Findings

No findings.

Conclusion

No malicious behavior or security vulnerability was found. The failed swap path uses fallible withdrawal and preserves issuance/accounting without adding panic, origin-bypass, dependency, or build-time execution surfaces.


🔍 AI Review — Auditor (domain review)

VERDICT: 👍

Author is LIKELY Gittensor by recent Subtensor-heavy contribution history, has repo write permission, and is not in the trusted allowlists.

PR body is substantive and matches the implementation. No duplicate-work blocker found; overlapping PRs touch nearby runtime or pallet files, but their scopes are adjacent accounting, root, governance, or cleanup work rather than a better candidate for this chain-buy swap-failure fix.

Spec-version auto-fix was not needed: the PR already bumps runtime/src/lib.rs from 424 to 426 for the devnet-ready target.

Auto-fix applied locally because this is not a fork: pallets/subtensor/src/tests/swap_hotkey_with_subnet.rs now removes the unused another_coldkey binding and restores an IsNetworkMember assertion for the already-registered hotkey setup.

Verification: git diff --check passed. I attempted the three focused cargo test --package pallet-subtensor --lib tests for the changed paths, but they could not start in this sandbox because rustup/cargo tried to write under read-only /home/runner/.rustup and /home/runner/.cargo.

Findings

No findings.

Prior-comment reconciliation

  • 66ac1209: addressed — Fixed locally by removing the unused another_coldkey binding and adding assert!(IsNetworkMember::<Test>::get(new_hotkey, netuid)); before the swap assertion.

Conclusion

The failed dynamic chain-buy path now refunds the deposited subnet-account TAO back into remaining credit before the existing recycle path, with focused accounting coverage and the prior low-risk test issue fixed locally. I found no merge-blocking domain issues.


📜 Previous run (superseded)
Sev File Finding Status
LOW pallets/subtensor/src/tests/swap_hotkey_with_subnet.rs:868 Restore the already-registered hotkey assertion ✅ Addressed
Fixed locally by removing the unused another_coldkey binding and adding assert!(IsNetworkMember::<Test>::get(new_hotkey, netuid)); before the swap assertion.

@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

Copy link
Copy Markdown
Contributor

🔄 AI review updated — Skeptic: SAFE Auditor: 👍

1 similar comment
@github-actions

Copy link
Copy Markdown
Contributor

🔄 AI review updated — Skeptic: SAFE Auditor: 👍

JohnReedV
JohnReedV previously approved these changes Jun 12, 2026
@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/tests/swap_hotkey_with_subnet.rs Outdated
@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

🔄 AI review updated — Skeptic: SAFE Auditor: 👍

gztensor and others added 2 commits July 1, 2026 09:24
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@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.

2 participants