1
1
use super :: * ;
2
2
use frame_support:: traits:: Get ;
3
- use substrate_fixed:: {
4
- transcendental:: log2,
5
- types:: I96F32 ,
6
- } ;
3
+ use substrate_fixed:: { transcendental:: log2, types:: I96F32 } ;
7
4
8
5
impl < T : Config > Pallet < T > {
9
-
10
6
/// Calculates the dynamic TAO emission for a given subnet.
11
7
///
12
8
/// This function determines the three terms tao_in, alpha_in, alpha_out
13
- /// which are consequetively , 1) the amount of tao injected into the pool
14
- /// 2) the amount of alpha injected into the pool and 3) the amount of alpha
9
+ /// which are consecutively , 1) the amount of tao injected into the pool
10
+ /// 2) the amount of alpha injected into the pool, and 3) the amount of alpha
15
11
/// left to be distributed towards miners/validators/owners per block.
16
12
///
17
13
/// # Arguments
@@ -21,14 +17,18 @@ impl<T: Config> Pallet<T> {
21
17
///
22
18
/// # Returns
23
19
/// * `(u64, u64, u64)` - A tuple containing:
24
- /// - `tao_in_emission`: The adjusted TAO emission always lower or equalt to tao_emission
20
+ /// - `tao_in_emission`: The adjusted TAO emission always lower or equal to tao_emission
25
21
/// - `alpha_in_emission`: The adjusted alpha emission amount to be added into the pool.
26
- /// - `alpha_out_emission`: The remaining alpha emission after adjustments to be distributed to miners/validatods .
22
+ /// - `alpha_out_emission`: The remaining alpha emission after adjustments to be distributed to miners/validators .
27
23
///
28
24
/// The algorithm ensures that the pool injection of tao_in_emission, alpha_in_emission does not effect the pool price
29
25
/// It also ensures that the total amount of alpha_in_emission + alpha_out_emission sum to 2 * alpha_block_emission
30
- /// It also ensure that 1 < alpha_out_emission < 2 * alpha_block_emission and 0 < alpha_in_emission < alpha_block_emission.
31
- pub fn get_dynamic_tao_emission ( netuid : u16 , tao_emission : u64 , alpha_block_emission : u64 ) -> ( u64 , u64 , u64 ) {
26
+ /// It also ensures that 1 < alpha_out_emission < 2 * alpha_block_emission and 0 < alpha_in_emission < alpha_block_emission.
27
+ pub fn get_dynamic_tao_emission (
28
+ netuid : u16 ,
29
+ tao_emission : u64 ,
30
+ alpha_block_emission : u64 ,
31
+ ) -> ( u64 , u64 , u64 ) {
32
32
// Init terms.
33
33
let mut tao_in_emission: I96F32 = I96F32 :: from_num ( tao_emission) ;
34
34
let float_alpha_block_emission: I96F32 = I96F32 :: from_num ( alpha_block_emission) ;
@@ -38,11 +38,18 @@ impl<T: Config> Pallet<T> {
38
38
log:: debug!( "{:?} - alpha_price: {:?}" , netuid, alpha_price) ;
39
39
40
40
// Get initial alpha_in
41
- let mut alpha_in_emission: I96F32 = I96F32 :: from_num ( tao_emission) . checked_div ( alpha_price) . unwrap_or ( float_alpha_block_emission) ;
41
+ let mut alpha_in_emission: I96F32 = I96F32 :: from_num ( tao_emission)
42
+ . checked_div ( alpha_price)
43
+ . unwrap_or ( float_alpha_block_emission) ;
42
44
43
45
// Check if we are emitting too much alpha_in
44
46
if alpha_in_emission >= float_alpha_block_emission {
45
- log:: debug!( "{:?} - alpha_in_emission: {:?} > alpha_block_emission: {:?}" , netuid, alpha_in_emission, float_alpha_block_emission) ;
47
+ log:: debug!(
48
+ "{:?} - alpha_in_emission: {:?} > alpha_block_emission: {:?}" ,
49
+ netuid,
50
+ alpha_in_emission,
51
+ float_alpha_block_emission
52
+ ) ;
46
53
47
54
// Scale down tao_in
48
55
tao_in_emission = alpha_price. saturating_mul ( float_alpha_block_emission) ;
@@ -58,15 +65,25 @@ impl<T: Config> Pallet<T> {
58
65
}
59
66
60
67
// Set Alpha in emission.
61
- let alpha_out_emission = I96F32 :: from_num ( 2 ) . saturating_mul ( float_alpha_block_emission) . saturating_sub ( alpha_in_emission) ;
68
+ let alpha_out_emission = I96F32 :: from_num ( 2 )
69
+ . saturating_mul ( float_alpha_block_emission)
70
+ . saturating_sub ( alpha_in_emission) ;
62
71
63
72
// Log results.
64
73
log:: debug!( "{:?} - tao_in_emission: {:?}" , netuid, tao_in_emission) ;
65
74
log:: debug!( "{:?} - alpha_in_emission: {:?}" , netuid, alpha_in_emission) ;
66
- log:: debug!( "{:?} - alpha_out_emission: {:?}" , netuid, alpha_out_emission) ;
75
+ log:: debug!(
76
+ "{:?} - alpha_out_emission: {:?}" ,
77
+ netuid,
78
+ alpha_out_emission
79
+ ) ;
67
80
68
81
// Return result.
69
- ( tao_in_emission. to_num :: < u64 > ( ) , alpha_in_emission. to_num :: < u64 > ( ) , alpha_out_emission. to_num :: < u64 > ( ) )
82
+ (
83
+ tao_in_emission. to_num :: < u64 > ( ) ,
84
+ alpha_in_emission. to_num :: < u64 > ( ) ,
85
+ alpha_out_emission. to_num :: < u64 > ( ) ,
86
+ )
70
87
}
71
88
72
89
/// Calculates the block emission based on the total issuance.
@@ -133,5 +150,4 @@ impl<T: Config> Pallet<T> {
133
150
}
134
151
Ok ( block_emission_u64)
135
152
}
136
-
137
- }
153
+ }
0 commit comments