Skip to content

Commit 72e6c8f

Browse files
committed
refactor(gamma): big decimal
1 parent eabf187 commit 72e6c8f

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

src/audit/src/offline/bin/main.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ pub struct Args {
3737
/// cross reference official results
3838
#[clap(short, long)]
3939
official_results: Option<String>,
40-
/// Quadratic scaling
40+
/// Gamma value for Quadratic scaling
4141
#[clap(short, long)]
4242
gamma: Option<String>,
43-
/// Quadratic scaling
43+
/// Rounding precision for arithmetic
4444
#[clap(short, long)]
4545
precision: Option<String>,
4646
}
@@ -103,8 +103,8 @@ fn main() -> Result<(), Box<dyn Error>> {
103103
let shares_and_results = extract_decryption_shares_and_results(all_fragments);
104104

105105
if let Some(gamma) = args.gamma {
106-
const SCALE_FACTOR: &str = "QUADRATIC_VOTING_SCALING_FACTOR";
107-
std::env::set_var(SCALE_FACTOR, gamma);
106+
const GAMMA: &str = "QUADRATIC_VOTING_GAMMA";
107+
std::env::set_var(GAMMA, gamma);
108108
}
109109

110110
if let Some(precision) = args.precision {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,14 +173,14 @@ impl TallyResult {
173173
} else {
174174
let index = choice.as_byte() as usize;
175175

176-
const SCALE_FACTOR: &str = "QUADRATIC_VOTING_SCALING_FACTOR";
176+
const GAMMA: &str = "QUADRATIC_VOTING_GAMMA";
177177
const PRECISION: &str = "QUADRATIC_VOTING_PRECISION";
178178

179-
let scaling_factor = env::var(SCALE_FACTOR).unwrap_or(1.to_string());
179+
let gamma = env::var(GAMMA).unwrap_or(1.to_string());
180180
let precision =
181181
i64::from_str(&env::var(PRECISION).unwrap_or(1.to_string())).unwrap_or(1);
182182

183-
let gamma = BigDecimal::from_str(&scaling_factor).unwrap_or(BigDecimal::from(1));
183+
let gamma = BigDecimal::from_str(&gamma).unwrap_or(BigDecimal::from(1));
184184
let stake = BigDecimal::from(weight.0);
185185

186186
let weight = (gamma * stake)

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,13 +165,13 @@ impl EncryptedTally {
165165
assert_eq!(ballot.vote().len(), self.r.len());
166166
assert_eq!(ballot.fingerprint(), &self.fingerprint);
167167

168-
const SCALE_FACTOR: &str = "QUADRATIC_VOTING_SCALING_FACTOR";
168+
const GAMMA: &str = "QUADRATIC_VOTING_GAMMA";
169169
const PRECISION: &str = "QUADRATIC_VOTING_PRECISION";
170170

171-
let scaling_factor = env::var(SCALE_FACTOR).unwrap_or(1.to_string());
171+
let gamma = env::var(GAMMA).unwrap_or(1.to_string());
172172
let precision = i64::from_str(&env::var(PRECISION).unwrap_or(1.to_string())).unwrap_or(1);
173173

174-
let gamma = BigDecimal::from_str(&scaling_factor).unwrap_or(BigDecimal::from(1));
174+
let gamma = BigDecimal::from_str(&gamma).unwrap_or(BigDecimal::from(1));
175175
let stake = BigDecimal::from(weight);
176176

177177
let weight = (gamma * stake).round(precision).to_u64().unwrap_or(weight);

0 commit comments

Comments
 (0)