@@ -2,7 +2,6 @@ package common
22
33import (
44 "encoding/hex"
5- "errors"
65 "fmt"
76
87 "github.com/onflow/crypto/random"
@@ -40,8 +39,9 @@ import (
4039// Returns:
4140// - flow.AssignmentList: the generated assignment list.
4241// - flow.ClusterList: the generate collection cluster list.
42+ // - bool: whether all cluster QCs can be created with only votes from internal nodes.
4343// - error: if any error occurs. Any error returned from this function is irrecoverable.
44- func ConstructClusterAssignment (log zerolog.Logger , partnerNodes , internalNodes flow.IdentityList , numCollectionClusters int , randomSource random.Rand ) (flow.AssignmentList , flow.ClusterList , error ) {
44+ func ConstructClusterAssignment (log zerolog.Logger , partnerNodes , internalNodes flow.IdentityList , numCollectionClusters int , randomSource random.Rand ) (flow.AssignmentList , flow.ClusterList , bool , error ) {
4545
4646 partnerCollectors := partnerNodes .Filter (filter.HasRole [flow.Identity ](flow .RoleCollection ))
4747 internalCollectors := internalNodes .Filter (filter.HasRole [flow.Identity ](flow .RoleCollection ))
@@ -78,7 +78,7 @@ func ConstructClusterAssignment(log zerolog.Logger, partnerNodes, internalNodes
7878 // first, round-robin internal nodes into each cluster
7979 for i , node := range internalCollectors {
8080 if node .InitialWeight != refWeight {
81- return nil , nil , fmt .Errorf ("current implementation requires all collectors (partner & interal nodes) to have equal weight" )
81+ return nil , nil , false , fmt .Errorf ("current implementation requires all collectors (partner & interal nodes) to have equal weight" )
8282 }
8383 clusterIndex := i % numCollectionClusters
8484 identifierLists [clusterIndex ] = append (identifierLists [clusterIndex ], node .NodeID )
@@ -88,17 +88,18 @@ func ConstructClusterAssignment(log zerolog.Logger, partnerNodes, internalNodes
8888 // next, round-robin partner nodes into each cluster
8989 for i , node := range partnerCollectors {
9090 if node .InitialWeight != refWeight {
91- return nil , nil , fmt .Errorf ("current implementation requires all collectors (partner & interal nodes) to have equal weight" )
91+ return nil , nil , false , fmt .Errorf ("current implementation requires all collectors (partner & interal nodes) to have equal weight" )
9292 }
9393 clusterIndex := i % numCollectionClusters
9494 identifierLists [clusterIndex ] = append (identifierLists [clusterIndex ], node .NodeID )
9595 constraint [clusterIndex ] -= 1
9696 }
9797
9898 // check the 2/3 constraint: for every cluster `i`, constraint[i] must be strictly positive
99+ canConstructAllClusterQCs := true
99100 for i := 0 ; i < numCollectionClusters ; i ++ {
100101 if constraint [i ] <= 0 {
101- return nil , nil , errors . New ( "there isn't enough internal nodes to have at least 1/3 internal nodes in each cluster" )
102+ canConstructAllClusterQCs = false
102103 }
103104 }
104105
@@ -110,7 +111,7 @@ func ConstructClusterAssignment(log zerolog.Logger, partnerNodes, internalNodes
110111 log .Fatal ().Err (err ).Msg ("could not create cluster list" )
111112 }
112113
113- return assignments , clusters , nil
114+ return assignments , clusters , canConstructAllClusterQCs , nil
114115}
115116
116117// ConvertClusterAssignmentsCdc converts golang cluster assignments type to Cadence type `[[String]]`.
0 commit comments