fix(dkg): prune dkg sessions older than the retention window#858
Merged
Conversation
0xHansLee
requested review from
jdubpark,
lucas2brh and
stevemilk
as code owners
July 21, 2026 05:19
|
Two things. The commit message says the window keeps "the previous |
DKG sessions were created per round but never deleted in production, so session_*.json files and the in-memory sessions map grew unbounded and processDecryptQueue scanned every session each tick. Replace the dead, phase-based CleanupExpiredSessions with a round-based PruneOldSessions that reuses DeleteSession to remove both the in-memory entry and the disk file, and call it when a round activates in handleDKGComplete. Retention keeps the active round plus the previous sessionRetentionRounds (10) rounds, a generous margin above the decrypt path's 2-round window. Node-local state only; the round-based criterion keeps it deterministic.
A crash between saveSession's write and rename leaves an orphaned session_<round>.json.tmp behind. loadSessions globs only the non-tmp name and DeleteSession/PruneOldSessions never target the .tmp, so these partial writes linger on disk indefinitely. Sweep orphaned .tmp files during loadSessions (startup, before the node serves requests, so no concurrent writer). Also defensively remove a stray .tmp for the round in DeleteSession.
0xHansLee
force-pushed
the
fix-prune-old-dkg-sessions
branch
from
July 22, 2026 08:52
9ea9f58 to
bd69818
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Local DKG sessions (the in-memory map and on-disk
session_*.jsonfiles) were never pruned and grew unbounded. The existingCleanupExpiredSessionswas dead code and would have deleted the active completed session.Fix
Add
PruneOldSessions, wired into round activation, deleting sessions for rounds older thanactiveRound - sessionRetentionRounds(= 10). Node-local only (noKVStore/consensus access); the round-based criterion is deterministic with no wall-clock dependence. Retention of 10 rounds comfortably exceeds the decrypt path's 2-round lookback.Tests
TestStateManager_PruneOldSessions,_RetainedRoundStillUsable,_NoopBelowHorizonissue: none