Skip to content

Commit

Permalink
vote: reuse ff to gate tvc constant update from 8 -> 16 (#322)
Browse files Browse the repository at this point in the history
  • Loading branch information
AshwinSekar authored Mar 19, 2024
1 parent f1d56e9 commit 228413c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 2 additions & 0 deletions programs/vote/src/vote_state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2173,6 +2173,7 @@ mod tests {

let mut feature_set = FeatureSet::default();
feature_set.activate(&feature_set::timely_vote_credits::id(), 1);
feature_set.activate(&feature_set::deprecate_unused_legacy_vote_plumbing::id(), 1);

// For each vote group, process all vote groups leading up to it and it itself, and ensure that the number of
// credits earned is correct for both regular votes and vote state updates
Expand Down Expand Up @@ -2307,6 +2308,7 @@ mod tests {

let mut feature_set = FeatureSet::default();
feature_set.activate(&feature_set::timely_vote_credits::id(), 1);
feature_set.activate(&feature_set::deprecate_unused_legacy_vote_plumbing::id(), 1);

// Retroactive voting is only possible with VoteStateUpdate transactions, which is why Vote transactions are
// not tested here
Expand Down
12 changes: 10 additions & 2 deletions sdk/program/src/vote/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ pub const VOTE_CREDITS_GRACE_SLOTS: u8 = 2;
// Maximum number of credits to award for a vote; this number of credits is awarded to votes on slots that land within the grace period. After that grace period, vote credits are reduced.
pub const VOTE_CREDITS_MAXIMUM_PER_SLOT: u8 = 16;

// Previous max per slot
pub const VOTE_CREDITS_MAXIMUM_PER_SLOT_OLD: u8 = 8;

#[frozen_abi(digest = "Ch2vVEwos2EjAVqSHCyJjnN2MNX1yrpapZTGhMSCjWUH")]
#[derive(Serialize, Default, Deserialize, Debug, PartialEq, Eq, Clone, AbiExample)]
pub struct Vote {
Expand Down Expand Up @@ -597,6 +600,11 @@ impl VoteState {
.votes
.get(index)
.map_or(0, |landed_vote| landed_vote.latency);
let max_credits = if deprecate_unused_legacy_vote_plumbing {
VOTE_CREDITS_MAXIMUM_PER_SLOT
} else {
VOTE_CREDITS_MAXIMUM_PER_SLOT_OLD
};

// If latency is 0, this means that the Lockout was created and stored from a software version that did not
// store vote latencies; in this case, 1 credit is awarded
Expand All @@ -606,13 +614,13 @@ impl VoteState {
match latency.checked_sub(VOTE_CREDITS_GRACE_SLOTS) {
None | Some(0) => {
// latency was <= VOTE_CREDITS_GRACE_SLOTS, so maximum credits are awarded
VOTE_CREDITS_MAXIMUM_PER_SLOT as u64
max_credits as u64
}

Some(diff) => {
// diff = latency - VOTE_CREDITS_GRACE_SLOTS, and diff > 0
// Subtract diff from VOTE_CREDITS_MAXIMUM_PER_SLOT which is the number of credits to award
match VOTE_CREDITS_MAXIMUM_PER_SLOT.checked_sub(diff) {
match max_credits.checked_sub(diff) {
// If diff >= VOTE_CREDITS_MAXIMUM_PER_SLOT, 1 credit is awarded
None | Some(0) => 1,

Expand Down

0 comments on commit 228413c

Please sign in to comment.