File tree 1 file changed +3
-4
lines changed
1 file changed +3
-4
lines changed Original file line number Diff line number Diff line change @@ -2103,6 +2103,8 @@ pub fn calculate_reppoe_threshold(
2103
2103
block_epoch : u32 ,
2104
2104
minimum_difficulty : u32 ,
2105
2105
) -> ( Hash , f64 ) {
2106
+ // Set minimum total_active_reputation to 1 to avoid division by zero
2107
+ let total_active_rep = std:: cmp:: max ( rep_eng. total_active_reputation ( ) , 1 ) ;
2106
2108
// Add 1 to reputation because otherwise a node with 0 reputation would
2107
2109
// never be eligible for a data request
2108
2110
let my_eligibility = u64:: from ( rep_eng. get_eligibility ( pkh) ) + 1 ;
@@ -2111,17 +2113,14 @@ pub fn calculate_reppoe_threshold(
2111
2113
let max = u64:: max_value ( ) ;
2112
2114
// Compute target eligibility and hard-cap it if required
2113
2115
let target = if after_third_hard_fork ( block_epoch, get_environment ( ) ) {
2114
- // TODO: Review if next line is required (check if total active reputation could be zero)
2115
- let total_active_rep = std:: cmp:: max ( rep_eng. total_active_reputation ( ) , 1 ) ;
2116
- // If eligibility is more than 100%, cap it to (max/minimum_difficulty*factor)%
2116
+ // Eligibility must never be greater than (max/minimum_difficulty)
2117
2117
std:: cmp:: min (
2118
2118
max / u64:: from ( minimum_difficulty) ,
2119
2119
( max / total_active_rep) . saturating_mul ( my_eligibility) ,
2120
2120
)
2121
2121
. saturating_mul ( factor)
2122
2122
} else {
2123
2123
// Check for overflow: when the probability is more than 100%, cap it to 100%
2124
- let total_active_rep = rep_eng. total_active_reputation ( ) ;
2125
2124
( max / total_active_rep)
2126
2125
. saturating_mul ( my_eligibility)
2127
2126
. saturating_mul ( factor)
You can’t perform that action at this time.
0 commit comments