Skip to content

Commit

Permalink
remove internal partners from root block creation
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangchiqing committed Sep 17, 2024
1 parent 5be1172 commit a4913f8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
6 changes: 5 additions & 1 deletion cmd/bootstrap/cmd/rootblock.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func rootBlock(cmd *cobra.Command, args []string) {
}

log.Info().Msg("collecting partner network and staking keys")
partnerNodes, err := common.ReadFullPartnerNodeInfos(log, flagPartnerWeights, flagPartnerNodeInfoDir)
rawPartnerNodes, err := common.ReadFullPartnerNodeInfos(log, flagPartnerWeights, flagPartnerNodeInfoDir)
if err != nil {
log.Fatal().Err(err).Msg("failed to read full partner node infos")
}
Expand All @@ -160,6 +160,10 @@ func rootBlock(cmd *cobra.Command, args []string) {

log.Info().Msg("")

log.Info().Msg("remove internal partner nodes")
partnerNodes := common.FilterInternalPartners(rawPartnerNodes, internalNodes)
log.Info().Msgf("removed %d internal partner nodes", len(rawPartnerNodes)-len(partnerNodes))

log.Info().Msg("checking constraints on consensus nodes")
checkConstraints(partnerNodes, internalNodes)
log.Info().Msg("")
Expand Down
3 changes: 3 additions & 0 deletions cmd/bootstrap/cmd/rootblock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ const rootBlockHappyPathLogs = "collecting partner network and staking keys" +
`read \d+ internal private node-info files` +
`read internal node configurations` +
`read \d+ weights for internal nodes` +
`remove internal partner nodes` +
`removed 0 internal partner nodes` +
`checking constraints on consensus nodes` +

`assembling network and staking keys` +
`wrote file \S+/node-infos.pub.json` +
`running DKG for consensus nodes` +
Expand Down
16 changes: 16 additions & 0 deletions cmd/util/cmd/common/node_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,3 +224,19 @@ func internalWeightsByAddress(log zerolog.Logger, config string) map[string]uint

return weights
}

// Reject any partner nodes that are in the internal node list.
func FilterInternalPartners(partners []bootstrap.NodeInfo, internal []bootstrap.NodeInfo) []bootstrap.NodeInfo {
lookup := make(map[flow.Identifier]struct{})
for _, node := range internal {
lookup[node.NodeID] = struct{}{}
}

var filtered []bootstrap.NodeInfo
for _, node := range partners {
if _, ok := lookup[node.NodeID]; !ok {
filtered = append(filtered, node)
}
}
return filtered
}

0 comments on commit a4913f8

Please sign in to comment.