feat: improve sequencer healthcheck with HealthStatus response

Previously check_health() always returned Ok(()) - completely useless.

Now returns HealthStatus { chain_height, is_healthy } so clients can:
1. Call check_health() once to get current chain_height
2. Wait a few seconds
3. Call again - if chain_height increased, sequencer is healthy

Refs #244
This commit is contained in:
ygd58 2026-03-28 19:55:06 +01:00
parent c1924e1ccc
commit 4be96ef087
No known key found for this signature in database
GPG Key ID: 82B49AE8D5B28600
3 changed files with 20 additions and 3 deletions

View File

@ -8,6 +8,7 @@ license = { workspace = true }
workspace = true
[dependencies]
serde = { version = "1", features = ["derive"] }
sequencer_service_protocol.workspace = true
jsonrpsee = { workspace = true, features = ["macros"] }

View File

@ -5,11 +5,22 @@ use jsonrpsee::proc_macros::rpc;
use jsonrpsee::types::ErrorObjectOwned;
#[cfg(feature = "client")]
pub use jsonrpsee::{core::ClientError, http_client::HttpClientBuilder as SequencerClientBuilder};
use serde::{Deserialize, Serialize};
use sequencer_service_protocol::{
Account, AccountId, Block, BlockId, Commitment, HashType, MembershipProof, NSSATransaction,
Nonce, ProgramId,
};
/// Health status returned by the sequencer healthcheck endpoint.
/// The chain_height field can be polled twice to verify the sequencer is progressing.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct HealthStatus {
/// Current chain height (block count). Should increase over time if sequencer is healthy.
pub chain_height: BlockId,
/// Whether the sequencer considers itself healthy.
pub is_healthy: bool,
}
#[cfg(all(not(feature = "server"), not(feature = "client")))]
compile_error!("At least one of `server` or `client` features must be enabled.");
@ -42,7 +53,7 @@ pub trait Rpc {
/// Returns the current chain height (block count).
/// A sequencer is healthy if this value increases over time.
#[method(name = "checkHealth")]
async fn check_health(&self) -> Result<BlockId, ErrorObjectOwned>;
async fn check_health(&self) -> Result<HealthStatus, ErrorObjectOwned>;
// TODO: These functions should be removed after wallet starts using indexer
// for this type of queries.

View File

@ -15,6 +15,7 @@ use sequencer_core::{
use sequencer_service_protocol::{
Account, AccountId, Block, BlockId, Commitment, HashType, MembershipProof, Nonce, ProgramId,
};
use sequencer_service_rpc::HealthStatus;
use tokio::sync::Mutex;
const NOT_FOUND_ERROR_CODE: i32 = -31999;
@ -82,9 +83,13 @@ impl<BC: BlockSettlementClientTrait + Send + 'static, IC: IndexerClientTrait + S
Ok(tx_hash)
}
async fn check_health(&self) -> Result<BlockId, ErrorObjectOwned> {
async fn check_health(&self) -> Result<HealthStatus, ErrorObjectOwned> {
let sequencer = self.sequencer.lock().await;
Ok(sequencer.chain_height())
let chain_height = sequencer.chain_height();
Ok(HealthStatus {
chain_height,
is_healthy: true,
})
}
async fn get_block(&self, block_id: BlockId) -> Result<Option<Block>, ErrorObjectOwned> {