Skip to content

Commit

Permalink
added avagoversion detection and network name
Browse files Browse the repository at this point in the history
  • Loading branch information
arturrez committed Jul 30, 2024
1 parent 31a7038 commit 21acc05
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 2 deletions.
71 changes: 71 additions & 0 deletions node/avalanchego.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Copyright (C) 2024, Ava Labs, Inc. All rights reserved.

Check failure on line 1 in node/avalanchego.go

View workflow job for this annotation

GitHub Actions / Lint

: # github.com/ava-labs/avalanche-tooling-sdk-go/node [github.com/ava-labs/avalanche-tooling-sdk-go/node.test]
// See the file LICENSE for licensing terms.

package node

import (
"encoding/json"
"fmt"

"github.com/ava-labs/avalanche-tooling-sdk-go/constants"
remoteconfig "github.com/ava-labs/avalanche-tooling-sdk-go/node/config"
"github.com/ava-labs/avalanche-tooling-sdk-go/utils"
"github.com/ava-labs/avalanchego/api/info"
)

func (h *Node) GetAvalancheGoVersion() (string, error) {
// Craft and send the HTTP POST request
requestBody := "{\"jsonrpc\":\"2.0\", \"id\":1,\"method\" :\"info.getNodeVersion\"}"
resp, err := h.Post("", requestBody)
if err != nil {
return "", err
}
if avalancheGoVersion, _, err := parseAvalancheGoOutput(resp); err != nil {
return "", err
} else {
return avalancheGoVersion, nil
}
}

func parseAvalancheGoOutput(byteValue []byte) (string, uint32, error) {
reply := map[string]interface{}{}
if err := json.Unmarshal(byteValue, &reply); err != nil {
return "", 0, err
}
resultMap := reply["result"]
resultJSON, err := json.Marshal(resultMap)
if err != nil {
return "", 0, err
}

nodeVersionReply := info.GetNodeVersionReply{}
if err := json.Unmarshal(resultJSON, &nodeVersionReply); err != nil {
return "", 0, err
}
return nodeVersionReply.VMVersions["platform"], uint32(nodeVersionReply.RPCProtocolVersion), nil
}

func (h *Node) GetAvalancheGoNetworkName() (string, error) {
if nodeConfigFileExists(*h) {
avagoConfig, err := h.GetAvalancheGoConfigData()
if err != nil {
return "", err
}
return utils.StringValue(avagoConfig, "network-id")
} else {
return "", fmt.Errorf("node config file does not exist")
}
}

func (h *Node) GetAvalancheGoConfigData() (map[string]interface{}, error) {
// get remote node.json file
nodeJSON, err := h.ReadFileBytes(remoteconfig.GetRemoteAvalancheNodeConfig(), constants.SSHFileOpsTimeout)
if err != nil {
return nil, err
}
var avagoConfig map[string]interface{}
if err := json.Unmarshal(nodeJSON, &avagoConfig); err != nil {
return nil, err
}
return avagoConfig, nil
}
13 changes: 11 additions & 2 deletions node/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ func (h *Node) MonitorNodes(ctx context.Context, targets []Node, chainID string)
}

// ValidateSubnets reconfigures avalanchego to validate subnets
func (h *Node) ValidateSubnets(ctx context.Context, networkName string, subnetsToTrack []string, avalancheGoVersion string) error {
func (h *Node) ValidateSubnets(subnetsToTrack []string) error {
// necessary checks
if !isAvalancheGoNode(*h) {
return fmt.Errorf("%s is not a avalanchego node", h.NodeID)
Expand All @@ -392,7 +392,15 @@ func (h *Node) ValidateSubnets(ctx context.Context, networkName string, subnetsT
if err := h.WaitForSSHShell(constants.SSHScriptTimeout); err != nil {
return err
}
if err := h.ComposeSSHSetupNode(networkName, subnetsToTrack, avalancheGoVersion, withMonitoring); err != nil {
avagoVersion, err := h.GetAvalancheGoVersion()
if err != nil {
return err
}
networkName, err := h.GetAvalancheGoNetworkName()
if err != nil {
return err
}
if err := h.ComposeSSHSetupNode(networkName, subnetsToTrack, avagoVersion, withMonitoring); err != nil {
return err
}
if err := h.RestartDockerCompose(constants.SSHScriptTimeout); err != nil {
Expand All @@ -401,6 +409,7 @@ func (h *Node) ValidateSubnets(ctx context.Context, networkName string, subnetsT

return nil
}

func (h *Node) RunSSHCopyMonitoringDashboards(monitoringDashboardPath string) error {
// TODO: download dashboards from github instead
remoteDashboardsPath := utils.GetRemoteComposeServicePath("grafana", "dashboards")
Expand Down

0 comments on commit 21acc05

Please sign in to comment.