Skip to content

Commit 99533bf

Browse files
committed
move cluster internal ratio check to constraints.go
1 parent d839fcf commit 99533bf

File tree

2 files changed

+23
-23
lines changed

2 files changed

+23
-23
lines changed

cmd/bootstrap/cmd/constraints.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,26 @@ func checkConstraints(partnerNodes, internalNodes []model.NodeInfo) {
3737

3838
ensureUniformNodeWeightsPerRole(all)
3939
}
40+
41+
// Check about the number of internal/partner nodes in each cluster. The identites
42+
// in each cluster do not matter for this check.
43+
// Each cluster must have >1/3 internal nodes.
44+
func checkClusterConstraint(clusters flow.ClusterList, partnersInfo []model.NodeInfo, internalsInfo []model.NodeInfo) bool {
45+
partners := model.ToIdentityList(partnersInfo)
46+
internals := model.ToIdentityList(internalsInfo)
47+
for _, cluster := range clusters {
48+
var clusterPartnerCount, clusterInternalCount int
49+
for _, node := range cluster {
50+
if _, exists := partners.ByNodeID(node.NodeID); exists {
51+
clusterPartnerCount++
52+
}
53+
if _, exists := internals.ByNodeID(node.NodeID); exists {
54+
clusterInternalCount++
55+
}
56+
}
57+
if clusterInternalCount*2 <= clusterPartnerCount {
58+
return false
59+
}
60+
}
61+
return true
62+
}

cmd/bootstrap/cmd/finalize_test.go

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -193,29 +193,6 @@ func TestEpochTimingConfig(t *testing.T) {
193193
})
194194
}
195195

196-
// Check about the number of internal/partner nodes in each cluster. The identites
197-
// in each cluster do not matter for this check.
198-
// Each cluster must have >1/3 internal nodes.
199-
func checkClusterConstraint(clusters flow.ClusterList, partnersInfo []model.NodeInfo, internalsInfo []model.NodeInfo) bool {
200-
partners := model.ToIdentityList(partnersInfo)
201-
internals := model.ToIdentityList(internalsInfo)
202-
for _, cluster := range clusters {
203-
var clusterPartnerCount, clusterInternalCount int
204-
for _, node := range cluster {
205-
if _, exists := partners.ByNodeID(node.NodeID); exists {
206-
clusterPartnerCount++
207-
}
208-
if _, exists := internals.ByNodeID(node.NodeID); exists {
209-
clusterInternalCount++
210-
}
211-
}
212-
if clusterInternalCount*2 <= clusterPartnerCount {
213-
return false
214-
}
215-
}
216-
return true
217-
}
218-
219196
func TestMergeNodeInfos(t *testing.T) {
220197
partnersLen := 7
221198
internalLen := 22

0 commit comments

Comments
 (0)