iota_grpc_client/api/ledger/
health.rs

1// Copyright (c) 2026 IOTA Stiftung
2// SPDX-License-Identifier: Apache-2.0
3
4//! High-level API for health check queries.
5
6use iota_grpc_types::v1::ledger_service::{GetHealthRequest, GetHealthResponse};
7
8use crate::{
9    Client,
10    api::{MetadataEnvelope, Result},
11};
12
13impl Client {
14    /// Check the health of the node.
15    ///
16    /// Returns a [`MetadataEnvelope`]`<`[`GetHealthResponse`]`>` with the
17    /// latest checkpoint sequence number and an estimated validator latency
18    /// field (reserved for future use).
19    ///
20    /// If the node's latest checkpoint is stale (beyond the threshold), the
21    /// server returns an `UNAVAILABLE` error.
22    ///
23    /// # Parameters
24    ///
25    /// - `threshold_ms` - Optional threshold in milliseconds. If provided, the
26    ///   node is considered healthy only if the latest executed checkpoint
27    ///   timestamp is within this many milliseconds of the current system time.
28    ///   If `None`, the server applies its default threshold (5 seconds).
29    pub async fn get_health(
30        &self,
31        threshold_ms: Option<u64>,
32    ) -> Result<MetadataEnvelope<GetHealthResponse>> {
33        let mut request = GetHealthRequest::default();
34        if let Some(ms) = threshold_ms {
35            request = request.with_threshold_ms(ms);
36        }
37
38        let mut client = self.ledger_service_client();
39        let response = client.get_health(request).await?;
40
41        Ok(MetadataEnvelope::from(response))
42    }
43}