From b717c9f9ecbbfd15233a1a6ae3f86662193708e9 Mon Sep 17 00:00:00 2001 From: Nour Alharithi Date: Tue, 12 Mar 2024 16:01:57 -0400 Subject: [PATCH] ignore prelaunch for killing process --- src/dlob-subscriber/DLOBSubscriberIO.ts | 57 ++++++------------------- src/index.ts | 2 +- 2 files changed, 14 insertions(+), 45 deletions(-) diff --git a/src/dlob-subscriber/DLOBSubscriberIO.ts b/src/dlob-subscriber/DLOBSubscriberIO.ts index 5cff973..bcedda3 100644 --- a/src/dlob-subscriber/DLOBSubscriberIO.ts +++ b/src/dlob-subscriber/DLOBSubscriberIO.ts @@ -46,6 +46,8 @@ export class DLOBSubscriberIO extends DLOBSubscriber { Map >; + public skipSlotStalenessCheckMarkets = new Set(); + constructor( config: DLOBSubscriptionConfig & { redisClient: RedisClient; @@ -73,6 +75,10 @@ export class DLOBSubscriberIO extends DLOBSubscriber { market.marketIndex ); const includeVamm = !isVariant(perpMarket.status, 'ammPaused'); + const oracleSource = perpMarket.amm.oracleSource; + if (isVariant(oracleSource, 'prelaunch')) { + this.skipSlotStalenessCheckMarkets.add(market.marketIndex); + } this.marketArgs.push({ marketIndex: market.marketIndex, @@ -175,9 +181,13 @@ export class DLOBSubscriberIO extends DLOBSubscriber { ); // Check if slot diffs are too large for oracle + const skipSlotCheck = + marketType === 'perp' && + this.skipSlotStalenessCheckMarkets.has(marketArgs.marketIndex); if ( Math.abs(slot - parseInt(l2Formatted['oracleData']['slot'])) > - this.killSwitchSlotDiffThreshold + this.killSwitchSlotDiffThreshold && + !skipSlotCheck ) { console.log(`Killing process due to slot diffs for market ${marketName}: dlobProvider slot: ${slot} @@ -194,7 +204,8 @@ export class DLOBSubscriberIO extends DLOBSubscriber { if ( lastMarketSlotAndTime && l2Formatted['marketSlot'] === lastMarketSlotAndTime.slot && - Date.now() - lastMarketSlotAndTime.ts > MAKRET_STALENESS_THRESHOLD + Date.now() - lastMarketSlotAndTime.ts > MAKRET_STALENESS_THRESHOLD && + !skipSlotCheck ) { console.log(`Killing process due to same slot for market ${marketName} after > ${MAKRET_STALENESS_THRESHOLD}ms: dlobProvider slot: ${slot} @@ -329,48 +340,6 @@ export class DLOBSubscriberIO extends DLOBSubscriber { marketArgs.marketIndex ); - // Check if slot diffs are too large for oracle - if ( - Math.abs(slot - parseInt(l3['oracleData']['slot'])) > - this.killSwitchSlotDiffThreshold - ) { - console.log(`Killing process due to slot diffs for market ${marketName}: - dlobProvider slot: ${slot} - oracle slot: ${l3['oracleData']['slot']} - `); - process.exit(1); - } - - // Check if times and slots are too different for market - const MAKRET_STALENESS_THRESHOLD = - marketType === 'perp' - ? PERP_MAKRET_STALENESS_THRESHOLD - : SPOT_MAKRET_STALENESS_THRESHOLD; - if ( - lastMarketSlotAndTime && - l3['marketSlot'] === lastMarketSlotAndTime.slot && - Date.now() - lastMarketSlotAndTime.ts > MAKRET_STALENESS_THRESHOLD - ) { - console.log(`Killing process due to same slot for market ${marketName} after > ${MAKRET_STALENESS_THRESHOLD}ms: - dlobProvider slot: ${slot} - market slot: ${l3['marketSlot']} - `); - process.exit(1); - } else if ( - lastMarketSlotAndTime && - l3['marketSlot'] !== lastMarketSlotAndTime.slot - ) { - console.log( - `Updating market slot for ${marketArgs.marketName} with slot ${l3['marketSlot']}` - ); - this.lastMarketSlotMap - .get(marketArgs.marketType) - .set(marketArgs.marketIndex, { - slot: l3['marketSlot'], - ts: Date.now(), - }); - } - this.redisClient.client.set( `last_update_orderbook_l3_${marketType}_${marketArgs.marketIndex}`, JSON.stringify(l3) diff --git a/src/index.ts b/src/index.ts index 8e3768e..634a10c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -276,7 +276,7 @@ const main = async (): Promise => { commitment: stateCommitment, }; slotSubscriber = new SlotSubscriber(connection, { - resubTimeoutMs: 5000 + resubTimeoutMs: 5000, }); await slotSubscriber.subscribe(); }