Skip to content

Commit

Permalink
vote: update benches and tests to TowerSync (solana-labs#725)
Browse files Browse the repository at this point in the history
  • Loading branch information
AshwinSekar authored Apr 12, 2024
1 parent 4f7e45b commit 499d36e
Show file tree
Hide file tree
Showing 10 changed files with 327 additions and 114 deletions.
18 changes: 9 additions & 9 deletions core/src/banking_stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,7 @@ mod tests {
},
solana_streamer::socket::SocketAddrSpace,
solana_vote_program::{
vote_state::VoteStateUpdate, vote_transaction::new_vote_state_update_transaction,
vote_state::TowerSync, vote_transaction::new_tower_sync_transaction,
},
std::{
sync::atomic::{AtomicBool, Ordering},
Expand Down Expand Up @@ -1382,8 +1382,8 @@ mod tests {
// Send a bunch of votes and transfers
let tpu_votes = (0..100_usize)
.map(|i| {
new_vote_state_update_transaction(
VoteStateUpdate::from(vec![
new_tower_sync_transaction(
TowerSync::from(vec![
(0, 8),
(1, 7),
(i as u64 + 10, 6),
Expand All @@ -1399,12 +1399,12 @@ mod tests {
.collect_vec();
let gossip_votes = (0..100_usize)
.map(|i| {
new_vote_state_update_transaction(
VoteStateUpdate::from(vec![
(0, 8),
(1, 7),
(i as u64 + 64 + 5, 6),
(i as u64 + 7, 1),
new_tower_sync_transaction(
TowerSync::from(vec![
(0, 9),
(1, 8),
(i as u64 + 5, 6),
(i as u64 + 63, 1),
]),
Hash::new_unique(),
&keypairs[i],
Expand Down
28 changes: 14 additions & 14 deletions core/src/banking_stage/latest_unprocessed_votes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,8 @@ mod tests {
},
solana_sdk::{hash::Hash, signature::Signer, system_transaction::transfer},
solana_vote_program::{
vote_state::VoteStateUpdate,
vote_transaction::{new_vote_state_update_transaction, new_vote_transaction},
vote_state::TowerSync,
vote_transaction::{new_tower_sync_transaction, new_vote_transaction},
},
std::{sync::Arc, thread::Builder},
};
Expand All @@ -370,9 +370,9 @@ mod tests {
keypairs: &ValidatorVoteKeypairs,
timestamp: Option<UnixTimestamp>,
) -> LatestValidatorVotePacket {
let mut vote = VoteStateUpdate::from(slots);
let mut vote = TowerSync::from(slots);
vote.timestamp = timestamp;
let vote_tx = new_vote_state_update_transaction(
let vote_tx = new_tower_sync_transaction(
vote,
Hash::new_unique(),
&keypairs.node_keypair,
Expand Down Expand Up @@ -435,10 +435,10 @@ mod tests {
.meta_mut()
.flags
.set(PacketFlags::SIMPLE_VOTE_TX, true);
let mut vote_state_update = Packet::from_data(
let mut tower_sync = Packet::from_data(
None,
new_vote_state_update_transaction(
VoteStateUpdate::from(vec![(0, 3), (1, 2), (2, 1)]),
new_tower_sync_transaction(
TowerSync::from(vec![(0, 3), (1, 2), (2, 1)]),
blockhash,
&keypairs.node_keypair,
&keypairs.vote_keypair,
Expand All @@ -447,14 +447,14 @@ mod tests {
),
)
.unwrap();
vote_state_update
tower_sync
.meta_mut()
.flags
.set(PacketFlags::SIMPLE_VOTE_TX, true);
let mut vote_state_update_switch = Packet::from_data(
let mut tower_sync_switch = Packet::from_data(
None,
new_vote_state_update_transaction(
VoteStateUpdate::from(vec![(0, 3), (1, 2), (3, 1)]),
new_tower_sync_transaction(
TowerSync::from(vec![(0, 3), (1, 2), (3, 1)]),
blockhash,
&keypairs.node_keypair,
&keypairs.vote_keypair,
Expand All @@ -463,7 +463,7 @@ mod tests {
),
)
.unwrap();
vote_state_update_switch
tower_sync_switch
.meta_mut()
.flags
.set(PacketFlags::SIMPLE_VOTE_TX, true);
Expand All @@ -480,8 +480,8 @@ mod tests {
let packet_batch = PacketBatch::new(vec![
vote,
vote_switch,
vote_state_update,
vote_state_update_switch,
tower_sync,
tower_sync_switch,
random_transaction,
]);

Expand Down
6 changes: 3 additions & 3 deletions core/src/banking_stage/unprocessed_transaction_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1000,7 +1000,7 @@ mod tests {
transaction::Transaction,
},
solana_vote_program::{
vote_state::VoteStateUpdate, vote_transaction::new_vote_state_update_transaction,
vote_state::TowerSync, vote_transaction::new_tower_sync_transaction,
},
std::error::Error,
};
Expand Down Expand Up @@ -1207,8 +1207,8 @@ mod tests {
)?;
let mut vote = Packet::from_data(
None,
new_vote_state_update_transaction(
VoteStateUpdate::default(),
new_tower_sync_transaction(
TowerSync::default(),
Hash::new_unique(),
&keypair,
&vote_keypair,
Expand Down
24 changes: 11 additions & 13 deletions core/src/cluster_info_vote_listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,7 @@ mod tests {
},
solana_vote::vote_sender_types::ReplayVoteSender,
solana_vote_program::{
vote_state::{Vote, VoteStateUpdate},
vote_state::{TowerSync, Vote},
vote_transaction,
},
std::{
Expand Down Expand Up @@ -1837,17 +1837,16 @@ mod tests {
let mut new_optimistic_confirmed_slots = vec![];

let validator0_keypairs = &validator_keypairs[0];
let (vote_pubkey, vote, _, signature) = vote_parser::parse_vote_transaction(
&vote_transaction::new_vote_state_update_transaction(
VoteStateUpdate::from(vec![(1, 3), (2, 2), (6, 1)]),
let (vote_pubkey, vote, _, signature) =
vote_parser::parse_vote_transaction(&vote_transaction::new_tower_sync_transaction(
TowerSync::from(vec![(1, 3), (2, 2), (6, 1)]),
Hash::default(),
&validator0_keypairs.node_keypair,
&validator0_keypairs.vote_keypair,
&validator0_keypairs.vote_keypair,
None,
),
)
.unwrap();
))
.unwrap();

ClusterInfoVoteListener::track_new_votes_and_notify_confirmations(
vote,
Expand All @@ -1869,17 +1868,16 @@ mod tests {

// Vote on a new slot, only those later than 6 should show up. 4 is skipped.
diff.clear();
let (vote_pubkey, vote, _, signature) = vote_parser::parse_vote_transaction(
&vote_transaction::new_vote_state_update_transaction(
VoteStateUpdate::from(vec![(1, 6), (2, 5), (3, 4), (4, 3), (7, 2), (8, 1)]),
let (vote_pubkey, vote, _, signature) =
vote_parser::parse_vote_transaction(&vote_transaction::new_tower_sync_transaction(
TowerSync::from(vec![(1, 6), (2, 5), (3, 4), (4, 3), (7, 2), (8, 1)]),
Hash::default(),
&validator0_keypairs.node_keypair,
&validator0_keypairs.vote_keypair,
&validator0_keypairs.vote_keypair,
None,
),
)
.unwrap();
))
.unwrap();

ClusterInfoVoteListener::track_new_votes_and_notify_confirmations(
vote,
Expand Down
31 changes: 16 additions & 15 deletions core/src/verified_vote_packets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ mod tests {
crossbeam_channel::{unbounded, Receiver, Sender},
solana_perf::packet::Packet,
solana_sdk::slot_hashes::MAX_ENTRIES,
solana_vote_program::vote_state::{Lockout, Vote, VoteStateUpdate},
solana_vote_program::vote_state::{Lockout, TowerSync, Vote},
std::collections::VecDeque,
};

Expand Down Expand Up @@ -616,10 +616,10 @@ mod tests {
let (s, r) = unbounded();
let vote_account_key = solana_sdk::pubkey::new_rand();

// Send three vote state updates that are out of order
let first_vote = VoteStateUpdate::from(vec![(2, 4), (4, 3), (6, 2), (7, 1)]);
let second_vote = VoteStateUpdate::from(vec![(2, 4), (4, 3), (11, 1)]);
let third_vote = VoteStateUpdate::from(vec![(2, 5), (4, 4), (11, 3), (12, 2), (13, 1)]);
// Send three tower syncs that are out of order
let first_vote = TowerSync::from(vec![(2, 4), (4, 3), (6, 2), (7, 1)]);
let second_vote = TowerSync::from(vec![(2, 4), (4, 3), (11, 1)]);
let third_vote = TowerSync::from(vec![(2, 5), (4, 4), (11, 3), (12, 2), (13, 1)]);

for vote in [second_vote, first_vote] {
s.send(vec![VerifiedVoteMetadata {
Expand Down Expand Up @@ -664,10 +664,10 @@ mod tests {
assert_eq!(13, slot);
}

fn send_vote_state_update_and_process(
fn send_tower_sync_and_process(
s: &Sender<Vec<VerifiedVoteMetadata>>,
r: &Receiver<Vec<VerifiedVoteMetadata>>,
vote: VoteStateUpdate,
vote: TowerSync,
vote_account_key: Pubkey,
verified_vote_packets: &mut VerifiedVotePackets,
) -> GossipVote {
Expand All @@ -692,8 +692,8 @@ mod tests {
let (s, r) = unbounded();
let vote_account_key = solana_sdk::pubkey::new_rand();

// Send identical vote state updates with different timestamps
let mut vote = VoteStateUpdate::from(vec![(2, 4), (4, 3), (6, 2), (7, 1)]);
// Send identical tower syncs with different timestamps
let mut vote = TowerSync::from(vec![(2, 4), (4, 3), (6, 2), (7, 1)]);
vote.timestamp = Some(5);

let mut vote_later_ts = vote.clone();
Expand All @@ -710,7 +710,7 @@ mod tests {
// Original vote
let GossipVote {
slot, timestamp, ..
} = send_vote_state_update_and_process(
} = send_tower_sync_and_process(
&s,
&r,
vote.clone(),
Expand All @@ -723,7 +723,7 @@ mod tests {
// Same vote with later timestamp should override
let GossipVote {
slot, timestamp, ..
} = send_vote_state_update_and_process(
} = send_tower_sync_and_process(
&s,
&r,
vote_later_ts.clone(),
Expand All @@ -736,7 +736,7 @@ mod tests {
// Same vote with earlier timestamp should not override
let GossipVote {
slot, timestamp, ..
} = send_vote_state_update_and_process(
} = send_tower_sync_and_process(
&s,
&r,
vote_earlier_ts,
Expand All @@ -749,7 +749,7 @@ mod tests {
// Same vote with no timestamp should not override
let GossipVote {
slot, timestamp, ..
} = send_vote_state_update_and_process(
} = send_tower_sync_and_process(
&s,
&r,
vote_no_ts,
Expand Down Expand Up @@ -798,10 +798,11 @@ mod tests {
Lockout::new_with_confirmation_count(slot, confirmation_count)
})
.collect::<VecDeque<Lockout>>();
let vote = VoteTransaction::from(VoteStateUpdate::new(
let vote = VoteTransaction::from(TowerSync::new(
slots,
Some(i - 32),
Hash::new_unique(),
Hash::new_unique(),
));
s.send(vec![VerifiedVoteMetadata {
vote_account_key,
Expand Down Expand Up @@ -858,7 +859,7 @@ mod tests {
let vote_account_key = solana_sdk::pubkey::new_rand();
let mut verified_vote_packets = VerifiedVotePackets(HashMap::new());

let vote = VoteTransaction::from(VoteStateUpdate::from(vec![(42, 1)]));
let vote = VoteTransaction::from(TowerSync::from(vec![(42, 1)]));
let hash_42 = vote.hash();
s.send(vec![VerifiedVoteMetadata {
vote_account_key,
Expand Down
6 changes: 3 additions & 3 deletions local-cluster/tests/local_cluster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ use {
pubkey::Pubkey,
signature::{Keypair, Signer},
system_program, system_transaction,
vote::state::VoteStateUpdate,
vote::state::TowerSync,
},
solana_streamer::socket::SocketAddrSpace,
solana_turbine::broadcast_stage::{
Expand Down Expand Up @@ -3915,13 +3915,13 @@ fn run_duplicate_shreds_broadcast_leader(vote_on_duplicate: bool) {
.zip(1..)
.collect();
vote_slots.reverse();
let mut vote = VoteStateUpdate::from(vote_slots);
let mut vote = TowerSync::from(vote_slots);
let root =
AncestorIterator::new_inclusive(latest_vote_slot, &leader_blockstore)
.nth(MAX_LOCKOUT_HISTORY);
vote.root = root;
vote.hash = vote_hash;
let vote_tx = vote_transaction::new_compact_vote_state_update_transaction(
let vote_tx = vote_transaction::new_tower_sync_transaction(
vote,
leader_vote_tx.message.recent_blockhash,
&node_keypair,
Expand Down
33 changes: 32 additions & 1 deletion programs/vote/benches/process_vote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ use {
solana_vote_program::{
vote_instruction::VoteInstruction,
vote_state::{
Vote, VoteInit, VoteState, VoteStateUpdate, VoteStateVersions, MAX_LOCKOUT_HISTORY,
TowerSync, Vote, VoteInit, VoteState, VoteStateUpdate, VoteStateVersions,
MAX_LOCKOUT_HISTORY,
},
},
test::Bencher,
Expand Down Expand Up @@ -172,3 +173,33 @@ fn bench_process_vote_state_update(bencher: &mut Bencher) {
instruction_data,
);
}

#[bench]
fn bench_process_tower_sync(bencher: &mut Bencher) {
let (num_initial_votes, slot_hashes, transaction_accounts, instruction_account_metas) =
create_accounts();

let num_vote_slots = MAX_LOCKOUT_HISTORY as Slot;
let last_vote_slot = num_initial_votes
.saturating_add(num_vote_slots)
.saturating_sub(1);
let last_vote_hash = slot_hashes
.iter()
.find(|(slot, _hash)| *slot == last_vote_slot)
.unwrap()
.1;
let slots_and_lockouts: Vec<(Slot, u32)> =
((num_initial_votes.saturating_add(1)..=last_vote_slot).zip((1u32..=31).rev())).collect();
let mut tower_sync = TowerSync::from(slots_and_lockouts);
tower_sync.root = Some(num_initial_votes);
tower_sync.hash = last_vote_hash;
tower_sync.block_id = Hash::new_unique();
let instruction_data = bincode::serialize(&VoteInstruction::TowerSync(tower_sync)).unwrap();

bench_process_vote_instruction(
bencher,
transaction_accounts,
instruction_account_metas,
instruction_data,
);
}
Loading

0 comments on commit 499d36e

Please sign in to comment.