Fix Reduce Equalise order in offhchain phragmen (#5892)

This commit is contained in:
Kian Paimani
2020-05-05 13:50:42 +02:00
committed by GitHub
parent 1f7f8abb33
commit 16af2642ff
5 changed files with 44 additions and 31 deletions
+3 -3
View File
@@ -599,11 +599,11 @@ pub fn evaluate_support<AccountId>(
) -> PhragmenScore {
let mut min_support = ExtendedBalance::max_value();
let mut sum: ExtendedBalance = Zero::zero();
// NOTE: this will probably saturate but using big num makes it even slower. We'll have to see.
// This must run on chain..
// NOTE: The third element might saturate but fine for now since this will run on-chain and need
// to be fast.
let mut sum_squared: ExtendedBalance = Zero::zero();
for (_, support) in support.iter() {
sum += support.total;
sum = sum.saturating_add(support.total);
let squared = support.total.saturating_mul(support.total);
sum_squared = sum_squared.saturating_add(squared);
if support.total < min_support {