11use super :: * ;
22use frame_support:: storage:: IterableStorageMap ;
33use safe_math:: * ;
4- use substrate_fixed:: types:: { I96F32 , I110F18 } ;
4+ use substrate_fixed:: types:: { U96F32 , U110F18 } ;
55
66impl < T : Config + pallet_drand:: Config > Pallet < T > {
77 /// Executes the necessary operations for each block.
@@ -11,8 +11,8 @@ impl<T: Config + pallet_drand::Config> Pallet<T> {
1111 // --- 1. Adjust difficulties.
1212 Self :: adjust_registration_terms_for_networks ( ) ;
1313 // --- 2. Get the current coinbase emission.
14- let block_emission: I96F32 =
15- I96F32 :: saturating_from_num ( Self :: get_block_emission ( ) . unwrap_or ( 0 ) ) ;
14+ let block_emission: U96F32 =
15+ U96F32 :: saturating_from_num ( Self :: get_block_emission ( ) . unwrap_or ( 0 ) ) ;
1616 log:: debug!( "Block emission: {:?}" , block_emission) ;
1717 // --- 3. Run emission through network.
1818 Self :: run_coinbase ( block_emission) ;
@@ -191,67 +191,67 @@ impl<T: Config + pallet_drand::Config> Pallet<T> {
191191 }
192192
193193 /// Calculates the upgraded difficulty by multiplying the current difficulty by the ratio ( reg_actual + reg_target / reg_target + reg_target )
194- /// We use I110F18 to avoid any overflows on u64. Also min_difficulty and max_difficulty bound the range.
194+ /// We use U110F18 to avoid any overflows on u64. Also min_difficulty and max_difficulty bound the range.
195195 ///
196196 pub fn upgraded_difficulty (
197197 netuid : u16 ,
198198 current_difficulty : u64 ,
199199 registrations_this_interval : u16 ,
200200 target_registrations_per_interval : u16 ,
201201 ) -> u64 {
202- let updated_difficulty: I110F18 = I110F18 :: saturating_from_num ( current_difficulty)
203- . saturating_mul ( I110F18 :: saturating_from_num (
202+ let updated_difficulty: U110F18 = U110F18 :: saturating_from_num ( current_difficulty)
203+ . saturating_mul ( U110F18 :: saturating_from_num (
204204 registrations_this_interval. saturating_add ( target_registrations_per_interval) ,
205205 ) )
206- . safe_div ( I110F18 :: saturating_from_num (
206+ . safe_div ( U110F18 :: saturating_from_num (
207207 target_registrations_per_interval. saturating_add ( target_registrations_per_interval) ,
208208 ) ) ;
209- let alpha: I110F18 = I110F18 :: saturating_from_num ( Self :: get_adjustment_alpha ( netuid) )
210- . safe_div ( I110F18 :: saturating_from_num ( u64:: MAX ) ) ;
211- let next_value: I110F18 = alpha
212- . saturating_mul ( I110F18 :: saturating_from_num ( current_difficulty) )
209+ let alpha: U110F18 = U110F18 :: saturating_from_num ( Self :: get_adjustment_alpha ( netuid) )
210+ . safe_div ( U110F18 :: saturating_from_num ( u64:: MAX ) ) ;
211+ let next_value: U110F18 = alpha
212+ . saturating_mul ( U110F18 :: saturating_from_num ( current_difficulty) )
213213 . saturating_add (
214- I110F18 :: saturating_from_num ( 1.0 )
214+ U110F18 :: saturating_from_num ( 1.0 )
215215 . saturating_sub ( alpha)
216216 . saturating_mul ( updated_difficulty) ,
217217 ) ;
218- if next_value >= I110F18 :: saturating_from_num ( Self :: get_max_difficulty ( netuid) ) {
218+ if next_value >= U110F18 :: saturating_from_num ( Self :: get_max_difficulty ( netuid) ) {
219219 Self :: get_max_difficulty ( netuid)
220- } else if next_value <= I110F18 :: saturating_from_num ( Self :: get_min_difficulty ( netuid) ) {
220+ } else if next_value <= U110F18 :: saturating_from_num ( Self :: get_min_difficulty ( netuid) ) {
221221 return Self :: get_min_difficulty ( netuid) ;
222222 } else {
223223 return next_value. saturating_to_num :: < u64 > ( ) ;
224224 }
225225 }
226226
227227 /// Calculates the upgraded burn by multiplying the current burn by the ratio ( reg_actual + reg_target / reg_target + reg_target )
228- /// We use I110F18 to avoid any overflows on u64. Also min_burn and max_burn bound the range.
228+ /// We use U110F18 to avoid any overflows on u64. Also min_burn and max_burn bound the range.
229229 ///
230230 pub fn upgraded_burn (
231231 netuid : u16 ,
232232 current_burn : u64 ,
233233 registrations_this_interval : u16 ,
234234 target_registrations_per_interval : u16 ,
235235 ) -> u64 {
236- let updated_burn: I110F18 = I110F18 :: saturating_from_num ( current_burn)
237- . saturating_mul ( I110F18 :: saturating_from_num (
236+ let updated_burn: U110F18 = U110F18 :: saturating_from_num ( current_burn)
237+ . saturating_mul ( U110F18 :: saturating_from_num (
238238 registrations_this_interval. saturating_add ( target_registrations_per_interval) ,
239239 ) )
240- . safe_div ( I110F18 :: saturating_from_num (
240+ . safe_div ( U110F18 :: saturating_from_num (
241241 target_registrations_per_interval. saturating_add ( target_registrations_per_interval) ,
242242 ) ) ;
243- let alpha: I110F18 = I110F18 :: saturating_from_num ( Self :: get_adjustment_alpha ( netuid) )
244- . safe_div ( I110F18 :: saturating_from_num ( u64:: MAX ) ) ;
245- let next_value: I110F18 = alpha
246- . saturating_mul ( I110F18 :: saturating_from_num ( current_burn) )
243+ let alpha: U110F18 = U110F18 :: saturating_from_num ( Self :: get_adjustment_alpha ( netuid) )
244+ . safe_div ( U110F18 :: saturating_from_num ( u64:: MAX ) ) ;
245+ let next_value: U110F18 = alpha
246+ . saturating_mul ( U110F18 :: saturating_from_num ( current_burn) )
247247 . saturating_add (
248- I110F18 :: saturating_from_num ( 1.0 )
248+ U110F18 :: saturating_from_num ( 1.0 )
249249 . saturating_sub ( alpha)
250250 . saturating_mul ( updated_burn) ,
251251 ) ;
252- if next_value >= I110F18 :: saturating_from_num ( Self :: get_max_burn_as_u64 ( netuid) ) {
252+ if next_value >= U110F18 :: saturating_from_num ( Self :: get_max_burn_as_u64 ( netuid) ) {
253253 Self :: get_max_burn_as_u64 ( netuid)
254- } else if next_value <= I110F18 :: saturating_from_num ( Self :: get_min_burn_as_u64 ( netuid) ) {
254+ } else if next_value <= U110F18 :: saturating_from_num ( Self :: get_min_burn_as_u64 ( netuid) ) {
255255 return Self :: get_min_burn_as_u64 ( netuid) ;
256256 } else {
257257 return next_value. saturating_to_num :: < u64 > ( ) ;
0 commit comments