Skip to content

Commit

Permalink
Addition of get_checkpoint_status and fields addition in RpcCheckpoin…
Browse files Browse the repository at this point in the history
…tInfo (#610)

* feat: addition of get_checkpoint_status and fields addition in RpcCheckpointInfo

* feat: unique error code for checkpoint & method renaming
  • Loading branch information
purusang authored Jan 17, 2025
1 parent 52c1eb4 commit 38abd51
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 8 deletions.
1 change: 1 addition & 0 deletions bin/prover-client/src/operators/checkpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ impl CheckpointOperator {
// TODO: likely unused and should be removed.
l2_blockid: Buf32::default().into(),
commitment: None,
confirmation_status: None,
};
let proof_ctx = self.construct_proof_ctx(&checkpoint_idx)?;

Expand Down
15 changes: 13 additions & 2 deletions bin/strata-client/src/rpc_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ use strata_rpc_api::{
};
use strata_rpc_types::{
errors::RpcServerError as Error, DaBlob, HexBytes, HexBytes32, L2BlockStatus, RpcBlockHeader,
RpcBridgeDuties, RpcChainState, RpcCheckpointInfo, RpcClientStatus, RpcDepositEntry,
RpcExecUpdate, RpcL1Status, RpcSyncStatus,
RpcBridgeDuties, RpcChainState, RpcCheckpointConfStatus, RpcCheckpointInfo, RpcClientStatus,
RpcDepositEntry, RpcExecUpdate, RpcL1Status, RpcSyncStatus,
};
use strata_rpc_utils::to_jsonrpsee_error;
use strata_state::{
Expand Down Expand Up @@ -566,6 +566,17 @@ impl<D: Database + Send + Sync + 'static> StrataApiServer for StrataRpcImpl<D> {
Ok(entry.map(Into::into))
}

async fn get_checkpoint_conf_status(
&self,
idx: u64,
) -> RpcResult<Option<RpcCheckpointConfStatus>> {
self.checkpoint_handle
.get_checkpoint(idx)
.await
.map(|opt| opt.map(Into::into))
.map_err(|e| Error::Checkpoint(e.to_string()).into())
}

async fn get_latest_checkpoint_index(&self, finalized: Option<bool>) -> RpcResult<Option<u64>> {
let finalized = finalized.unwrap_or(false);
if finalized {
Expand Down
11 changes: 9 additions & 2 deletions crates/rpc/api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use strata_db::types::{L1TxEntry, L1TxStatus};
use strata_primitives::bridge::{OperatorIdx, PublickeyTable};
use strata_rpc_types::{
types::{RpcBlockHeader, RpcClientStatus, RpcL1Status},
HexBytes, HexBytes32, L2BlockStatus, RpcBridgeDuties, RpcChainState, RpcCheckpointInfo,
RpcDepositEntry, RpcExecUpdate, RpcSyncStatus,
HexBytes, HexBytes32, L2BlockStatus, RpcBridgeDuties, RpcChainState, RpcCheckpointConfStatus,
RpcCheckpointInfo, RpcDepositEntry, RpcExecUpdate, RpcSyncStatus,
};
use strata_state::{
block::L2Block, client_state::ClientState, id::L2BlockId, operation::ClientUpdateOutput,
Expand Down Expand Up @@ -109,6 +109,13 @@ pub trait StrataApi {
#[method(name = "getCheckpointInfo")]
async fn get_checkpoint_info(&self, idx: u64) -> RpcResult<Option<RpcCheckpointInfo>>;

/// Get the checkpoint confirmation status if checkpoint exists
#[method(name = "getCheckpointConfStatus")]
async fn get_checkpoint_conf_status(
&self,
idx: u64,
) -> RpcResult<Option<RpcCheckpointConfStatus>>;

/// Get the l2block status from its height
/// This assumes that the block finalization is always sequential. i.e all the blocks before the
/// last finalized block are also finalized
Expand Down
10 changes: 7 additions & 3 deletions crates/rpc/types/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ pub enum RpcServerError {
#[error("Invalid proof for checkpoint {0}: {1}")]
InvalidProof(u64, String),

#[error("Checkpoint retrieval failed: {0}")]
Checkpoint(String),

/// Generic internal error message. If this is used often it should be made
/// into its own error type.
#[error("{0}")]
Expand All @@ -78,14 +81,15 @@ impl RpcServerError {
Self::ClientNotStarted => -32606,
Self::BeforeGenesis => -32607,
Self::FetchLimitReached(_, _) => -32608,
Self::UnknownIdx(_) => -32608,
Self::MissingL1BlockManifest(_) => -32609,
Self::MissingCheckpointInDb(_) => -32610,
Self::ProofAlreadyCreated(_) => -32611,
Self::InvalidProof(_, _) => -32612,
Self::BlockingAbort(_) => -32001,
Self::UnknownIdx(_) => -32613,
Self::Checkpoint(_) => -32614,
Self::Other(_) => -32000,
Self::OtherEx(_, _) => -32000,
Self::OtherEx(_, _) => -32001,
Self::BlockingAbort(_) => -32002,
}
}
}
Expand Down
33 changes: 32 additions & 1 deletion crates/rpc/types/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use bitcoin::{hashes::Hash, Network, Txid, Wtxid};
use serde::{Deserialize, Serialize};
use strata_db::types::{CheckpointCommitment, CheckpointEntry};
use strata_db::types::{CheckpointCommitment, CheckpointConfStatus, CheckpointEntry};
use strata_primitives::{
bridge::OperatorIdx,
l1::{BitcoinAmount, L1TxRef, OutputRef},
Expand Down Expand Up @@ -258,6 +258,33 @@ impl From<CheckpointCommitment> for RpcCheckpointCommitmentInfo {
}
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum RpcCheckpointConfStatus {
/// Pending to be posted on L1
Pending,
/// Confirmed on L1
Confirmed,
/// Finalized on L1
Finalized,
}

impl From<CheckpointConfStatus> for RpcCheckpointConfStatus {
fn from(value: CheckpointConfStatus) -> Self {
match value {
CheckpointConfStatus::Pending => Self::Pending,
CheckpointConfStatus::Confirmed => Self::Confirmed,
CheckpointConfStatus::Finalized => Self::Finalized,
}
}
}

impl From<CheckpointEntry> for RpcCheckpointConfStatus {
fn from(value: CheckpointEntry) -> Self {
value.confirmation_status.into()
}
}

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct RpcCheckpointInfo {
/// The index of the checkpoint
Expand All @@ -273,6 +300,8 @@ pub struct RpcCheckpointInfo {
pub l2_blockid: L2BlockId,
/// Info on txn where checkpoint is committed on chain
pub commitment: Option<RpcCheckpointCommitmentInfo>,
/// Confirmation status of checkpoint
pub confirmation_status: Option<RpcCheckpointConfStatus>,
}

impl From<BatchInfo> for RpcCheckpointInfo {
Expand All @@ -283,6 +312,7 @@ impl From<BatchInfo> for RpcCheckpointInfo {
l2_range: value.l2_range,
l2_blockid: value.l2_blockid,
commitment: None,
confirmation_status: None,
}
}
}
Expand All @@ -291,6 +321,7 @@ impl From<CheckpointEntry> for RpcCheckpointInfo {
fn from(value: CheckpointEntry) -> Self {
let mut item: Self = value.batch_info.into();
item.commitment = value.commitment.map(Into::into);
item.confirmation_status = Some(value.confirmation_status.into());
item
}
}
Expand Down

0 comments on commit 38abd51

Please sign in to comment.