Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Alexander Hentschel <alex.hentschel@flowfoundation.org>
  • Loading branch information
durkmurder and AlexHentschel authored Dec 10, 2024
1 parent 7053c88 commit 0687e30
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
9 changes: 5 additions & 4 deletions storage/badger/dkg_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,12 @@ func NewRecoverableRandomBeaconStateMachine(collector module.CacheMetrics, db *b
}, nil
}

// InsertMyBeaconPrivateKey stores the random beacon private key for an epoch.
// InsertMyBeaconPrivateKey stores the random beacon private key for an epoch and transitions the
// state machine into the [flow.DKGStateCompleted] state.
//
// CAUTION: these keys are stored before they are validated against the
// canonical key vector and may not be valid for use in signing. Use storage.SafeBeaconKeys interface
// to guarantee only keys safe for signing are returned.
// canonical key vector and may not be valid for use in signing. Use [storage.SafeBeaconKeys]
// interface to guarantee only keys safe for signing are returned.
// Error returns:
// - [storage.ErrAlreadyExists] - if there is already a key stored for given epoch.
// - [storage.InvalidDKGStateTransitionError] - if the requested state transition is invalid.
Expand Down Expand Up @@ -168,7 +169,7 @@ func (ds *RecoverablePrivateBeaconKeyStateMachine) processStateTransition(epochC
// - [storage.ErrNotFound] - if there is no state stored for given epoch, meaning the state machine is in initial state.
func (ds *RecoverablePrivateBeaconKeyStateMachine) GetDKGState(epochCounter uint64) (flow.DKGState, error) {
var currentState flow.DKGState
err := ds.db.Update(operation.RetrieveDKGStateForEpoch(epochCounter, &currentState))
err := ds.db.View(operation.RetrieveDKGStateForEpoch(epochCounter, &currentState))
return currentState, err
}

Expand Down
16 changes: 9 additions & 7 deletions storage/dkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type SafeBeaconKeys interface {
RetrieveMyBeaconPrivateKey(epochCounter uint64) (key crypto.PrivateKey, safe bool, err error)
}

// DKGStateReader is a read-only interface for reading state of the Random Beacon Recoverable State Machine.
// DKGStateReader is a read-only interface for low-level reading of the Random Beacon Recoverable State Machine.
type DKGStateReader interface {
SafeBeaconKeys

Expand All @@ -48,10 +48,11 @@ type DKGStateReader interface {
UnsafeRetrieveMyBeaconPrivateKey(epochCounter uint64) (crypto.PrivateKey, error)
}

// DKGState is the storage interface for storing all artifacts and state
// related to the DKG process, including the latest state of a running or completed DKG, and computed beacon keys.
// It allows to initiate state transitions to the Random Beacon Recoverable State Machine by calling respective methods.
// It supports all state transitions for the happy path. Recovery from the epoch fallback mode is supported by the EpochRecoveryMyBeaconKey interface.
// DKGState is the storage interface for storing all artifacts and state related to the DKG process,
// including the latest state of a running or completed DKG, and computed beacon keys. DKGState
// supports all state transitions that can occur for an individual node during the happy path
// epoch switchover of the network as a whole. Recovery from the epoch fallback mode is supported
// by the EpochRecoveryMyBeaconKey interface.
type DKGState interface {
DKGStateReader

Expand All @@ -64,10 +65,11 @@ type DKGState interface {
// - [storage.InvalidDKGStateTransitionError] - if the requested state transition is invalid.
SetDKGState(epochCounter uint64, newState flow.DKGState) error

// InsertMyBeaconPrivateKey stores the random beacon private key for an epoch.
// InsertMyBeaconPrivateKey stores the random beacon private key for an epoch and transitions the
// state machine into the [flow.DKGStateCompleted] state.
//
// CAUTION: these keys are stored before they are validated against the
// canonical key vector and may not be valid for use in signing. Use SafeBeaconKeys
// canonical key vector and may not be valid for use in signing. Use [SafeBeaconKeys]
// to guarantee only keys safe for signing are returned
// Error returns:
// - [storage.ErrAlreadyExists] - if there is already a key stored for given epoch.
Expand Down

0 comments on commit 0687e30

Please sign in to comment.