diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs index e0f109c7990310..98ba277a683bfc 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -60,7 +60,7 @@ use { epoch_accounts_hash::{self, EpochAccountsHash}, epoch_stakes::{EpochStakes, NodeVoteAccounts}, inline_spl_associated_token_account, inline_spl_token, - installed_scheduler_pool::InstalledSchedulerBox, + installed_scheduler_pool::InstalledSchedulerBoxInBank, message_processor::MessageProcessor, rent_collector::{CollectedInfo, RentCollector}, rent_debits::RentDebits, @@ -1101,7 +1101,7 @@ pub struct Bank { /// true when the bank's freezing or destruction has completed bank_freeze_or_destruction_incremented: AtomicBool, - pub(crate) scheduler: RwLock, + pub(crate) scheduler: RwLock, } struct VoteWithStakeDelegations { @@ -1323,7 +1323,7 @@ impl Bank { accounts_data_size_delta_off_chain: AtomicI64::new(0), fee_structure: FeeStructure::default(), loaded_programs_cache: Arc::>::default(), - scheduler: RwLock::::default(), + scheduler: RwLock::::default(), }; bank.bank_created(); @@ -1622,7 +1622,7 @@ impl Bank { accounts_data_size_delta_off_chain: AtomicI64::new(0), fee_structure: parent.fee_structure.clone(), loaded_programs_cache: parent.loaded_programs_cache.clone(), - scheduler: RwLock::::default(), + scheduler: RwLock::::default(), }; let (_, ancestors_time_us) = measure_us!({ @@ -1949,7 +1949,7 @@ impl Bank { accounts_data_size_delta_off_chain: AtomicI64::new(0), fee_structure: FeeStructure::default(), loaded_programs_cache: Arc::>::default(), - scheduler: RwLock::::default(), + scheduler: RwLock::::default(), }; bank.bank_created(); diff --git a/runtime/src/bank_forks.rs b/runtime/src/bank_forks.rs index de3411b2f96e2c..d68945b7a0d1cc 100644 --- a/runtime/src/bank_forks.rs +++ b/runtime/src/bank_forks.rs @@ -67,7 +67,7 @@ pub struct BankForks { pub accounts_hash_interval_slots: Slot, last_accounts_hash_slot: Slot, in_vote_only_mode: Arc, - pub(crate) scheduler_pool: InstalledSchedulerPoolArc, + pub(crate) scheduler_pool: Option, } impl Index for BankForks { @@ -190,7 +190,7 @@ impl BankForks { accounts_hash_interval_slots: std::u64::MAX, last_accounts_hash_slot: root, in_vote_only_mode: Arc::new(AtomicBool::new(false)), - scheduler_pool: InstalledSchedulerPoolArc::default(), + scheduler_pool: None, } } diff --git a/runtime/src/installed_scheduler_pool.rs b/runtime/src/installed_scheduler_pool.rs index 2c2355967c6d61..83408d1c86107c 100644 --- a/runtime/src/installed_scheduler_pool.rs +++ b/runtime/src/installed_scheduler_pool.rs @@ -38,8 +38,8 @@ use { // Send + Sync is needed to be a field of BankForks #[cfg_attr(any(test, feature = "test-in-workspace"), automock)] pub trait InstalledSchedulerPool: Send + Sync + Debug { - fn take_from_pool(&self, context: SchedulingContext) -> SchedulerBox; - fn return_to_pool(&self, scheduler: SchedulerBox); + fn take_from_pool(&self, context: SchedulingContext) -> InstalledSchedulerBox; + fn return_to_pool(&self, scheduler: InstalledSchedulerBox); } #[cfg_attr(any(test, feature = "test-in-workspace"), automock)] @@ -49,7 +49,7 @@ pub trait InstalledSchedulerPool: Send + Sync + Debug { // Send + Sync is needed to be a field of Bank pub trait InstalledScheduler: Send + Sync + Debug { fn scheduler_id(&self) -> SchedulerId; - fn scheduler_pool(&self) -> SchedulerPoolArc; + fn scheduler_pool(&self) -> InstalledSchedulerPoolArc; // Calling this is illegal as soon as schedule_termiantion is called on &self. fn schedule_execution(&self, sanitized_tx: &SanitizedTransaction, index: usize); @@ -70,8 +70,7 @@ pub trait InstalledScheduler: Send + Sync + Debug { fn replace_scheduler_context(&mut self, context: SchedulingContext); } -pub type SchedulerPoolArc = Arc; -pub(crate) type InstalledSchedulerPoolArc = Option; +pub type InstalledSchedulerPoolArc = Arc; pub type SchedulerId = u64; @@ -88,16 +87,16 @@ pub enum WaitReason { ReinitializedForRecentBlockhash, } -pub type SchedulerBox = Box; +pub type InstalledSchedulerBox = Box; // somewhat arbitrary new type just to pacify Bank's frozen_abi... #[derive(Debug, Default)] -pub(crate) struct InstalledSchedulerBox(Option); +pub(crate) struct InstalledSchedulerBoxInBank(Option); #[cfg(RUSTC_WITH_SPECIALIZATION)] use solana_frozen_abi::abi_example::AbiExample; #[cfg(RUSTC_WITH_SPECIALIZATION)] -impl AbiExample for InstalledSchedulerBox { +impl AbiExample for InstalledSchedulerBoxInBank { fn example() -> Self { Self(None) } @@ -182,7 +181,7 @@ impl Deref for BankWithScheduler { } impl BankForks { - pub fn install_scheduler_pool(&mut self, pool: SchedulerPoolArc) { + pub fn install_scheduler_pool(&mut self, pool: InstalledSchedulerPoolArc) { info!("Installed new scheduler_pool into bank_forks: {:?}", pool); assert!(self.scheduler_pool.replace(pool).is_none()); } @@ -196,7 +195,7 @@ impl BankForks { } impl Bank { - pub fn install_scheduler(&self, scheduler: SchedulerBox) { + pub fn install_scheduler(&self, scheduler: InstalledSchedulerBox) { let mut scheduler_guard = self.scheduler.write().expect("not poisoned"); assert!(scheduler_guard.0.replace(scheduler).is_none()); } @@ -318,7 +317,7 @@ mod tests { solana_sdk::system_transaction, }; - fn setup_mocked_scheduler_pool(seq: &mut Sequence) -> SchedulerPoolArc { + fn setup_mocked_scheduler_pool(seq: &mut Sequence) -> InstalledSchedulerPoolArc { let mut mock = MockInstalledSchedulerPool::new(); mock.expect_return_to_pool() .times(1) @@ -330,7 +329,7 @@ mod tests { fn setup_mocked_scheduler_with_extra( wait_reasons: impl Iterator, f: Option, - ) -> SchedulerBox { + ) -> InstalledSchedulerBox { let mut mock = MockInstalledScheduler::new(); let mut seq = Sequence::new(); @@ -353,7 +352,9 @@ mod tests { Box::new(mock) } - fn setup_mocked_scheduler(wait_reasons: impl Iterator) -> SchedulerBox { + fn setup_mocked_scheduler( + wait_reasons: impl Iterator, + ) -> InstalledSchedulerBox { setup_mocked_scheduler_with_extra( wait_reasons, None:: ()>, diff --git a/scheduler-pool/src/lib.rs b/scheduler-pool/src/lib.rs index 4c3581b584e09d..2b5123573f0d82 100644 --- a/scheduler-pool/src/lib.rs +++ b/scheduler-pool/src/lib.rs @@ -16,8 +16,9 @@ use { solana_program_runtime::timings::ExecuteTimings, solana_runtime::{ installed_scheduler_pool::{ - InstalledScheduler, InstalledSchedulerPool, ResultWithTimings, SchedulerBox, - SchedulerId, SchedulerPoolArc, SchedulingContext, WaitReason, + InstalledScheduler, InstalledSchedulerBox, InstalledSchedulerPool, + InstalledSchedulerPoolArc, ResultWithTimings, SchedulerId, SchedulingContext, + WaitReason, }, prioritization_fee_cache::PrioritizationFeeCache, vote_sender_types::ReplayVoteSender, @@ -31,7 +32,7 @@ use { // types aren't available there... #[derive(Debug)] pub struct SchedulerPool { - schedulers: Mutex>, + schedulers: Mutex>, log_messages_bytes_limit: Option, transaction_status_sender: Option, replay_vote_sender: Option, @@ -45,9 +46,9 @@ impl SchedulerPool { transaction_status_sender: Option, replay_vote_sender: Option, prioritization_fee_cache: Arc, - ) -> SchedulerPoolArc { + ) -> InstalledSchedulerPoolArc { Arc::new_cyclic(|weak_self| Self { - schedulers: Mutex::>::default(), + schedulers: Mutex::>::default(), log_messages_bytes_limit, transaction_status_sender, replay_vote_sender, @@ -64,7 +65,7 @@ impl SchedulerPool { } impl InstalledSchedulerPool for SchedulerPool { - fn take_from_pool(&self, context: SchedulingContext) -> SchedulerBox { + fn take_from_pool(&self, context: SchedulingContext) -> InstalledSchedulerBox { assert!(!context.bank().with_scheduler()); let mut schedulers = self.schedulers.lock().expect("not poisoned"); @@ -75,11 +76,11 @@ impl InstalledSchedulerPool for SchedulerPool { scheduler.replace_scheduler_context(context); scheduler } else { - Box::new(Scheduler::spawn(self.self_arc(), context)) + Box::new(PooledScheduler::spawn(self.self_arc(), context)) } } - fn return_to_pool(&self, scheduler: SchedulerBox) { + fn return_to_pool(&self, scheduler: InstalledSchedulerBox) { assert!(scheduler.scheduling_context().is_none()); self.schedulers @@ -93,14 +94,14 @@ impl InstalledSchedulerPool for SchedulerPool { // this will be replaced with more proper implementation... // not usable at all, especially for mainnet-beta #[derive(Debug)] -struct Scheduler { +struct PooledScheduler { id: SchedulerId, pool: Arc, context: Option, result_with_timings: Mutex>, } -impl Scheduler { +impl PooledScheduler { fn spawn(pool: Arc, initial_context: SchedulingContext) -> Self { Self { id: thread_rng().gen::(), @@ -110,12 +111,12 @@ impl Scheduler { } } } -impl InstalledScheduler for Scheduler { +impl InstalledScheduler for PooledScheduler { fn scheduler_id(&self) -> SchedulerId { self.id } - fn scheduler_pool(&self) -> SchedulerPoolArc { + fn scheduler_pool(&self) -> InstalledSchedulerPoolArc { self.pool.clone() }