Skip to content

Commit d5d620a

Browse files
committed
apollo_l1_provider: remove some panics in the L1 Provider
1 parent 331f1c6 commit d5d620a

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

crates/apollo_l1_provider/src/l1_provider.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ impl L1Provider {
169169
if let Err(previously_consumed_at) =
170170
self.tx_manager.consume_tx(tx_hash, consumed_at, self.clock.unix_now())
171171
{
172+
// TODO(guyn): need to check if this is really a critical bug, or if we can
173+
// log and ignore.
172174
panic!(
173175
"Double consumption of {tx_hash} at {consumed_at}, previously \
174176
consumed at {previously_consumed_at}."
@@ -228,12 +230,10 @@ impl L1Provider {
228230
);
229231
Ok(txs)
230232
}
231-
ProviderState::Pending => {
232-
panic!(
233-
"get_txs called while in pending state. Panicking in order to restart the \
234-
provider and bootstrap again."
235-
);
236-
}
233+
ProviderState::Pending => Err(L1ProviderError::UnexpectedProviderState {
234+
expected: ProviderState::Propose,
235+
found: self.state,
236+
}),
237237
ProviderState::Bootstrap => Err(L1ProviderError::OutOfSessionGetTransactions),
238238
ProviderState::Validate => Err(L1ProviderError::GetTransactionConsensusBug),
239239
ProviderState::Uninitialized => Err(L1ProviderError::Uninitialized),
@@ -259,12 +259,10 @@ impl L1Provider {
259259
Ok(self.tx_manager.validate_tx(tx_hash, self.clock.unix_now()))
260260
}
261261
ProviderState::Propose => Err(L1ProviderError::ValidateTransactionConsensusBug),
262-
ProviderState::Pending => {
263-
panic!(
264-
"validate called while in pending state. Panicking in order to restart the \
265-
provider and bootstrap again."
266-
);
267-
}
262+
ProviderState::Pending => Err(L1ProviderError::UnexpectedProviderState {
263+
expected: ProviderState::Validate,
264+
found: self.state,
265+
}),
268266
ProviderState::Bootstrap => Err(L1ProviderError::OutOfSessionValidate),
269267
ProviderState::Uninitialized => Err(L1ProviderError::Uninitialized),
270268
}

crates/apollo_l1_provider_types/src/errors.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ use serde::{Deserialize, Serialize};
55
use starknet_api::block::BlockNumber;
66
use thiserror::Error;
77

8+
use crate::ProviderState;
9+
810
#[derive(Clone, Debug, Error, PartialEq, Eq, Serialize, Deserialize)]
911
pub enum L1ProviderError {
1012
#[error("`get_txs` while in `Validate` state")]
@@ -22,6 +24,8 @@ pub enum L1ProviderError {
2224
Uninitialized,
2325
#[error("Unexpected height: expected {expected_height}, got {got}")]
2426
UnexpectedHeight { expected_height: BlockNumber, got: BlockNumber },
27+
#[error("Unexpected provider state: {expected}, got: {found}")]
28+
UnexpectedProviderState { expected: ProviderState, found: ProviderState },
2529
#[error("Cannot transition from {from} to {to}")]
2630
UnexpectedProviderStateTransition { from: String, to: String },
2731
#[error("`validate` called while in `Propose` state")]

0 commit comments

Comments
 (0)