Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

oracle kill switch #80

Merged
merged 10 commits into from
Jan 23, 2024
16 changes: 16 additions & 0 deletions src/dlob-subscriber/DLOBSubscriberIO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,21 @@ export class DLOBSubscriberIO extends DLOBSubscriber {
public marketL2Args: wsMarketL2Args[] = [];
public lastSeenL2Formatted: Map<MarketType, Map<number, any>>;
redisClient: RedisClient;
public killSwitchSlotDiffThreshold: number;

constructor(
config: DLOBSubscriptionConfig & {
redisClient: RedisClient;
perpMarketInfos: wsMarketInfo[];
spotMarketInfos: wsMarketInfo[];
spotMarketSubscribers: SubscriberLookup;
killSwitchSlotDiffThreshold?: number;
}
) {
super(config);
this.redisClient = config.redisClient;
this.killSwitchSlotDiffThreshold =
config.killSwitchSlotDiffThreshold || 200;

// Set up appropriate maps
this.lastSeenL2Formatted = new Map();
Expand Down Expand Up @@ -139,6 +143,18 @@ export class DLOBSubscriberIO extends DLOBSubscriber {
l2Args.marketIndex
);

if (
Math.abs(slot - parseInt(l2Formatted['oracleData']['slot'])) >
this.killSwitchSlotDiffThreshold
) {
console.log(`Killing process due to slot diffs for market ${marketName}:
dlobProvider slot: ${slot}
oracle slot: ${l2Formatted['oracleData']['slot']}
market slot: ${l2Formatted['marketSlot']}
`);
process.exit(1);
}

const l2Formatted_depth100 = Object.assign({}, l2Formatted, {
bids: l2Formatted.bids.slice(0, 100),
asks: l2Formatted.asks.slice(0, 100),
Expand Down
4 changes: 4 additions & 0 deletions src/publishers/dlobPublisher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ const ORDERBOOK_UPDATE_INTERVAL =
parseInt(process.env.ORDERBOOK_UPDATE_INTERVAL) || 1000;
const WS_FALLBACK_FETCH_INTERVAL = 10_000;

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 =
process.env.PERP_MARKETS_TO_LOAD !== undefined
Expand Down Expand Up @@ -395,6 +398,7 @@ const main = async () => {
spotMarketSubscribers: MARKET_SUBSCRIBERS,
perpMarketInfos,
spotMarketInfos,
killSwitchSlotDiffThreshold: KILLSWITCH_SLOT_DIFF_THRESHOLD,
});
await dlobSubscriber.subscribe();
if (useWebsocket && !FEATURE_FLAGS.DISABLE_GPA_REFRESH) {
Expand Down
Loading