@@ -10,34 +10,31 @@ import (
10
10
model "github.com/onflow/flow-go/model/bootstrap"
11
11
"github.com/onflow/flow-go/model/dkg"
12
12
"github.com/onflow/flow-go/model/encodable"
13
+ "github.com/onflow/flow-go/model/flow"
13
14
"github.com/onflow/flow-go/state/protocol/inmem"
14
15
)
15
16
16
- func runBeaconKG (nodes []model.NodeInfo ) dkg.DKGData {
17
+ func runBeaconKG (nodes []model.NodeInfo ) ( dkg.ThresholdKeySet , flow. DKGIndexMap ) {
17
18
n := len (nodes )
18
-
19
19
log .Info ().Msgf ("read %v node infos for DKG" , n )
20
20
21
21
log .Debug ().Msgf ("will run DKG" )
22
- var dkgData dkg.DKGData
23
- var err error
24
- dkgData , err = bootstrapDKG .RandomBeaconKG (n , GenerateRandomSeed (crypto .KeyGenSeedMinLen ))
22
+ randomBeaconData , err := bootstrapDKG .RandomBeaconKG (n , GenerateRandomSeed (crypto .KeyGenSeedMinLen ))
25
23
if err != nil {
26
24
log .Fatal ().Err (err ).Msg ("error running DKG" )
27
25
}
28
26
log .Info ().Msgf ("finished running DKG" )
29
27
30
- pubKeyShares := make ([]encodable.RandomBeaconPubKey , 0 , len (dkgData .PubKeyShares ))
31
- for _ , pubKey := range dkgData .PubKeyShares {
32
- pubKeyShares = append (pubKeyShares , encodable.RandomBeaconPubKey {PublicKey : pubKey })
33
- }
34
-
35
- privKeyShares := make ([]encodable.RandomBeaconPrivKey , 0 , len (dkgData .PrivKeyShares ))
36
- for i , privKey := range dkgData .PrivKeyShares {
28
+ encodableParticipants := make ([]inmem.ThresholdParticipant , 0 , len (nodes ))
29
+ for i , privKey := range randomBeaconData .PrivKeyShares {
37
30
nodeID := nodes [i ].NodeID
38
31
39
32
encKey := encodable.RandomBeaconPrivKey {PrivateKey : privKey }
40
- privKeyShares = append (privKeyShares , encKey )
33
+ encodableParticipants = append (encodableParticipants , inmem.ThresholdParticipant {
34
+ PrivKeyShare : encKey ,
35
+ PubKeyShare : encodable.RandomBeaconPubKey {PublicKey : randomBeaconData .PubKeyShares [i ]},
36
+ NodeID : nodeID ,
37
+ })
41
38
42
39
err = common .WriteJSON (fmt .Sprintf (model .PathRandomBeaconPriv , nodeID ), flagOutdir , encKey )
43
40
if err != nil {
@@ -46,18 +43,22 @@ func runBeaconKG(nodes []model.NodeInfo) dkg.DKGData {
46
43
log .Info ().Msgf ("wrote file %s/%s" , flagOutdir , fmt .Sprintf (model .PathRandomBeaconPriv , nodeID ))
47
44
}
48
45
46
+ indexMap := make (flow.DKGIndexMap , len (nodes ))
47
+ for i , node := range nodes {
48
+ indexMap [node .NodeID ] = i
49
+ }
50
+
49
51
// write full DKG info that will be used to construct QC
50
- err = common .WriteJSON (model .PathRootDKGData , flagOutdir , inmem.EncodableFullDKG {
52
+ err = common .WriteJSON (model .PathRootDKGData , flagOutdir , inmem.ThresholdKeySet {
51
53
GroupKey : encodable.RandomBeaconPubKey {
52
- PublicKey : dkgData .PubGroupKey ,
54
+ PublicKey : randomBeaconData .PubGroupKey ,
53
55
},
54
- PubKeyShares : pubKeyShares ,
55
- PrivKeyShares : privKeyShares ,
56
+ Participants : encodableParticipants ,
56
57
})
57
58
if err != nil {
58
59
log .Fatal ().Err (err ).Msg ("failed to write json" )
59
60
}
60
61
log .Info ().Msgf ("wrote file %s/%s" , flagOutdir , model .PathRootDKGData )
61
62
62
- return dkgData
63
+ return randomBeaconData , indexMap
63
64
}
0 commit comments