Skip to content

Conversation

@unconst
Copy link
Contributor

@unconst unconst commented Nov 20, 2025

Summary

This PR introduces a new Delegated root claim type and a per-subnet validator claim configuration so that stakers can opt into inheriting their validator’s claim behavior (Swap or Keep) on each subnet. It also fixes accounting by recording TAO outflow when alpha is swapped during root claims.


What’s changing

1. New Delegated claim type

  • Extend RootClaimTypeEnum:

    pub enum RootClaimTypeEnum {
        Swap,
        Keep,
        /// Delegate choice to subnet.
        Delegated,
    }
  • Change the default coldkey root claim type to Delegated:

    #[pallet::type_value]
    pub fn DefaultRootClaimType<T: Config>() -> RootClaimTypeEnum {
        RootClaimTypeEnum::Delegated
    }

    New stakers will, by default, delegate their claim behavior to the validator on each subnet.

2. Per-subnet validator claim configuration

  • Introduce a new storage map for validator claim type:

    #[pallet::storage] // MAP (hotkey, netuid) -> RootClaimTypeEnum
    pub type ValidatorClaimType<T: Config> = StorageDoubleMap<
        _,
        Blake2_128Concat,
        T::AccountId,
        Identity,
        NetUid,
        RootClaimTypeEnum,
        ValueQuery,
        DefaultRootClaimType<T>,
    >;
  • New extrinsic to let validators configure claim behavior on a per-subnet basis:

    #[pallet::call_index(125)]
    pub fn set_validator_claim_type(
        origin: OriginFor<T>,
        hotkey: T::AccountId,
        netuid: NetUid,
        new_claim_type: RootClaimTypeEnum,
    ) -> DispatchResult
    • Only the coldkey that owns hotkey may call this (enforced by coldkey_owns_hotkey).

    • new_claim_type is restricted to Swap or Keep. Attempting to set Delegated results in:

      Error::<T>::InvalidRootClaimType
    • Emits:

      Event::ValidatorClaimTypeSet { hotkey, root_claim_type }

3. Claim resolution logic for Delegated

  • In claim_root_for_hotkey_on_subnet, the root_claim_type parameter is now mutable and we resolve Delegated before processing:

    if root_claim_type == RootClaimTypeEnum::Delegated {
        root_claim_type = ValidatorClaimType::<T>::get(hotkey, netuid);
    }
  • A Delegated arm is added to the match as a safety net and should never be hit after resolution; it logs an error and returns early.

This means:

  • If a staker’s RootClaimType is Delegated, they will use the subnet validator’s configured Swap/Keep choice for that hotkey + subnet.
  • If a staker explicitly sets Swap or Keep, that explicit choice is respected regardless of the validator setting.

4. TAO outflow accounting for swaps

  • When root_claim_type == Swap, we now record TAO outflow after a successful swap:

    Self::record_tao_outflow(netuid, owed_tao.amount_paid_out.into());

    This ensures subnet TAO outflow metrics correctly reflect alpha→TAO swaps performed during root claims.

5. Tests

Add test_claim_root_with_delegated_claim_type to cover the new behavior:

  • Sets up a subnet with:

    • A validator hotkey + owner coldkey.
    • Two stakers (Alice and Bob) each holding 10% of the root stake behind the same validator hotkey.
    • A configured swap pool and price (alpha:TAO = 2:1).
  • Scenario 1 – Validator = Keep

    • Validator sets set_validator_claim_type(..., Keep).

    • Alice uses the default Delegated claim type.

    • Bob explicitly sets RootClaimType = Keep.

    • After distributing root emission and calling claim_root:

      • Alice and Bob both receive equal alpha stake on the subnet.
      • Their TAO stake on root remains unchanged.
  • Scenario 2 – Validator = Swap

    • Validator changes claim type to Swap.

    • Another emission is distributed and both Alice and Bob claim again.

    • Alice (delegated) now behaves as Swap:

      • Her subnet alpha stake stays ~constant.
      • Her TAO stake on root increases according to the swap rate.
    • Bob (explicit Keep) continues to accumulate alpha on the subnet with unchanged TAO stake.

  • The test asserts:

    • Delegated stakers track validator claim type changes.
    • Explicit staker claim types override validator settings.
    • Keep stakes alpha on the subnet; Swap converts to TAO and stakes on root.
    • Quantitative expectations for both alpha and TAO balances are within tolerance.

Rationale

This PR lets stakers opt into a sane default by delegating claim behavior to the subnet validator, while still allowing advanced users to override their own behavior. Validators gain an explicit, on-chain control point for how root emissions are handled per subnet. At the same time, TAO outflow accounting for swap-based claims is made explicit, improving tracking and observability of network flows.

@github-actions github-actions bot added the hotfix This PR needs to be merged very quickly and will likely skip testing on devnet and testnet label Nov 20, 2025
@unconst unconst changed the base branch from main to devnet-ready November 20, 2025 23:41
@unconst unconst added enhancement New feature or request and removed hotfix This PR needs to be merged very quickly and will likely skip testing on devnet and testnet labels Nov 20, 2025
@sam0x17 sam0x17 added the skip-cargo-audit This PR fails cargo audit but needs to be merged anyway label Nov 21, 2025
@opentensor opentensor deleted a comment from github-actions bot Nov 24, 2025
Copy link
Collaborator

@shamil-gadelshin shamil-gadelshin left a comment

Choose a reason for hiding this comment

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

I found a minor bug (incompatibility with the pending PR). Looks good otherwise.

@shamil-gadelshin
Copy link
Collaborator

Latest update

  • merged PR Root claim upgrade (part 1) #2218 with related code update (additional root claim type and logic around it)
  • modified set_validator_claim_type to support the new root claim type

@shamil-gadelshin shamil-gadelshin requested review from 0xcacti, camfairchild, sam0x17 and shamil-gadelshin and removed request for 0xcacti November 26, 2025 12:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request 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.

6 participants