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 2f95b3e
Show file tree
Hide file tree
Showing 2 changed files with 21 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
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 2f95b3e

Please sign in to comment.