opentensor / subtensor

Bittensor Blockchain Layer
The Unlicense
123 stars 131 forks source link

Running STAO and DTAO concurrently #453

Open gztensor opened 1 month ago

gztensor commented 1 month ago
  1. change the emission calculation to the following:
    sum_tao = sum([p.tao_in for p in pools])
    sum_prices = sum([p.price for p in pools])
    emission = [p.tao_in/sum_tao for p in pools]
    for i, p in enumerate(pools):
        if sum_prices > 1.0:
            p.inject( tao_in = 0, alpha_in = 1, alpha_out = 1 )
        else:
            p.inject( tao_in = emission[i], alpha_in = 0, alpha_out = 1 )

    Note that the emission is now p.tao_in/sum_tao which is the ratio of TAO in the pool to the total TAO in the pools. This is the exact same calculation for STAO, where the emission for the subnet is tao_in_network/sum_tao_in_networks

TotalSubnetStake and DynamicTAOReserve are the same values in an STAO/DTAO environment

  1. When we migrate from STAO --> DTAO we will need to unstake everyone
  // --- 5. Iterate over all stakes and unstake them if they are in 
        // this subnet. The subnet is not dynamic so this is all clean unstakes.
        SubStake::<T>::iter().for_each(|((cold_i, hot_i, subnet_i), stake_amount_i)| {
            if subnet_i == netuid {
                // Unstake everyone from this subnet.
                Self::decrease_stake_on_coldkey_hotkey_account( cold_i, hot_i, subnet_i, stake_amount_i );
            }
        });
        TotalSubnetStake::<T>::insert( netuid, 0 ); // We have cleared all the stake on this subnet.
  1. Prices no longer are required except here:
if sum_prices > 1.0:
            p.inject( tao_in = 0, alpha_in = 1, alpha_out = 1 )
        else:
            p.inject( tao_in = emission[i], alpha_in = 0, alpha_out = 1 )

For STAO subnets we just always emit TAO (as if prices were > 1)

gztensor commented 1 month ago

Test plan

_Definition: Price threshold = SUM( Emission( subnet ) for subnet in DTAO_SUBNETS )/ SUM( Emission( subnet ) for subnet in ALLSUBNETS )

For STAO subnets:

For DTAO subnets

Corner cases

Sanity checks

gztensor commented 1 month ago

Converting a subnet from STAO to DTAO

Branch: feat/stao-dtao-transition

gztensor commented 1 month ago

Transition check list: