Skip to content

Commit 491490c

Browse files
committed
feat(rug): fractional powers without roots
1 parent 5c45c45 commit 491490c

File tree

4 files changed

+11
-10
lines changed

4 files changed

+11
-10
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,11 @@ impl TallyResult {
181181
const PRECISION: &str = "QUADRATIC_VOTING_PRECISION";
182182

183183
// Apply quadratic scaling if gamma value specified in env var. Else gamma is 1 and has no effect.
184-
let gamma = f64::from_str(&env::var(GAMMA).unwrap_or(1.0.to_string())).unwrap();
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+
}
185189

186190
let precision =
187191
u32::from_str(&env::var(PRECISION).unwrap_or(1.to_string())).unwrap_or(1);

src/chain-libs/chain-vote/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const_format = "0.2"
1616
base64 = "0.21.0"
1717
rug = "1.26.1"
1818
num = "0.4.3"
19-
tracing = "*"
19+
2020

2121

2222
[dev-dependencies]

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ use base64::{engine::general_purpose, Engine as _};
1818
use num::Rational32;
1919
use rug::Integer;
2020

21-
use tracing::info;
22-
2321
use cryptoxide::blake2b::Blake2b;
2422
use cryptoxide::digest::Digest;
2523

@@ -174,7 +172,11 @@ impl EncryptedTally {
174172
const PRECISION: &str = "QUADRATIC_VOTING_PRECISION";
175173

176174
// Apply quadratic scaling if gamma value specified in env var. Else gamma is 1 and has no effect.
177-
let gamma = f64::from_str(&env::var(GAMMA).unwrap_or(1.0.to_string())).unwrap();
175+
let mut gamma = f64::from_str(&env::var(GAMMA).unwrap_or(1.0.to_string())).unwrap();
176+
// Gamma must be between 0 and 1, anything else is treated as bad input; defaulting gamma to 1.
177+
if gamma < 0.0 || gamma > 1.0 {
178+
gamma = 1.0;
179+
}
178180

179181
let precision = u32::from_str(&env::var(PRECISION).unwrap_or(1.to_string())).unwrap_or(1);
180182

@@ -189,10 +191,6 @@ impl EncryptedTally {
189191
let gamma = Float::with_val(precision, &Rational::from((*numer, *denom)));
190192

191193
let stake_with_gamma_scaling = stake.clone().pow(&gamma);
192-
info!(
193-
"{} to the power of {} is: {}",
194-
stake, gamma, stake_with_gamma_scaling
195-
);
196194

197195
let weight = stake_with_gamma_scaling
198196
.to_integer_round(Round::Down)

0 commit comments

Comments
 (0)