Merge pull request #4126 from nymtech/chore/adjust-selection-weights
using performance^20 when calculating active set selection weight
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
|
||||
use cosmwasm_schema::cw_serde;
|
||||
use cosmwasm_std::Decimal;
|
||||
use cosmwasm_std::OverflowError;
|
||||
use cosmwasm_std::Uint128;
|
||||
use serde::de::Error;
|
||||
use serde::{Deserialize, Deserializer};
|
||||
@@ -71,6 +72,10 @@ impl Percent {
|
||||
// we know the cast from u128 to u8 is a safe one since the internal value must be within 0 - 1 range
|
||||
truncate_decimal(hundred * self.0).u128() as u8
|
||||
}
|
||||
|
||||
pub fn checked_pow(&self, exp: u32) -> Result<Self, OverflowError> {
|
||||
self.0.checked_pow(exp).map(Percent)
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for Percent {
|
||||
|
||||
@@ -24,7 +24,15 @@ struct MixnodeWithStakeAndPerformance {
|
||||
|
||||
impl MixnodeWithStakeAndPerformance {
|
||||
fn to_selection_weight(&self) -> f64 {
|
||||
let scaled_stake = self.total_stake * self.performance;
|
||||
let scaled_performance = match self.performance.checked_pow(20) {
|
||||
Ok(perf) => perf,
|
||||
Err(overflow) => {
|
||||
warn!("the node's performance ({}) has overflow while scaling it by the factor of 20: {overflow}. Setting it to 0 instead.", self.performance);
|
||||
return 0.;
|
||||
}
|
||||
};
|
||||
|
||||
let scaled_stake = self.total_stake * scaled_performance;
|
||||
stake_to_f64(scaled_stake)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user