Skip to content

Commit fb3d031

Browse files
apollo_l1_provider: add uninitialized state to provider (#9571)
1 parent 18d6b3b commit fb3d031

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

crates/apollo_l1_provider/src/l1_provider.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ impl L1Provider {
5252
// Start the provider, get first-scrape events, start L2 sync.
5353
pub async fn initialize(&mut self, events: Vec<Event>) -> L1ProviderResult<()> {
5454
info!("Initializing l1 provider");
55+
// TODO(guyn): a future PR will replace this check. It will also no longer trigger the
56+
// start_l2_sync call.
5557
if !self.state.is_bootstrapping() {
5658
// FIXME: This should be return FatalError or similar, which should trigger a planned
5759
// restart from the infra, since this CAN happen if the scraper recovered from a crash.
@@ -196,6 +198,7 @@ impl L1Provider {
196198
}
197199
ProviderState::Bootstrap => Err(L1ProviderError::OutOfSessionGetTransactions),
198200
ProviderState::Validate => Err(L1ProviderError::GetTransactionConsensusBug),
201+
ProviderState::Uninitialized => Err(L1ProviderError::Uninitialized),
199202
}
200203
}
201204

@@ -225,6 +228,7 @@ impl L1Provider {
225228
);
226229
}
227230
ProviderState::Bootstrap => Err(L1ProviderError::OutOfSessionValidate),
231+
ProviderState::Uninitialized => Err(L1ProviderError::Uninitialized),
228232
}
229233
}
230234

@@ -544,6 +548,7 @@ impl L1ProviderBuilder {
544548
self.config.l1_handler_cancellation_timelock_seconds,
545549
self.config.l1_handler_consumption_timelock_seconds,
546550
),
551+
// TODO(guyn): in a future PR, this will be replaced with ProviderState::Uninitialized.
547552
state: ProviderState::Bootstrap,
548553
config: self.config,
549554
clock: self.clock.unwrap_or_else(|| Arc::new(DefaultClock)),

crates/apollo_l1_provider/src/lib.rs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,33 +26,39 @@ use crate::transaction_manager::TransactionManagerConfig;
2626
/// Current state of the provider, where pending means: idle, between proposal/validation cycles.
2727
#[derive(Clone, Debug, Eq, PartialEq)]
2828
pub enum ProviderState {
29-
/// Provider is not read for proposing or validating. Use start_block to transition to Propose
29+
/// Provider has not been initialized yet, needs to do bootstrapping at least once.
30+
Uninitialized,
31+
// TODO(guyn): in a upcoming PR, bootstrap will be available not only on startup.
32+
/// Provider is catching up using sync. Only happens on startup.
33+
Bootstrap,
34+
/// Provider is not ready for proposing or validating. Use start_block to transition to Propose
3035
/// or Validate.
3136
Pending,
32-
/// Provider is ready for proposing. Use commit_block to finish and return to Pending.
37+
/// Provider is ready for proposing. Use get_txs to get what you need for a new proposal. Use
38+
/// commit_block to finish and return to Pending.
3339
Propose,
34-
/// Provider is catching up using sync. Only happens on startup.
35-
Bootstrap,
36-
/// Provider is ready for validating. Use validate to validate a transaction.
40+
/// Provider is ready for validating. Use validate to validate a transaction. Use commit_block
41+
/// to finish and return to Pending.
3742
Validate,
3843
}
3944

4045
impl ProviderState {
4146
pub fn as_str(&self) -> &str {
4247
match self {
48+
ProviderState::Uninitialized => "Uninitialized",
4349
ProviderState::Pending => "Pending",
4450
ProviderState::Propose => "Propose",
4551
ProviderState::Bootstrap => "Bootstrap",
4652
ProviderState::Validate => "Validate",
4753
}
4854
}
4955

50-
pub fn is_bootstrapping(&self) -> bool {
51-
if let ProviderState::Bootstrap = self {
52-
return true;
53-
}
56+
pub fn uninitialized(&self) -> bool {
57+
matches!(self, ProviderState::Uninitialized)
58+
}
5459

55-
false
60+
pub fn is_bootstrapping(&self) -> bool {
61+
matches!(self, ProviderState::Bootstrap)
5662
}
5763

5864
fn transition_to_pending(&self) -> ProviderState {

0 commit comments

Comments
 (0)