@@ -33,6 +33,21 @@ pub trait InstalledScheduler: Send + Sync + Debug + 'static {
3333 transaction_with_index : & ' a ( & ' a SanitizedTransaction , usize ) ,
3434 ) ;
3535
36+ /// Wait for a scheduler to terminate after it is notified with the given reason.
37+ ///
38+ /// Firstly, this function blocks the current thread while waiting for the scheduler to
39+ /// complete all of the executions for the scheduled transactions. This means the scheduler has
40+ /// prepared the finalized `ResultWithTimings` at least internally at the time of existing from
41+ /// this function. If no trsanction is scheduled, the result and timing will be `Ok(())` and
42+ /// `ExecuteTimings::default()` respectively. This is done in the same way regardless of
43+ /// `WaitReason`.
44+ ///
45+ /// After that, the scheduler may behave differently depending on the reason, regarding the
46+ /// final bookkeeping. Specifically, this function guaranteed to return
47+ /// `Some(finalized_result_with_timings)` unless the reason is `PausedForRecentBlockhash`. In
48+ /// the case of `PausedForRecentBlockhash`, the scheduler is responsible to retain the
49+ /// finalized `ResultWithTimings` until it's `wait_for_termination()`-ed with one of the other
50+ /// two reasons later.
3651 #[ must_use]
3752 fn wait_for_termination ( & mut self , reason : & WaitReason ) -> Option < ResultWithTimings > ;
3853}
@@ -41,19 +56,28 @@ pub type DefaultInstalledSchedulerBox = Box<dyn InstalledScheduler>;
4156
4257pub type ResultWithTimings = ( Result < ( ) > , ExecuteTimings ) ;
4358
59+ /// A hint from the bank about the reason the caller is waiting on its scheduler termination.
4460#[ derive( Debug , PartialEq , Eq , Clone , Copy ) ]
4561pub enum WaitReason {
46- // most normal termination waiting mode; couldn't be done implicitly inside Bank::freeze() -> () to return
47- // the result and timing in some way to higher-layer subsystems;
62+ // The bank wants its scheduler to terminate after the completion of transaction execution, in
63+ // order to freeze itself immediately thereafter. This is by far the most normal wait reason.
64+ //
65+ // Note that `wait_for_termination(TerminatedToFreeze)` must explicitly be done prior
66+ // to Bank::freeze(). This can't be done inside Bank::freeze() implicitly to remain it
67+ // infallible.
4868 TerminatedToFreeze ,
49- // just behaves like TerminatedToFreeze but hint that this is called from Drop::drop().
69+ // The bank wants its scheduler to terminate just like `TerminatedToFreeze` and indicate that
70+ // Drop::drop() is the caller.
5071 DroppedFromBankForks ,
51- // scheduler is paused without being returned to the pool to collect ResultWithTimings later.
72+ // The bank wants its scheduler to pause the scheduler after the completion without being
73+ // returned to the pool to collect scheduler's internally-held `ResultWithTimings` later.
5274 PausedForRecentBlockhash ,
5375}
5476
5577impl WaitReason {
5678 pub fn is_paused ( & self ) -> bool {
79+ // Exhaustive `match` is preferred here than `matches!()` to trigger an explicit
80+ // decision to be made, should we add new variants like `PausedForFooBar`...
5781 match self {
5882 WaitReason :: PausedForRecentBlockhash => true ,
5983 WaitReason :: TerminatedToFreeze | WaitReason :: DroppedFromBankForks => false ,
0 commit comments