From b9192e543e4e5e30f5ad93ff0fb8668d756df8fa Mon Sep 17 00:00:00 2001 From: Nour Alharithi Date: Tue, 26 Dec 2023 10:52:16 -0800 Subject: [PATCH 1/6] unfinished commit --- src/index.ts | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/src/index.ts b/src/index.ts index aa7fc59..9b1bc2b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -56,9 +56,24 @@ import { RedisClient } from './utils/redisClient'; require('dotenv').config(); -const REDIS_HOST = process.env.REDIS_HOST || 'localhost'; -const REDIS_PORT = process.env.REDIS_PORT || '6379'; -const REDIS_PASSWORD = process.env.REDIS_PASSWORD; +// Reading in Redis env vars +const REDIS_HOSTS_ENV = process.env.REDIS_HOSTS as string || 'localhost'; +const REDIS_HOSTS = REDIS_HOSTS_ENV.includes(',') + ? REDIS_HOSTS_ENV.trim() + .replace(/^\[|\]$/g, '') + .split(/\s*,\s*/) + : [REDIS_HOSTS_ENV]; + +const REDIS_PASSWORDS_ENV = process.env.REDIS_HOSTS as string; +const REDIS_PASSWORDS = REDIS_PASSWORDS_ENV.includes(',') + ? REDIS_PASSWORDS_ENV.trim() + .replace(/^\[|\]$/g, '') + .split(/\s*,\s*/) + : [REDIS_PASSWORDS_ENV]; +if (REDIS_HOSTS.length !== REDIS_PASSWORDS.length) { + throw('REDIS_HOSTS and REDIS_PASSWORDS must be the same length'); +} +const REDIS_PORT = '6379'; const driftEnv = (process.env.ENV || 'devnet') as DriftEnv; const commitHash = process.env.COMMIT; @@ -321,10 +336,17 @@ const main = async () => { ); let redisClient: RedisClient; + const redisClients: Array = []; + let redisClientMap: if (useRedis) { logger.info('Connecting to redis'); - redisClient = new RedisClient(REDIS_HOST, REDIS_PORT, REDIS_PASSWORD); - await redisClient.connect(); + for (let i = 0; i < REDIS_HOSTS.length; i++) { + redisClients.push( + new RedisClient(REDIS_HOSTS[i], REDIS_PORT, REDIS_PASSWORDS[i]) + ); + await redisClients[i].connect(); + } + redisClient = redisClients[0]; } logger.info(`Initializing all market subscribers...`); From 3ffb6e7330f3ccb9306a29af269817c413bf1949 Mon Sep 17 00:00:00 2001 From: Nour Alharithi Date: Tue, 26 Dec 2023 13:07:40 -0800 Subject: [PATCH 2/6] rotate redis connecitons --- src/index.ts | 132 +++++++++++++++++++++++++++++++++++++++----- src/serverLite.ts | 138 ++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 245 insertions(+), 25 deletions(-) diff --git a/src/index.ts b/src/index.ts index 9b1bc2b..a6737ea 100644 --- a/src/index.ts +++ b/src/index.ts @@ -57,23 +57,32 @@ import { RedisClient } from './utils/redisClient'; require('dotenv').config(); // Reading in Redis env vars -const REDIS_HOSTS_ENV = process.env.REDIS_HOSTS as string || 'localhost'; +const REDIS_HOSTS_ENV = (process.env.REDIS_HOSTS as string) || 'localhost'; const REDIS_HOSTS = REDIS_HOSTS_ENV.includes(',') ? REDIS_HOSTS_ENV.trim() .replace(/^\[|\]$/g, '') .split(/\s*,\s*/) : [REDIS_HOSTS_ENV]; -const REDIS_PASSWORDS_ENV = process.env.REDIS_HOSTS as string; +const REDIS_PASSWORDS_ENV = (process.env.REDIS_PASSWORDS as string) || ''; const REDIS_PASSWORDS = REDIS_PASSWORDS_ENV.includes(',') ? REDIS_PASSWORDS_ENV.trim() .replace(/^\[|\]$/g, '') .split(/\s*,\s*/) : [REDIS_PASSWORDS_ENV]; -if (REDIS_HOSTS.length !== REDIS_PASSWORDS.length) { - throw('REDIS_HOSTS and REDIS_PASSWORDS must be the same length'); + +const REDIS_PORTS_ENV = (process.env.REDIS_PORTS as string) || '6379'; +const REDIS_PORTS = REDIS_PORTS_ENV.includes(',') + ? REDIS_PORTS_ENV.trim() + .replace(/^\[|\]$/g, '') + .split(/\s*,\s*/) + : [REDIS_PORTS_ENV]; +if ( + REDIS_PORTS.length !== REDIS_PASSWORDS.length || + REDIS_PORTS.length !== REDIS_HOSTS.length +) { + throw 'REDIS_HOSTS and REDIS_PASSWORDS and REDIS_PORTS must be the same length'; } -const REDIS_PORT = '6379'; const driftEnv = (process.env.ENV || 'devnet') as DriftEnv; const commitHash = process.env.COMMIT; @@ -84,6 +93,8 @@ const stateCommitment: Commitment = 'processed'; const serverPort = process.env.PORT || 6969; export const ORDERBOOK_UPDATE_INTERVAL = 1000; const WS_FALLBACK_FETCH_INTERVAL = ORDERBOOK_UPDATE_INTERVAL * 10; +const SLOT_STALENESS_TOLERANCE = + parseInt(process.env.SLOT_STALENESS_TOLERANCE) || 20; const useWebsocket = process.env.USE_WEBSOCKET?.toLowerCase() === 'true'; const rateLimitCallsPerSecond = process.env.RATE_LIMIT_CALLS_PER_SECOND ? parseInt(process.env.RATE_LIMIT_CALLS_PER_SECOND) @@ -335,18 +346,39 @@ const main = async () => { `DLOBSubscriber initialized in ${Date.now() - initDlobSubscriberStart} ms` ); - let redisClient: RedisClient; const redisClients: Array = []; - let redisClientMap: + const spotMarketRedisMap: Map< + number, + { client: RedisClient; clientIndex: number } + > = new Map(); + const perpMarketRedisMap: Map< + number, + { client: RedisClient; clientIndex: number } + > = new Map(); if (useRedis) { logger.info('Connecting to redis'); for (let i = 0; i < REDIS_HOSTS.length; i++) { redisClients.push( - new RedisClient(REDIS_HOSTS[i], REDIS_PORT, REDIS_PASSWORDS[i]) + new RedisClient( + REDIS_HOSTS[i], + REDIS_PORTS[i], + REDIS_PASSWORDS[i] || undefined + ) ); await redisClients[i].connect(); } - redisClient = redisClients[0]; + for (let i = 0; i < sdkConfig.SPOT_MARKETS.length; i++) { + spotMarketRedisMap.set(sdkConfig.SPOT_MARKETS[i].marketIndex, { + client: redisClients[0], + clientIndex: 0, + }); + } + for (let i = 0; i < sdkConfig.PERP_MARKETS.length; i++) { + perpMarketRedisMap.set(sdkConfig.PERP_MARKETS[i].marketIndex, { + client: redisClients[0], + clientIndex: 0, + }); + } } logger.info(`Initializing all market subscribers...`); @@ -757,6 +789,7 @@ const main = async () => { !grouping ) { let redisL2: string; + const redisClient = perpMarketRedisMap.get(normedMarketIndex).client; if (parseInt(adjustedDepth as string) === 5) { redisL2 = await redisClient.client.get( `last_update_orderbook_perp_${normedMarketIndex}_depth_5` @@ -772,9 +805,22 @@ const main = async () => { } if ( redisL2 && - dlobProvider.getSlot() - parseInt(JSON.parse(redisL2).slot) < 10 - ) + dlobProvider.getSlot() - parseInt(JSON.parse(redisL2).slot) < + SLOT_STALENESS_TOLERANCE + ) { l2Formatted = redisL2; + } else { + if (redisL2 && redisClients.length > 1) { + const nextClientIndex = + (perpMarketRedisMap.get(normedMarketIndex).clientIndex + 1) % + redisClients.length; + perpMarketRedisMap.set(normedMarketIndex, { + client: redisClients[nextClientIndex], + clientIndex: nextClientIndex, + }); + console.log('Rotated redis client to index ', nextClientIndex); + } + } } else if ( isSpot && `${includeSerum}`?.toLowerCase() === 'true' && @@ -783,6 +829,7 @@ const main = async () => { !grouping ) { let redisL2: string; + const redisClient = spotMarketRedisMap.get(normedMarketIndex).client; if (parseInt(adjustedDepth as string) === 5) { redisL2 = await redisClient.client.get( `last_update_orderbook_spot_${normedMarketIndex}_depth_5` @@ -798,9 +845,22 @@ const main = async () => { } if ( redisL2 && - dlobProvider.getSlot() - parseInt(JSON.parse(redisL2).slot) < 10 - ) + dlobProvider.getSlot() - parseInt(JSON.parse(redisL2).slot) < + SLOT_STALENESS_TOLERANCE + ) { l2Formatted = redisL2; + } else { + if (redisL2 && redisClients.length > 1) { + const nextClientIndex = + (spotMarketRedisMap.get(normedMarketIndex).clientIndex + 1) % + redisClients.length; + spotMarketRedisMap.set(normedMarketIndex, { + client: redisClients[nextClientIndex], + clientIndex: nextClientIndex, + }); + console.log('Rotated redis client to index ', nextClientIndex); + } + } } if (l2Formatted) { @@ -939,6 +999,8 @@ const main = async () => { !normedParam['grouping'] ) { let redisL2: string; + const redisClient = + perpMarketRedisMap.get(normedMarketIndex).client; if (parseInt(adjustedDepth as string) === 5) { redisL2 = await redisClient.client.get( `last_update_orderbook_perp_${normedMarketIndex}_depth_5` @@ -954,8 +1016,27 @@ const main = async () => { } if (redisL2) { const parsedRedisL2 = JSON.parse(redisL2); - if (dlobProvider.getSlot() - parseInt(parsedRedisL2.slot) < 10) + if ( + dlobProvider.getSlot() - parseInt(parsedRedisL2.slot) < + SLOT_STALENESS_TOLERANCE + ) { l2Formatted = parsedRedisL2; + } else { + if (redisClients.length > 1) { + const nextClientIndex = + (perpMarketRedisMap.get(normedMarketIndex).clientIndex + + 1) % + redisClients.length; + perpMarketRedisMap.set(normedMarketIndex, { + client: redisClients[nextClientIndex], + clientIndex: nextClientIndex, + }); + console.log( + 'Rotated redis client to index ', + nextClientIndex + ); + } + } } } else if ( isSpot && @@ -964,6 +1045,8 @@ const main = async () => { !normedParam['grouping'] ) { let redisL2: string; + const redisClient = + spotMarketRedisMap.get(normedMarketIndex).client; if (parseInt(adjustedDepth as string) === 5) { redisL2 = await redisClient.client.get( `last_update_orderbook_spot_${normedMarketIndex}_depth_5` @@ -979,8 +1062,27 @@ const main = async () => { } if (redisL2) { const parsedRedisL2 = JSON.parse(redisL2); - if (dlobProvider.getSlot() - parseInt(parsedRedisL2.slot) < 10) + if ( + dlobProvider.getSlot() - parseInt(parsedRedisL2.slot) < + SLOT_STALENESS_TOLERANCE + ) { l2Formatted = parsedRedisL2; + } else { + if (redisClients.length > 1) { + const nextClientIndex = + (spotMarketRedisMap.get(normedMarketIndex).clientIndex + + 1) % + redisClients.length; + spotMarketRedisMap.set(normedMarketIndex, { + client: redisClients[nextClientIndex], + clientIndex: nextClientIndex, + }); + console.log( + 'Rotated redis client to index ', + nextClientIndex + ); + } + } } } diff --git a/src/serverLite.ts b/src/serverLite.ts index 187b8ed..aeea93d 100644 --- a/src/serverLite.ts +++ b/src/serverLite.ts @@ -30,9 +30,33 @@ import { require('dotenv').config(); -const REDIS_HOST = process.env.REDIS_HOST || 'localhost'; -const REDIS_PORT = process.env.REDIS_PORT || '6379'; -const REDIS_PASSWORD = process.env.REDIS_PASSWORD; +// Reading in Redis env vars +const REDIS_HOSTS_ENV = (process.env.REDIS_HOSTS as string) || 'localhost'; +const REDIS_HOSTS = REDIS_HOSTS_ENV.includes(',') + ? REDIS_HOSTS_ENV.trim() + .replace(/^\[|\]$/g, '') + .split(/\s*,\s*/) + : [REDIS_HOSTS_ENV]; + +const REDIS_PASSWORDS_ENV = (process.env.REDIS_PASSWORDS as string) || ''; +const REDIS_PASSWORDS = REDIS_PASSWORDS_ENV.includes(',') + ? REDIS_PASSWORDS_ENV.trim() + .replace(/^\[|\]$/g, '') + .split(/\s*,\s*/) + : [REDIS_PASSWORDS_ENV]; + +const REDIS_PORTS_ENV = (process.env.REDIS_PORTS as string) || '6379'; +const REDIS_PORTS = REDIS_PORTS_ENV.includes(',') + ? REDIS_PORTS_ENV.trim() + .replace(/^\[|\]$/g, '') + .split(/\s*,\s*/) + : [REDIS_PORTS_ENV]; +if ( + REDIS_PORTS.length !== REDIS_PASSWORDS.length || + REDIS_PORTS.length !== REDIS_HOSTS.length +) { + throw 'REDIS_HOSTS and REDIS_PASSWORDS and REDIS_PORTS must be the same length'; +} const driftEnv = (process.env.ENV || 'devnet') as DriftEnv; const commitHash = process.env.COMMIT; @@ -132,10 +156,38 @@ logger.info(`Commit: ${commitHash}`); const main = async () => { // Redis connect - logger.info('Connecting to redis'); - const redisClient = new RedisClient(REDIS_HOST, REDIS_PORT, REDIS_PASSWORD); - await redisClient.connect(); - + const redisClients: Array = []; + const spotMarketRedisMap: Map< + number, + { client: RedisClient; clientIndex: number } + > = new Map(); + const perpMarketRedisMap: Map< + number, + { client: RedisClient; clientIndex: number } + > = new Map(); + for (let i = 0; i < REDIS_HOSTS.length; i++) { + redisClients.push( + new RedisClient( + REDIS_HOSTS[i], + REDIS_PORTS[i], + REDIS_PASSWORDS[i] || undefined + ) + ); + await redisClients[i].connect(); + } + for (let i = 0; i < sdkConfig.SPOT_MARKETS.length; i++) { + spotMarketRedisMap.set(sdkConfig.SPOT_MARKETS[i].marketIndex, { + client: redisClients[0], + clientIndex: 0, + }); + } + for (let i = 0; i < sdkConfig.PERP_MARKETS.length; i++) { + perpMarketRedisMap.set(sdkConfig.PERP_MARKETS[i].marketIndex, { + client: redisClients[0], + clientIndex: 0, + }); + } + // Slot subscriber for source const connection = new Connection(endpoint, { commitment: stateCommitment, @@ -154,7 +206,13 @@ const main = async () => { ); const handleStartup = async (_req, res, _next) => { - if (redisClient.connected) { + let healthy= false; + for (const redisClient of redisClients) { + if (redisClient.connected) { + healthy = true; + } + } + if (healthy) { res.writeHead(200); res.end('OK'); } else { @@ -205,6 +263,7 @@ const main = async () => { !grouping ) { let redisL2: string; + const redisClient = perpMarketRedisMap.get(normedMarketIndex).client; if (parseInt(adjustedDepth as string) === 5) { redisL2 = await redisClient.client.get( `last_update_orderbook_perp_${normedMarketIndex}_depth_5` @@ -223,6 +282,17 @@ const main = async () => { slotSubscriber.getSlot() - parseInt(JSON.parse(redisL2).slot); if (slotDiff < SLOT_STALENESS_TOLERANCE) { l2Formatted = redisL2; + } else { + if (redisClients.length > 1) { + const nextClientIndex = + (perpMarketRedisMap.get(normedMarketIndex).clientIndex + 1) % + redisClients.length; + perpMarketRedisMap.set(normedMarketIndex, { + client: redisClients[nextClientIndex], + clientIndex: nextClientIndex, + }); + console.log('Rotated redis client to index ', nextClientIndex); + } } } } else if ( @@ -233,6 +303,7 @@ const main = async () => { !grouping ) { let redisL2: string; + const redisClient = spotMarketRedisMap.get(normedMarketIndex).client; if (parseInt(adjustedDepth as string) === 5) { redisL2 = await redisClient.client.get( `last_update_orderbook_spot_${normedMarketIndex}_depth_5` @@ -251,6 +322,17 @@ const main = async () => { slotSubscriber.getSlot() - parseInt(JSON.parse(redisL2).slot); if (slotDiff < SLOT_STALENESS_TOLERANCE) { l2Formatted = redisL2; + } else { + if (redisClients.length > 1) { + const nextClientIndex = + (spotMarketRedisMap.get(normedMarketIndex).clientIndex + 1) % + redisClients.length; + spotMarketRedisMap.set(normedMarketIndex, { + client: redisClients[nextClientIndex], + clientIndex: nextClientIndex, + }); + console.log('Rotated redis client to index ', nextClientIndex); + } } } } @@ -341,6 +423,8 @@ const main = async () => { !normedParam['grouping'] ) { let redisL2: string; + const redisClient = + perpMarketRedisMap.get(normedMarketIndex).client; if (parseInt(adjustedDepth as string) === 5) { redisL2 = await redisClient.client.get( `last_update_orderbook_perp_${normedMarketIndex}_depth_5` @@ -359,8 +443,24 @@ const main = async () => { if ( slotSubscriber.getSlot() - parseInt(parsedRedisL2.slot) < SLOT_STALENESS_TOLERANCE - ) + ) { l2Formatted = parsedRedisL2; + } else { + if (redisClients.length > 1) { + const nextClientIndex = + (perpMarketRedisMap.get(normedMarketIndex).clientIndex + + 1) % + redisClients.length; + perpMarketRedisMap.set(normedMarketIndex, { + client: redisClients[nextClientIndex], + clientIndex: nextClientIndex, + }); + console.log( + 'Rotated redis client to index ', + nextClientIndex + ); + } + } } } else if ( isSpot && @@ -369,6 +469,8 @@ const main = async () => { !normedParam['grouping'] ) { let redisL2: string; + const redisClient = + spotMarketRedisMap.get(normedMarketIndex).client; if (parseInt(adjustedDepth as string) === 5) { redisL2 = await redisClient.client.get( `last_update_orderbook_spot_${normedMarketIndex}_depth_5` @@ -387,8 +489,24 @@ const main = async () => { if ( slotSubscriber.getSlot() - parseInt(parsedRedisL2.slot) < SLOT_STALENESS_TOLERANCE - ) + ) { l2Formatted = parsedRedisL2; + } else { + if (redisClients.length > 1) { + const nextClientIndex = + (spotMarketRedisMap.get(normedMarketIndex).clientIndex + + 1) % + redisClients.length; + spotMarketRedisMap.set(normedMarketIndex, { + client: redisClients[nextClientIndex], + clientIndex: nextClientIndex, + }); + console.log( + 'Rotated redis client to index ', + nextClientIndex + ); + } + } } if (l2Formatted) { From 4ac33bac9cd07ebb5d51fa2fc0bb31a44d332958 Mon Sep 17 00:00:00 2001 From: GitHub Actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 27 Dec 2023 21:10:36 +0000 Subject: [PATCH 3/6] Bumping sdk dependency to 2.53.0-beta.6 --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 7ae52d9..20ac12c 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "license": "Apache-2.0", "dependencies": { "@coral-xyz/anchor": "^0.29.0", - "@drift-labs/sdk": "2.53.0-beta.5", + "@drift-labs/sdk": "2.53.0-beta.6", "@opentelemetry/api": "^1.1.0", "@opentelemetry/auto-instrumentations-node": "^0.31.1", "@opentelemetry/exporter-prometheus": "^0.31.0", diff --git a/yarn.lock b/yarn.lock index 55b5cfd..4178302 100644 --- a/yarn.lock +++ b/yarn.lock @@ -115,10 +115,10 @@ enabled "2.0.x" kuler "^2.0.0" -"@drift-labs/sdk@2.53.0-beta.5": - version "2.53.0-beta.5" - resolved "https://registry.yarnpkg.com/@drift-labs/sdk/-/sdk-2.53.0-beta.5.tgz#2cbd77105e3248886a345cb07a67fd60407eae3a" - integrity sha512-EAW+eqSkAe490IblsC0/hFWeYFLU9wZ71yq1nw6Aemq0RC6ygsN/eaQiVMOO1v8MQ5ar/ef6n27FFHO4k5UOkg== +"@drift-labs/sdk@2.53.0-beta.6": + version "2.53.0-beta.6" + resolved "https://registry.yarnpkg.com/@drift-labs/sdk/-/sdk-2.53.0-beta.6.tgz#49cd6e26198edb1391e21bd9c567781dfcd440b6" + integrity sha512-WDJm1KkD5CTeYt3E1rllujnj5DAcJyaRmDzhyKGn7JnclCCOZ9LeUFZuvRFZvkr+YU+YtX/jIH3tAPmECHjQcQ== dependencies: "@coral-xyz/anchor" "0.28.1-beta.2" "@ellipsis-labs/phoenix-sdk" "^1.4.2" From 936422db5dbef182e60bba00a5a807d9e797dc1a Mon Sep 17 00:00:00 2001 From: GitHub Actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 27 Dec 2023 21:16:50 +0000 Subject: [PATCH 4/6] Bumping sdk dependency to 2.53.0-beta.7 --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 20ac12c..a59d309 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "license": "Apache-2.0", "dependencies": { "@coral-xyz/anchor": "^0.29.0", - "@drift-labs/sdk": "2.53.0-beta.6", + "@drift-labs/sdk": "2.53.0-beta.7", "@opentelemetry/api": "^1.1.0", "@opentelemetry/auto-instrumentations-node": "^0.31.1", "@opentelemetry/exporter-prometheus": "^0.31.0", diff --git a/yarn.lock b/yarn.lock index 4178302..c350cfc 100644 --- a/yarn.lock +++ b/yarn.lock @@ -115,10 +115,10 @@ enabled "2.0.x" kuler "^2.0.0" -"@drift-labs/sdk@2.53.0-beta.6": - version "2.53.0-beta.6" - resolved "https://registry.yarnpkg.com/@drift-labs/sdk/-/sdk-2.53.0-beta.6.tgz#49cd6e26198edb1391e21bd9c567781dfcd440b6" - integrity sha512-WDJm1KkD5CTeYt3E1rllujnj5DAcJyaRmDzhyKGn7JnclCCOZ9LeUFZuvRFZvkr+YU+YtX/jIH3tAPmECHjQcQ== +"@drift-labs/sdk@2.53.0-beta.7": + version "2.53.0-beta.7" + resolved "https://registry.yarnpkg.com/@drift-labs/sdk/-/sdk-2.53.0-beta.7.tgz#4d2da1af253344e6a71955601026f4e2f6114346" + integrity sha512-oBHkLs5gyuaTprGKmEG9TZ1Zxz01XElSgVkVZjGULWdZF2P9RR5/UeOlSwXrCpju9sTnu1r4suO4F+pM165urA== dependencies: "@coral-xyz/anchor" "0.28.1-beta.2" "@ellipsis-labs/phoenix-sdk" "^1.4.2" From 6a8fab67cc04e32a7d8d5ecd087a9006625d05a1 Mon Sep 17 00:00:00 2001 From: GitHub Actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 27 Dec 2023 21:21:11 +0000 Subject: [PATCH 5/6] Bumping sdk dependency to 2.53.0-beta.8 --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index a59d309..7697e4a 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "license": "Apache-2.0", "dependencies": { "@coral-xyz/anchor": "^0.29.0", - "@drift-labs/sdk": "2.53.0-beta.7", + "@drift-labs/sdk": "2.53.0-beta.8", "@opentelemetry/api": "^1.1.0", "@opentelemetry/auto-instrumentations-node": "^0.31.1", "@opentelemetry/exporter-prometheus": "^0.31.0", diff --git a/yarn.lock b/yarn.lock index c350cfc..cbb5f50 100644 --- a/yarn.lock +++ b/yarn.lock @@ -115,10 +115,10 @@ enabled "2.0.x" kuler "^2.0.0" -"@drift-labs/sdk@2.53.0-beta.7": - version "2.53.0-beta.7" - resolved "https://registry.yarnpkg.com/@drift-labs/sdk/-/sdk-2.53.0-beta.7.tgz#4d2da1af253344e6a71955601026f4e2f6114346" - integrity sha512-oBHkLs5gyuaTprGKmEG9TZ1Zxz01XElSgVkVZjGULWdZF2P9RR5/UeOlSwXrCpju9sTnu1r4suO4F+pM165urA== +"@drift-labs/sdk@2.53.0-beta.8": + version "2.53.0-beta.8" + resolved "https://registry.yarnpkg.com/@drift-labs/sdk/-/sdk-2.53.0-beta.8.tgz#bc12747a8f2c4fa26b979fa6a8202a3bd3f52b2b" + integrity sha512-R2OPzgWjEVrJMeSwXa/UiquM6c72iOnFdoHbXJ4JJPd/KJDvghjOIXshF+7ttf80Uwswrox0sEhCJOYcYZOMIQ== dependencies: "@coral-xyz/anchor" "0.28.1-beta.2" "@ellipsis-labs/phoenix-sdk" "^1.4.2" From 42f8ecea7d3ce5dca50cd4aa8607dbf7c1c9cab4 Mon Sep 17 00:00:00 2001 From: Nour Alharithi Date: Wed, 27 Dec 2023 18:22:41 -0800 Subject: [PATCH 6/6] small log changes --- src/index.ts | 14 ++++++++------ src/publishers/dlobPublisher.ts | 3 ++- src/serverLite.ts | 22 ++++++++++++---------- 3 files changed, 22 insertions(+), 17 deletions(-) diff --git a/src/index.ts b/src/index.ts index a6737ea..931aef3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -818,7 +818,9 @@ const main = async () => { client: redisClients[nextClientIndex], clientIndex: nextClientIndex, }); - console.log('Rotated redis client to index ', nextClientIndex); + console.log( + `Rotated redis client to index ${nextClientIndex} for perp market ${normedMarketIndex}` + ); } } } else if ( @@ -858,7 +860,9 @@ const main = async () => { client: redisClients[nextClientIndex], clientIndex: nextClientIndex, }); - console.log('Rotated redis client to index ', nextClientIndex); + console.log( + `Rotated redis client to index ${nextClientIndex} for spot market ${normedMarketIndex}` + ); } } } @@ -1032,8 +1036,7 @@ const main = async () => { clientIndex: nextClientIndex, }); console.log( - 'Rotated redis client to index ', - nextClientIndex + `Rotated redis client to index ${nextClientIndex} for perp market ${normedMarketIndex}` ); } } @@ -1078,8 +1081,7 @@ const main = async () => { clientIndex: nextClientIndex, }); console.log( - 'Rotated redis client to index ', - nextClientIndex + `Rotated redis client to index ${nextClientIndex} for spot market ${normedMarketIndex}` ); } } diff --git a/src/publishers/dlobPublisher.ts b/src/publishers/dlobPublisher.ts index f54e46b..10d9504 100644 --- a/src/publishers/dlobPublisher.ts +++ b/src/publishers/dlobPublisher.ts @@ -324,7 +324,8 @@ const main = async () => { const initAllMarketSubscribersStart = Date.now(); MARKET_SUBSCRIBERS = await initializeAllMarketSubscribers(driftClient); logger.info( - `All market subscribers initialized in ${Date.now() - initAllMarketSubscribersStart + `All market subscribers initialized in ${ + Date.now() - initAllMarketSubscribersStart } ms` ); diff --git a/src/serverLite.ts b/src/serverLite.ts index aeea93d..f607797 100644 --- a/src/serverLite.ts +++ b/src/serverLite.ts @@ -187,7 +187,7 @@ const main = async () => { clientIndex: 0, }); } - + // Slot subscriber for source const connection = new Connection(endpoint, { commitment: stateCommitment, @@ -206,7 +206,7 @@ const main = async () => { ); const handleStartup = async (_req, res, _next) => { - let healthy= false; + let healthy = false; for (const redisClient of redisClients) { if (redisClient.connected) { healthy = true; @@ -291,7 +291,9 @@ const main = async () => { client: redisClients[nextClientIndex], clientIndex: nextClientIndex, }); - console.log('Rotated redis client to index ', nextClientIndex); + console.log( + `Rotated redis client to index ${nextClientIndex} for perp market ${normedMarketIndex}` + ); } } } @@ -331,7 +333,9 @@ const main = async () => { client: redisClients[nextClientIndex], clientIndex: nextClientIndex, }); - console.log('Rotated redis client to index ', nextClientIndex); + console.log( + `Rotated redis client to index ${nextClientIndex} for spot market ${normedMarketIndex}` + ); } } } @@ -424,7 +428,7 @@ const main = async () => { ) { let redisL2: string; const redisClient = - perpMarketRedisMap.get(normedMarketIndex).client; + perpMarketRedisMap.get(normedMarketIndex).client; if (parseInt(adjustedDepth as string) === 5) { redisL2 = await redisClient.client.get( `last_update_orderbook_perp_${normedMarketIndex}_depth_5` @@ -456,8 +460,7 @@ const main = async () => { clientIndex: nextClientIndex, }); console.log( - 'Rotated redis client to index ', - nextClientIndex + `Rotated redis client to index ${nextClientIndex} for perp market ${normedMarketIndex}` ); } } @@ -470,7 +473,7 @@ const main = async () => { ) { let redisL2: string; const redisClient = - spotMarketRedisMap.get(normedMarketIndex).client; + spotMarketRedisMap.get(normedMarketIndex).client; if (parseInt(adjustedDepth as string) === 5) { redisL2 = await redisClient.client.get( `last_update_orderbook_spot_${normedMarketIndex}_depth_5` @@ -502,8 +505,7 @@ const main = async () => { clientIndex: nextClientIndex, }); console.log( - 'Rotated redis client to index ', - nextClientIndex + `Rotated redis client to index ${nextClientIndex} for spot market ${normedMarketIndex}` ); } }