Skip to content

Commit ee37f6d

Browse files
author
unconst
committed
move to moving prices rather than tao reserves
1 parent f29c736 commit ee37f6d

File tree

3 files changed

+43
-11
lines changed

3 files changed

+43
-11
lines changed

pallets/subtensor/src/coinbase/run_coinbase.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,13 @@ impl<T: Config> Pallet<T> {
4444
log::debug!("All subnet netuids: {:?}", subnets);
4545

4646
// --- 2. Get sum of tao reserves ( in a later version we will switch to prices. )
47-
let mut tao_sum: I96F32 = I96F32::from_num(0.0);
47+
let mut total_moving_prices: I96F32 = I96F32::from_num(0.0);
4848
for netuid_i in subnets.iter() {
49-
// Get and add subnet TAO in reserve.
50-
tao_sum = tao_sum.saturating_add( asfloat!( SubnetTAO::<T>::get(netuid_i)) );
49+
// Get and update the moving price of each subnet adding the total together.
50+
Self::update_moving_price( *netuid_i );
51+
total_moving_prices = total_moving_prices.saturating_add( Self::get_moving_alpha_price( *netuid_i ) );
5152
}
52-
log::debug!("tao_sum: {:?}", tao_sum);
53+
log::debug!("total_moving_prices: {:?}", total_moving_prices);
5354

5455
// --- 3. Get subnet terms (tao_in, alpha_in, and alpha_out)
5556
// Computation is described in detail in the dtao whitepaper.
@@ -61,10 +62,10 @@ impl<T: Config> Pallet<T> {
6162
let price_i: I96F32 = Self::get_alpha_price(*netuid_i);
6263
log::debug!("price_i: {:?}", price_i);
6364
// Get subnet TAO.
64-
let subnet_tao_i: I96F32 = asfloat!( SubnetTAO::<T>::get(netuid_i) );
65-
log::debug!("subnet_tao_i: {:?}", subnet_tao_i);
65+
let moving_price_i: I96F32 = Self::get_moving_alpha_price( *netuid_i );
66+
log::debug!("moving_price_i: {:?}", moving_price_i);
6667
// Emission is price over total.
67-
let tao_in_i: I96F32 = block_emission.saturating_mul(subnet_tao_i).checked_div(tao_sum).unwrap_or(asfloat!(0.0));
68+
let mut tao_in_i: I96F32 = block_emission.saturating_mul(moving_price_i).checked_div(total_moving_prices).unwrap_or(asfloat!(0.0));
6869
log::debug!("tao_in_i: {:?}", tao_in_i);
6970
// Get alpha_emission total
7071
let alpha_emission_i: I96F32 = asfloat!(Self::get_block_emission_for_issuance(Self::get_alpha_issuance(*netuid_i)).unwrap_or(0));
@@ -75,8 +76,8 @@ impl<T: Config> Pallet<T> {
7576
// Get alpha_out.
7677
let alpha_out_i = alpha_emission_i;
7778
// Only emit TAO if the subnetwork allows registration.
78-
if !Self::get_network_registration_allowed(*netuid)
79-
&& Self::get_network_pow_registration_allowed(*netuid)
79+
if !Self::get_network_registration_allowed(*netuid_i)
80+
&& Self::get_network_pow_registration_allowed(*netuid_i)
8081
{
8182
tao_in_i = asfloat!( 0.0 );
8283
}

pallets/subtensor/src/lib.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,16 @@ pub mod pallet {
732732
T::InitialDissolveNetworkScheduleDuration::get()
733733
}
734734

735+
#[pallet::type_value]
736+
/// Default moving alpha for the moving price.
737+
pub fn DefaultMovingAlpha<T: Config>() -> I96F32 {
738+
I96F32::saturating_from_num(0.0001)
739+
}
740+
#[pallet::type_value]
741+
/// Default subnet moving price.
742+
pub fn DefaultMovingPrice<T: Config>() -> I96F32 {
743+
I96F32::saturating_from_num(0.0)
744+
}
735745
#[pallet::type_value]
736746
/// Default value for Share Pool variables
737747
pub fn DefaultSharePoolZero<T: Config>() -> U64F64 {
@@ -904,14 +914,16 @@ pub mod pallet {
904914
///
905915
/// Eventually, Bittensor should migrate to using Holds afterwhich time we will not require this
906916
/// separate accounting.
907-
#[pallet::storage] // --- ITEM ( paused_coinbase )
908-
pub type PendingBlockEmission<T> = StorageValue<_, u64, ValueQuery, DefaultZeroU64<T>>;
909917
#[pallet::storage] // --- ITEM ( total_issuance )
910918
pub type TotalIssuance<T> = StorageValue<_, u64, ValueQuery, DefaultTotalIssuance<T>>;
911919
#[pallet::storage] // --- ITEM ( total_stake )
912920
pub type TotalStake<T> = StorageValue<_, u64, ValueQuery>;
913921
#[pallet::storage] // --- ITEM ( dynamic_block ) -- block when dynamic was turned on.
914922
pub type DynamicBlock<T> = StorageValue<_, u64, ValueQuery>;
923+
#[pallet::storage] // --- ITEM ( moving_alpha ) -- subnet moving alpha.
924+
pub type SubnetMovingAlpha<T> = StorageValue<_, I96F32, ValueQuery, DefaultMovingAlpha<T>>;
925+
#[pallet::storage] // --- MAP ( netuid ) --> moving_price | The subnet moving price.
926+
pub type SubnetMovingPrice<T: Config> = StorageMap<_, Identity, u16, I96F32, ValueQuery, DefaultMovingPrice<T>>;
915927
#[pallet::storage] // --- MAP ( netuid ) --> total_volume | The total amount of TAO bought and sold since the start of the network.
916928
pub type SubnetVolume<T: Config> =
917929
StorageMap<_, Identity, u16, u128, ValueQuery, DefaultZeroU128<T>>;

pallets/subtensor/src/staking/stake_utils.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,25 @@ impl<T: Config> Pallet<T> {
4545
.unwrap_or(I96F32::saturating_from_num(0))
4646
}
4747
}
48+
pub fn get_moving_alpha_price(netuid: u16) -> I96F32 {
49+
if netuid == Self::get_root_netuid() {
50+
return I96F32::saturating_from_num(1.0); // Root.
51+
}
52+
else if SubnetMechanism::<T>::get(netuid) == 0 {
53+
return I96F32::saturating_from_num(1.0); // Stable
54+
}
55+
else {
56+
return SubnetMovingPrice::<T>::get( netuid );
57+
}
58+
}
59+
pub fn update_moving_price( netuid: u16 ) {
60+
let alpha: I96F32 = SubnetMovingAlpha::<T>::get();
61+
let minus_alpha: I96F32 = I96F32::saturating_from_num(1.0).saturating_sub(alpha);
62+
let current_price: I96F32 = alpha.saturating_mul( Self::get_alpha_price(netuid) );
63+
let current_moving: I96F32 = minus_alpha.saturating_mul( Self::get_moving_alpha_price(netuid) );
64+
let new_moving: I96F32 = current_price.saturating_add( current_moving );
65+
SubnetMovingPrice::<T>::insert( netuid, new_moving);
66+
}
4867

4968
/// Retrieves the global global weight as a normalized value between 0 and 1.
5069
///

0 commit comments

Comments
 (0)