From 7f93c5da7af25ea49afb868839f30b4513cfce2e Mon Sep 17 00:00:00 2001 From: Steven Luscher Date: Tue, 8 Oct 2024 14:29:46 +0000 Subject: [PATCH] Fetch the next slot by watching the trailing edge (completed) instead of the leading edge (firstShredReceived) --- utils/slot.mjs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/utils/slot.mjs b/utils/slot.mjs index a0a9ffc..0eca7f0 100644 --- a/utils/slot.mjs +++ b/utils/slot.mjs @@ -17,10 +17,19 @@ let nextSlotPromise; .slotsUpdatesNotifications() .subscribe({ abortSignal: AbortSignal.any([]) }); for await (const { slot, type } of slotNotifications) { - if (type === "firstShredReceived") { + let nextSlot; + switch (type) { + case 'completed': + nextSlot = slot + 1n; + break; + case 'firstShredReceived': + nextSlot = slot; + break + } + if (nextSlot != null) { attempts = 0; if (resolveSlotPromise) { - resolveSlotPromise(slot); + resolveSlotPromise(nextSlot); } resolveSlotPromise = undefined; nextSlotPromise = undefined; @@ -28,7 +37,7 @@ let nextSlotPromise; } if (++attempts >= MAX_SLOT_FETCH_ATTEMPTS) { console.log( - `ERROR: Max attempts for fetching slot type "firstShredReceived" reached, exiting` + `ERROR: Max attempts for fetching slot type "completed" or "firstShredReceived" reached, exiting` ); process.exit(0); }