Skip to content

Commit 981d209

Browse files
committed
revert(scaling for encrypted tally only): tally fragment
1 parent 82ec649 commit 981d209

File tree

1 file changed

+1
-44
lines changed
  • src/chain-libs/chain-impl-mockchain/src/vote

1 file changed

+1
-44
lines changed

src/chain-libs/chain-impl-mockchain/src/vote/tally.rs

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,7 @@ use crate::{
33
value::Value,
44
vote::{Choice, Options},
55
};
6-
76
use chain_vote::EncryptedTally;
8-
use core::cmp::Ordering;
9-
use num::FromPrimitive;
10-
11-
use num::Rational32;
12-
use rug::Integer;
13-
use rug::{float::Round, ops::Pow, Float, Rational};
14-
15-
use std::str::FromStr;
16-
17-
use std::env;
187
use std::fmt;
198
use thiserror::Error;
209

@@ -177,39 +166,7 @@ impl TallyResult {
177166
} else {
178167
let index = choice.as_byte() as usize;
179168

180-
const GAMMA: &str = "QUADRATIC_VOTING_GAMMA";
181-
const PRECISION: &str = "QUADRATIC_VOTING_PRECISION";
182-
183-
// Apply quadratic scaling if gamma value specified in env var. Else gamma is 1 and has no effect.
184-
let mut gamma = f64::from_str(&env::var(GAMMA).unwrap_or(1.0.to_string())).unwrap();
185-
// Gamma must be between 0 and 1, anything else is treated as bad input; defaulting gamma to 1.
186-
if gamma < 0.0 || gamma > 1.0 {
187-
gamma = 1.0;
188-
}
189-
190-
let precision =
191-
u32::from_str(&env::var(PRECISION).unwrap_or(1.to_string())).unwrap_or(1);
192-
193-
let gamma = Rational32::from_f64(gamma).unwrap_or(Rational32::from_integer(1));
194-
let denom = gamma.denom();
195-
let numer = gamma.numer();
196-
197-
let stake = Float::with_val(precision, weight.0);
198-
199-
// rational = gamma in rational form i.e fraction
200-
// 0.5 = 1/2
201-
let gamma = Float::with_val(precision, &Rational::from((*numer, *denom)));
202-
203-
let stake_with_gamma_scaling = stake.clone().pow(&gamma);
204-
205-
let weight = stake_with_gamma_scaling
206-
.to_integer_round(Round::Nearest)
207-
.unwrap_or((Integer::from(weight.0), Ordering::Less))
208-
.0
209-
.to_u64()
210-
.unwrap_or(weight.0);
211-
212-
self.results[index] = self.results[index].saturating_add(Weight(weight));
169+
self.results[index] = self.results[index].saturating_add(weight);
213170

214171
Ok(())
215172
}

0 commit comments

Comments
 (0)