Skip to content

Commit

Permalink
check pool box rate in pool health assessment;
Browse files Browse the repository at this point in the history
  • Loading branch information
greenhat committed Jun 30, 2023
1 parent c6ab8d1 commit 9149462
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
17 changes: 9 additions & 8 deletions core/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,15 +201,16 @@ async fn pool_health(oracle_pool: Arc<OraclePool>) -> Result<Json<serde_json::Va
fn pool_health_sync(oracle_pool: Arc<OraclePool>) -> Result<PoolHealth, ApiError> {
let node_api = NodeApi::new(ORACLE_SECRETS.node_api_key.clone(), &ORACLE_CONFIG.node_url);
let current_height = (node_api.node.current_block_height()? as u32).into();
let pool_box_height = oracle_pool
.get_pool_box_source()
.get_pool_box()?
.get_box()
.creation_height
.into();
let pool_box = &oracle_pool.get_pool_box_source().get_pool_box()?;
let pool_box_height = pool_box.get_box().creation_height.into();
let network_prefix = node_api.get_change_address()?.network();
let pool_health =
check_pool_health(current_height, pool_box_height, oracle_pool, network_prefix)?;
let pool_health = check_pool_health(
current_height,
pool_box_height,
pool_box.rate(),
oracle_pool,
network_prefix,
)?;
Ok(pool_health)
}

Expand Down
1 change: 1 addition & 0 deletions core/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ pub fn update_metrics(oracle_pool: Arc<OraclePool>) -> Result<(), anyhow::Error>
let pool_health = check_pool_health(
current_height,
pool_box_height,
pool_box.rate(),
oracle_pool.clone(),
network_prefix,
)?;
Expand Down
7 changes: 5 additions & 2 deletions core/src/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::oracle_state::OraclePool;
use crate::oracle_types::BlockHeight;
use crate::oracle_types::EpochLength;
use crate::oracle_types::MinDatapoints;
use crate::oracle_types::Rate;
use crate::pool_config::POOL_CONFIG;

#[derive(Debug, serde::Serialize, Copy, Clone)]
Expand Down Expand Up @@ -52,6 +53,7 @@ pub struct PoolHealth {
pub fn check_pool_health(
current_height: BlockHeight,
pool_box_height: BlockHeight,
pool_box_rate: Rate,
oracle_pool: Arc<OraclePool>,
network_prefix: NetworkPrefix,
) -> Result<PoolHealth, anyhow::Error> {
Expand All @@ -64,8 +66,9 @@ pub fn check_pool_health(
.0
.into();
let acceptable_pool_box_delay_blocks = 3;
let is_healthy =
pool_box_height >= current_height - epoch_length - acceptable_pool_box_delay_blocks;
let is_healthy = pool_box_height >= current_height - epoch_length - acceptable_pool_box_delay_blocks
// on bootstrap pool box created with rate 0
&& pool_box_rate != 0;
let total_oracle_token_count = oracle_pool.get_total_oracle_token_count()?;
let all_oracles = get_all_oracle_boxes(oracle_pool, network_prefix)?;
let active_oracles = get_active_oracle_boxes(&all_oracles, pool_box_height);
Expand Down

0 comments on commit 9149462

Please sign in to comment.