-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
neofs-adm: add new command morph netmap-candidates
This command lists netmap candidates in the netmap contract. It allows checking if a node has been bootstrapped successfully. Closes #1889. Signed-off-by: Ekaterina Pavlova <ekt@morphbits.io>
- Loading branch information
1 parent
af62f2d
commit 37dfbf3
Showing
5 changed files
with
96 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package morph | ||
|
||
import ( | ||
"encoding/hex" | ||
"fmt" | ||
|
||
"github.com/nspcc-dev/neo-go/pkg/rpcclient/invoker" | ||
"github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap" | ||
neofsnetmap "github.com/nspcc-dev/neofs-sdk-go/netmap" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
func listNetmapCandidatesNodes(cmd *cobra.Command, _ []string) error { | ||
c, err := getN3Client(viper.GetViper()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
inv := invoker.New(c, nil) | ||
|
||
nnsCs, err := c.GetContractStateByID(1) | ||
if err != nil { | ||
return fmt.Errorf("can't get NNS contract info: %w", err) | ||
} | ||
|
||
nmHash, err := nnsResolveHash(inv, nnsCs.Hash, netmapContract+".neofs") | ||
if err != nil { | ||
return fmt.Errorf("can't get netmap contract hash: %w", err) | ||
} | ||
|
||
res, err := inv.Call(nmHash, "netmapCandidates") | ||
if err != nil { | ||
return fmt.Errorf("can't fetch list of network config keys from the netmap contract: %w", err) | ||
} | ||
|
||
nm, err := netmap.DecodeNetMap(res.Stack) | ||
|
||
if err != nil { | ||
return fmt.Errorf("unable to decode netmap: %w", err) | ||
} | ||
cmd.Println("Epoch:", nm.Epoch()) | ||
|
||
nodes := nm.Nodes() | ||
for i := range nodes { | ||
PrettyPrintNodeInfo(cmd, nodes[i], i, "", false) | ||
} | ||
return nil | ||
} | ||
|
||
// PrettyPrintNodeInfo and PrettyPrintNetMap copied from | ||
// "github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/common", can be imported but new package is needed. | ||
func PrettyPrintNodeInfo(cmd *cobra.Command, node netmap.NodeInfo, | ||
index int, indent string, short bool) { | ||
var strState string | ||
|
||
switch { | ||
default: | ||
strState = "STATE_UNSUPPORTED" | ||
case node.IsOnline(): | ||
strState = "ONLINE" | ||
case node.IsOffline(): | ||
strState = "OFFLINE" | ||
case node.IsMaintenance(): | ||
strState = "MAINTENANCE" | ||
} | ||
|
||
cmd.Printf("%sNode %d: %s %s ", indent, index+1, hex.EncodeToString(node.PublicKey()), strState) | ||
|
||
neofsnetmap.IterateNetworkEndpoints(node, func(endpoint string) { | ||
cmd.Printf("%s ", endpoint) | ||
}) | ||
cmd.Println() | ||
|
||
if !short { | ||
node.IterateAttributes(func(key, value string) { | ||
cmd.Printf("%s\t%s: %s\n", indent, key, value) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters