@@ -58,18 +58,24 @@ impl<T: Config> Pallet<T> {
58
58
}
59
59
}
60
60
pub fn update_moving_price ( netuid : u16 ) {
61
- let blocks_since_registration = U96F32 :: saturating_from_num (
62
- Self :: get_current_block_as_u64 ( ) . saturating_sub ( NetworkRegisteredAt :: < T > :: get ( netuid) ) ,
63
- ) ;
61
+ let blocks_since_start_call = U96F32 :: 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
+ } ) ;
64
70
65
71
// Use halving time hyperparameter. The meaning of this parameter can be best explained under
66
72
// the assumption of a constant price and SubnetMovingAlpha == 0.5: It is how many blocks it
67
73
// will take in order for the distance between current EMA of price and current price to shorten
68
74
// by half.
69
75
let halving_time = EMAPriceHalvingBlocks :: < T > :: get ( netuid) ;
70
76
let current_ma_unsigned = U96F32 :: saturating_from_num ( SubnetMovingAlpha :: < T > :: get ( ) ) ;
71
- let alpha: U96F32 = current_ma_unsigned. saturating_mul ( blocks_since_registration . safe_div (
72
- blocks_since_registration . saturating_add ( U96F32 :: saturating_from_num ( halving_time) ) ,
77
+ let alpha: U96F32 = current_ma_unsigned. saturating_mul ( blocks_since_start_call . safe_div (
78
+ blocks_since_start_call . saturating_add ( U96F32 :: saturating_from_num ( halving_time) ) ,
73
79
) ) ;
74
80
// Because alpha = b / (b + h), where b and h > 0, alpha < 1, so 1 - alpha > 0.
75
81
// We can use unsigned type here: U96F32
0 commit comments