github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/state/cluster/root_block.go (about)

     1  package cluster
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/onflow/flow-go/model/cluster"
     7  	"github.com/onflow/flow-go/model/flow"
     8  )
     9  
    10  // CanonicalClusterID returns the canonical chain ID for the given cluster in
    11  // the given epoch.
    12  func CanonicalClusterID(epoch uint64, participants flow.IdentifierList) flow.ChainID {
    13  	return flow.ChainID(fmt.Sprintf("cluster-%d-%s", epoch, participants.ID()))
    14  }
    15  
    16  // these globals are filled by the static initializer
    17  var rootBlockPayload = cluster.EmptyPayload(flow.ZeroID)
    18  var rootBlockPayloadHash = rootBlockPayload.Hash()
    19  
    20  // CanonicalRootBlock returns the canonical root block for the given
    21  // cluster in the given epoch. It contains an empty collection referencing
    22  func CanonicalRootBlock(epoch uint64, participants flow.IdentitySkeletonList) *cluster.Block {
    23  	chainID := CanonicalClusterID(epoch, participants.NodeIDs())
    24  
    25  	header := &flow.Header{
    26  		ChainID:            chainID,
    27  		ParentID:           flow.ZeroID,
    28  		Height:             0,
    29  		PayloadHash:        rootBlockPayloadHash,
    30  		Timestamp:          flow.GenesisTime,
    31  		View:               0,
    32  		ParentVoterIndices: nil,
    33  		ParentVoterSigData: nil,
    34  		ProposerID:         flow.ZeroID,
    35  		ProposerSigData:    nil,
    36  	}
    37  
    38  	return &cluster.Block{
    39  		Header:  header,
    40  		Payload: &rootBlockPayload,
    41  	}
    42  }