diff --git a/Cargo.lock b/Cargo.lock index 019b08ba5c8ee9..ee843ebf273fea 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6824,6 +6824,7 @@ dependencies = [ "solana-tpu-client", "solana-transaction-status", "solana-turbine", + "solana-unified-scheduler-logic", "solana-unified-scheduler-pool", "solana-version", "solana-vote", diff --git a/core/Cargo.toml b/core/Cargo.toml index bba797068b58f7..0143180ced5b4d 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -120,6 +120,7 @@ solana-program-runtime = { workspace = true } solana-sdk = { workspace = true, features = ["dev-context-only-utils"] } solana-stake-program = { workspace = true } solana-system-program = { workspace = true } +solana-unified-scheduler-logic = { workspace = true } solana-unified-scheduler-pool = { workspace = true, features = [ "dev-context-only-utils", ] } diff --git a/core/tests/unified_scheduler.rs b/core/tests/unified_scheduler.rs index 75795f2f6c01ee..a6a1e1e19582f0 100644 --- a/core/tests/unified_scheduler.rs +++ b/core/tests/unified_scheduler.rs @@ -17,16 +17,13 @@ use { solana_ledger::genesis_utils::create_genesis_config, solana_runtime::{ accounts_background_service::AbsRequestSender, bank::Bank, bank_forks::BankForks, - genesis_utils::GenesisConfigInfo, prioritization_fee_cache::PrioritizationFeeCache, + genesis_utils::GenesisConfigInfo, installed_scheduler_pool::SchedulingContext, + prioritization_fee_cache::PrioritizationFeeCache, }, solana_runtime_transaction::runtime_transaction::RuntimeTransaction, - solana_sdk::{ - hash::Hash, - pubkey::Pubkey, - system_transaction, - transaction::{Result, SanitizedTransaction}, - }, + solana_sdk::{hash::Hash, pubkey::Pubkey, system_transaction, transaction::Result}, solana_timings::ExecuteTimings, + solana_unified_scheduler_logic::Task, solana_unified_scheduler_pool::{ DefaultTaskHandler, HandlerContext, PooledScheduler, SchedulerPool, TaskHandler, }, @@ -48,9 +45,8 @@ fn test_scheduler_waited_by_drop_bank_service() { fn handle( result: &mut Result<()>, timings: &mut ExecuteTimings, - bank: &Arc, - transaction: &RuntimeTransaction, - index: usize, + scheduling_context: &SchedulingContext, + task: &Task, handler_context: &HandlerContext, ) { info!("Stalling at StallingHandler::handle()..."); @@ -59,7 +55,7 @@ fn test_scheduler_waited_by_drop_bank_service() { std::thread::sleep(std::time::Duration::from_secs(3)); info!("Now entering into DefaultTaskHandler::handle()..."); - DefaultTaskHandler::handle(result, timings, bank, transaction, index, handler_context); + DefaultTaskHandler::handle(result, timings, scheduling_context, task, handler_context); } } diff --git a/unified-scheduler-pool/src/lib.rs b/unified-scheduler-pool/src/lib.rs index 4a27de9496bb8e..11831c64e74848 100644 --- a/unified-scheduler-pool/src/lib.rs +++ b/unified-scheduler-pool/src/lib.rs @@ -21,7 +21,6 @@ use { execute_batch, TransactionBatchWithIndexes, TransactionStatusSender, }, solana_runtime::{ - bank::Bank, installed_scheduler_pool::{ initialized_result_with_timings, InstalledScheduler, InstalledSchedulerBox, InstalledSchedulerPool, InstalledSchedulerPoolArc, ResultWithTimings, ScheduleResult, @@ -411,9 +410,8 @@ pub trait TaskHandler: Send + Sync + Debug + Sized + 'static { fn handle( result: &mut Result<()>, timings: &mut ExecuteTimings, - bank: &Arc, - transaction: &RuntimeTransaction, - index: usize, + scheduling_context: &SchedulingContext, + task: &Task, handler_context: &HandlerContext, ); } @@ -425,13 +423,16 @@ impl TaskHandler for DefaultTaskHandler { fn handle( result: &mut Result<()>, timings: &mut ExecuteTimings, - bank: &Arc, - transaction: &RuntimeTransaction, - index: usize, + scheduling_context: &SchedulingContext, + task: &Task, handler_context: &HandlerContext, ) { // scheduler must properly prevent conflicting tx executions. thus, task handler isn't // responsible for locking. + let bank = scheduling_context.bank(); + let transaction = task.transaction(); + let index = task.task_index(); + let batch = bank.prepare_unlocked_batch_from_single_tx(transaction); let batch_with_indexes = TransactionBatchWithIndexes { batch, @@ -786,7 +787,7 @@ impl, TH: TaskHandler> ThreadManager { } fn execute_task_with_handler( - bank: &Arc, + scheduling_context: &SchedulingContext, executed_task: &mut Box, handler_context: &HandlerContext, ) { @@ -794,9 +795,8 @@ impl, TH: TaskHandler> ThreadManager { TH::handle( &mut executed_task.result_with_timings.0, &mut executed_task.result_with_timings.1, - bank, - executed_task.task.transaction(), - executed_task.task.task_index(), + scheduling_context, + &executed_task.task, handler_context, ); } @@ -1192,7 +1192,7 @@ impl, TH: TaskHandler> ThreadManager { } let mut task = ExecutedTask::new_boxed(task); Self::execute_task_with_handler( - runnable_task_receiver.context().bank(), + runnable_task_receiver.context(), &mut task, &pool.handler_context, ); @@ -1752,9 +1752,8 @@ mod tests { fn handle( _result: &mut Result<()>, timings: &mut ExecuteTimings, - _bank: &Arc, - _transaction: &RuntimeTransaction, - _index: usize, + _bank: &SchedulingContext, + _task: &Task, _handler_context: &HandlerContext, ) { timings.metrics[ExecuteTimingType::CheckUs] += 123; @@ -1935,9 +1934,8 @@ mod tests { fn handle( result: &mut Result<()>, _timings: &mut ExecuteTimings, - _bank: &Arc, - _transaction: &RuntimeTransaction, - _index: usize, + _bank: &SchedulingContext, + _task: &Task, _handler_context: &HandlerContext, ) { *result = Err(TransactionError::AccountNotFound); @@ -2046,9 +2044,8 @@ mod tests { fn handle( _result: &mut Result<()>, _timings: &mut ExecuteTimings, - _bank: &Arc, - _transaction: &RuntimeTransaction, - _index: usize, + _bank: &SchedulingContext, + _task: &Task, _handler_context: &HandlerContext, ) { *TASK_COUNT.lock().unwrap() += 1; @@ -2383,11 +2380,11 @@ mod tests { fn handle( _result: &mut Result<()>, _timings: &mut ExecuteTimings, - _bank: &Arc, - _transaction: &RuntimeTransaction, - index: usize, + _bank: &SchedulingContext, + task: &Task, _handler_context: &HandlerContext, ) { + let index = task.task_index(); if index == 0 { sleepless_testing::at(PanickingHanlderCheckPoint::BeforeNotifiedPanic); } else if index == 1 { @@ -2463,11 +2460,11 @@ mod tests { fn handle( result: &mut Result<()>, _timings: &mut ExecuteTimings, - _bank: &Arc, - _transaction: &RuntimeTransaction, - index: usize, + _bank: &SchedulingContext, + task: &Task, _handler_context: &HandlerContext, ) { + let index = task.task_index(); *TASK_COUNT.lock().unwrap() += 1; if index == 1 { *result = Err(TransactionError::AccountNotFound); @@ -2532,24 +2529,17 @@ mod tests { fn handle( result: &mut Result<()>, timings: &mut ExecuteTimings, - bank: &Arc, - transaction: &RuntimeTransaction, - index: usize, + bank: &SchedulingContext, + task: &Task, handler_context: &HandlerContext, ) { + let index = task.task_index(); match index { STALLED_TRANSACTION_INDEX => *LOCK_TO_STALL.lock().unwrap(), BLOCKED_TRANSACTION_INDEX => {} _ => unreachable!(), }; - DefaultTaskHandler::handle( - result, - timings, - bank, - transaction, - index, - handler_context, - ); + DefaultTaskHandler::handle(result, timings, bank, task, handler_context); } } @@ -2617,13 +2607,12 @@ mod tests { fn handle( _result: &mut Result<()>, _timings: &mut ExecuteTimings, - bank: &Arc, - _transaction: &RuntimeTransaction, - index: usize, + context: &SchedulingContext, + task: &Task, _handler_context: &HandlerContext, ) { // The task index must always be matched to the slot. - assert_eq!(index as Slot, bank.slot()); + assert_eq!(task.task_index() as Slot, context.bank().slot()); } } @@ -2716,7 +2705,6 @@ mod tests { transaction: RuntimeTransaction, index: usize, ) -> ScheduleResult { - let transaction_and_index = (transaction, index); let context = self.context().clone(); let pool = self.3.clone(); @@ -2728,12 +2716,15 @@ mod tests { let mut result = Ok(()); let mut timings = ExecuteTimings::default(); + let task = SchedulingStateMachine::create_task(transaction, index, &mut |_| { + UsageQueue::default() + }); + ::handle( &mut result, &mut timings, - context.bank(), - &transaction_and_index.0, - transaction_and_index.1, + &context, + &task, &pool.handler_context, ); (result, timings) @@ -2923,6 +2914,7 @@ mod tests { let result = &mut Ok(()); let timings = &mut ExecuteTimings::default(); let prioritization_fee_cache = Arc::new(PrioritizationFeeCache::new(0u64)); + let scheduling_context = &SchedulingContext::new(bank.clone()); let handler_context = &HandlerContext { log_messages_bytes_limit: None, transaction_status_sender: None, @@ -2930,7 +2922,8 @@ mod tests { prioritization_fee_cache, }; - DefaultTaskHandler::handle(result, timings, bank, &tx, 0, handler_context); + let task = SchedulingStateMachine::create_task(tx, 0, &mut |_| UsageQueue::default()); + DefaultTaskHandler::handle(result, timings, scheduling_context, &task, handler_context); assert_matches!(result, Err(TransactionError::AccountLoadedTwice)); } }