From e4ed4814223ed3c9b9c2903a40c6fc58c0fee855 Mon Sep 17 00:00:00 2001 From: Nour Alharithi Date: Tue, 23 Jan 2024 13:25:57 -0800 Subject: [PATCH] consolidate conditions for killswitch --- src/dlob-subscriber/DLOBSubscriberIO.ts | 14 +++++++------- src/publishers/dlobPublisher.ts | 6 +++--- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/dlob-subscriber/DLOBSubscriberIO.ts b/src/dlob-subscriber/DLOBSubscriberIO.ts index c4039cb..6fad2a0 100644 --- a/src/dlob-subscriber/DLOBSubscriberIO.ts +++ b/src/dlob-subscriber/DLOBSubscriberIO.ts @@ -15,8 +15,6 @@ import { l2WithBNToStrings, } from '../utils/utils'; -const SLOT_DIFF_KILLSWITCH_THRESHOLD = 200; - type wsMarketL2Args = { marketIndex: number; marketType: MarketType; @@ -38,7 +36,7 @@ export class DLOBSubscriberIO extends DLOBSubscriber { public marketL2Args: wsMarketL2Args[] = []; public lastSeenL2Formatted: Map>; redisClient: RedisClient; - public marketKillSwitchSlotDiffThreshold: number; + public killSwitchSlotDiffThreshold: number; constructor( config: DLOBSubscriptionConfig & { @@ -46,13 +44,13 @@ export class DLOBSubscriberIO extends DLOBSubscriber { perpMarketInfos: wsMarketInfo[]; spotMarketInfos: wsMarketInfo[]; spotMarketSubscribers: SubscriberLookup; - marketKillSwitchSlotDiffThreshold?: number; + killSwitchSlotDiffThreshold?: number; } ) { super(config); this.redisClient = config.redisClient; - this.marketKillSwitchSlotDiffThreshold = - config.marketKillSwitchSlotDiffThreshold || 200; + this.killSwitchSlotDiffThreshold = + config.killSwitchSlotDiffThreshold || 200; // Set up appropriate maps this.lastSeenL2Formatted = new Map(); @@ -147,7 +145,9 @@ export class DLOBSubscriberIO extends DLOBSubscriber { if ( 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: dlobProvider slot: ${slot} diff --git a/src/publishers/dlobPublisher.ts b/src/publishers/dlobPublisher.ts index caa45ef..4181a9b 100644 --- a/src/publishers/dlobPublisher.ts +++ b/src/publishers/dlobPublisher.ts @@ -71,8 +71,8 @@ const ORDERBOOK_UPDATE_INTERVAL = parseInt(process.env.ORDERBOOK_UPDATE_INTERVAL) || 1000; const WS_FALLBACK_FETCH_INTERVAL = 10_000; -const MARKET_KILLSWITCH_SLOT_DIFF_THRESHOLD = - parseInt(process.env.MARKET_KILLSWITCH_SLOT_DIFF_THRESHOLD) || 300; +const KILLSWITCH_SLOT_DIFF_THRESHOLD = + parseInt(process.env.KILLSWITCH_SLOT_DIFF_THRESHOLD) || 200; // comma separated list of perp market indexes to load: i.e. 0,1,2,3 const PERP_MARKETS_TO_LOAD = @@ -398,7 +398,7 @@ const main = async () => { spotMarketSubscribers: MARKET_SUBSCRIBERS, perpMarketInfos, spotMarketInfos, - marketKillSwitchSlotDiffThreshold: MARKET_KILLSWITCH_SLOT_DIFF_THRESHOLD, + killSwitchSlotDiffThreshold: KILLSWITCH_SLOT_DIFF_THRESHOLD, }); await dlobSubscriber.subscribe(); if (useWebsocket && !FEATURE_FLAGS.DISABLE_GPA_REFRESH) {