diff --git a/tig-protocol/src/contracts/algorithms.rs b/tig-protocol/src/contracts/algorithms.rs index 472bfe4c..1cd7787f 100644 --- a/tig-protocol/src/contracts/algorithms.rs +++ b/tig-protocol/src/contracts/algorithms.rs @@ -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); + } } } } diff --git a/tig-protocol/src/contracts/players.rs b/tig-protocol/src/contracts/players.rs index 63d4ccbc..b79661d4 100644 --- a/tig-protocol/src/contracts/players.rs +++ b/tig-protocol/src/contracts/players.rs @@ -209,7 +209,7 @@ pub async fn set_vote( .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( 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| { diff --git a/tig-structs/src/core.rs b/tig-structs/src/core.rs index d8a497be..6b885642 100644 --- a/tig-structs/src/core.rs +++ b/tig-structs/src/core.rs @@ -272,9 +272,9 @@ serializable_struct_with_getters! { block_confirmed: u32, round_submitted: u32, round_pushed: u32, - round_vote_ends: u32, - vote_tally: HashMap, - voted_breakthrough: Option, + round_votes_tallied: u32, + votes_tally: HashMap, + round_active: Option, round_merged: Option, banned: bool, }