subtensor icon indicating copy to clipboard operation
subtensor copied to clipboard

Delegate set claim type

Open unconst opened this issue 2 months ago • 1 comments

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.

unconst avatar Nov 20 '25 23:11 unconst

Latest update

  • merged PR https://github.com/opentensor/subtensor/pull/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 avatar Nov 26 '25 12:11 shamil-gadelshin

The last commits change tao outflow registration: new root prop multiplier bounded by 10.

shamil-gadelshin avatar Dec 09 '25 14:12 shamil-gadelshin