-
Notifications
You must be signed in to change notification settings - Fork 179
/
qc.go
47 lines (38 loc) · 1.56 KB
/
qc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package cmd
import (
"fmt"
"path/filepath"
"github.com/onflow/flow-go/cmd/bootstrap/run"
"github.com/onflow/flow-go/consensus/hotstuff/model"
"github.com/onflow/flow-go/model/bootstrap"
"github.com/onflow/flow-go/model/dkg"
"github.com/onflow/flow-go/model/flow"
)
// constructRootQC constructs root QC based on root block, votes and dkg info
func constructRootQC(block *flow.Block, votes []*model.Vote, allNodes, internalNodes []bootstrap.NodeInfo, dkgData dkg.DKGData) *flow.QuorumCertificate {
identities := bootstrap.ToIdentityList(allNodes)
participantData, err := run.GenerateQCParticipantData(allNodes, internalNodes, dkgData)
if err != nil {
log.Fatal().Err(err).Msg("failed to generate QC participant data")
}
qc, err := run.GenerateRootQC(block, votes, participantData, identities)
if err != nil {
log.Fatal().Err(err).Msg("generating root QC failed")
}
return qc
}
// NOTE: allNodes must be in the same order as when generating the DKG
func constructRootVotes(block *flow.Block, allNodes, internalNodes []bootstrap.NodeInfo, dkgData dkg.DKGData) {
participantData, err := run.GenerateQCParticipantData(allNodes, internalNodes, dkgData)
if err != nil {
log.Fatal().Err(err).Msg("failed to generate QC participant data")
}
votes, err := run.GenerateRootBlockVotes(block, participantData)
if err != nil {
log.Fatal().Err(err).Msg("generating votes for root block failed")
}
for _, vote := range votes {
path := filepath.Join(bootstrap.DirnameRootBlockVotes, fmt.Sprintf(bootstrap.FilenameRootBlockVote, vote.SignerID))
writeJSON(path, vote)
}
}