From 1029f1055f8b8277e527e3399aba663d15ed48ee Mon Sep 17 00:00:00 2001 From: Andrew Fitzgerald Date: Wed, 27 Nov 2024 10:18:30 -0600 Subject: [PATCH] test both ReceiveAndBuffer in scheduler_controller --- .../scheduler_controller.rs | 128 +++++++++++------- 1 file changed, 79 insertions(+), 49 deletions(-) diff --git a/core/src/banking_stage/transaction_scheduler/scheduler_controller.rs b/core/src/banking_stage/transaction_scheduler/scheduler_controller.rs index a6696a4126378d..71331456d0eb73 100644 --- a/core/src/banking_stage/transaction_scheduler/scheduler_controller.rs +++ b/core/src/banking_stage/transaction_scheduler/scheduler_controller.rs @@ -442,8 +442,9 @@ mod tests { scheduler_messages::{ConsumeWork, FinishedConsumeWork, TransactionBatchId}, tests::create_slow_genesis_config, transaction_scheduler::receive_and_buffer::SanitizedTransactionReceiveAndBuffer, + TransactionViewReceiveAndBuffer, }, - banking_trace::BankingPacketBatch, + banking_trace::{BankingPacketBatch, BankingPacketReceiver}, sigverify::SigverifyTracerPacketStats, }, crossbeam_channel::{unbounded, Receiver, Sender}, @@ -456,21 +457,15 @@ mod tests { solana_perf::packet::{to_packet_batches, PacketBatch, NUM_PACKETS}, solana_poh::poh_recorder::{PohRecorder, Record, WorkingBankEntry}, solana_runtime::bank::Bank, - solana_runtime_transaction::runtime_transaction::RuntimeTransaction, + solana_runtime_transaction::transaction_meta::StaticMeta, solana_sdk::{ - compute_budget::ComputeBudgetInstruction, - fee_calculator::FeeRateGovernor, - hash::Hash, - message::Message, - poh_config::PohConfig, - pubkey::Pubkey, - signature::Keypair, - signer::Signer, - system_instruction, system_transaction, - transaction::{SanitizedTransaction, Transaction}, + compute_budget::ComputeBudgetInstruction, fee_calculator::FeeRateGovernor, hash::Hash, + message::Message, poh_config::PohConfig, pubkey::Pubkey, signature::Keypair, + signer::Signer, system_instruction, system_transaction, transaction::Transaction, }, std::sync::{atomic::AtomicBool, Arc, RwLock}, tempfile::TempDir, + test_case::test_case, }; fn create_channels(num: usize) -> (Vec>, Vec>) { @@ -479,7 +474,7 @@ mod tests { // Helper struct to create tests that hold channels, files, etc. // such that our tests can be more easily set up and run. - struct TestFrame { + struct TestFrame { bank: Arc, mint_keypair: Keypair, _ledger_path: TempDir, @@ -488,18 +483,38 @@ mod tests { poh_recorder: Arc>, banking_packet_sender: Sender, Option)>>, - consume_work_receivers: - Vec>>>, - finished_consume_work_sender: - Sender>>, + consume_work_receivers: Vec>>, + finished_consume_work_sender: Sender>, + } + + fn test_create_sanitized_transaction_receive_and_buffer( + receiver: BankingPacketReceiver, + bank_forks: Arc>, + ) -> SanitizedTransactionReceiveAndBuffer { + SanitizedTransactionReceiveAndBuffer::new( + PacketDeserializer::new(receiver), + bank_forks, + false, + ) + } + + fn test_create_transaction_view_receive_and_buffer( + receiver: BankingPacketReceiver, + bank_forks: Arc>, + ) -> TransactionViewReceiveAndBuffer { + TransactionViewReceiveAndBuffer { + receiver, + bank_forks, + } } #[allow(clippy::type_complexity)] - fn create_test_frame( + fn create_test_frame( num_threads: usize, + create_receive_and_buffer: impl FnOnce(BankingPacketReceiver, Arc>) -> R, ) -> ( - TestFrame, - SchedulerController, SanitizedTransactionReceiveAndBuffer>, + TestFrame, + SchedulerController, R>, ) { let GenesisConfigInfo { mut genesis_config, @@ -527,7 +542,8 @@ mod tests { let decision_maker = DecisionMaker::new(Pubkey::new_unique(), poh_recorder.clone()); let (banking_packet_sender, banking_packet_receiver) = unbounded(); - let packet_deserializer = PacketDeserializer::new(banking_packet_receiver); + let receive_and_buffer = + create_receive_and_buffer(banking_packet_receiver, bank_forks.clone()); let (consume_work_senders, consume_work_receivers) = create_channels(num_threads); let (finished_consume_work_sender, finished_consume_work_receiver) = unbounded(); @@ -544,12 +560,6 @@ mod tests { finished_consume_work_sender, }; - let receive_and_buffer = SanitizedTransactionReceiveAndBuffer::new( - packet_deserializer, - bank_forks.clone(), - false, - ); - let scheduler_controller = SchedulerController::new( decision_maker, receive_and_buffer, @@ -601,10 +611,7 @@ mod tests { // In the tests, the decision will not become stale, so it is more convenient // to receive first and then schedule. fn test_receive_then_schedule( - scheduler_controller: &mut SchedulerController< - Arc, - SanitizedTransactionReceiveAndBuffer, - >, + scheduler_controller: &mut SchedulerController, impl ReceiveAndBuffer>, ) { let decision = scheduler_controller .decision_maker @@ -615,10 +622,13 @@ mod tests { assert!(scheduler_controller.process_transactions(&decision).is_ok()); } - #[test] + #[test_case(test_create_sanitized_transaction_receive_and_buffer; "Sdk")] + #[test_case(test_create_transaction_view_receive_and_buffer; "View")] #[should_panic(expected = "batch id 0 is not being tracked")] - fn test_unexpected_batch_id() { - let (test_frame, scheduler_controller) = create_test_frame(1); + fn test_unexpected_batch_id( + create_receive_and_buffer: impl FnOnce(BankingPacketReceiver, Arc>) -> R, + ) { + let (test_frame, scheduler_controller) = create_test_frame(1, create_receive_and_buffer); let TestFrame { finished_consume_work_sender, .. @@ -639,9 +649,13 @@ mod tests { scheduler_controller.run().unwrap(); } - #[test] - fn test_schedule_consume_single_threaded_no_conflicts() { - let (test_frame, mut scheduler_controller) = create_test_frame(1); + #[test_case(test_create_sanitized_transaction_receive_and_buffer; "Sdk")] + #[test_case(test_create_transaction_view_receive_and_buffer; "View")] + fn test_schedule_consume_single_threaded_no_conflicts( + create_receive_and_buffer: impl FnOnce(BankingPacketReceiver, Arc>) -> R, + ) { + let (test_frame, mut scheduler_controller) = + create_test_frame(1, create_receive_and_buffer); let TestFrame { bank, mint_keypair, @@ -695,9 +709,13 @@ mod tests { assert_eq!(message_hashes, vec![&tx2_hash, &tx1_hash]); } - #[test] - fn test_schedule_consume_single_threaded_conflict() { - let (test_frame, mut scheduler_controller) = create_test_frame(1); + #[test_case(test_create_sanitized_transaction_receive_and_buffer; "Sdk")] + #[test_case(test_create_transaction_view_receive_and_buffer; "View")] + fn test_schedule_consume_single_threaded_conflict( + create_receive_and_buffer: impl FnOnce(BankingPacketReceiver, Arc>) -> R, + ) { + let (test_frame, mut scheduler_controller) = + create_test_frame(1, create_receive_and_buffer); let TestFrame { bank, mint_keypair, @@ -754,9 +772,13 @@ mod tests { assert_eq!(message_hashes, vec![&tx2_hash, &tx1_hash]); } - #[test] - fn test_schedule_consume_single_threaded_multi_batch() { - let (test_frame, mut scheduler_controller) = create_test_frame(1); + #[test_case(test_create_sanitized_transaction_receive_and_buffer; "Sdk")] + #[test_case(test_create_transaction_view_receive_and_buffer; "View")] + fn test_schedule_consume_single_threaded_multi_batch( + create_receive_and_buffer: impl FnOnce(BankingPacketReceiver, Arc>) -> R, + ) { + let (test_frame, mut scheduler_controller) = + create_test_frame(1, create_receive_and_buffer); let TestFrame { bank, mint_keypair, @@ -818,9 +840,13 @@ mod tests { ); } - #[test] - fn test_schedule_consume_simple_thread_selection() { - let (test_frame, mut scheduler_controller) = create_test_frame(2); + #[test_case(test_create_sanitized_transaction_receive_and_buffer; "Sdk")] + #[test_case(test_create_transaction_view_receive_and_buffer; "View")] + fn test_schedule_consume_simple_thread_selection( + create_receive_and_buffer: impl FnOnce(BankingPacketReceiver, Arc>) -> R, + ) { + let (test_frame, mut scheduler_controller) = + create_test_frame(2, create_receive_and_buffer); let TestFrame { bank, mint_keypair, @@ -885,9 +911,13 @@ mod tests { assert_eq!(t1_actual, t1_expected); } - #[test] - fn test_schedule_consume_retryable() { - let (test_frame, mut scheduler_controller) = create_test_frame(1); + #[test_case(test_create_sanitized_transaction_receive_and_buffer; "Sdk")] + #[test_case(test_create_transaction_view_receive_and_buffer; "View")] + fn test_schedule_consume_retryable( + create_receive_and_buffer: impl FnOnce(BankingPacketReceiver, Arc>) -> R, + ) { + let (test_frame, mut scheduler_controller) = + create_test_frame(1, create_receive_and_buffer); let TestFrame { bank, mint_keypair,