From ceb3ee2cb68ee5f6f86a8f76df9761dcec4e700c Mon Sep 17 00:00:00 2001 From: Leo Zhang Date: Thu, 19 Sep 2024 09:19:09 -0700 Subject: [PATCH] Apply suggestions from code review Co-authored-by: Alexander Hentschel --- cmd/bootstrap/cmd/rootblock.go | 9 +++++++++ cmd/util/cmd/common/node_info.go | 3 ++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/cmd/bootstrap/cmd/rootblock.go b/cmd/bootstrap/cmd/rootblock.go index 7d9f612ee10..d8e5143f477 100644 --- a/cmd/bootstrap/cmd/rootblock.go +++ b/cmd/bootstrap/cmd/rootblock.go @@ -145,6 +145,11 @@ func rootBlock(cmd *cobra.Command, args []string) { log.Fatal().Err(err).Msg("invalid epoch timing config") } + // Read partner node's information and internal node's information. + // With "internal nodes" we reference nodes, whose private keys we have. In comparison, + // for "partner nodes" we generally do not have their keys. However, we allow some overlap, + // in that we tolerate a configuration where information about an "internal node" is also + // duplicated in the list of "partner nodes". log.Info().Msg("collecting partner network and staking keys") rawPartnerNodes, err := common.ReadFullPartnerNodeInfos(log, flagPartnerWeights, flagPartnerNodeInfoDir) if err != nil { @@ -160,6 +165,10 @@ func rootBlock(cmd *cobra.Command, args []string) { log.Info().Msg("") + // we now convert to the strict meaning of: "internal nodes" vs "partner nodes" + // • "internal nodes" we have they private keys for + // • "partner nodes" we don't have the keys for + // • both sets are disjoint (no common nodes) log.Info().Msg("remove internal partner nodes") partnerNodes := common.FilterInternalPartners(rawPartnerNodes, internalNodes) log.Info().Msgf("removed %d internal partner nodes", len(rawPartnerNodes)-len(partnerNodes)) diff --git a/cmd/util/cmd/common/node_info.go b/cmd/util/cmd/common/node_info.go index 6f2a93a4917..9263e5c96a3 100644 --- a/cmd/util/cmd/common/node_info.go +++ b/cmd/util/cmd/common/node_info.go @@ -225,7 +225,8 @@ func internalWeightsByAddress(log zerolog.Logger, config string) map[string]uint return weights } -// Reject any partner nodes that are in the internal node list. +// FilterInternalPartners returns the `partners`, dropping any entries that are also in `internal` +// Formally, this function implements the set difference `partners \ internal`. func FilterInternalPartners(partners []bootstrap.NodeInfo, internal []bootstrap.NodeInfo) []bootstrap.NodeInfo { lookup := make(map[flow.Identifier]struct{}) for _, node := range internal {