File tree Expand file tree Collapse file tree 3 files changed +26
-11
lines changed
chain-impl-mockchain/src/vote Expand file tree Collapse file tree 3 files changed +26
-11
lines changed Original file line number Diff line number Diff line change @@ -40,6 +40,9 @@ pub struct Args {
40
40
/// Gamma value for Quadratic scaling
41
41
#[ clap( short, long) ]
42
42
gamma : Option < String > ,
43
+ /// Rounding precision for arithmetic
44
+ #[ clap( short, long) ]
45
+ precision : Option < String > ,
43
46
}
44
47
45
48
fn main ( ) -> Result < ( ) , Box < dyn Error > > {
@@ -70,6 +73,11 @@ fn main() -> Result<(), Box<dyn Error>> {
70
73
std:: env:: set_var ( GAMMA , gamma) ;
71
74
}
72
75
76
+ if let Some ( precision) = args. precision {
77
+ const PRECISION : & str = "QUADRATIC_VOTING_PRECISION" ;
78
+ std:: env:: set_var ( PRECISION , precision) ;
79
+ }
80
+
73
81
// Load and replay fund fragments from storage
74
82
let storage_path = PathBuf :: from ( args. fragments ) ;
75
83
Original file line number Diff line number Diff line change @@ -191,12 +191,14 @@ impl TallyResult {
191
191
let numer = gamma. numer ( ) ;
192
192
193
193
let stake = Float :: with_val ( precision, weight. 0 ) ;
194
- // r = gamma in rational form
195
- let exp_r = Rational :: from ( ( * numer, * denom) ) ;
196
- let exp_f = Float :: with_val ( precision, & exp_r) ;
197
- let p = stake. clone ( ) . pow ( & exp_f) ;
198
194
199
- let weight = p
195
+ // rational = gamma in rational form i.e fraction
196
+ // 0.5 = 1/2
197
+ let gamma = Float :: with_val ( precision, & Rational :: from ( ( * numer, * denom) ) ) ;
198
+
199
+ let stake_with_gamma_scaling = stake. clone ( ) . pow ( & gamma) ;
200
+
201
+ let weight = stake_with_gamma_scaling
200
202
. to_integer_round ( Round :: Down )
201
203
. unwrap_or ( ( Integer :: from ( weight. 0 ) , Ordering :: Less ) )
202
204
. 0
Original file line number Diff line number Diff line change @@ -183,13 +183,18 @@ impl EncryptedTally {
183
183
let numer = gamma. numer ( ) ;
184
184
185
185
let stake = Float :: with_val ( precision, weight) ;
186
- // r = gamma in rational form
187
- let exp_r = Rational :: from ( ( * numer, * denom) ) ;
188
- let exp_f = Float :: with_val ( precision, & exp_r) ;
189
- let p = stake. clone ( ) . pow ( & exp_f) ;
190
- info ! ( "{} to the power of {} is: {}" , stake, exp_f, p) ;
191
186
192
- let weight = p
187
+ // rational = gamma in rational form i.e fraction
188
+ // 0.5 = 1/2
189
+ let gamma = Float :: with_val ( precision, & Rational :: from ( ( * numer, * denom) ) ) ;
190
+
191
+ 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
+ ) ;
196
+
197
+ let weight = stake_with_gamma_scaling
193
198
. to_integer_round ( Round :: Down )
194
199
. unwrap_or ( ( Integer :: from ( weight) , Ordering :: Less ) )
195
200
. 0
You can’t perform that action at this time.
0 commit comments