@@ -33,6 +33,21 @@ pub trait InstalledScheduler: Send + Sync + Debug + 'static {
33
33
transaction_with_index : & ' a ( & ' a SanitizedTransaction , usize ) ,
34
34
) ;
35
35
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.
36
51
#[ must_use]
37
52
fn wait_for_termination ( & mut self , reason : & WaitReason ) -> Option < ResultWithTimings > ;
38
53
}
@@ -41,19 +56,28 @@ pub type DefaultInstalledSchedulerBox = Box<dyn InstalledScheduler>;
41
56
42
57
pub type ResultWithTimings = ( Result < ( ) > , ExecuteTimings ) ;
43
58
59
+ /// A hint from the bank about the reason the caller is waiting on its scheduler termination.
44
60
#[ derive( Debug , PartialEq , Eq , Clone , Copy ) ]
45
61
pub 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.
48
68
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.
50
71
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.
52
74
PausedForRecentBlockhash ,
53
75
}
54
76
55
77
impl WaitReason {
56
78
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`...
57
81
match self {
58
82
WaitReason :: PausedForRecentBlockhash => true ,
59
83
WaitReason :: TerminatedToFreeze | WaitReason :: DroppedFromBankForks => false ,
0 commit comments