github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/storage/dkg.go (about)

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