@@ -5,21 +5,81 @@ import (
55 "time"
66
77 "github.com/onflow/flow-go/cmd/bootstrap/run"
8+ "github.com/onflow/flow-go/model/dkg"
89 "github.com/onflow/flow-go/model/flow"
10+ "github.com/onflow/flow-go/module/signature"
11+ "github.com/onflow/flow-go/state/protocol/inmem"
912)
1013
11- func constructRootBlock ( rootChain string , rootParent string , rootHeight uint64 , rootTimestamp string ) * flow. Block {
12-
14+ // constructRootHeader constructs a header for the root block.
15+ func constructRootHeader ( rootChain string , rootParent string , rootHeight uint64 , rootTimestamp string ) * flow. Header {
1316 chainID := parseChainID (rootChain )
1417 parentID := parseParentID (rootParent )
1518 height := rootHeight
1619 timestamp := parseRootTimestamp (rootTimestamp )
1720
18- block := run .GenerateRootBlock (chainID , parentID , height , timestamp )
21+ return run .GenerateRootHeader (chainID , parentID , height , timestamp )
22+ }
1923
24+ // constructRootBlock constructs a valid root block based on the given header, setup, and commit.
25+ func constructRootBlock (rootHeader * flow.Header , setup * flow.EpochSetup , commit * flow.EpochCommit ) * flow.Block {
26+ block := & flow.Block {
27+ Header : rootHeader ,
28+ Payload : nil ,
29+ }
30+ block .SetPayload (flow.Payload {
31+ Guarantees : nil ,
32+ Seals : nil ,
33+ Receipts : nil ,
34+ Results : nil ,
35+ ProtocolStateID : inmem .ProtocolStateFromEpochServiceEvents (setup , commit ).ID (),
36+ })
2037 return block
2138}
2239
40+ // constructRootEpochEvents constructs the epoch setup and commit events for the first epoch after spork.
41+ func constructRootEpochEvents (
42+ firstView uint64 ,
43+ participants flow.IdentityList ,
44+ assignments flow.AssignmentList ,
45+ clusterQCs []* flow.QuorumCertificate ,
46+ dkgData dkg.DKGData ) (* flow.EpochSetup , * flow.EpochCommit ) {
47+ epochSetup := & flow.EpochSetup {
48+ Counter : flagEpochCounter ,
49+ FirstView : firstView ,
50+ FinalView : firstView + flagNumViewsInEpoch - 1 ,
51+ DKGPhase1FinalView : firstView + flagNumViewsInStakingAuction + flagNumViewsInDKGPhase - 1 ,
52+ DKGPhase2FinalView : firstView + flagNumViewsInStakingAuction + flagNumViewsInDKGPhase * 2 - 1 ,
53+ DKGPhase3FinalView : firstView + flagNumViewsInStakingAuction + flagNumViewsInDKGPhase * 3 - 1 ,
54+ Participants : participants .Sort (flow .Canonical [flow .Identity ]).ToSkeleton (),
55+ Assignments : assignments ,
56+ RandomSource : GenerateRandomSeed (flow .EpochSetupRandomSourceLength ),
57+ }
58+
59+ qcsWithSignerIDs := make ([]* flow.QuorumCertificateWithSignerIDs , 0 , len (clusterQCs ))
60+ for i , clusterQC := range clusterQCs {
61+ members := assignments [i ]
62+ signerIDs , err := signature .DecodeSignerIndicesToIdentifiers (members , clusterQC .SignerIndices )
63+ if err != nil {
64+ log .Fatal ().Err (err ).Msgf ("could not decode signer IDs from clusterQC at index %v" , i )
65+ }
66+ qcsWithSignerIDs = append (qcsWithSignerIDs , & flow.QuorumCertificateWithSignerIDs {
67+ View : clusterQC .View ,
68+ BlockID : clusterQC .BlockID ,
69+ SignerIDs : signerIDs ,
70+ SigData : clusterQC .SigData ,
71+ })
72+ }
73+
74+ epochCommit := & flow.EpochCommit {
75+ Counter : flagEpochCounter ,
76+ ClusterQCs : flow .ClusterQCVoteDatasFromQCs (qcsWithSignerIDs ),
77+ DKGGroupKey : dkgData .PubGroupKey ,
78+ DKGParticipantKeys : dkgData .PubKeyShares ,
79+ }
80+ return epochSetup , epochCommit
81+ }
82+
2383func parseChainID (chainID string ) flow.ChainID {
2484 switch chainID {
2585 case "main" :
0 commit comments