Skip to content

PalletId-based subnet account Ids maintain subnet TAO reserves#2524

Merged
sam0x17 merged 73 commits into
devnet-readyfrom
chore/imbalances
Apr 28, 2026
Merged

PalletId-based subnet account Ids maintain subnet TAO reserves#2524
sam0x17 merged 73 commits into
devnet-readyfrom
chore/imbalances

Conversation

@gztensor
Copy link
Copy Markdown
Contributor

@gztensor gztensor commented Mar 19, 2026

Description

  • Every subnet will have an account ID and the subnet swap pool reserves will be stored in subnet account balance.
  • The subnet account ID is derived from SubtensorModule account ID and does not have a private key, so no transactions may be initiated by this account.
  • Use of subnet account IDs as hotkeys for staking, registration of neurons, or as a subnet owner hotkey will be forbidden.

TAO management for subnet registration

  • When a new subnet is registered, the lock cost is transferred to the subnet account and is recorded to the SubnetLocked map for the newly registered netuid.
  • When subnet is dissolved, some of the SubnetLocked amount may be returned to the subnet owner. The owner emission TAO is excluded from the returned portion. If owner emission TAO is higher than lock cost, zero is returned for lock cost and the remainder is recycled.

Implementation Checklist

  • Derive subnet account IDs
  • Create runtime API subnetInfoRuntimeApi::getSubnetAccountId for clients to read the subnet account IDs
  • Organize all TAO balance operations, especially creating and destroying TAO, into one place: mint_tao, burn_tao, recycle_tao, transfer_tao.
    • Cover all functions with tests
  • Migration to mint TAO stored in SubnetTAO into subnet accounts. This will make balances pallet TotalIssuance match the subtensor pallet TotalIssuance.
  • Move remove_balance_from_coldkey_account and add_balance_to_coldkey_account methods to test-only code (tests+benchmarks). Convert original TAO moving logic into transfer_tao and use it inside stake_into_subnet and untake_from_subnet.
  • Use subnet accounts for storing subnet reserves for Alpha <> TAO swaps.
  • Use ballet balances mint in get_block_emission, make it return imbalance that is consumed later in run_counbase
  • Use subnet accounts for injecting of newly minted TAO (consume imbalances) in run_coinbase.
  • Handle unspent credit (error log + recycle), error-log attempts to spend more.
  • Subnet Locks
    • Use subnet accounts for subnet locks
    • Add corresponding migration: Mint TAO locked into subnet accounts
    • In rao release (v2.0.0) the lock was burned (TotalIssuance reduction), in the subsequent migration migrate_restore_subnet_locked we restored locks into SubnetLocked, but did not increase the TotalIssuance back. So, in this PR we will increase subtensor pallet TotalIssuance by total of SubnetLocked update in migrate_restore_subnet_locked.
  • Maintain subtensor pallet total issuance within tao.rs file only (consider burning TAO when balances drop below ED)
  • Test dissolving network with stakes: Make sure all TAO is distributed to stakers, sn owner, etc. and nothing remains on the sn account ID.
  • Remove adjustment of TI on every runtime upgrade
  • Deprecate sudo_set_total_issuance in admin pallet
  • Implement consistent behavior of locks: store TAO + refund on dissolution and recycle the rest.
  • Document special accounts IDs (subnets, burn)

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 added 26 commits March 25, 2026 14:50
…ldkey_account and add_balance_to_coldkey_account methods to test-only code.
Comment thread pallets/subtensor/src/migrations/migrate_subnet_tao_to_subnet_balance.rs Outdated
Comment thread pallets/subtensor/src/subnets/subnet.rs
Comment thread pallets/subtensor/src/macros/dispatches.rs
Comment thread pallets/subtensor/src/staking/stake_utils.rs Outdated
Comment thread pallets/subtensor/src/coinbase/tao.rs Outdated
Comment thread pallets/subtensor/src/subnets/subnet.rs
evgeny-s
evgeny-s previously approved these changes Apr 27, 2026
Copy link
Copy Markdown
Collaborator

@evgeny-s evgeny-s left a comment

Choose a reason for hiding this comment

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

LGTM

@shamil-gadelshin shamil-gadelshin self-requested a review April 28, 2026 14:39
@sam0x17 sam0x17 merged commit e3829a4 into devnet-ready Apr 28, 2026
207 of 208 checks passed
LandynDev added a commit to LandynDev/subtensor that referenced this pull request Apr 30, 2026
Resolves conflicts from upstream chore/imbalances merge (opentensor#2524) and
small follow-on PRs (opentensor#2621, opentensor#2623).

- chain-extensions/src/types.rs: add upstream's CannotUseSystemAccount=20,
  shift our CannotBurnOrRecycleOnRootSubnet to 21 and SubtokenDisabled to 22
- chain-extensions/src/tests.rs: switch our recycle/burn test calls from
  pallet_subtensor::Pallet::<mock::Test>::add_balance_to_coldkey_account
  to the mock free function (pallet method removed in opentensor#2524)
- docs/wasm-contracts.md: align Output table with new discriminants 21/22
- pallets/admin-utils/src/weights.rs: accept upstream regenerated
  sudo_set_total_issuance weights
evgeny-s added a commit that referenced this pull request May 18, 2026
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.

5 participants