vote: reuse ff to gate tvc constant update from 8 -> 16 (#322)
This commit is contained in:
parent
f1d56e95f5
commit
228413ca8a
|
@ -2173,6 +2173,7 @@ mod tests {
|
||||||
|
|
||||||
let mut feature_set = FeatureSet::default();
|
let mut feature_set = FeatureSet::default();
|
||||||
feature_set.activate(&feature_set::timely_vote_credits::id(), 1);
|
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
|
// 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
|
// credits earned is correct for both regular votes and vote state updates
|
||||||
|
@ -2307,6 +2308,7 @@ mod tests {
|
||||||
|
|
||||||
let mut feature_set = FeatureSet::default();
|
let mut feature_set = FeatureSet::default();
|
||||||
feature_set.activate(&feature_set::timely_vote_credits::id(), 1);
|
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
|
// Retroactive voting is only possible with VoteStateUpdate transactions, which is why Vote transactions are
|
||||||
// not tested here
|
// not tested here
|
||||||
|
|
|
@ -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.
|
// 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;
|
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")]
|
#[frozen_abi(digest = "Ch2vVEwos2EjAVqSHCyJjnN2MNX1yrpapZTGhMSCjWUH")]
|
||||||
#[derive(Serialize, Default, Deserialize, Debug, PartialEq, Eq, Clone, AbiExample)]
|
#[derive(Serialize, Default, Deserialize, Debug, PartialEq, Eq, Clone, AbiExample)]
|
||||||
pub struct Vote {
|
pub struct Vote {
|
||||||
|
@ -597,6 +600,11 @@ impl VoteState {
|
||||||
.votes
|
.votes
|
||||||
.get(index)
|
.get(index)
|
||||||
.map_or(0, |landed_vote| landed_vote.latency);
|
.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
|
// 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
|
// store vote latencies; in this case, 1 credit is awarded
|
||||||
|
@ -606,13 +614,13 @@ impl VoteState {
|
||||||
match latency.checked_sub(VOTE_CREDITS_GRACE_SLOTS) {
|
match latency.checked_sub(VOTE_CREDITS_GRACE_SLOTS) {
|
||||||
None | Some(0) => {
|
None | Some(0) => {
|
||||||
// latency was <= VOTE_CREDITS_GRACE_SLOTS, so maximum credits are awarded
|
// latency was <= VOTE_CREDITS_GRACE_SLOTS, so maximum credits are awarded
|
||||||
VOTE_CREDITS_MAXIMUM_PER_SLOT as u64
|
max_credits as u64
|
||||||
}
|
}
|
||||||
|
|
||||||
Some(diff) => {
|
Some(diff) => {
|
||||||
// diff = latency - VOTE_CREDITS_GRACE_SLOTS, and diff > 0
|
// 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
|
// 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
|
// If diff >= VOTE_CREDITS_MAXIMUM_PER_SLOT, 1 credit is awarded
|
||||||
None | Some(0) => 1,
|
None | Some(0) => 1,
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue