1
1
use super :: * ;
2
2
use frame_support:: storage:: IterableStorageDoubleMap ;
3
- use frame_support:: storage:: IterableStorageMap ;
4
- use sp_runtime:: Saturating ;
5
- use substrate_fixed:: types:: I110F18 ;
6
3
use substrate_fixed:: types:: I64F64 ;
7
4
use substrate_fixed:: types:: I96F32 ;
8
5
@@ -190,8 +187,8 @@ impl<T: Config> Pallet<T> {
190
187
mining_emission : u64 ,
191
188
) {
192
189
// --- 1. First, calculate the hotkey's share of the emission.
193
- let take_proportion: I64F64 =
194
- I64F64 :: from_num ( Delegates :: < T > :: get ( hotkey ) ) . saturating_div ( I64F64 :: from_num ( u16:: MAX ) ) ;
190
+ let take_proportion: I64F64 = I64F64 :: from_num ( Delegates :: < T > :: get ( hotkey ) )
191
+ . saturating_div ( I64F64 :: from_num ( u16:: MAX ) ) ;
195
192
let hotkey_take: u64 = take_proportion
196
193
. saturating_mul ( I64F64 :: from_num ( validating_emission) )
197
194
. to_num :: < u64 > ( ) ;
@@ -274,8 +271,8 @@ impl<T: Config> Pallet<T> {
274
271
let total_hotkey_stake: u64 = Self :: get_total_stake_for_hotkey ( hotkey) ;
275
272
276
273
// --- 5 Calculate the emission take for the hotkey.
277
- let take_proportion: I64F64 =
278
- I64F64 :: from_num ( Delegates :: < T > :: get ( hotkey ) ) . saturating_div ( I64F64 :: from_num ( u16:: MAX ) ) ;
274
+ let take_proportion: I64F64 = I64F64 :: from_num ( Delegates :: < T > :: get ( hotkey ) )
275
+ . saturating_div ( I64F64 :: from_num ( u16:: MAX ) ) ;
279
276
let hotkey_take: u64 =
280
277
( take_proportion. saturating_mul ( I64F64 :: from_num ( emission) ) ) . to_num :: < u64 > ( ) ;
281
278
@@ -287,11 +284,15 @@ impl<T: Config> Pallet<T> {
287
284
288
285
// --- 8 Iterate over each nominator.
289
286
for ( nominator, nominator_stake) in
290
- <Stake < T > as IterableStorageDoubleMap < T :: AccountId , T :: AccountId , u64 > >:: iter_prefix ( hotkey)
287
+ <Stake < T > as IterableStorageDoubleMap < T :: AccountId , T :: AccountId , u64 > >:: iter_prefix (
288
+ hotkey,
289
+ )
291
290
{
292
291
// --- 9 Check if the stake was manually increased by the user since the last emission drain for this hotkey.
293
292
// If it was, skip this nominator as they will not receive their proportion of the emission.
294
- if LastAddStakeIncrease :: < T > :: get ( hotkey, nominator. clone ( ) ) > last_hotkey_emission_drain {
293
+ if LastAddStakeIncrease :: < T > :: get ( hotkey, nominator. clone ( ) )
294
+ > last_hotkey_emission_drain
295
+ {
295
296
continue ;
296
297
}
297
298
@@ -365,9 +366,10 @@ impl<T: Config> Pallet<T> {
365
366
if tempo == 0 {
366
367
return u64:: MAX ;
367
368
}
368
- ( tempo as u64 ) . saturating_sub (
369
- ( block_number. saturating_add ( ( netuid as u64 ) . saturating_add ( 1 ) ) )
370
- % ( tempo as u64 ) . saturating_add ( 1 ) ,
371
- )
369
+ let netuid_plus_one = ( netuid as u64 ) . saturating_add ( 1 ) ;
370
+ let block_plus_netuid = block_number. saturating_add ( netuid_plus_one) ;
371
+ let tempo_plus_one = ( tempo as u64 ) . saturating_add ( 1 ) ;
372
+ let remainder = block_plus_netuid. rem_euclid ( tempo_plus_one) ;
373
+ ( tempo as u64 ) . saturating_sub ( remainder)
372
374
}
373
375
}
0 commit comments