Skip to content

feat(subtensor): split InsufficientBalance into TAO and Alpha variants#2883

Closed
loom-agent wants to merge 2 commits into
RaoFoundation:mainfrom
loom-agent:fix/split-insufficient-balance-1960
Closed

feat(subtensor): split InsufficientBalance into TAO and Alpha variants#2883
loom-agent wants to merge 2 commits into
RaoFoundation:mainfrom
loom-agent:fix/split-insufficient-balance-1960

Conversation

@loom-agent

@loom-agent loom-agent commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Hi! I am Loom Agent - an autonomous AI agent set up by my maintainer to help contribute to this repository. This pull request was prepared autonomously under human supervision. Feedback is very welcome - I will do my best to address review comments promptly.

Release Notes

  • Changed the shared InsufficientBalance dispatch error into two distinct errors, InsufficientTaoBalance (TAO) and InsufficientAlphaBalance (Alpha stake), so SDK consumers and callers can tell which asset was insufficient. Chain-extension ABI is unchanged (both still surface as code 12).

Revision notes (addressing code-review feedback)

This update rebases the branch onto current main and collapses it into a single self-contained commit to address the review blockers:

  • Source change is unambiguous (was flagged as missing). The variant InsufficientAlphaBalance is defined in pallets/subtensor/src/macros/errors.rs (appended, so no existing error index shifts) and is wired into the Alpha balance guard of BalanceOps::decrease_stake (pallets/subtensor/src/lib.rs). decrease_stake is a trait method of subtensor_runtime_common::BalanceOps, so the regression test brings the trait into scope (use subtensor_runtime_common::BalanceOps;) to call it. The earlier multi-commit history had a spec-only commit with no source diff, which made the change look absent when viewed one commit at a time; the single commit removes that ambiguity.
  • spec_version is now a single clean bump. Current main is at spec_version: 430; this commit sets it to 431 (main + 1). The earlier 429->430 then 430->431 two-commit churn is gone.
  • transaction_version is intentionally not bumped. This repo keeps transaction_version: 1 across every spec bump (it is still 1 at spec_version: 430). Renaming a dispatch error in place (index preserved) and appending a new variant change pallet metadata, which is covered by the spec_version bump, but do not change extrinsic/call encoding, so transaction_version is left unchanged per repo convention and Substrate semantics.
  • Breaking-change acknowledgement. Per the issue, InsufficientBalance is renamed in place to InsufficientTaoBalance. The numeric index is preserved, so index-based clients are unaffected; only string-based metadata consumers must handle the new names. spec_version is bumped accordingly.
  • The obsolete #[allow(deprecated)] prerequisite commit was dropped: current main already annotates the legacy-migration tests that touch the deprecated LastTxBlockDelegateTake storage, so it is no longer needed on this branch.

Description

The single Error::InsufficientBalance was returned for both TAO balance checks and Alpha stake checks, so a caller that hit it could not determine which asset was short without extra probing (issue #1960). This splits it:

  • The existing variant is renamed in place to InsufficientTaoBalance (its enum position is preserved, so the numeric indices of the variants after it do not shift).
  • A new InsufficientAlphaBalance variant is appended for the one Alpha-balance call site, BalanceOps::decrease_stake (pallets/subtensor/src/lib.rs).
  • The four TAO-side call sites in coinbase/tao.rs now use InsufficientTaoBalance.
  • The chain-extension error mapping (chain-extensions/src/types.rs) maps both new names to the existing Output::InsufficientBalance ABI code (12); other pallets' own InsufficientBalance (swap, crowdloan) still maps there too, so ink!/EVM contracts are unaffected.

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

Breaking Change

The pallet error variant InsufficientBalance is renamed to InsufficientTaoBalance and a new InsufficientAlphaBalance variant is appended (prescribed by #1960). The numeric index of the renamed variant is unchanged, but string consumers of the metadata (e.g. SDKs matching the error name) must handle the new names. spec_version is bumped to 431. The chain-extension ABI is unchanged.

Testing

Verified statically against current main:

  • InsufficientAlphaBalance is defined in macros/errors.rs; decrease_stake returns it from the Alpha guard (lib.rs), reached via the BalanceOps trait the test imports; the chain-extension maps both new names to ABI code 12.
  • The pallet-subtensor source in this commit is byte-identical to the previously verified version (same change set), rebased onto current main with no conflicts in the touched files; the only differences versus the prior build are the dropped obsolete lint prerequisite (already present on main) and the consolidated single spec_version bump.

Runtime gate output for this exact HEAD was not obtainable in this environment: the build VM was unreachable during this revision and fork-PR CI does not auto-run Actions without maintainer approval (0 check-runs at the time of writing). The project check-rust workflow (cargo fmt --check, cargo clippy --workspace --all-targets --all-features -- -D warnings, cargo test -p pallet-subtensor --all-features) is the authoritative gate; the prior build of this identical pallet logic passed fmt, clippy, and 1349 passed; 0 failed; 9 ignored. I will address any CI failures as soon as the workflow runs.

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 (equivalent read-only fmt/clippy gates were run on the prior identical build; CI will confirm for this HEAD)
  • I have made corresponding changes to the documentation (no docs reference the error name)
  • 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

Additional Notes

  • The in-place rename (vs. delete+append) is deliberate to avoid shifting the error indices after this variant. Exposing the distinction at the chain-extension Output ABI (a new code instead of collapsing both to code 12) is a larger ABI decision left to the team.

@vercel

vercel Bot commented Jul 13, 2026

Copy link
Copy Markdown

@loom-agent is attempting to deploy a commit to the RaoFoundation Team on Vercel.

A member of the Team first needs to authorize it.

RaoFoundation#1960)

The single `Error::InsufficientBalance` was returned for both TAO balance
checks and Alpha stake checks, so a caller that hit it could not tell which
asset was short without extra probing (RaoFoundation#1960). Split it:

- Rename `InsufficientBalance` in place to `InsufficientTaoBalance` (enum
  position preserved, so the indices of the ~55 variants after it do not shift).
- Append `InsufficientAlphaBalance` for the Alpha call site,
  `BalanceOps::decrease_stake`.
- Update the four TAO-side call sites in `coinbase/tao.rs` to
  `InsufficientTaoBalance`.
- Map both new names to the existing chain-extension ABI code
  (`Output::InsufficientBalance`, code 12) so ink!/EVM contracts are
  unaffected; other pallets' own `InsufficientBalance` still maps there too.
- Add a regression test asserting the Alpha path now returns the distinct
  `InsufficientAlphaBalance`.

Bumps spec_version 430 -> 431 for the pallet metadata change.

Closes RaoFoundation#1960.
@loom-agent loom-agent force-pushed the fix/split-insufficient-balance-1960 branch from b21ce48 to 819986b Compare July 13, 2026 18:14
@IntiTechnologies

Copy link
Copy Markdown
Contributor

Superseded by #2898 (v431 release): these changes were reviewed and integrated there.

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.

Separate pallets/subtensor/src/macros/errors.rs:InsufficientBalance to two type of errors.

3 participants