@@ -8,14 +8,17 @@ use color_eyre::{
88use itertools:: Itertools ;
99use jormungandr_lib:: {
1010 crypto:: hash:: Hash ,
11- interfaces:: { Address , Block0Configuration , Initial , Tally , VoteProposalStatus , VotePlanStatus } ,
11+ interfaces:: {
12+ Address , Block0Configuration , Initial , Tally , VotePlanStatus , VoteProposalStatus ,
13+ } ,
1214} ;
15+ use log:: debug;
1316use vit_servicing_station_lib:: db:: models:: { challenges:: Challenge , proposals:: Proposal } ;
1417
1518pub use types:: * ;
1619pub use util:: build_path_for_challenge;
1720
18- use self :: { types :: NotFundedReason , io :: vecs_to_maps } ;
21+ use self :: { io :: vecs_to_maps , types :: NotFundedReason } ;
1922
2023pub mod io;
2124mod types;
@@ -93,11 +96,13 @@ pub fn calculate_results(
9396 let mut depletion = fund;
9497
9598 for proposal_id in sorted_ids {
99+ debug ! ( "calculating proposal_id: {proposal_id}" ) ;
96100 let proposal = & proposals[ proposal_id] ;
97101 let voteplan = & voteplans[ proposal_id] ;
98102 let ( total_result, threshold_success) = success_results[ proposal_id] ;
99103 let ( yes, no) = extract_yes_no_votes ( proposal, voteplan) ?;
100104
105+ debug ! ( "" ) ;
101106 let funded = threshold_success && depletion > 0 && depletion >= proposal. proposal_funds ;
102107
103108 let not_funded_reason = match ( funded, threshold_success) {
@@ -135,7 +140,7 @@ fn calculate_vote_difference_and_threshold_success(
135140 voteplans : & HashMap < Hash , VoteProposalStatus > ,
136141 threshold : f64 ,
137142 total_stake_threshold : f64 ,
138- ) -> Result < HashMap < Hash , ( u64 , bool ) > > {
143+ ) -> Result < HashMap < Hash , ( i64 , bool ) > > {
139144 let result = proposals
140145 . iter ( )
141146 . map ( |( id, prop) | {
@@ -155,18 +160,26 @@ fn calculate_vote_difference_and_threshold_success(
155160fn calculate_approval_threshold (
156161 proposal : & Proposal ,
157162 voteplan : & VoteProposalStatus ,
158- approval_threshold : f64 ,
163+ threshold : f64 ,
159164 total_stake_threshold : f64 ,
160- ) -> Result < ( u64 , bool ) > {
165+ ) -> Result < ( i64 , bool ) > {
166+ debug ! (
167+ "calculating approval threshold for proposal_id: {}" ,
168+ & proposal. proposal_id
169+ ) ;
170+
161171 let ( yes, no) = extract_yes_no_votes ( proposal, voteplan) ?;
172+ debug ! ( "yes votes: {yes}, no votes: {no}" ) ;
162173
163174 let total = yes + no;
164- let diff = yes - no;
175+ let diff = yes as i64 - no as i64 ;
165176
166177 let pass_total_threshold = total as f64 >= total_stake_threshold;
167- let pass_relative_threshold = ( yes as f64 / no as f64 ) >= approval_threshold ;
178+ let pass_relative_threshold = ( yes as f64 / no as f64 ) >= threshold ;
168179 let success = pass_total_threshold && pass_relative_threshold;
169180
181+ debug ! ( "success: {success}, total_threshold: {pass_total_threshold}, relative_threshold: {pass_relative_threshold}" ) ;
182+
170183 Ok ( ( diff, success) )
171184}
172185
0 commit comments