github.com/onflow/flow-go@v0.33.17/storage/dkg.go (about) 1 package storage 2 3 import ( 4 "github.com/onflow/flow-go/crypto" 5 "github.com/onflow/flow-go/model/flow" 6 ) 7 8 // DKGState is the storage interface for storing all artifacts and state 9 // related to the DKG process, including the latest state of a running or 10 // completed DKG, and computed beacon keys. 11 type DKGState interface { 12 13 // SetDKGStarted sets the flag indicating the DKG has started for the given epoch. 14 // Error returns: storage.ErrAlreadyExists 15 SetDKGStarted(epochCounter uint64) error 16 17 // GetDKGStarted checks whether the DKG has been started for the given epoch. 18 // No errors expected during normal operation. 19 GetDKGStarted(epochCounter uint64) (bool, error) 20 21 // SetDKGEndState stores that the DKG has ended, and its end state. 22 // Error returns: storage.ErrAlreadyExists 23 SetDKGEndState(epochCounter uint64, endState flow.DKGEndState) error 24 25 // GetDKGEndState retrieves the end state for the given DKG. 26 // Error returns: storage.ErrNotFound 27 GetDKGEndState(epochCounter uint64) (flow.DKGEndState, error) 28 29 // InsertMyBeaconPrivateKey stores the random beacon private key for an epoch. 30 // 31 // CAUTION: these keys are stored before they are validated against the 32 // canonical key vector and may not be valid for use in signing. Use SafeBeaconKeys 33 // to guarantee only keys safe for signing are returned 34 // Error returns: storage.ErrAlreadyExists 35 InsertMyBeaconPrivateKey(epochCounter uint64, key crypto.PrivateKey) error 36 37 // RetrieveMyBeaconPrivateKey retrieves the random beacon private key for an epoch. 38 // 39 // CAUTION: these keys are stored before they are validated against the 40 // canonical key vector and may not be valid for use in signing. Use SafeBeaconKeys 41 // to guarantee only keys safe for signing are returned 42 // Error returns: storage.ErrNotFound 43 RetrieveMyBeaconPrivateKey(epochCounter uint64) (crypto.PrivateKey, error) 44 } 45 46 // SafeBeaconKeys is a safe way to access beacon keys. 47 type SafeBeaconKeys interface { 48 49 // RetrieveMyBeaconPrivateKey retrieves my beacon private key for the given 50 // epoch, only if my key has been confirmed valid and safe for use. 51 // 52 // Returns: 53 // - (key, true, nil) if the key is present and confirmed valid 54 // - (nil, false, nil) if the key has been marked invalid or unavailable 55 // -> no beacon key will ever be available for the epoch in this case 56 // - (nil, false, storage.ErrNotFound) if the DKG has not ended 57 // - (nil, false, error) for any unexpected exception 58 RetrieveMyBeaconPrivateKey(epochCounter uint64) (key crypto.PrivateKey, safe bool, err error) 59 }