github.com/koko1123/flow-go-1@v0.29.6/consensus/hotstuff/committees/leader/cluster.go (about) 1 package leader 2 3 import ( 4 "fmt" 5 6 "github.com/koko1123/flow-go-1/state/protocol" 7 "github.com/koko1123/flow-go-1/state/protocol/seed" 8 ) 9 10 // SelectionForCluster pre-computes and returns leaders for the given cluster 11 // committee in the given epoch. 12 func SelectionForCluster(cluster protocol.Cluster, epoch protocol.Epoch) (*LeaderSelection, error) { 13 14 // sanity check to ensure the cluster and epoch match 15 counter, err := epoch.Counter() 16 if err != nil { 17 return nil, fmt.Errorf("could not get epoch counter: %w", err) 18 } 19 if counter != cluster.EpochCounter() { 20 return nil, fmt.Errorf("inconsistent counter between epoch (%d) and cluster (%d)", counter, cluster.EpochCounter()) 21 } 22 23 identities := cluster.Members() 24 // get the random source of the current epoch 25 randomSeed, err := epoch.RandomSource() 26 if err != nil { 27 return nil, fmt.Errorf("could not get leader selection seed for cluster (index: %v) at epoch: %v: %w", cluster.Index(), counter, err) 28 } 29 // create random number generator from the seed and customizer 30 rng, err := seed.PRGFromRandomSource(randomSeed, seed.ProtocolCollectorClusterLeaderSelection(cluster.Index())) 31 if err != nil { 32 return nil, fmt.Errorf("could not create rng: %w", err) 33 } 34 35 firstView := cluster.RootBlock().Header.View 36 // TODO what is a good value here? 37 finalView := firstView + EstimatedSixMonthOfViews 38 39 leaders, err := ComputeLeaderSelection( 40 firstView, 41 rng, 42 int(finalView-firstView+1), 43 identities, 44 ) 45 return leaders, err 46 }