Skip to content

Commit

Permalink
vote: deprecate legacy vote instructions (#587)
Browse files Browse the repository at this point in the history
* vote: deprecate legacy vote instructions

* fix tests
  • Loading branch information
AshwinSekar authored Aug 15, 2024
1 parent 6476d5f commit 993d223
Show file tree
Hide file tree
Showing 19 changed files with 275 additions and 195 deletions.
44 changes: 3 additions & 41 deletions core/src/banking_stage/latest_unprocessed_votes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,8 +424,7 @@ mod tests {
},
solana_sdk::{hash::Hash, signature::Signer, system_transaction::transfer},
solana_vote_program::{
vote_state::TowerSync,
vote_transaction::{new_tower_sync_transaction, new_vote_transaction},
vote_state::TowerSync, vote_transaction::new_tower_sync_transaction,
},
std::{sync::Arc, thread::Builder},
};
Expand Down Expand Up @@ -467,40 +466,8 @@ mod tests {
#[test]
fn test_deserialize_vote_packets() {
let keypairs = ValidatorVoteKeypairs::new_rand();
let bankhash = Hash::new_unique();
let blockhash = Hash::new_unique();
let switch_proof = Hash::new_unique();
let mut vote = Packet::from_data(
None,
new_vote_transaction(
vec![0, 1, 2],
bankhash,
blockhash,
&keypairs.node_keypair,
&keypairs.vote_keypair,
&keypairs.vote_keypair,
None,
),
)
.unwrap();
vote.meta_mut().flags.set(PacketFlags::SIMPLE_VOTE_TX, true);
let mut vote_switch = Packet::from_data(
None,
new_vote_transaction(
vec![0, 1, 2],
bankhash,
blockhash,
&keypairs.node_keypair,
&keypairs.vote_keypair,
&keypairs.vote_keypair,
Some(switch_proof),
),
)
.unwrap();
vote_switch
.meta_mut()
.flags
.set(PacketFlags::SIMPLE_VOTE_TX, true);
let mut tower_sync = Packet::from_data(
None,
new_tower_sync_transaction(
Expand Down Expand Up @@ -543,13 +510,8 @@ mod tests {
),
)
.unwrap();
let packet_batch = PacketBatch::new(vec![
vote,
vote_switch,
tower_sync,
tower_sync_switch,
random_transaction,
]);
let packet_batch =
PacketBatch::new(vec![tower_sync, tower_sync_switch, random_transaction]);

let deserialized_packets = deserialize_packets(
&packet_batch,
Expand Down
12 changes: 5 additions & 7 deletions core/src/banking_stage/qos_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ mod tests {
signature::{Keypair, Signer},
system_transaction,
},
solana_vote_program::vote_transaction,
solana_vote_program::{vote_state::TowerSync, vote_transaction},
std::sync::Arc,
};

Expand All @@ -612,9 +612,8 @@ mod tests {
system_transaction::transfer(&keypair, &keypair.pubkey(), 1, Hash::default()),
);
let vote_tx = SanitizedTransaction::from_transaction_for_tests(
vote_transaction::new_vote_transaction(
vec![42],
Hash::default(),
vote_transaction::new_tower_sync_transaction(
TowerSync::from(vec![(42, 1)]),
Hash::default(),
&keypair,
&keypair,
Expand Down Expand Up @@ -656,9 +655,8 @@ mod tests {
system_transaction::transfer(&keypair, &keypair.pubkey(), 1, Hash::default()),
);
let vote_tx = SanitizedTransaction::from_transaction_for_tests(
vote_transaction::new_vote_transaction(
vec![42],
Hash::default(),
vote_transaction::new_tower_sync_transaction(
TowerSync::from(vec![(42, 1)]),
Hash::default(),
&keypair,
&keypair,
Expand Down
7 changes: 3 additions & 4 deletions core/src/banking_stage/unprocessed_packet_batches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ mod tests {
system_instruction, system_transaction,
transaction::{SimpleAddressLoader, Transaction},
},
solana_vote_program::vote_transaction,
solana_vote_program::{vote_state::TowerSync, vote_transaction},
};

fn simple_deserialized_packet() -> DeserializedPacket {
Expand Down Expand Up @@ -467,9 +467,8 @@ mod tests {
let keypair = Keypair::new();
let transfer_tx =
system_transaction::transfer(&keypair, &keypair.pubkey(), 1, Hash::default());
let vote_tx = vote_transaction::new_vote_transaction(
vec![42],
Hash::default(),
let vote_tx = vote_transaction::new_tower_sync_transaction(
TowerSync::from(vec![(42, 1)]),
Hash::default(),
&keypair,
&keypair,
Expand Down
45 changes: 21 additions & 24 deletions core/src/cluster_info_vote_listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ mod tests {
signature::{Keypair, Signature, Signer},
},
solana_vote_program::{
vote_state::{TowerSync, Vote},
vote_state::{TowerSync, Vote, MAX_LOCKOUT_HISTORY},
vote_transaction,
},
std::{
Expand All @@ -749,11 +749,9 @@ mod tests {
solana_logger::setup();
let node_keypair = Keypair::new();
let vote_keypair = Keypair::new();
let slots: Vec<_> = (0..31).collect();

let vote_tx = vote_transaction::new_vote_transaction(
slots,
Hash::default(),
let tower_sync = TowerSync::new_from_slot(MAX_LOCKOUT_HISTORY as u64, Hash::default());
let vote_tx = vote_transaction::new_tower_sync_transaction(
tower_sync,
Hash::default(),
&node_keypair,
&vote_keypair,
Expand Down Expand Up @@ -918,12 +916,12 @@ mod tests {
votes_sender: &VerifiedVoteTransactionsSender,
replay_votes_sender: &ReplayVoteSender,
) {
let tower_sync = TowerSync::new_from_slots(gossip_vote_slots, Hash::default(), None);
validator_voting_keypairs.iter().for_each(|keypairs| {
let node_keypair = &keypairs.node_keypair;
let vote_keypair = &keypairs.vote_keypair;
let vote_tx = vote_transaction::new_vote_transaction(
gossip_vote_slots.clone(),
Hash::default(),
let vote_tx = vote_transaction::new_tower_sync_transaction(
tower_sync.clone(),
Hash::default(),
node_keypair,
vote_keypair,
Expand Down Expand Up @@ -1121,9 +1119,10 @@ mod tests {
let node_keypair = &keypairs.node_keypair;
let vote_keypair = &keypairs.vote_keypair;
expected_votes.push((vote_keypair.pubkey(), vec![i as Slot + 1]));
vote_transaction::new_vote_transaction(
vec![i as u64 + 1],
bank_hash,
let tower_sync =
TowerSync::new_from_slots(vec![(i as u64 + 1)], bank_hash, None);
vote_transaction::new_tower_sync_transaction(
tower_sync,
Hash::default(),
node_keypair,
vote_keypair,
Expand Down Expand Up @@ -1218,9 +1217,10 @@ mod tests {
for &e in &events {
if e == 0 || e == 2 {
// Create vote transaction
let vote_tx = vote_transaction::new_vote_transaction(
vec![vote_slot],
vote_bank_hash,
let tower_sync =
TowerSync::new_from_slots(vec![(vote_slot)], vote_bank_hash, None);
let vote_tx = vote_transaction::new_tower_sync_transaction(
tower_sync,
Hash::default(),
node_keypair,
vote_keypair,
Expand Down Expand Up @@ -1315,10 +1315,9 @@ mod tests {
// in the tracker
let validator0_keypairs = &validator_keypairs[0];
let voted_slot = bank.slot() + 1;
let vote_tx = vec![vote_transaction::new_vote_transaction(
let vote_tx = vec![vote_transaction::new_tower_sync_transaction(
// Must vote > root to be processed
vec![voted_slot],
Hash::default(),
TowerSync::from(vec![(voted_slot, 1)]),
Hash::default(),
&validator0_keypairs.node_keypair,
&validator0_keypairs.vote_keypair,
Expand Down Expand Up @@ -1362,10 +1361,9 @@ mod tests {
let vote_txs: Vec<_> = [first_slot_in_new_epoch - 1, first_slot_in_new_epoch]
.iter()
.map(|slot| {
vote_transaction::new_vote_transaction(
vote_transaction::new_tower_sync_transaction(
// Must vote > root to be processed
vec![*slot],
Hash::default(),
TowerSync::from(vec![(*slot, 1)]),
Hash::default(),
&validator0_keypairs.node_keypair,
&validator0_keypairs.vote_keypair,
Expand Down Expand Up @@ -1462,9 +1460,8 @@ mod tests {
let validator_vote_keypair = validator_vote_keypairs.unwrap_or(&other);
// TODO authorized_voter_keypair should be different from vote-keypair
// but that is what create_genesis_... currently generates.
vote_transaction::new_vote_transaction(
vec![0],
Hash::default(),
vote_transaction::new_tower_sync_transaction(
TowerSync::from(vec![(0, 1)]),
Hash::default(),
&validator_vote_keypair.node_keypair,
&validator_vote_keypair.vote_keypair,
Expand Down
27 changes: 17 additions & 10 deletions core/src/commitment_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,10 @@ mod tests {
solana_sdk::{account::Account, pubkey::Pubkey, signature::Signer},
solana_stake_program::stake_state,
solana_vote_program::{
vote_state::{self, process_slot_vote_unchecked, VoteStateVersions},
vote_state::{
self, process_slot_vote_unchecked, TowerSync, VoteStateVersions,
MAX_LOCKOUT_HISTORY,
},
vote_transaction,
},
};
Expand Down Expand Up @@ -568,9 +571,9 @@ mod tests {
&Pubkey::default(),
x + 1,
);
let vote = vote_transaction::new_vote_transaction(
vec![x],
previous_bank.hash(),
let tower_sync = TowerSync::new_from_slot(x, previous_bank.hash());
let vote = vote_transaction::new_tower_sync_transaction(
tower_sync,
previous_bank.last_blockhash(),
&validator_vote_keypairs.node_keypair,
&validator_vote_keypairs.vote_keypair,
Expand Down Expand Up @@ -601,9 +604,9 @@ mod tests {
&Pubkey::default(),
34,
);
let vote33 = vote_transaction::new_vote_transaction(
vec![33],
bank33.hash(),
let tower_sync = TowerSync::new_from_slot(33, bank33.hash());
let vote33 = vote_transaction::new_tower_sync_transaction(
tower_sync,
bank33.last_blockhash(),
&validator_vote_keypairs.node_keypair,
&validator_vote_keypairs.vote_keypair,
Expand Down Expand Up @@ -683,9 +686,13 @@ mod tests {
&Pubkey::default(),
x + 1,
);
let vote = vote_transaction::new_vote_transaction(
vec![x],
previous_bank.hash(),
// Skip 34 as it is not part of this fork.
let lowest_slot = x - MAX_LOCKOUT_HISTORY as u64;
let slots: Vec<_> = (lowest_slot..(x + 1)).filter(|s| *s != 34).collect();
let tower_sync =
TowerSync::new_from_slots(slots, previous_bank.hash(), Some(lowest_slot - 1));
let vote = vote_transaction::new_tower_sync_transaction(
tower_sync,
previous_bank.last_blockhash(),
&validator_vote_keypairs.node_keypair,
&validator_vote_keypairs.vote_keypair,
Expand Down
14 changes: 7 additions & 7 deletions core/src/replay_stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4501,7 +4501,7 @@ pub(crate) mod tests {
solana_streamer::socket::SocketAddrSpace,
solana_transaction_status::VersionedTransactionWithStatusMeta,
solana_vote_program::{
vote_state::{self, VoteStateVersions},
vote_state::{self, TowerSync, VoteStateVersions},
vote_transaction,
},
std::{
Expand Down Expand Up @@ -5464,9 +5464,9 @@ pub(crate) mod tests {
LatestValidatorVotesForFrozenBanks::default();
let bank0 = bank_forks.read().unwrap().get(0).unwrap();
let my_keypairs = keypairs.get(&my_node_pubkey).unwrap();
let vote_tx = vote_transaction::new_vote_transaction(
vec![0],
bank0.hash(),
let tower_sync = TowerSync::new_from_slots(vec![0], bank0.hash(), None);
let vote_tx = vote_transaction::new_tower_sync_transaction(
tower_sync,
bank0.last_blockhash(),
&my_keypairs.node_keypair,
&my_keypairs.vote_keypair,
Expand Down Expand Up @@ -6408,9 +6408,9 @@ pub(crate) mod tests {
// Process a vote for slot 0 in bank 5
let validator0_keypairs = &validator_keypairs.get(&sender).unwrap();
let bank0 = bank_forks.read().unwrap().get(0).unwrap();
let vote_tx = vote_transaction::new_vote_transaction(
vec![0],
bank0.hash(),
let tower_sync = TowerSync::new_from_slots(vec![0], bank0.hash(), None);
let vote_tx = vote_transaction::new_tower_sync_transaction(
tower_sync,
bank0.last_blockhash(),
&validator0_keypairs.node_keypair,
&validator0_keypairs.vote_keypair,
Expand Down
39 changes: 33 additions & 6 deletions core/src/vote_simulator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@ use {
},
},
solana_sdk::{clock::Slot, hash::Hash, pubkey::Pubkey, signature::Signer},
solana_vote_program::vote_transaction,
solana_vote_program::{
vote_state::{process_vote_unchecked, Lockout, TowerSync},
vote_transaction,
},
std::{
collections::{HashMap, HashSet},
collections::{HashMap, HashSet, VecDeque},
sync::{Arc, RwLock},
},
trees::{tr, Tree, TreeWalk},
Expand Down Expand Up @@ -98,10 +101,34 @@ impl VoteSimulator {
if vote.contains(&parent) {
let keypairs = self.validator_keypairs.get(pubkey).unwrap();
let latest_blockhash = parent_bank.last_blockhash();
let vote_tx = vote_transaction::new_vote_transaction(
// Must vote > root to be processed
vec![parent],
parent_bank.hash(),
let tower_sync = if let Some(vote_account) =
parent_bank.get_vote_account(&keypairs.vote_keypair.pubkey())
{
let mut vote_state = vote_account.vote_state().unwrap().clone();
process_vote_unchecked(
&mut vote_state,
solana_vote_program::vote_state::Vote::new(
vec![parent],
parent_bank.hash(),
),
)
.unwrap();
TowerSync::new(
vote_state.votes.iter().map(|vote| vote.lockout).collect(),
vote_state.root_slot,
parent_bank.hash(),
Hash::default(),
)
} else {
TowerSync::new(
VecDeque::from([Lockout::new(parent)]),
Some(root),
parent_bank.hash(),
Hash::default(),
)
};
let vote_tx = vote_transaction::new_tower_sync_transaction(
tower_sync,
latest_blockhash,
&keypairs.node_keypair,
&keypairs.vote_keypair,
Expand Down
7 changes: 3 additions & 4 deletions cost-model/src/cost_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ mod tests {
MessageHash, SanitizedTransaction, SimpleAddressLoader, VersionedTransaction,
},
},
solana_vote_program::vote_transaction,
solana_vote_program::{vote_state::TowerSync, vote_transaction},
std::cmp,
};

Expand Down Expand Up @@ -438,9 +438,8 @@ mod tests {
start_hash: &Hash,
) -> (SanitizedTransaction, TransactionCost) {
let keypair = Keypair::new();
let transaction = vote_transaction::new_vote_transaction(
vec![42],
Hash::default(),
let transaction = vote_transaction::new_tower_sync_transaction(
TowerSync::from(vec![(42, 1)]),
*start_hash,
mint_keypair,
&keypair,
Expand Down
Loading

0 comments on commit 993d223

Please sign in to comment.