github.com/koko1123/flow-go-1@v0.29.6/module/dkg.go (about) 1 package module 2 3 import ( 4 "github.com/onflow/flow-go/crypto" 5 "github.com/koko1123/flow-go-1/model/flow" 6 "github.com/koko1123/flow-go-1/model/messages" 7 ) 8 9 // DKGContractClient enables interacting with the DKG smart contract. This 10 // contract is deployed to the service account as part of a collection of 11 // smart contracts that facilitate and manage epoch transitions. 12 type DKGContractClient interface { 13 14 // Broadcast broadcasts a message to all other nodes participating in the 15 // DKG. The message is broadcast by submitting a transaction to the DKG 16 // smart contract. An error is returned if the transaction has failed has 17 // failed. 18 // TBD: retry logic 19 Broadcast(msg messages.BroadcastDKGMessage) error 20 21 // ReadBroadcast reads the broadcast messages from the smart contract. 22 // Messages are returned in the order in which they were broadcast (received 23 // and stored in the smart contract). The parameters are: 24 // 25 // * fromIndex: return messages with index >= fromIndex 26 // * referenceBlock: a marker for the state against which the query should 27 // be executed 28 // 29 // DKG nodes should call ReadBroadcast one final time once they have 30 // observed the phase deadline trigger to guarantee they receive all 31 // messages for that phase. 32 ReadBroadcast(fromIndex uint, referenceBlock flow.Identifier) ([]messages.BroadcastDKGMessage, error) 33 34 // SubmitResult submits the final public result of the DKG protocol. This 35 // represents the group public key and the node's local computation of the 36 // public keys for each DKG participant. 37 // 38 // SubmitResult must be called strictly after the final phase has ended. 39 SubmitResult(crypto.PublicKey, []crypto.PublicKey) error 40 } 41 42 // DKGController controls the execution of a Joint Feldman DKG instance. 43 type DKGController interface { 44 45 // Run starts the DKG controller and starts phase 1. It is a blocking call 46 // that blocks until the controller is shutdown or until an error is 47 // encountered in one of the protocol phases. 48 Run() error 49 50 // EndPhase1 notifies the controller to end phase 1, and start phase 2. 51 EndPhase1() error 52 53 // EndPhase2 notifies the controller to end phase 2, and start phase 3. 54 EndPhase2() error 55 56 // End terminates the DKG state machine and records the artifacts. 57 End() error 58 59 // Shutdown stops the controller regardless of the current state. 60 Shutdown() 61 62 // Poll instructs the controller to actively fetch broadcast messages (ex. 63 // read from DKG smart contract). The method does not return until all 64 // received messages are processed. 65 Poll(blockReference flow.Identifier) error 66 67 // GetArtifacts returns our node's private key share, the group public key, 68 // and the list of all nodes' public keys (including ours), as computed by 69 // the DKG. 70 GetArtifacts() (crypto.PrivateKey, crypto.PublicKey, []crypto.PublicKey) 71 72 // GetIndex returns the index of this node in the DKG committee list. 73 GetIndex() int 74 75 // SubmitResult instructs the broker to publish the results of the DKG run 76 // (ex. publish to DKG smart contract). 77 SubmitResult() error 78 } 79 80 // DKGControllerFactory is a factory to create instances of DKGController. 81 type DKGControllerFactory interface { 82 83 // Create instantiates a new DKGController. 84 Create(dkgInstanceID string, participants flow.IdentityList, seed []byte) (DKGController, error) 85 }