Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding an option to boostrapcmd to pull candidate access nodes in addition to proposed nodes #6489

Merged
merged 2 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 34 additions & 4 deletions cmd/bootstrap/cmd/partner_infos.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ const (
)

var (
flagANAddress string
flagANNetworkKey string
flagNetworkEnv string
flagANAddress string
flagANNetworkKey string
flagNetworkEnv string
flagIncludeAccessNodes bool
)

// populatePartnerInfos represents the `populate-partner-infos` command which will read the proposed node
Expand All @@ -55,6 +56,7 @@ func init() {
populatePartnerInfosCMD.Flags().StringVar(&flagANAddress, "access-address", "", "the address of the access node used for client connections")
populatePartnerInfosCMD.Flags().StringVar(&flagANNetworkKey, "access-network-key", "", "the network key of the access node used for client connections in hex string format")
populatePartnerInfosCMD.Flags().StringVar(&flagNetworkEnv, "network", "mainnet", "the network string, expecting one of ( mainnet | testnet | emulator )")
populatePartnerInfosCMD.Flags().BoolVar(&flagIncludeAccessNodes, "include-candidate-access-nodes", false, "whether to include the candidate access nodes")

cmd.MarkFlagRequired(populatePartnerInfosCMD, "access-address")
}
Expand All @@ -76,13 +78,26 @@ func populatePartnerInfosRun(_ *cobra.Command, _ []string) {
flow.RoleAccess: 0,
}
totalNumOfPartnerNodes := 0
var allNodes []cadence.Value

nodeInfos, err := executeGetProposedNodesInfosScript(ctx, flowClient)
if err != nil {
log.Fatal().Err(err).Msg("could not get node info for nodes in the proposed table")
}
allNodes = nodeInfos.(cadence.Array).Values[:]

for _, info := range nodeInfos.(cadence.Array).Values {
log.Info().Int("total_proposed_nodes", len(allNodes)).Msg("total nodes in proposed table")

if flagIncludeAccessNodes {
candidateNodeInfos, err := executeGetCandidateAccessNodesInfosScript(ctx, flowClient)
if err != nil {
log.Fatal().Err(err).Msg("could not get node info for nodes in the proposed table")
}
log.Info().Int("total_candidate_access_nodes", len(candidateNodeInfos.(cadence.Array).Values)).Msg("total access nodes in candidate table")
allNodes = append(allNodes, candidateNodeInfos.(cadence.Array).Values[:]...)
}

for _, info := range allNodes {
nodePubInfo, err := parseNodeInfo(info)
if err != nil {
log.Fatal().Err(err).Msg("could not parse node info from cadence script")
Expand Down Expand Up @@ -146,6 +161,21 @@ func executeGetProposedNodesInfosScript(ctx context.Context, client *client.Clie
return infos, nil
}

// GetNodeInfoForCandidateNodesScript executes the get node info for each Access node ID in the candidate table
func executeGetCandidateAccessNodesInfosScript(ctx context.Context, client *client.Client) (cadence.Value, error) {
script, err := common.GetNodeInfoForCandidateNodesScript(flagNetworkEnv)
if err != nil {
return nil, fmt.Errorf("failed to get cadence script: %w", err)
}

infos, err := client.ExecuteScriptAtLatestBlock(ctx, script, []cadence.Value{})
if err != nil {
return nil, fmt.Errorf("failed to execute the get node info script: %w", err)
}

return infos, nil
}

// parseNodeInfo convert node info retrieved from cadence script
func parseNodeInfo(info cadence.Value) (*bootstrap.NodeInfoPub, error) {
fields := cadence.FieldsMappedByName(info.(cadence.Struct))
Expand Down
28 changes: 28 additions & 0 deletions cmd/util/cmd/common/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,21 @@ const (

return infos
}`

getInfoForCandidateAccessNodesScript = `
import FlowIDTableStaking from "FlowIDTableStaking"
access(all) fun main(): [FlowIDTableStaking.NodeInfo] {
let candidateNodes = FlowIDTableStaking.getCandidateNodeList()
let candidateAccessNodes = candidateNodes[UInt8(5)]!
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this statement filters out all nodes except the Access node (type 5)


let nodeInfos: [FlowIDTableStaking.NodeInfo] = []
for nodeID in candidateAccessNodes.keys {
let nodeInfo = FlowIDTableStaking.NodeInfo(nodeID: nodeID)
nodeInfos.append(nodeInfo)
}

return nodeInfos
}`
)

// GetNodeInfoForProposedNodesScript returns a script that will return an array of FlowIDTableStaking.NodeInfo for each
Expand All @@ -37,3 +52,16 @@ func GetNodeInfoForProposedNodesScript(network string) ([]byte, error) {
),
), nil
}

// GetNodeInfoForCandidateNodesScript returns a script that will return an array of FlowIDTableStaking.NodeInfo for each
// node in the candidate table (nodes which have staked but not yet chosen by the network).
func GetNodeInfoForCandidateNodesScript(network string) ([]byte, error) {
contracts := systemcontracts.SystemContractsForChain(flow.ChainID(fmt.Sprintf("flow-%s", network)))

return []byte(
templates.ReplaceAddresses(
getInfoForCandidateAccessNodesScript,
contracts.AsTemplateEnv(),
),
), nil
}
Loading