fix(dkg): make dkg session field access uniformly mutex safe#860
Open
0xHansLee wants to merge 1 commit into
Open
fix(dkg): make dkg session field access uniformly mutex safe#8600xHansLee wants to merge 1 commit into
0xHansLee wants to merge 1 commit into
Conversation
DKGSession.mu guarded only a subset of fields; many others were read and written as raw fields across goroutines, racing the decrypt worker and the recovery/finalization paths and risking a torn slice-header read. - Add Snapshot() and marshal a locked deep copy in saveSession, closing the marshal-vs-mutation race for every field at once. - Route the concurrency-exposed reads (decrypt worker, finalize contract call, ResumeDKGService) through RLock getters that return byte-slice copies; add SetIndex/SetFinalized locked setters and convert the matching raw writes. - recover()-wrap the async DKG-service goroutines spawned from resumeFailedSession, mirroring the decrypt worker's guard. Node-local only (StateManager JSON/in-memory, gated by isDKGSvcEnabled with a gasless context); no KVStore, consensus, or app-hash impact.
0xHansLee
requested review from
jdubpark,
lucas2brh and
stevemilk
as code owners
July 24, 2026 05:57
stevemilk
approved these changes
Jul 24, 2026
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
DKGSessioncarries async.RWMutex, but many of its fields were read and written raw across the keeper. The session pointer is shared between the ABCI thread, the async DKG goroutines, and the decrypt worker, so raw access races — most sharplysaveSessionmarshaling the live pointer while another goroutine mutates it, which can tear a slice header and panic the validator.Fix
DKGSessionfield access through mutex-protected accessors: getters clone slices, and grouped setters (SetSetupResult,SetCodeCommitmentIfEmpty) write related fields atomically under one lock.saveSessionmarshals aSnapshot()deep copy taken under RLock instead of the live pointer.Test coverage
go test -race -coverpkg=./client/x/dkg/... ./client/x/dkg/...DKGSessionaccessors (getters,HasSetupData,SetSetupResult,SetCodeCommitmentIfEmpty,Snapshot)keeperpackageissue: #859