@@ -56,26 +56,30 @@ impl<T: Config> Pallet<T> {
5656 SubnetMovingPrice :: < T > :: get ( netuid)
5757 }
5858 }
59+
5960 pub fn update_moving_price ( netuid : u16 ) {
60- let blocks_since_registration = I96F32 :: saturating_from_num (
61- Self :: get_current_block_as_u64 ( ) . saturating_sub ( NetworkRegisteredAt :: < T > :: get ( netuid) ) ,
62- ) ;
61+ let blocks_since_start_call = I96F32 :: saturating_from_num ( {
62+ // We expect FirstEmissionBlockNumber to be set earlier, and we take the block when
63+ // `start_call` was called (first block before FirstEmissionBlockNumber).
64+ let start_call_block = FirstEmissionBlockNumber :: < T > :: get ( netuid)
65+ . unwrap_or_default ( )
66+ . saturating_sub ( 1 ) ;
67+
68+ Self :: get_current_block_as_u64 ( ) . saturating_sub ( start_call_block)
69+ } ) ;
6370
64- // Use halving time hyperparameter. The meaning of this parameter can be best explained under
65- // the assumption of a constant price and SubnetMovingAlpha == 0.5: It is how many blocks it
66- // will take in order for the distance between current EMA of price and current price to shorten
67- // by half.
6871 let halving_time = EMAPriceHalvingBlocks :: < T > :: get ( netuid) ;
6972 let alpha: I96F32 =
70- SubnetMovingAlpha :: < T > :: get ( ) . saturating_mul ( blocks_since_registration . safe_div (
71- blocks_since_registration . saturating_add ( I96F32 :: saturating_from_num ( halving_time) ) ,
73+ SubnetMovingAlpha :: < T > :: get ( ) . saturating_mul ( blocks_since_start_call . safe_div (
74+ blocks_since_start_call . saturating_add ( I96F32 :: saturating_from_num ( halving_time) ) ,
7275 ) ) ;
7376 let minus_alpha: I96F32 = I96F32 :: saturating_from_num ( 1.0 ) . saturating_sub ( alpha) ;
7477 let current_price: I96F32 = alpha
7578 . saturating_mul ( Self :: get_alpha_price ( netuid) . min ( I96F32 :: saturating_from_num ( 1.0 ) ) ) ;
7679 let current_moving: I96F32 =
7780 minus_alpha. saturating_mul ( Self :: get_moving_alpha_price ( netuid) ) ;
7881 let new_moving: I96F32 = current_price. saturating_add ( current_moving) ;
82+
7983 SubnetMovingPrice :: < T > :: insert ( netuid, new_moving) ;
8084 }
8185
0 commit comments