mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 14:41:11 +00:00
Remove multiply_by_rational (#11598)
* Removed multiply_by_rational Replaced with multiply_by_rational_with_rounding * fixes * Test Fixes * nightly fmt * Test Fix * Fixed fuzzer.
This commit is contained in:
@@ -25,9 +25,9 @@ use crate::{
|
||||
IdentifierT, PerThing128, VoteWeight, Voter,
|
||||
};
|
||||
use sp_arithmetic::{
|
||||
helpers_128bit::multiply_by_rational,
|
||||
helpers_128bit::multiply_by_rational_with_rounding,
|
||||
traits::{Bounded, Zero},
|
||||
Rational128,
|
||||
Rational128, Rounding,
|
||||
};
|
||||
use sp_std::prelude::*;
|
||||
|
||||
@@ -143,10 +143,11 @@ pub fn seq_phragmen_core<AccountId: IdentifierT>(
|
||||
for edge in &voter.edges {
|
||||
let mut candidate = edge.candidate.borrow_mut();
|
||||
if !candidate.elected && !candidate.approval_stake.is_zero() {
|
||||
let temp_n = multiply_by_rational(
|
||||
let temp_n = multiply_by_rational_with_rounding(
|
||||
voter.load.n(),
|
||||
voter.budget,
|
||||
candidate.approval_stake,
|
||||
Rounding::Down,
|
||||
)
|
||||
.unwrap_or(Bounded::max_value());
|
||||
let temp_d = voter.load.d();
|
||||
@@ -184,9 +185,14 @@ pub fn seq_phragmen_core<AccountId: IdentifierT>(
|
||||
for edge in &mut voter.edges {
|
||||
if edge.candidate.borrow().elected {
|
||||
// update internal state.
|
||||
edge.weight = multiply_by_rational(voter.budget, edge.load.n(), voter.load.n())
|
||||
// If result cannot fit in u128. Not much we can do about it.
|
||||
.unwrap_or(Bounded::max_value());
|
||||
edge.weight = multiply_by_rational_with_rounding(
|
||||
voter.budget,
|
||||
edge.load.n(),
|
||||
voter.load.n(),
|
||||
Rounding::Down,
|
||||
)
|
||||
// If result cannot fit in u128. Not much we can do about it.
|
||||
.unwrap_or(Bounded::max_value());
|
||||
} else {
|
||||
edge.weight = 0
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user