github.com/koko1123/flow-go-1@v0.29.6/storage/badger/operation/dkg.go (about) 1 package operation 2 3 import ( 4 "errors" 5 6 "github.com/dgraph-io/badger/v3" 7 8 "github.com/koko1123/flow-go-1/model/encodable" 9 "github.com/koko1123/flow-go-1/model/flow" 10 "github.com/koko1123/flow-go-1/storage" 11 ) 12 13 // InsertMyBeaconPrivateKey stores the random beacon private key for the given epoch. 14 // 15 // CAUTION: This method stores confidential information and should only be 16 // used in the context of the secrets database. This is enforced in the above 17 // layer (see storage.DKGState). 18 func InsertMyBeaconPrivateKey(epochCounter uint64, info *encodable.RandomBeaconPrivKey) func(*badger.Txn) error { 19 return insert(makePrefix(codeBeaconPrivateKey, epochCounter), info) 20 } 21 22 // RetrieveMyBeaconPrivateKey retrieves the random beacon private key for the given epoch. 23 // 24 // CAUTION: This method stores confidential information and should only be 25 // used in the context of the secrets database. This is enforced in the above 26 // layer (see storage.DKGState). 27 func RetrieveMyBeaconPrivateKey(epochCounter uint64, info *encodable.RandomBeaconPrivKey) func(*badger.Txn) error { 28 return retrieve(makePrefix(codeBeaconPrivateKey, epochCounter), info) 29 } 30 31 // InsertDKGStartedForEpoch stores a flag indicating that the DKG has been started for 32 // the given epoch. 33 func InsertDKGStartedForEpoch(epochCounter uint64) func(*badger.Txn) error { 34 return insert(makePrefix(codeDKGStarted, epochCounter), true) 35 } 36 37 // RetrieveDKGStartedForEpoch retrieves the DKG started flag for the given epoch. 38 // If no flag is set, started is set to false. 39 func RetrieveDKGStartedForEpoch(epochCounter uint64, started *bool) func(*badger.Txn) error { 40 return func(tx *badger.Txn) error { 41 err := retrieve(makePrefix(codeDKGStarted, epochCounter), started)(tx) 42 if errors.Is(err, storage.ErrNotFound) { 43 // flag not set - therefore DKG not started 44 *started = false 45 return nil 46 } else if err != nil { 47 // storage error - set started to zero value 48 *started = false 49 return err 50 } 51 return nil 52 } 53 } 54 55 // InsertDKGEndStateForEpoch stores the DKG end state for the epoch. 56 func InsertDKGEndStateForEpoch(epochCounter uint64, endState flow.DKGEndState) func(*badger.Txn) error { 57 return insert(makePrefix(codeDKGEnded, epochCounter), endState) 58 } 59 60 // RetrieveDKGEndStateForEpoch retrieves the DKG end state for the epoch. 61 func RetrieveDKGEndStateForEpoch(epochCounter uint64, endState *flow.DKGEndState) func(*badger.Txn) error { 62 return retrieve(makePrefix(codeDKGEnded, epochCounter), endState) 63 }