Skip to content

chore: move epoch and current slot tracking to web worker#347

Open
asuzuki-jumptrading wants to merge 2 commits into
mainfrom
asuzuki/epoch-webworker
Open

chore: move epoch and current slot tracking to web worker#347
asuzuki-jumptrading wants to merge 2 commits into
mainfrom
asuzuki/epoch-webworker

Conversation

@asuzuki-jumptrading

Copy link
Copy Markdown
Collaborator
  • This is to prepare to move the skipped cluster slots to the web worker

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Moves epoch detection (currentEpoch / nextEpoch) and currentSlot progression logic out of the main thread Jotai atoms layer and into the WebSocket web worker, in preparation for moving additional slot-related processing (e.g., skipped cluster slots) into the worker.

Changes:

  • Replaced main-thread epoch derivation / caching with worker-side epochCache that computes and publishes currentSlot + {currentEpoch,nextEpoch} to the UI.
  • Extended worker→UI message protocol to include currentSlot and epochData messages.
  • Updated main-thread WS data plumbing to consume the new worker messages and stop processing epoch:new events in useUpdateAtoms.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/atoms.ts Removes epoch list/derivation logic; makes epochAtom/nextEpochAtom worker-fed primitives; stops advancing currentSlot from setSlotStatusAtom.
src/api/worker/types.ts Adds FromWorkerMessage variants for currentSlot and epochData (carrying Epoch types).
src/api/worker/messageHandler.ts Adds epochCache and feeds it with epoch:new and qualifying slot updates; posts new worker messages.
src/api/worker/cache/epochCache.ts New worker-side cache responsible for tracking currentSlot and resolving current/next epoch.
src/api/useSetAtomWsData.ts Consumes currentSlot/epochData worker messages to set atoms; stops handling epoch topic in main-thread update switch.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/api/worker/cache/epochCache.ts Outdated
Comment thread src/api/worker/cache/epochCache.ts
@asuzuki-jumptrading asuzuki-jumptrading force-pushed the asuzuki/epoch-webworker branch from f10ed12 to 86a7974 Compare June 3, 2026 22:29
Comment thread src/atoms.ts
set(_currentSlotAtom, (prev) => Math.max(slot, prev ?? 0));
},
);
return atom(

@asuzuki-jumptrading asuzuki-jumptrading Jun 3, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR corrects the nextLeaderSlot update to only get called with the new max current slot (instead of for all set current slot calls).

This comment was marked as outdated.

This comment was marked as outdated.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Comment thread src/api/worker/wsWorker.ts
Comment thread src/api/worker/wsWorker.ts Outdated
@asuzuki-jumptrading asuzuki-jumptrading force-pushed the asuzuki/epoch-webworker branch from e36b12d to 49c0d35 Compare June 3, 2026 23:41
@asuzuki-jumptrading asuzuki-jumptrading marked this pull request as ready for review June 3, 2026 23:43
historyWindowMs: overviewRenderWindowMs + overviewHistoryBufferMs,
};

function isEntry<

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved to types.ts

Comment thread src/api/worker/cache/epochCache.ts Outdated
Comment thread src/api/worker/messageHandler.ts Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants