Skip to content

Commit d013809

Browse files
mergify[bot]AshwinSekar
authored andcommitted
v1.17: vote: deprecate unused legacy vote tx plumbing (backport of pyth-network#274) (pyth-network#275)
* vote: deprecate unused legacy vote tx plumbing (pyth-network#274) (cherry picked from commit b27c80a) # Conflicts: # sdk/src/feature_set.rs * fix conflicts --------- Co-authored-by: Ashwin Sekar <ashwin@anza.xyz> Co-authored-by: Ashwin Sekar <ashwin@solana.com>
1 parent e7ae631 commit d013809

File tree

4 files changed

+87
-24
lines changed

4 files changed

+87
-24
lines changed

programs/vote/benches/process_vote.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ fn create_accounts() -> (Slot, SlotHashes, Vec<TransactionAccount>, Vec<AccountM
4848
);
4949

5050
for next_vote_slot in 0..num_initial_votes {
51-
vote_state.process_next_vote_slot(next_vote_slot, 0, 0);
51+
vote_state.process_next_vote_slot(next_vote_slot, 0, 0, true, true);
5252
}
5353
let mut vote_account_data: Vec<u8> = vec![0; VoteState::size_of()];
5454
let versioned = VoteStateVersions::new_current(vote_state);

programs/vote/src/vote_state/mod.rs

Lines changed: 62 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,9 @@ pub fn process_new_vote_state(
616616
let timely_vote_credits = feature_set.map_or(false, |f| {
617617
f.is_active(&feature_set::timely_vote_credits::id())
618618
});
619+
let deprecate_unused_legacy_vote_plumbing = feature_set.map_or(false, |f| {
620+
f.is_active(&feature_set::deprecate_unused_legacy_vote_plumbing::id())
621+
});
619622
let mut earned_credits = if timely_vote_credits { 0_u64 } else { 1_u64 };
620623

621624
if let Some(new_root) = new_root {
@@ -625,7 +628,11 @@ pub fn process_new_vote_state(
625628
if current_vote.slot() <= new_root {
626629
if timely_vote_credits || (current_vote.slot() != new_root) {
627630
earned_credits = earned_credits
628-
.checked_add(vote_state.credits_for_vote_at_index(current_vote_state_index))
631+
.checked_add(vote_state.credits_for_vote_at_index(
632+
current_vote_state_index,
633+
timely_vote_credits,
634+
deprecate_unused_legacy_vote_plumbing,
635+
))
629636
.expect("`earned_credits` does not overflow");
630637
}
631638
current_vote_state_index = current_vote_state_index
@@ -738,11 +745,19 @@ pub fn process_vote_unfiltered(
738745
slot_hashes: &[SlotHash],
739746
epoch: Epoch,
740747
current_slot: Slot,
748+
timely_vote_credits: bool,
749+
deprecate_unused_legacy_vote_plumbing: bool,
741750
) -> Result<(), VoteError> {
742751
check_slots_are_valid(vote_state, vote_slots, &vote.hash, slot_hashes)?;
743-
vote_slots
744-
.iter()
745-
.for_each(|s| vote_state.process_next_vote_slot(*s, epoch, current_slot));
752+
vote_slots.iter().for_each(|s| {
753+
vote_state.process_next_vote_slot(
754+
*s,
755+
epoch,
756+
current_slot,
757+
timely_vote_credits,
758+
deprecate_unused_legacy_vote_plumbing,
759+
)
760+
});
746761
Ok(())
747762
}
748763

@@ -752,6 +767,8 @@ pub fn process_vote(
752767
slot_hashes: &[SlotHash],
753768
epoch: Epoch,
754769
current_slot: Slot,
770+
timely_vote_credits: bool,
771+
deprecate_unused_legacy_vote_plumbing: bool,
755772
) -> Result<(), VoteError> {
756773
if vote.slots.is_empty() {
757774
return Err(VoteError::EmptySlots);
@@ -773,6 +790,8 @@ pub fn process_vote(
773790
slot_hashes,
774791
epoch,
775792
current_slot,
793+
timely_vote_credits,
794+
deprecate_unused_legacy_vote_plumbing,
776795
)
777796
}
778797

@@ -789,6 +808,8 @@ pub fn process_vote_unchecked(vote_state: &mut VoteState, vote: Vote) -> Result<
789808
&slot_hashes,
790809
vote_state.current_epoch(),
791810
0,
811+
true,
812+
true,
792813
)
793814
}
794815

@@ -1036,7 +1057,18 @@ pub fn process_vote_with_account<S: std::hash::BuildHasher>(
10361057
) -> Result<(), InstructionError> {
10371058
let mut vote_state = verify_and_get_vote_state(vote_account, clock, signers)?;
10381059

1039-
process_vote(&mut vote_state, vote, slot_hashes, clock.epoch, clock.slot)?;
1060+
let timely_vote_credits = feature_set.is_active(&feature_set::timely_vote_credits::id());
1061+
let deprecate_unused_legacy_vote_plumbing =
1062+
feature_set.is_active(&feature_set::deprecate_unused_legacy_vote_plumbing::id());
1063+
process_vote(
1064+
&mut vote_state,
1065+
vote,
1066+
slot_hashes,
1067+
clock.epoch,
1068+
clock.slot,
1069+
timely_vote_credits,
1070+
deprecate_unused_legacy_vote_plumbing,
1071+
)?;
10401072
if let Some(timestamp) = vote.timestamp {
10411073
vote.slots
10421074
.iter()
@@ -1219,7 +1251,7 @@ mod tests {
12191251
134, 135,
12201252
]
12211253
.into_iter()
1222-
.for_each(|v| vote_state.process_next_vote_slot(v, 4, 0));
1254+
.for_each(|v| vote_state.process_next_vote_slot(v, 4, 0, false, true));
12231255

12241256
let version1_14_11_serialized = bincode::serialize(&VoteStateVersions::V1_14_11(Box::new(
12251257
VoteState1_14_11::from(vote_state.clone()),
@@ -1511,11 +1543,11 @@ mod tests {
15111543
let slot_hashes: Vec<_> = vote.slots.iter().rev().map(|x| (*x, vote.hash)).collect();
15121544

15131545
assert_eq!(
1514-
process_vote(&mut vote_state_a, &vote, &slot_hashes, 0, 0),
1546+
process_vote(&mut vote_state_a, &vote, &slot_hashes, 0, 0, true, true),
15151547
Ok(())
15161548
);
15171549
assert_eq!(
1518-
process_vote(&mut vote_state_b, &vote, &slot_hashes, 0, 0),
1550+
process_vote(&mut vote_state_b, &vote, &slot_hashes, 0, 0, true, true),
15191551
Ok(())
15201552
);
15211553
assert_eq!(recent_votes(&vote_state_a), recent_votes(&vote_state_b));
@@ -1528,12 +1560,12 @@ mod tests {
15281560
let vote = Vote::new(vec![0], Hash::default());
15291561
let slot_hashes: Vec<_> = vec![(0, vote.hash)];
15301562
assert_eq!(
1531-
process_vote(&mut vote_state, &vote, &slot_hashes, 0, 0),
1563+
process_vote(&mut vote_state, &vote, &slot_hashes, 0, 0, true, true),
15321564
Ok(())
15331565
);
15341566
let recent = recent_votes(&vote_state);
15351567
assert_eq!(
1536-
process_vote(&mut vote_state, &vote, &slot_hashes, 0, 0),
1568+
process_vote(&mut vote_state, &vote, &slot_hashes, 0, 0, true, true),
15371569
Err(VoteError::VoteTooOld)
15381570
);
15391571
assert_eq!(recent, recent_votes(&vote_state));
@@ -1593,7 +1625,7 @@ mod tests {
15931625
let vote = Vote::new(vec![0], Hash::default());
15941626
let slot_hashes: Vec<_> = vec![(*vote.slots.last().unwrap(), vote.hash)];
15951627
assert_eq!(
1596-
process_vote(&mut vote_state, &vote, &slot_hashes, 0, 0),
1628+
process_vote(&mut vote_state, &vote, &slot_hashes, 0, 0, true, true),
15971629
Ok(())
15981630
);
15991631
assert_eq!(
@@ -1609,7 +1641,7 @@ mod tests {
16091641
let vote = Vote::new(vec![0], Hash::default());
16101642
let slot_hashes: Vec<_> = vec![(*vote.slots.last().unwrap(), vote.hash)];
16111643
assert_eq!(
1612-
process_vote(&mut vote_state, &vote, &slot_hashes, 0, 0),
1644+
process_vote(&mut vote_state, &vote, &slot_hashes, 0, 0, true, true),
16131645
Ok(())
16141646
);
16151647

@@ -1628,7 +1660,7 @@ mod tests {
16281660
let vote = Vote::new(vec![0], Hash::default());
16291661
let slot_hashes: Vec<_> = vec![(*vote.slots.last().unwrap(), vote.hash)];
16301662
assert_eq!(
1631-
process_vote(&mut vote_state, &vote, &slot_hashes, 0, 0),
1663+
process_vote(&mut vote_state, &vote, &slot_hashes, 0, 0, true, true),
16321664
Ok(())
16331665
);
16341666

@@ -1645,7 +1677,7 @@ mod tests {
16451677

16461678
let vote = Vote::new(vec![], Hash::default());
16471679
assert_eq!(
1648-
process_vote(&mut vote_state, &vote, &[], 0, 0),
1680+
process_vote(&mut vote_state, &vote, &[], 0, 0, true, true),
16491681
Err(VoteError::EmptySlots)
16501682
);
16511683
}
@@ -1901,7 +1933,9 @@ mod tests {
19011933
&vote,
19021934
&slot_hashes,
19031935
0,
1904-
vote_group.1 // vote_group.1 is the slot in which the vote was cast
1936+
vote_group.1, // vote_group.1 is the slot in which the vote was cast
1937+
true,
1938+
true
19051939
),
19061940
Ok(())
19071941
);
@@ -2793,7 +2827,7 @@ mod tests {
27932827
// error with `VotesTooOldAllFiltered`
27942828
let slot_hashes = vec![(3, Hash::new_unique()), (2, Hash::new_unique())];
27952829
assert_eq!(
2796-
process_vote(&mut vote_state, &vote, &slot_hashes, 0, 0),
2830+
process_vote(&mut vote_state, &vote, &slot_hashes, 0, 0, true, true),
27972831
Err(VoteError::VotesTooOldAllFiltered)
27982832
);
27992833

@@ -2807,7 +2841,7 @@ mod tests {
28072841
.1;
28082842

28092843
let vote = Vote::new(vec![old_vote_slot, vote_slot], vote_slot_hash);
2810-
process_vote(&mut vote_state, &vote, &slot_hashes, 0, 0).unwrap();
2844+
process_vote(&mut vote_state, &vote, &slot_hashes, 0, 0, true, true).unwrap();
28112845
assert_eq!(
28122846
vote_state
28132847
.votes
@@ -2836,8 +2870,17 @@ mod tests {
28362870
.unwrap()
28372871
.1;
28382872
let vote = Vote::new(vote_slots, vote_hash);
2839-
process_vote_unfiltered(&mut vote_state, &vote.slots, &vote, slot_hashes, 0, 0)
2840-
.unwrap();
2873+
process_vote_unfiltered(
2874+
&mut vote_state,
2875+
&vote.slots,
2876+
&vote,
2877+
slot_hashes,
2878+
0,
2879+
0,
2880+
true,
2881+
true,
2882+
)
2883+
.unwrap();
28412884
}
28422885

28432886
vote_state

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

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,8 @@ impl VoteState {
448448
next_vote_slot: Slot,
449449
epoch: Epoch,
450450
current_slot: Slot,
451+
timely_vote_credits: bool,
452+
deprecate_unused_legacy_vote_plumbing: bool,
451453
) {
452454
// Ignore votes for slots earlier than we already have votes for
453455
if self
@@ -460,13 +462,21 @@ impl VoteState {
460462
self.pop_expired_votes(next_vote_slot);
461463

462464
let landed_vote = LandedVote {
463-
latency: Self::compute_vote_latency(next_vote_slot, current_slot),
465+
latency: if timely_vote_credits || !deprecate_unused_legacy_vote_plumbing {
466+
Self::compute_vote_latency(next_vote_slot, current_slot)
467+
} else {
468+
0
469+
},
464470
lockout: Lockout::new(next_vote_slot),
465471
};
466472

467473
// Once the stack is full, pop the oldest lockout and distribute rewards
468474
if self.votes.len() == MAX_LOCKOUT_HISTORY {
469-
let credits = self.credits_for_vote_at_index(0);
475+
let credits = self.credits_for_vote_at_index(
476+
0,
477+
timely_vote_credits,
478+
deprecate_unused_legacy_vote_plumbing,
479+
);
470480
let landed_vote = self.votes.pop_front().unwrap();
471481
self.root_slot = Some(landed_vote.slot());
472482

@@ -511,15 +521,20 @@ impl VoteState {
511521
}
512522

513523
/// Returns the credits to award for a vote at the given lockout slot index
514-
pub fn credits_for_vote_at_index(&self, index: usize) -> u64 {
524+
pub fn credits_for_vote_at_index(
525+
&self,
526+
index: usize,
527+
timely_vote_credits: bool,
528+
deprecate_unused_legacy_vote_plumbing: bool,
529+
) -> u64 {
515530
let latency = self
516531
.votes
517532
.get(index)
518533
.map_or(0, |landed_vote| landed_vote.latency);
519534

520535
// If latency is 0, this means that the Lockout was created and stored from a software version that did not
521536
// store vote latencies; in this case, 1 credit is awarded
522-
if latency == 0 {
537+
if latency == 0 || (deprecate_unused_legacy_vote_plumbing && !timely_vote_credits) {
523538
1
524539
} else {
525540
match latency.checked_sub(VOTE_CREDITS_GRACE_SLOTS) {

sdk/src/feature_set.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,10 @@ pub mod disable_bpf_loader_instructions {
748748
solana_sdk::declare_id!("7WeS1vfPRgeeoXArLh7879YcB9mgE9ktjPDtajXeWfXn");
749749
}
750750

751+
pub mod deprecate_unused_legacy_vote_plumbing {
752+
solana_sdk::declare_id!("6Uf8S75PVh91MYgPQSHnjRAPQq6an5BDv9vomrCwDqLe");
753+
}
754+
751755
lazy_static! {
752756
/// Map of feature identifiers to user-visible description
753757
pub static ref FEATURE_NAMES: HashMap<Pubkey, &'static str> = [
@@ -930,6 +934,7 @@ lazy_static! {
930934
(index_erasure_conflict_duplicate_proofs::id(), "generate duplicate proofs for index and erasure conflicts #34360"),
931935
(curve25519_restrict_msm_length::id(), "restrict curve25519 multiscalar multiplication vector lengths #34763"),
932936
(disable_bpf_loader_instructions::id(), "disable bpf loader management instructions #34194"),
937+
(deprecate_unused_legacy_vote_plumbing::id(), "Deprecate unused legacy vote tx plumbing"),
933938
/*************** ADD NEW FEATURES HERE ***************/
934939
]
935940
.iter()

0 commit comments

Comments
 (0)