From 3280b8b00d958ad48926c8e2acf8a60c0abbf817 Mon Sep 17 00:00:00 2001 From: Ryo Onodera Date: Sun, 15 Dec 2024 16:02:38 +0900 Subject: [PATCH] Extract duplicate tpu bank handling code for US --- banking-bench/Cargo.toml | 2 +- banking-bench/src/main.rs | 18 +++++++++--------- core/src/banking_simulation.rs | 15 +++++++++------ core/src/banking_stage.rs | 18 +++++++++++++++++- core/src/replay_stage.rs | 12 +++++++----- 5 files changed, 43 insertions(+), 22 deletions(-) diff --git a/banking-bench/Cargo.toml b/banking-bench/Cargo.toml index 3bcaff24673478..fad676fcc24cab 100644 --- a/banking-bench/Cargo.toml +++ b/banking-bench/Cargo.toml @@ -16,7 +16,7 @@ log = { workspace = true } rand = { workspace = true } rayon = { workspace = true } solana-client = { workspace = true } -solana-core = { workspace = true } +solana-core = { workspace = true, features = ["dev-context-only-utils"] } solana-gossip = { workspace = true } solana-ledger = { workspace = true } solana-logger = { workspace = true } diff --git a/banking-bench/src/main.rs b/banking-bench/src/main.rs index 41faf84b9acab8..2b2c11ffe7e985 100644 --- a/banking-bench/src/main.rs +++ b/banking-bench/src/main.rs @@ -8,7 +8,7 @@ use { rayon::prelude::*, solana_client::connection_cache::ConnectionCache, solana_core::{ - banking_stage::BankingStage, + banking_stage::{update_bank_forks_and_poh_recorder_for_new_tpu_bank, BankingStage}, banking_trace::{BankingTracer, Channels, BANKING_TRACE_DIR_DEFAULT_BYTE_LIMIT}, validator::BlockProductionMethod, }, @@ -559,16 +559,16 @@ fn main() { new_bank_time.stop(); let mut insert_time = Measure::start("insert_time"); - bank_forks.write().unwrap().insert(new_bank); + assert_matches!(poh_recorder.read().unwrap().bank(), None); + update_bank_forks_and_poh_recorder_for_new_tpu_bank( + &bank_forks, + &poh_recorder, + new_bank, + false, + ); bank = bank_forks.read().unwrap().working_bank_with_scheduler(); + assert_matches!(poh_recorder.read().unwrap().bank(), Some(_)); insert_time.stop(); - - assert!(poh_recorder.read().unwrap().bank().is_none()); - poh_recorder - .write() - .unwrap() - .set_bank_for_test(bank.clone()); - assert!(poh_recorder.read().unwrap().bank().is_some()); debug!( "new_bank_time: {}us insert_time: {}us poh_time: {}us", new_bank_time.as_us(), diff --git a/core/src/banking_simulation.rs b/core/src/banking_simulation.rs index 61f5f0acdfee9d..a1acdf81cef210 100644 --- a/core/src/banking_simulation.rs +++ b/core/src/banking_simulation.rs @@ -1,7 +1,9 @@ #![cfg(feature = "dev-context-only-utils")] use { crate::{ - banking_stage::{BankingStage, LikeClusterInfo}, + banking_stage::{ + update_bank_forks_and_poh_recorder_for_new_tpu_bank, BankingStage, LikeClusterInfo, + }, banking_trace::{ BankingTracer, ChannelLabel, Channels, TimedTracedEvent, TracedEvent, TracedSender, TracerThread, BANKING_TRACE_DIR_DEFAULT_BYTE_LIMIT, BASENAME, @@ -484,16 +486,17 @@ impl SimulatorLoop { logger.log_frozen_bank_cost(&bank); } self.retransmit_slots_sender.send(bank.slot()).unwrap(); - self.bank_forks.write().unwrap().insert(new_bank); + update_bank_forks_and_poh_recorder_for_new_tpu_bank( + &self.bank_forks, + &self.poh_recorder, + new_bank, + false, + ); bank = self .bank_forks .read() .unwrap() .working_bank_with_scheduler(); - self.poh_recorder - .write() - .unwrap() - .set_bank(bank.clone_with_scheduler(), false); } else { logger.log_ongoing_bank_cost(&bank); } diff --git a/core/src/banking_stage.rs b/core/src/banking_stage.rs index 2f8c8596e85c39..b44394f37f8b3d 100644 --- a/core/src/banking_stage.rs +++ b/core/src/banking_stage.rs @@ -2,6 +2,8 @@ //! to construct a software pipeline. The stage uses all available CPU cores and //! can do its processing in parallel with signature verification on the GPU. +#[cfg(feature = "dev-context-only-utils")] +use qualifier_attr::qualifiers; use { self::{ committer::Committer, @@ -38,7 +40,7 @@ use { }, solana_poh::poh_recorder::{PohRecorder, TransactionRecorder}, solana_runtime::{ - bank_forks::BankForks, prioritization_fee_cache::PrioritizationFeeCache, + bank::Bank, bank_forks::BankForks, prioritization_fee_cache::PrioritizationFeeCache, vote_sender_types::ReplayVoteSender, }, solana_sdk::{pubkey::Pubkey, timing::AtomicInterval}, @@ -805,6 +807,20 @@ impl BankingStage { } } +#[cfg_attr(feature = "dev-context-only-utils", qualifiers(pub))] +pub(crate) fn update_bank_forks_and_poh_recorder_for_new_tpu_bank( + bank_forks: &RwLock, + poh_recorder: &RwLock, + tpu_bank: Bank, + track_transaction_indexes: bool, +) { + let tpu_bank = bank_forks.write().unwrap().insert(tpu_bank); + poh_recorder + .write() + .unwrap() + .set_bank(tpu_bank, track_transaction_indexes); +} + #[cfg(test)] mod tests { use { diff --git a/core/src/replay_stage.rs b/core/src/replay_stage.rs index 0e0125a300594f..23ca9f1b2cdb1e 100644 --- a/core/src/replay_stage.rs +++ b/core/src/replay_stage.rs @@ -2,6 +2,7 @@ use { crate::{ + banking_stage::update_bank_forks_and_poh_recorder_for_new_tpu_bank, banking_trace::BankingTracer, cluster_info_vote_listener::{ DuplicateConfirmedSlotsReceiver, GossipVerifiedVoteHashReceiver, VoteTracker, @@ -2220,11 +2221,12 @@ impl ReplayStage { // new()-ing of its child bank banking_tracer.hash_event(parent.slot(), &parent.last_blockhash(), &parent.hash()); - let tpu_bank = bank_forks.write().unwrap().insert(tpu_bank); - poh_recorder - .write() - .unwrap() - .set_bank(tpu_bank, track_transaction_indexes); + update_bank_forks_and_poh_recorder_for_new_tpu_bank( + bank_forks, + poh_recorder, + tpu_bank, + track_transaction_indexes, + ); true } else { error!("{} No next leader found", my_pubkey);