-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
108 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use thiserror::Error; | ||
|
||
/// Represents errors that can occur during checkpoint-related operations. | ||
/// | ||
/// This error type encompasses various failure scenarios that may occur when | ||
/// interacting with checkpoints, including RPC communication issues, | ||
/// data validation problems, and serialization errors. Each variant provides | ||
/// detailed information about the specific error condition. | ||
#[derive(Error, Debug)] | ||
pub enum CheckpointError { | ||
/// Occurs when the RPC request to fetch checkpoint data fails. | ||
#[error("Failed to fetch checkpoint data: {0}")] | ||
FetchError(String), | ||
|
||
/// Occurs when no checkpoint data is returned from the sequencer. | ||
#[error("No checkpoint data returned from sequencer for index {0}")] | ||
CheckpointNotFound(u64), | ||
|
||
/// Occurs when failed to submit checkpoint proof to the sequencer. | ||
#[error("Failed to submit checkpoint proof for index {index}: {error}")] | ||
SubmitProofError { index: u64, error: String }, | ||
} | ||
|
||
/// A type alias for Results involving checkpoint operations. | ||
pub type CheckpointResult<T> = Result<T, CheckpointError>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,20 @@ | ||
use jsonrpsee::{core::client::ClientT, http_client::HttpClient, rpc_params}; | ||
use tracing::error; | ||
|
||
use super::error::CheckpointResult; | ||
use crate::checkpoint_runner::error::CheckpointError; | ||
|
||
/// Fetches the latest checkpoint index from the sequencer client. | ||
pub async fn fetch_latest_checkpoint_index(sequencer_client: &HttpClient) -> anyhow::Result<u64> { | ||
match sequencer_client | ||
.request("strata_getLatestCheckpointIndex", rpc_params![]) | ||
pub async fn fetch_latest_checkpoint_index(sequencer_client: &HttpClient) -> CheckpointResult<u64> { | ||
sequencer_client | ||
.request::<Option<u64>, _>("strata_getLatestCheckpointIndex", rpc_params![]) | ||
.await | ||
{ | ||
Ok(Some(idx)) => Ok(idx), | ||
Ok(None) => { | ||
error!("Failed to fetch current checkpoint"); | ||
Err(anyhow::anyhow!("Failed to fetch current checkpoint")) | ||
} | ||
Err(e) => { | ||
error!("Failed to fetch current checkpoint index: {}", e); | ||
Err(anyhow::anyhow!( | ||
"Failed to fetch current checkpoint index: {}", | ||
e | ||
)) | ||
} | ||
} | ||
.map_err(|e| { | ||
error!("Failed to fetch current checkpoint index: {e}"); | ||
CheckpointError::FetchError(e.to_string()) | ||
})? | ||
.ok_or_else(|| { | ||
error!("No checkpoint index returned from sequencer"); | ||
CheckpointError::CheckpointNotFound(0) | ||
}) | ||
} | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
//! A module defining operations for the checkpoint proof generation | ||
pub mod error; | ||
pub mod fetch; | ||
pub mod runner; | ||
pub mod submit; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters