Skip to content

Commit

Permalink
v1.18: Update maximum credits awarded per vote from 8 to 16 (#324)
Browse files Browse the repository at this point in the history
Update maximum credits awarded per vote from 8 to 16

This reduces the maximum penalty for voting after the grace period by
roughly 50%.  This new value was derived from looking at the effects
that TVC at max credits 8 would have for recent epochs (500+) and
noting that the effect was a bit extreme, up to and exceeding 10%
"bonus" for faster voters.  This change reduces that maximum bonus by
roughly half.

In addition, the TVC feature key has been changed, and this change is
also feature flagged behind a plumbing flag.

Co-authored-by: bji <[email protected]>
  • Loading branch information
2 people authored and willhickey committed Mar 23, 2024
1 parent 2be4ebc commit 5e4fe6b
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 35 deletions.
105 changes: 74 additions & 31 deletions programs/vote/src/vote_state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2031,32 +2031,32 @@ mod tests {
vec![32],
35,
// root: 1
// when slot 1 was voted on in slot 9, it earned 2 credits
2,
// when slot 1 was voted on in slot 9, it earned 10 credits
10,
),
// Now another vote, should earn one credit
(
vec![33],
36,
// root: 2
// when slot 2 was voted on in slot 9, it earned 3 credits
2 + 3, // 5
// when slot 2 was voted on in slot 9, it earned 11 credits
10 + 11, // 21
),
// Two votes in sequence
(
vec![34, 35],
37,
// root: 4
// when slots 3 and 4 were voted on in slot 9, they earned 4 and 5 credits
5 + 4 + 5, // 14
// when slots 3 and 4 were voted on in slot 9, they earned 12 and 13 credits
21 + 12 + 13, // 46
),
// 3 votes in sequence
(
vec![36, 37, 38],
39,
// root: 7
// slots 5, 6, and 7 earned 6, 7, and 8 credits when voted in slot 9
14 + 6 + 7 + 8, // 35
// slots 5, 6, and 7 earned 14, 15, and 16 credits when voted in slot 9
46 + 14 + 15 + 16, // 91
),
(
// 30 votes in sequence
Expand All @@ -2066,14 +2066,36 @@ mod tests {
],
69,
// root: 37
// slot 8 was voted in slot 9, earning 8 credits
// slots 9 - 25 earned 1 credit when voted in slot 34
// slot 26, 27, 28, 29, 30, 31 earned 2, 3, 4, 5, 6, 7 credits when voted in slot 34
// slot 32 earned 7 credits when voted in slot 35
// slot 33 earned 7 credits when voted in slot 36
// slot 34 and 35 earned 7 and 8 credits when voted in slot 37
// slot 36 and 37 earned 7 and 8 credits when voted in slot 39
35 + 8 + ((25 - 9) + 1) + 2 + 3 + 4 + 5 + 6 + 7 + 7 + 7 + 7 + 8 + 7 + 8, // 131
// slot 8 was voted in slot 9, earning 16 credits
// slots 9 - 25 earned 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 4, 5, 6, 7, 8, and 9 credits when voted in
// slot 34
// slot 26, 27, 28, 29, 30, 31 earned 10, 11, 12, 13, 14, 15 credits when voted in slot 34
// slot 32 earned 15 credits when voted in slot 35
// slot 33 earned 15 credits when voted in slot 36
// slot 34 and 35 earned 15 and 16 credits when voted in slot 37
// slot 36 and 37 earned 15 and 16 credits when voted in slot 39
91 + 16
+ 9 // * 1
+ 2
+ 3
+ 4
+ 5
+ 6
+ 7
+ 8
+ 9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 15
+ 15
+ 15
+ 16
+ 15
+ 16, // 327
),
// 31 votes in sequence
(
Expand All @@ -2083,11 +2105,29 @@ mod tests {
],
100,
// root: 68
// slot 38 earned 8 credits when voted in slot 39
// slot 39 - 60 earned 1 credit each when voted in slot 69
// slot 61, 62, 63, 64, 65, 66, 67, 68 earned 2, 3, 4, 5, 6, 7, 8, and 8 credits when
// slot 38 earned 16 credits when voted in slot 39
// slot 39 - 60 earned 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 4, 5, 6, 7, 8, and 9 credits
// when voted in slot 69
// slot 61, 62, 63, 64, 65, 66, 67, 68 earned 10, 11, 12, 13, 14, 15, 16, and 16 credits when
// voted in slot 69
131 + 8 + ((60 - 39) + 1) + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 8, // 204
327 + 16
+ 14 // * 1
+ 2
+ 3
+ 4
+ 5
+ 6
+ 7
+ 8
+ 9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 16, // 508
),
// Votes with expiry
(
Expand All @@ -2096,15 +2136,15 @@ mod tests {
// root: 74
// slots 96 - 114 expire
// slots 69 - 74 earned 1 credit when voted in slot 100
204 + ((74 - 69) + 1), // 210
508 + ((74 - 69) + 1), // 514
),
// More votes with expiry of a large number of votes
(
vec![200, 201],
202,
// root: 74
// slots 119 - 124 expire
210,
514,
),
(
vec![
Expand All @@ -2113,23 +2153,25 @@ mod tests {
],
227,
// root: 95
// slot 75 - 91 earned 1 credit each when voted in slot 100
// slot 92, 93, 94, 95 earned 2, 3, 4, 5, credits when voted in slot 100
210 + ((91 - 75) + 1) + 2 + 3 + 4 + 5, // 241
// slot 75 - 91 earned 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 4, 5, 6, 7, 8, and 9 credits when voted in
// slot 100
// slot 92, 93, 94, 95 earned 10, 11, 12, 13, credits when voted in slot 100
514 + 9 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13, // 613
),
(
vec![227, 228, 229, 230, 231, 232, 233, 234, 235, 236],
237,
// root: 205
// slot 115 - 118 earned 1 credit when voted in slot 130
// slot 200 and 201 earned 8 credits when voted in slot 202
// slot 115 - 118 earned 3, 4, 5, and 6 credits when voted in slot 130
// slot 200 and 201 earned 16 credits when voted in slot 202
// slots 202 - 205 earned 1 credit when voted in slot 227
241 + 1 + 1 + 1 + 1 + 8 + 8 + 1 + 1 + 1 + 1, // 265
613 + 3 + 4 + 5 + 6 + 16 + 16 + 1 + 1 + 1 + 1, // 667
),
];

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 @@ -2256,14 +2298,15 @@ mod tests {
42,
// root: 10
Some(10),
// when slots 1 - 6 were voted on in slot 12, they earned 1, 1, 1, 2, 3, and 4 credits
// when slots 7 - 10 were voted on in slot 11, they earned 6, 7, 8, and 8 credits
1 + 1 + 1 + 2 + 3 + 4 + 6 + 7 + 8 + 8,
// when slots 1 - 6 were voted on in slot 12, they earned 7, 8, 9, 10, 11, and 12 credits
// when slots 7 - 10 were voted on in slot 11, they earned 14, 15, 16, and 16 credits
7 + 8 + 9 + 10 + 11 + 12 + 14 + 15 + 16 + 16,
),
];

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
14 changes: 11 additions & 3 deletions sdk/program/src/vote/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ const DEFAULT_PRIOR_VOTERS_OFFSET: usize = 114;
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 = 8;
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)]
Expand Down Expand Up @@ -531,6 +534,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 @@ -540,13 +548,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
2 changes: 1 addition & 1 deletion sdk/src/feature_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ pub mod enable_poseidon_syscall {
}

pub mod timely_vote_credits {
solana_sdk::declare_id!("2oXpeh141pPZCTCFHBsvCwG2BtaHZZAtrVhwaxSy6brS");
solana_sdk::declare_id!("tvcF6b1TRz353zKuhBjinZkKzjmihXmBAHJdjNYw1sQ");
}

pub mod remaining_compute_units_syscall_enabled {
Expand Down

0 comments on commit 5e4fe6b

Please sign in to comment.