Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add StatusResponse::is_network_healthy #2197

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions bindings/nodejs/lib/types/models/api/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ export interface StatusResponse {
* Tells whether the node is healthy or not.
*/
isHealthy: boolean;
/**
* Tells whether the network is healthy (finalization is not delayed).
*/
isNetworkHealthy: boolean;
/**
* A notion of time that is anchored to the latest accepted block.
*/
Expand Down
2 changes: 2 additions & 0 deletions bindings/python/iota_sdk/types/node_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class StatusResponse:

Attributes:
is_healthy: Tells whether the node is healthy or not.
is_network_healthy: Tells whether the network is healthy (finalization is not delayed).
accepted_tangle_time: A notion of time that is anchored to the latest accepted block.
relative_accepted_tangle_time: The time after Accepted Tangle Time has advanced with the system clock.
confirmed_tangle_time: A notion of time that is anchored to the latest confirmed block.
Expand All @@ -27,6 +28,7 @@ class StatusResponse:
pruning_epoch: The index of the epoch before which the tangle history is pruned.
"""
is_healthy: bool
is_network_healthy: bool
accepted_tangle_time: int = field(metadata=config(
encoder=str
))
Expand Down
3 changes: 2 additions & 1 deletion sdk/examples/how_tos/client/get_health.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {

// Get node health.
let is_healthy = client.get_health(&node_url).await?;
let is_network_healthy = client.get_network_health().await?;

println!("Healthy: {is_healthy}");
println!("Healthy: node {is_healthy}, network {is_network_healthy}");

Ok(())
}
19 changes: 19 additions & 0 deletions sdk/src/client/node_api/core/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,25 @@ impl ClientInner {

self.get_request(PATH, None, false).await
}

/// Returns whether the network is healthy (finalization is not delayed).
/// GET /api/core/v3/network/health
pub async fn get_network_health(&self) -> Result<bool, ClientError> {
const PATH: &str = "api/core/v3/network/health";

let nodes = self.node_manager.read().await.get_nodes(PATH, None)?;
let client = crate::client::node_manager::http_client::HttpClient::new(DEFAULT_USER_AGENT.to_string());

for node in &nodes {
if let Ok(res) = client.get(node, DEFAULT_API_TIMEOUT).await {
if res.status() == 200 {
return Ok(true);
}
}
}

Ok(false)
}
}

impl Client {
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/client/node_manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl NodeManager {
NodeManagerBuilder::new()
}

fn get_nodes(&self, path: &str, query: Option<&str>) -> Result<Vec<Node>, ClientError> {
pub(crate) fn get_nodes(&self, path: &str, query: Option<&str>) -> Result<Vec<Node>, ClientError> {
let mut nodes_with_modified_url: Vec<Node> = Vec::new();

// Set primary nodes first, so they will also be used first for requests.
Expand Down
1 change: 1 addition & 0 deletions sdk/src/types/api/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ impl PermanodeInfoResponse {
#[serde(rename_all = "camelCase")]
pub struct StatusResponse {
pub is_healthy: bool,
pub is_network_healthy: bool,
#[serde(with = "option_string")]
pub accepted_tangle_time: Option<u64>,
#[serde(with = "option_string")]
Expand Down
Loading