more health check fixes, check slot rate
This commit is contained in:
@@ -13,7 +13,7 @@ const HEALTH_CHECK_CONFIG = {
|
|||||||
CHECK_INTERVAL_MS: 2000,
|
CHECK_INTERVAL_MS: 2000,
|
||||||
// Maximum time allowed between slot updates
|
// Maximum time allowed between slot updates
|
||||||
MAX_SLOT_STALENESS_MS: 5000,
|
MAX_SLOT_STALENESS_MS: 5000,
|
||||||
// Minimum expected slot advancement rate (slots per second)
|
// Minimum expected slot advancement rate (slots slower than 1 per second is problematic)
|
||||||
MIN_SLOT_RATE: 1,
|
MIN_SLOT_RATE: 1,
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
@@ -49,13 +49,27 @@ function evaluateHealth(currentSlot: number): {
|
|||||||
const timeDelta = now - globalHealthState.lastSlotTimestamp;
|
const timeDelta = now - globalHealthState.lastSlotTimestamp;
|
||||||
const slotDelta = currentSlot - globalHealthState.lastSlot;
|
const slotDelta = currentSlot - globalHealthState.lastSlot;
|
||||||
|
|
||||||
// Update state if slot has progressed
|
// If slot has progressed, we are healthy, check rate and update state.
|
||||||
if (currentSlot > globalHealthState.lastSlot) {
|
if (currentSlot > globalHealthState.lastSlot) {
|
||||||
|
// Update state
|
||||||
globalHealthState.lastSlot = currentSlot;
|
globalHealthState.lastSlot = currentSlot;
|
||||||
globalHealthState.lastSlotTimestamp = now;
|
globalHealthState.lastSlotTimestamp = now;
|
||||||
|
|
||||||
|
// Check if slot update rate is too low
|
||||||
|
const slotRate = (slotDelta / timeDelta) * 1000; // Convert to per second
|
||||||
|
if (slotRate < HEALTH_CHECK_CONFIG.MIN_SLOT_RATE) {
|
||||||
|
return {
|
||||||
|
isHealthy: false,
|
||||||
|
reason: `Slot update rate ${slotRate.toFixed(
|
||||||
|
2
|
||||||
|
)} slots/sec below minimum ${HEALTH_CHECK_CONFIG.MIN_SLOT_RATE}`,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return { isHealthy: true };
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if slots are too stale
|
// If slot has NOT progressed, check for staleness.
|
||||||
if (timeDelta > HEALTH_CHECK_CONFIG.MAX_SLOT_STALENESS_MS) {
|
if (timeDelta > HEALTH_CHECK_CONFIG.MAX_SLOT_STALENESS_MS) {
|
||||||
return {
|
return {
|
||||||
isHealthy: false,
|
isHealthy: false,
|
||||||
@@ -63,17 +77,7 @@ function evaluateHealth(currentSlot: number): {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if slot update rate is too low
|
// Slot has not progressed, but not stale yet. Still healthy.
|
||||||
const slotRate = (slotDelta / timeDelta) * 1000; // Convert to per second
|
|
||||||
if (slotRate < HEALTH_CHECK_CONFIG.MIN_SLOT_RATE) {
|
|
||||||
return {
|
|
||||||
isHealthy: false,
|
|
||||||
reason: `Slot update rate ${slotRate.toFixed(
|
|
||||||
2
|
|
||||||
)} slots/sec below minimum ${HEALTH_CHECK_CONFIG.MIN_SLOT_RATE}`,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return { isHealthy: true };
|
return { isHealthy: true };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import {
|
|||||||
ZERO,
|
ZERO,
|
||||||
QUOTE_PRECISION,
|
QUOTE_PRECISION,
|
||||||
PRICE_PRECISION,
|
PRICE_PRECISION,
|
||||||
BASE_PRECISION
|
BASE_PRECISION,
|
||||||
} from '@drift-labs/sdk';
|
} from '@drift-labs/sdk';
|
||||||
import {
|
import {
|
||||||
createMarketBasedAuctionParams,
|
createMarketBasedAuctionParams,
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ import {
|
|||||||
AssetType,
|
AssetType,
|
||||||
MainnetSpotMarkets,
|
MainnetSpotMarkets,
|
||||||
DevnetSpotMarkets,
|
DevnetSpotMarkets,
|
||||||
QUOTE_PRECISION,
|
|
||||||
PERCENTAGE_PRECISION_EXP,
|
PERCENTAGE_PRECISION_EXP,
|
||||||
} from '@drift-labs/sdk';
|
} from '@drift-labs/sdk';
|
||||||
import { RedisClient } from '@drift/common/clients';
|
import { RedisClient } from '@drift/common/clients';
|
||||||
|
|||||||
Reference in New Issue
Block a user