diff --git a/core/benches/banking_stage.rs b/core/benches/banking_stage.rs index bb4a15c075..ae0bd6b07b 100644 --- a/core/benches/banking_stage.rs +++ b/core/benches/banking_stage.rs @@ -37,6 +37,9 @@ use { }, solana_streamer::socket::SocketAddrSpace, solana_tpu_client::connection_cache::ConnectionCache, + solana_vote_program::{ + vote_state::VoteStateUpdate, vote_transaction::new_vote_state_update_transaction, + }, std::{ sync::{atomic::Ordering, Arc, RwLock}, time::{Duration, Instant}, @@ -142,9 +145,37 @@ fn make_programs_txs(txes: usize, hash: Hash) -> Vec { .collect() } +fn make_vote_txs(txes: usize) -> Vec { + // 1000 voters + let num_voters = 1000; + let (keypairs, vote_keypairs): (Vec<_>, Vec<_>) = (0..num_voters) + .map(|_| (Keypair::new(), Keypair::new())) + .unzip(); + (0..txes) + .map(|i| { + // Quarter of the votes should be filtered out + let vote = if i % 4 == 0 { + VoteStateUpdate::from(vec![(2, 1)]) + } else { + VoteStateUpdate::from(vec![(i as u64, 1)]) + }; + new_vote_state_update_transaction( + vote, + Hash::new_unique(), + &keypairs[i % num_voters], + &vote_keypairs[i % num_voters], + &vote_keypairs[i % num_voters], + None, + ) + }) + .collect() +} + enum TransactionType { Accounts, Programs, + AccountsAndVotes, + ProgramsAndVotes, } fn bench_banking(bencher: &mut Bencher, tx_type: TransactionType) { @@ -182,8 +213,18 @@ fn bench_banking(bencher: &mut Bencher, tx_type: TransactionType) { debug!("threads: {} txs: {}", num_threads, txes); let transactions = match tx_type { - TransactionType::Accounts => make_accounts_txs(txes, &mint_keypair, genesis_config.hash()), - TransactionType::Programs => make_programs_txs(txes, genesis_config.hash()), + TransactionType::Accounts | TransactionType::AccountsAndVotes => { + make_accounts_txs(txes, &mint_keypair, genesis_config.hash()) + } + TransactionType::Programs | TransactionType::ProgramsAndVotes => { + make_programs_txs(txes, genesis_config.hash()) + } + }; + let vote_txs = match tx_type { + TransactionType::AccountsAndVotes | TransactionType::ProgramsAndVotes => { + Some(make_vote_txs(txes)) + } + _ => None, }; // fund all the accounts @@ -210,6 +251,16 @@ fn bench_banking(bencher: &mut Bencher, tx_type: TransactionType) { } bank.clear_signatures(); let verified: Vec<_> = to_packet_batches(&transactions, PACKETS_PER_BATCH); + let vote_packets = vote_txs.map(|vote_txs| { + let mut packet_batches = to_packet_batches(&vote_txs, PACKETS_PER_BATCH); + for batch in packet_batches.iter_mut() { + for packet in batch.iter_mut() { + packet.meta.set_simple_vote(true); + } + } + packet_batches + }); + let ledger_path = get_tmp_ledger_path!(); { let blockstore = Arc::new( @@ -250,7 +301,14 @@ fn bench_banking(bencher: &mut Bencher, tx_type: TransactionType) { bencher.iter(move || { let now = Instant::now(); let mut sent = 0; - + if let Some(vote_packets) = &vote_packets { + tpu_vote_sender + .send((vote_packets[start..start + chunk_len].to_vec(), None)) + .unwrap(); + vote_sender + .send((vote_packets[start..start + chunk_len].to_vec(), None)) + .unwrap(); + } for v in verified[start..start + chunk_len].chunks(chunk_len / num_threads) { debug!( "sending... {}..{} {} v.len: {}", @@ -264,6 +322,7 @@ fn bench_banking(bencher: &mut Bencher, tx_type: TransactionType) { } verified_sender.send((v.to_vec(), None)).unwrap(); } + check_txs(&signal_receiver2, txes / CHUNKS); // This signature clear may not actually clear the signatures @@ -279,8 +338,6 @@ fn bench_banking(bencher: &mut Bencher, tx_type: TransactionType) { start += chunk_len; start %= verified.len(); }); - drop(tpu_vote_sender); - drop(vote_sender); exit.store(true, Ordering::Relaxed); poh_service.join().unwrap(); } @@ -297,6 +354,16 @@ fn bench_banking_stage_multi_programs(bencher: &mut Bencher) { bench_banking(bencher, TransactionType::Programs); } +#[bench] +fn bench_banking_stage_multi_accounts_with_voting(bencher: &mut Bencher) { + bench_banking(bencher, TransactionType::AccountsAndVotes); +} + +#[bench] +fn bench_banking_stage_multi_programs_with_voting(bencher: &mut Bencher) { + bench_banking(bencher, TransactionType::ProgramsAndVotes); +} + fn simulate_process_entries( randomize_txs: bool, mint_keypair: &Keypair, diff --git a/sdk/src/packet.rs b/sdk/src/packet.rs index 2befff66be..08389860f9 100644 --- a/sdk/src/packet.rs +++ b/sdk/src/packet.rs @@ -169,6 +169,11 @@ impl Meta { self.flags.set(PacketFlags::TRACER_PACKET, is_tracer); } + #[inline] + pub fn set_simple_vote(&mut self, is_simple_vote: bool) { + self.flags.set(PacketFlags::SIMPLE_VOTE_TX, is_simple_vote); + } + #[inline] pub fn forwarded(&self) -> bool { self.flags.contains(PacketFlags::FORWARDED)