diff --git a/poh/benches/poh.rs b/poh/benches/poh.rs index 5ea2d3a9babf35..2515444de62fd2 100644 --- a/poh/benches/poh.rs +++ b/poh/benches/poh.rs @@ -5,8 +5,20 @@ extern crate test; use { solana_entry::poh::Poh, - solana_poh::poh_service::DEFAULT_HASHES_PER_BATCH, - solana_sdk::hash::Hash, + solana_ledger::{ + blockstore::Blockstore, + genesis_utils::{create_genesis_config, GenesisConfigInfo}, + get_tmp_ledger_path_auto_delete, + leader_schedule_cache::LeaderScheduleCache, + }, + solana_perf::test_tx::test_tx, + solana_poh::{poh_recorder::PohRecorder, poh_service::DEFAULT_HASHES_PER_BATCH}, + solana_runtime::bank::Bank, + solana_sdk::{ + hash::{hash, Hash}, + poh_config::PohConfig, + transaction::SanitizedTransaction, + }, std::sync::{ atomic::{AtomicBool, Ordering}, Arc, Mutex, @@ -65,3 +77,80 @@ fn bench_poh_lock_time_per_batch(bencher: &mut Bencher) { poh.hash(DEFAULT_HASHES_PER_BATCH); }) } + +#[bench] +fn bench_poh_recorder_record_transaction_index(bencher: &mut Bencher) { + let ledger_path = get_tmp_ledger_path_auto_delete!(); + let blockstore = + Blockstore::open(ledger_path.path()).expect("Expected to be able to open database ledger"); + let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(2); + let bank = Arc::new(Bank::new_for_tests(&genesis_config)); + let prev_hash = bank.last_blockhash(); + + let (mut poh_recorder, _entry_receiver, _record_receiver) = PohRecorder::new( + 0, + prev_hash, + bank.clone(), + Some((4, 4)), + bank.ticks_per_slot(), + Arc::new(blockstore), + &std::sync::Arc::new(LeaderScheduleCache::new_from_bank(&bank)), + &PohConfig::default(), + Arc::new(AtomicBool::default()), + ); + let h1 = hash(b"hello Agave, hello Anza!"); + + poh_recorder.set_bank_with_transaction_index_for_test(bank.clone()); + poh_recorder.tick(); + let txs: [SanitizedTransaction; 7] = [ + SanitizedTransaction::from_transaction_for_tests(test_tx()), + SanitizedTransaction::from_transaction_for_tests(test_tx()), + SanitizedTransaction::from_transaction_for_tests(test_tx()), + SanitizedTransaction::from_transaction_for_tests(test_tx()), + SanitizedTransaction::from_transaction_for_tests(test_tx()), + SanitizedTransaction::from_transaction_for_tests(test_tx()), + SanitizedTransaction::from_transaction_for_tests(test_tx()), + ]; + + bencher.iter(|| { + let _record_result = poh_recorder + .record( + bank.slot(), + test::black_box(h1), + test::black_box(txs.clone()) + .iter() + .map(|tx| tx.to_versioned_transaction()) + .collect(), + ) + .unwrap() + .unwrap(); + }); + poh_recorder.tick(); +} + +#[bench] +fn bench_poh_recorder_set_bank(bencher: &mut Bencher) { + let ledger_path = get_tmp_ledger_path_auto_delete!(); + let blockstore = + Blockstore::open(ledger_path.path()).expect("Expected to be able to open database ledger"); + let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(2); + let bank = Arc::new(Bank::new_for_tests(&genesis_config)); + let prev_hash = bank.last_blockhash(); + + let (mut poh_recorder, _entry_receiver, _record_receiver) = PohRecorder::new( + 0, + prev_hash, + bank.clone(), + Some((4, 4)), + bank.ticks_per_slot(), + Arc::new(blockstore), + &std::sync::Arc::new(LeaderScheduleCache::new_from_bank(&bank)), + &PohConfig::default(), + Arc::new(AtomicBool::default()), + ); + bencher.iter(|| { + poh_recorder.set_bank_with_transaction_index_for_test(bank.clone()); + poh_recorder.tick(); + poh_recorder.clear_bank_for_test(); + }); +} diff --git a/poh/src/poh_recorder.rs b/poh/src/poh_recorder.rs index 5c6f5d26c7f4f5..3fe76d5274bcf8 100644 --- a/poh/src/poh_recorder.rs +++ b/poh/src/poh_recorder.rs @@ -734,11 +734,16 @@ impl PohRecorder { self.set_bank(BankWithScheduler::new_without_scheduler(bank), false) } - #[cfg(test)] + #[cfg(feature = "dev-context-only-utils")] pub fn set_bank_with_transaction_index_for_test(&mut self, bank: Arc) { self.set_bank(BankWithScheduler::new_without_scheduler(bank), true) } + #[cfg(feature = "dev-context-only-utils")] + pub fn clear_bank_for_test(&mut self) { + self.clear_bank(); + } + // Flush cache will delay flushing the cache for a bank until it past the WorkingBank::min_tick_height // On a record flush will flush the cache at the WorkingBank::min_tick_height, since a record // occurs after the min_tick_height was generated