From 2ca9707fc0e8876436b550b31f63e1e21d145595 Mon Sep 17 00:00:00 2001 From: Chris Heaney Date: Mon, 20 Nov 2023 17:43:50 -0500 Subject: [PATCH 1/3] make user stats polling time 0 --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 6b16267..820a5bb 100644 --- a/src/index.ts +++ b/src/index.ts @@ -217,7 +217,7 @@ const main = async () => { accountLoader: new BulkAccountLoader( connection, stateCommitment, - ORDERBOOK_UPDATE_INTERVAL * 10 + 0 ), }); await userStatsMap.subscribe(); From b4bdbd617f7654afcdf5becea4478448b3a486f4 Mon Sep 17 00:00:00 2001 From: Chris Heaney Date: Mon, 20 Nov 2023 18:01:28 -0500 Subject: [PATCH 2/3] use bulk account loader for most recent slot --- src/index.ts | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/index.ts b/src/index.ts index 820a5bb..f8a2baf 100644 --- a/src/index.ts +++ b/src/index.ts @@ -184,7 +184,6 @@ const main = async () => { }); const dlobCoder = DLOBOrdersCoder.create(); - const slotSubscriber = new SlotSubscriber(connection, {}); const lamportsBalance = await connection.getBalance(wallet.publicKey); logger.info( @@ -199,12 +198,15 @@ const main = async () => { logger.error(e); }); - await slotSubscriber.subscribe(); - slotSubscriber.eventEmitter.on('newSlot', async (slot: number) => { + setInterval(async () => { + if (lastSlotReceivedMutex.isLocked()) { + return; + } + await lastSlotReceivedMutex.runExclusive(async () => { - lastSlotReceived = slot; + lastSlotReceived = bulkAccountLoader.getSlot(); }); - }); + }, ORDERBOOK_UPDATE_INTERVAL); const userMap = new UserMap( driftClient, @@ -225,7 +227,7 @@ const main = async () => { const dlobSubscriber = new DLOBSubscriber({ driftClient, dlobSource: userMap, - slotSource: slotSubscriber, + slotSource: bulkAccountLoader, updateFrequency: ORDERBOOK_UPDATE_INTERVAL, }); await dlobSubscriber.subscribe(); @@ -255,7 +257,7 @@ const main = async () => { // object with userAccount key and orders object serialized const orders: Array = []; const oracles: Array = []; - const slot = slotSubscriber.currentSlot; + const slot = bulkAccountLoader.getSlot(); for (const market of driftClient.getPerpMarketAccounts()) { const oracle = driftClient.getOracleDataForPerpMarket( @@ -299,7 +301,7 @@ const main = async () => { app.get('/orders/json', async (_req, res, next) => { try { // object with userAccount key and orders object serialized - const slot = slotSubscriber.currentSlot; + const slot = bulkAccountLoader.getSlot(); const orders: Array = []; const oracles: Array = []; for (const market of driftClient.getPerpMarketAccounts()) { @@ -462,7 +464,7 @@ const main = async () => { res.end( JSON.stringify({ - slot: slotSubscriber.currentSlot, + slot: bulkAccountLoader.getSlot(), data: dlobCoder.encode(dlobOrders).toString('base64'), }) ); @@ -551,7 +553,7 @@ const main = async () => { .getDLOB() .getRestingLimitBids( normedMarketIndex, - slotSubscriber.getSlot(), + bulkAccountLoader.getSlot(), normedMarketType, oracle ) @@ -562,7 +564,7 @@ const main = async () => { .getDLOB() .getRestingLimitAsks( normedMarketIndex, - slotSubscriber.getSlot(), + bulkAccountLoader.getSlot(), normedMarketType, oracle ) From e7bd57ad8cd50b19bd242ad5a81838e0cc8af845 Mon Sep 17 00:00:00 2001 From: Chris Heaney Date: Mon, 20 Nov 2023 18:47:11 -0500 Subject: [PATCH 3/3] tweak updates for lastSlotReceivedMutex --- src/index.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/index.ts b/src/index.ts index f8a2baf..8ff170f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -199,10 +199,6 @@ const main = async () => { }); setInterval(async () => { - if (lastSlotReceivedMutex.isLocked()) { - return; - } - await lastSlotReceivedMutex.runExclusive(async () => { lastSlotReceived = bulkAccountLoader.getSlot(); });