Skip to content

Commit 228413c

Browse files
authored
vote: reuse ff to gate tvc constant update from 8 -> 16 (#322)
1 parent f1d56e9 commit 228413c

File tree

2 files changed

+12
-2
lines changed
  • programs/vote/src/vote_state
  • sdk/program/src/vote/state

2 files changed

+12
-2
lines changed

programs/vote/src/vote_state/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2173,6 +2173,7 @@ mod tests {
21732173

21742174
let mut feature_set = FeatureSet::default();
21752175
feature_set.activate(&feature_set::timely_vote_credits::id(), 1);
2176+
feature_set.activate(&feature_set::deprecate_unused_legacy_vote_plumbing::id(), 1);
21762177

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

23082309
let mut feature_set = FeatureSet::default();
23092310
feature_set.activate(&feature_set::timely_vote_credits::id(), 1);
2311+
feature_set.activate(&feature_set::deprecate_unused_legacy_vote_plumbing::id(), 1);
23102312

23112313
// Retroactive voting is only possible with VoteStateUpdate transactions, which is why Vote transactions are
23122314
// not tested here

sdk/program/src/vote/state/mod.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ pub const VOTE_CREDITS_GRACE_SLOTS: u8 = 2;
4747
// 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.
4848
pub const VOTE_CREDITS_MAXIMUM_PER_SLOT: u8 = 16;
4949

50+
// Previous max per slot
51+
pub const VOTE_CREDITS_MAXIMUM_PER_SLOT_OLD: u8 = 8;
52+
5053
#[frozen_abi(digest = "Ch2vVEwos2EjAVqSHCyJjnN2MNX1yrpapZTGhMSCjWUH")]
5154
#[derive(Serialize, Default, Deserialize, Debug, PartialEq, Eq, Clone, AbiExample)]
5255
pub struct Vote {
@@ -597,6 +600,11 @@ impl VoteState {
597600
.votes
598601
.get(index)
599602
.map_or(0, |landed_vote| landed_vote.latency);
603+
let max_credits = if deprecate_unused_legacy_vote_plumbing {
604+
VOTE_CREDITS_MAXIMUM_PER_SLOT
605+
} else {
606+
VOTE_CREDITS_MAXIMUM_PER_SLOT_OLD
607+
};
600608

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

612620
Some(diff) => {
613621
// diff = latency - VOTE_CREDITS_GRACE_SLOTS, and diff > 0
614622
// Subtract diff from VOTE_CREDITS_MAXIMUM_PER_SLOT which is the number of credits to award
615-
match VOTE_CREDITS_MAXIMUM_PER_SLOT.checked_sub(diff) {
623+
match max_credits.checked_sub(diff) {
616624
// If diff >= VOTE_CREDITS_MAXIMUM_PER_SLOT, 1 credit is awarded
617625
None | Some(0) => 1,
618626

0 commit comments

Comments
 (0)