Skip to content

Commit

Permalink
Fetch the next slot by watching the trailing edge (completed) instead…
Browse files Browse the repository at this point in the history
… of the leading edge (firstShredReceived)
  • Loading branch information
steveluscher committed Oct 12, 2024
1 parent c4b18e1 commit 7f93c5d
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions utils/slot.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,27 @@ 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;
continue;
}
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);
}
Expand Down

0 comments on commit 7f93c5d

Please sign in to comment.