Skip to content
Open
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
42 changes: 33 additions & 9 deletions watchdog/candid.did
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,36 @@ type height_status = variant {
ahead;
};

/// Block API providers.
/// Bitcoin block API providers.
type bitcoin_block_api = variant {
api_bitaps_com_mainnet;
api_blockchair_com_mainnet;
api_blockcypher_com_mainnet;
bitcoin_canister;
blockchain_info_mainnet;
blockstream_info_mainnet;
dogecoin_api_blockchair_com_mainnet;
dogecoin_api_blockcypher_com_mainnet;
dogecoin_canister;
dogecoin_tokenview_mainnet;
mempool_mainnet;
mempool_testnet;
};

/// Information about a block from a specific API provider.
type block_info = record {
/// Block API provider.
/// Bitcoin block API provider.
provider : bitcoin_block_api;

/// Block height.
height : opt nat64;
};

/// Information about a block from a specific API provider.
type block_info_v2 = record {
/// Block API provider name (e.g. bitcoin_mempool_mainnet).
provider : text;

/// Block height.
height : opt nat64;
};

// The health status of the canister monitored.
type health_status = record {
/// Main chain height of the canister.
Expand All @@ -54,10 +59,25 @@ type health_status = record {
/// Canister height status.
height_status : height_status;

/// Block info from the explorers.
/// Block info from the Bitcoin explorers.
explorers : vec block_info;
};

// The health status of the canister monitored.
type health_status_v2 = record {
/// Main chain height of the canister.
canister_height : opt nat64;

/// Height target derived from explorer heights.
explorer_height : opt nat64;

/// Canister height status.
height_status : height_status;

/// Block info from the explorers.
explorers : vec block_info_v2;
};

/// Network.
type network = variant {
bitcoin_mainnet;
Expand Down Expand Up @@ -95,7 +115,7 @@ type config = record {
interval_between_fetches_sec : nat64;

/// Explorers to use for fetching block data.
explorers : vec bitcoin_block_api;
explorers : vec text;

/// Type of subnet on which the watchdog and target canisters are deployed.
subnet_type : subnet_type;
Expand Down Expand Up @@ -127,9 +147,13 @@ type watchdog_arg = variant {
};

service : (watchdog_arg) -> {
/// Returns the health status of the target canister.
/// [DEPRECATED] Returns the health status of the target canister (Bitcoin only).
/// Please use `health_status_v2` instead.
health_status : () -> (health_status) query;

/// Returns the health status of the target canister.
health_status_v2 : () -> (health_status_v2) query;

/// Returns the configuration of the Watchdog canister.
/// This is a debug endpoint and may be unstable.
get_config : () -> (config) query;
Expand Down
10 changes: 4 additions & 6 deletions watchdog/src/api_access.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
use crate::{
health::{HealthStatus, HeightStatus},
print,
};
use crate::health::HealthStatusInternal;
use crate::{health::HeightStatus, print};
use ic_btc_interface::{Config as CanisterConfig, Flag, SetConfigRequest};

/// Calculates the target value of the canister API access flag.
fn calculate_target(health: HealthStatus) -> Option<Flag> {
fn calculate_target(health: HealthStatusInternal) -> Option<Flag> {
match health.height_status {
HeightStatus::Ok => Some(Flag::Enabled),
HeightStatus::Behind | HeightStatus::Ahead => Some(Flag::Disabled),
Expand Down Expand Up @@ -56,7 +54,7 @@ async fn update_api_access(target: Option<Flag>) {

/// Synchronizes the API access flag of the canister.
pub async fn synchronise_api_access() {
let target = calculate_target(crate::health::health_status());
let target = calculate_target(crate::health::health_status_internal());
crate::storage::set_api_access_target(target);

if target.is_some() {
Expand Down
Loading
Loading