Rename fields to votes tallied.

This commit is contained in:
FiveMovesAhead 2024-12-04 04:33:21 +00:00
parent 3e8ac7badb
commit 461dcd19aa
3 changed files with 14 additions and 13 deletions

View File

@ -151,7 +151,7 @@ pub(crate) async fn update(cache: &mut AddBlockCache) {
// update votes
for breakthrough_state in voting_breakthroughs_state.values_mut() {
breakthrough_state.vote_tally = HashMap::from([
breakthrough_state.votes_tally = HashMap::from([
(true, PreciseNumber::from(0)),
(false, PreciseNumber::from(0)),
]);
@ -161,13 +161,13 @@ pub(crate) async fn update(cache: &mut AddBlockCache) {
for (breakthrough_id, vote) in player_state.votes.iter() {
let yes = vote.value;
if let Some(breakthrough_state) = voting_breakthroughs_state.get_mut(breakthrough_id) {
let n = breakthrough_state.round_vote_ends - block_details.round;
let n = breakthrough_state.round_votes_tallied - block_details.round;
let votes: PreciseNumber = player_data
.deposit_by_locked_period
.iter()
.skip(n as usize)
.sum();
*breakthrough_state.vote_tally.get_mut(&yes).unwrap() += votes;
*breakthrough_state.votes_tally.get_mut(&yes).unwrap() += votes;
}
}
}
@ -287,12 +287,13 @@ pub(crate) async fn update(cache: &mut AddBlockCache) {
let yes_threshold = PreciseNumber::from_f64(config.breakthroughs.min_percent_yes_votes);
let zero = PreciseNumber::from(0);
for breakthrough in voting_breakthroughs_state.values_mut() {
if breakthrough.round_vote_ends == block_details.round + 1 {
let yes = &breakthrough.vote_tally[&true];
let no = &breakthrough.vote_tally[&false];
if breakthrough.round_votes_tallied == block_details.round + 1 {
let yes = &breakthrough.votes_tally[&true];
let no = &breakthrough.votes_tally[&false];
let total = yes + no;
breakthrough.voted_breakthrough =
Some(total != zero && yes / total >= yes_threshold);
if total != zero && yes / total >= yes_threshold {
breakthrough.round_active = Some(block_details.round + 1);
}
}
}
}

View File

@ -209,7 +209,7 @@ pub async fn set_vote<T: Context>(
.await
.ok_or_else(|| anyhow!("Invalid breakthrough '{}'", breakthrough_id))?;
if breakthrough_state.round_pushed <= latest_block_details.round
&& latest_block_details.round < breakthrough_state.round_vote_ends
&& latest_block_details.round < breakthrough_state.round_votes_tallied
{
return Err(anyhow!("Cannot vote on breakthrough '{}'", breakthrough_id));
}
@ -224,7 +224,7 @@ pub async fn set_vote<T: Context>(
let player_data = ctx
.get_player_block_data(&player_id, &latest_block_id)
.await;
let n = breakthrough_state.round_vote_ends - latest_block_details.round
let n = breakthrough_state.round_votes_tallied - latest_block_details.round
+ config.breakthroughs.min_lock_period_to_vote;
let zero = PreciseNumber::from(0);
if player_data.is_some_and(|d| {

View File

@ -272,9 +272,9 @@ serializable_struct_with_getters! {
block_confirmed: u32,
round_submitted: u32,
round_pushed: u32,
round_vote_ends: u32,
vote_tally: HashMap<bool, PreciseNumber>,
voted_breakthrough: Option<bool>,
round_votes_tallied: u32,
votes_tally: HashMap<bool, PreciseNumber>,
round_active: Option<u32>,
round_merged: Option<u32>,
banned: bool,
}