1
1
use super :: * ;
2
- use crate :: epoch:: math:: * ;
3
2
use alloc:: collections:: BTreeMap ;
3
+ use safe_math:: * ;
4
4
use substrate_fixed:: types:: I96F32 ;
5
5
use tle:: stream_ciphers:: AESGCMStreamCipherProvider ;
6
6
use tle:: tlock:: tld;
@@ -118,7 +118,7 @@ impl<T: Config> Pallet<T> {
118
118
let tao_in: u64 = mech_emission
119
119
. checked_mul ( subnet_proportion)
120
120
. unwrap_or ( I96F32 :: from_num ( 0 ) )
121
- . to_num :: < u64 > ( ) ;
121
+ . saturating_to_num :: < u64 > ( ) ;
122
122
log:: debug!(
123
123
"Subnet TAO emission (E_s) for netuid {:?}: {:?}" ,
124
124
netuid,
@@ -201,7 +201,7 @@ impl<T: Config> Pallet<T> {
201
201
// Calculate the owner cut.
202
202
let owner_cut: u64 = I96F32 :: from_num ( alpha_out_emission)
203
203
. saturating_mul ( Self :: get_float_subnet_owner_cut ( ) )
204
- . to_num :: < u64 > ( ) ;
204
+ . saturating_to_num :: < u64 > ( ) ;
205
205
log:: debug!( "Owner cut for netuid {:?}: {:?}" , netuid, owner_cut) ;
206
206
// Store the owner cut for this subnet.
207
207
* owner_cuts. entry ( * netuid) . or_insert ( 0 ) = owner_cut;
@@ -225,20 +225,25 @@ impl<T: Config> Pallet<T> {
225
225
let pending_alpha_emission: I96F32 =
226
226
I96F32 :: from_num ( remaining_emission) . saturating_sub ( root_emission_in_alpha) ;
227
227
// Sell root emission through the pool.
228
- let root_emission_in_tao: u64 =
229
- Self :: swap_alpha_for_tao ( * netuid, root_emission_in_alpha. to_num :: < u64 > ( ) ) ;
230
- SubnetAlphaEmissionSell :: < T > :: insert ( * netuid, root_emission_in_alpha. to_num :: < u64 > ( ) ) ;
228
+ let root_emission_in_tao: u64 = Self :: swap_alpha_for_tao (
229
+ * netuid,
230
+ root_emission_in_alpha. saturating_to_num :: < u64 > ( ) ,
231
+ ) ;
232
+ SubnetAlphaEmissionSell :: < T > :: insert (
233
+ * netuid,
234
+ root_emission_in_alpha. saturating_to_num :: < u64 > ( ) ,
235
+ ) ;
231
236
// Accumulate root divs for subnet.
232
237
PendingRootDivs :: < T > :: mutate ( * netuid, |total| {
233
238
* total = total. saturating_add ( root_emission_in_tao) ;
234
239
} ) ;
235
240
// Accumulate alpha that was swapped for the pending root divs.
236
241
PendingAlphaSwapped :: < T > :: mutate ( * netuid, |total| {
237
- * total = total. saturating_add ( root_emission_in_alpha. to_num :: < u64 > ( ) ) ;
242
+ * total = total. saturating_add ( root_emission_in_alpha. saturating_to_num :: < u64 > ( ) ) ;
238
243
} ) ;
239
244
// Accumulate alpha emission in pending.
240
245
PendingEmission :: < T > :: mutate ( * netuid, |total| {
241
- * total = total. saturating_add ( pending_alpha_emission. to_num :: < u64 > ( ) ) ;
246
+ * total = total. saturating_add ( pending_alpha_emission. saturating_to_num :: < u64 > ( ) ) ;
242
247
} ) ;
243
248
// Accumulate the owner cut in pending.
244
249
PendingOwnerCut :: < T > :: mutate ( * netuid, |total| {
@@ -413,14 +418,14 @@ impl<T: Config> Pallet<T> {
413
418
// Store the root-alpha divs under hotkey_j
414
419
root_alpha_divs
415
420
. entry ( hotkey_j. clone ( ) )
416
- . and_modify ( |e| * e = e. saturating_add ( root_divs. to_num :: < u64 > ( ) ) )
417
- . or_insert ( root_divs. to_num :: < u64 > ( ) ) ;
421
+ . and_modify ( |e| * e = e. saturating_add ( root_divs. saturating_to_num :: < u64 > ( ) ) )
422
+ . or_insert ( root_divs. saturating_to_num :: < u64 > ( ) ) ;
418
423
total_root_alpha_divs =
419
- total_root_alpha_divs. saturating_add ( root_divs. to_num :: < u64 > ( ) ) ;
424
+ total_root_alpha_divs. saturating_add ( root_divs. saturating_to_num :: < u64 > ( ) ) ;
420
425
log:: debug!(
421
426
"Stored root alpha dividends for hotkey {:?}: {:?}" ,
422
427
hotkey_j,
423
- root_divs. to_num :: <u64 >( )
428
+ root_divs. saturating_to_num :: <u64 >( )
424
429
) ;
425
430
}
426
431
}
@@ -478,26 +483,26 @@ impl<T: Config> Pallet<T> {
478
483
hotkey_j,
479
484
& Owner :: < T > :: get ( hotkey_j. clone ( ) ) ,
480
485
netuid,
481
- validator_take. to_num :: < u64 > ( ) ,
486
+ validator_take. saturating_to_num :: < u64 > ( ) ,
482
487
) ;
483
488
log:: debug!(
484
489
"Distributed validator take for hotkey {:?} on netuid {:?}: {:?}" ,
485
490
hotkey_j,
486
491
netuid,
487
- validator_take. to_num :: <u64 >( )
492
+ validator_take. saturating_to_num :: <u64 >( )
488
493
) ;
489
494
490
495
// Distribute the alpha divs to the hotkey.
491
496
Self :: increase_stake_for_hotkey_on_subnet (
492
497
hotkey_j,
493
498
netuid,
494
- rem_divs_j. to_num :: < u64 > ( ) ,
499
+ rem_divs_j. saturating_to_num :: < u64 > ( ) ,
495
500
) ;
496
501
log:: debug!(
497
502
"Distributed alpha dividends for hotkey {:?} on netuid {:?}: {:?}" ,
498
503
hotkey_j,
499
504
netuid,
500
- rem_divs_j. to_num :: <u64 >( )
505
+ rem_divs_j. saturating_to_num :: <u64 >( )
501
506
) ;
502
507
503
508
// Record dividends for this hotkey on this subnet.
@@ -522,7 +527,7 @@ impl<T: Config> Pallet<T> {
522
527
. unwrap_or ( I96F32 :: from_num ( 0 ) ) ;
523
528
let root_divs_to_pay: u64 = proportion
524
529
. saturating_mul ( I96F32 :: from_num ( pending_root_divs) )
525
- . to_num :: < u64 > ( ) ;
530
+ . saturating_to_num :: < u64 > ( ) ;
526
531
log:: debug!(
527
532
"Proportion for hotkey {:?}: {:?}, root_divs_to_pay: {:?}" ,
528
533
hotkey_j,
@@ -581,7 +586,7 @@ impl<T: Config> Pallet<T> {
581
586
let combined_contribution: I96F32 = alpha_contribution. saturating_add ( root_contribution) ;
582
587
583
588
// Return the combined contribution as a u64
584
- combined_contribution. to_num :: < u64 > ( )
589
+ combined_contribution. saturating_to_num :: < u64 > ( )
585
590
}
586
591
587
592
/// Returns a list of tuples for each parent associated with this hotkey including self
@@ -695,7 +700,7 @@ impl<T: Config> Pallet<T> {
695
700
. checked_div ( total_contribution)
696
701
. unwrap_or ( I96F32 :: from_num ( 0 ) ) ;
697
702
let parent_emission: u64 =
698
- ( remaining_emission. saturating_mul ( emission_factor) ) . to_num :: < u64 > ( ) ;
703
+ ( remaining_emission. saturating_mul ( emission_factor) ) . saturating_to_num :: < u64 > ( ) ;
699
704
700
705
// Add the parent's emission to the distribution list
701
706
dividend_tuples. push ( ( parent, parent_emission) ) ;
@@ -707,7 +712,7 @@ impl<T: Config> Pallet<T> {
707
712
// This includes the take left from the parents and the self contribution.
708
713
let child_emission = remaining_emission
709
714
. saturating_add ( child_emission_take)
710
- . to_num :: < u64 > ( )
715
+ . saturating_to_num :: < u64 > ( )
711
716
. saturating_sub ( to_parents) ;
712
717
713
718
// Add the hotkey's own emission to the distribution list
0 commit comments