consolidate conditions for killswitch

This commit is contained in:
Nour Alharithi
2024-01-23 13:25:57 -08:00
parent 56b3d9e9bd
commit e4ed481422
2 changed files with 10 additions and 10 deletions

View File

@@ -15,8 +15,6 @@ import {
l2WithBNToStrings, l2WithBNToStrings,
} from '../utils/utils'; } from '../utils/utils';
const SLOT_DIFF_KILLSWITCH_THRESHOLD = 200;
type wsMarketL2Args = { type wsMarketL2Args = {
marketIndex: number; marketIndex: number;
marketType: MarketType; marketType: MarketType;
@@ -38,7 +36,7 @@ export class DLOBSubscriberIO extends DLOBSubscriber {
public marketL2Args: wsMarketL2Args[] = []; public marketL2Args: wsMarketL2Args[] = [];
public lastSeenL2Formatted: Map<MarketType, Map<number, any>>; public lastSeenL2Formatted: Map<MarketType, Map<number, any>>;
redisClient: RedisClient; redisClient: RedisClient;
public marketKillSwitchSlotDiffThreshold: number; public killSwitchSlotDiffThreshold: number;
constructor( constructor(
config: DLOBSubscriptionConfig & { config: DLOBSubscriptionConfig & {
@@ -46,13 +44,13 @@ export class DLOBSubscriberIO extends DLOBSubscriber {
perpMarketInfos: wsMarketInfo[]; perpMarketInfos: wsMarketInfo[];
spotMarketInfos: wsMarketInfo[]; spotMarketInfos: wsMarketInfo[];
spotMarketSubscribers: SubscriberLookup; spotMarketSubscribers: SubscriberLookup;
marketKillSwitchSlotDiffThreshold?: number; killSwitchSlotDiffThreshold?: number;
} }
) { ) {
super(config); super(config);
this.redisClient = config.redisClient; this.redisClient = config.redisClient;
this.marketKillSwitchSlotDiffThreshold = this.killSwitchSlotDiffThreshold =
config.marketKillSwitchSlotDiffThreshold || 200; config.killSwitchSlotDiffThreshold || 200;
// Set up appropriate maps // Set up appropriate maps
this.lastSeenL2Formatted = new Map(); this.lastSeenL2Formatted = new Map();
@@ -147,7 +145,9 @@ export class DLOBSubscriberIO extends DLOBSubscriber {
if ( if (
Math.abs(slot - parseInt(l2Formatted['oracleData']['slot'])) > Math.abs(slot - parseInt(l2Formatted['oracleData']['slot'])) >
SLOT_DIFF_KILLSWITCH_THRESHOLD this.killSwitchSlotDiffThreshold ||
Math.abs(slot - l2Formatted['marketSlot']) >
this.killSwitchSlotDiffThreshold
) { ) {
console.log(`Killing process due to slot diffs: console.log(`Killing process due to slot diffs:
dlobProvider slot: ${slot} dlobProvider slot: ${slot}

View File

@@ -71,8 +71,8 @@ const ORDERBOOK_UPDATE_INTERVAL =
parseInt(process.env.ORDERBOOK_UPDATE_INTERVAL) || 1000; parseInt(process.env.ORDERBOOK_UPDATE_INTERVAL) || 1000;
const WS_FALLBACK_FETCH_INTERVAL = 10_000; const WS_FALLBACK_FETCH_INTERVAL = 10_000;
const MARKET_KILLSWITCH_SLOT_DIFF_THRESHOLD = const KILLSWITCH_SLOT_DIFF_THRESHOLD =
parseInt(process.env.MARKET_KILLSWITCH_SLOT_DIFF_THRESHOLD) || 300; parseInt(process.env.KILLSWITCH_SLOT_DIFF_THRESHOLD) || 200;
// comma separated list of perp market indexes to load: i.e. 0,1,2,3 // comma separated list of perp market indexes to load: i.e. 0,1,2,3
const PERP_MARKETS_TO_LOAD = const PERP_MARKETS_TO_LOAD =
@@ -398,7 +398,7 @@ const main = async () => {
spotMarketSubscribers: MARKET_SUBSCRIBERS, spotMarketSubscribers: MARKET_SUBSCRIBERS,
perpMarketInfos, perpMarketInfos,
spotMarketInfos, spotMarketInfos,
marketKillSwitchSlotDiffThreshold: MARKET_KILLSWITCH_SLOT_DIFF_THRESHOLD, killSwitchSlotDiffThreshold: KILLSWITCH_SLOT_DIFF_THRESHOLD,
}); });
await dlobSubscriber.subscribe(); await dlobSubscriber.subscribe();
if (useWebsocket && !FEATURE_FLAGS.DISABLE_GPA_REFRESH) { if (useWebsocket && !FEATURE_FLAGS.DISABLE_GPA_REFRESH) {