Skip to content

Commit

Permalink
neofs-adm: add new command morph netmap-candidates (#2529)
Browse files Browse the repository at this point in the history
This command lists netmap candidates in the netmap contract. It allows
checking if a node has been bootstrapped successfully.

Closes #1889.
  • Loading branch information
roman-khimov committed Aug 30, 2023
2 parents f5ad4a8 + b621852 commit 5955244
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ minor release, the component will be purged, so be prepared (see `Updating` sect
- Sessions to RPC server running in IR's local consensus mode (#2532)
- `neofs-cli object nodes` command to get SNs for an object (#2512)
- Fetching container estimations via iterators to prevent NeoVM stack overflow (#2173)
- `neofs-adm morph netmap-candidates` CLI command (#1889)

### Fixed
- `neo-go` RPC connection loss handling (#1337)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package common
package cmdprinter

import (
"encoding/hex"
Expand Down
49 changes: 49 additions & 0 deletions cmd/neofs-adm/internal/modules/morph/netmap_candidates.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package morph

import (
"fmt"

"github.com/nspcc-dev/neo-go/pkg/rpcclient/invoker"
"github.com/nspcc-dev/neofs-node/cmd/internal/cmdprinter"
"github.com/nspcc-dev/neofs-node/pkg/morph/client/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)
}
if res.State != "HALT" {
return fmt.Errorf("netmap contract returned unexpected exception: %s", res.FaultException)
}

nm, err := netmap.DecodeNetMap(res.Stack)

if err != nil {
return fmt.Errorf("unable to decode netmap: %w", err)
}
nodes := nm.Nodes()
for i := range nodes {
cmdprinter.PrettyPrintNodeInfo(cmd, nodes[i], i, "", false)
}
return nil
}
12 changes: 12 additions & 0 deletions cmd/neofs-adm/internal/modules/morph/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,15 @@ var (
},
RunE: depositNotary,
}
netmapCandidatesCmd = &cobra.Command{
Use: "netmap-candidates",
Short: "List netmap candidates nodes",
Args: cobra.NoArgs,
PreRun: func(cmd *cobra.Command, _ []string) {
_ = viper.BindPFlag(endpointFlag, cmd.Flags().Lookup(endpointFlag))
},
RunE: listNetmapCandidatesNodes,
}
)

func init() {
Expand Down Expand Up @@ -350,4 +359,7 @@ func init() {
depositNotaryCmd.Flags().String(walletAccountFlag, "", "Wallet account address")
depositNotaryCmd.Flags().String(refillGasAmountFlag, "", "Amount of GAS to deposit")
depositNotaryCmd.Flags().String(notaryDepositTillFlag, "", "Notary deposit duration in blocks")

RootCmd.AddCommand(netmapCandidatesCmd)
netmapCandidatesCmd.Flags().StringP(endpointFlag, "r", "", "N3 RPC node endpoint")
}
3 changes: 2 additions & 1 deletion cmd/neofs-cli/modules/container/nodes.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package container

import (
"github.com/nspcc-dev/neofs-node/cmd/internal/cmdprinter"
internalclient "github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/client"
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/common"
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/commonflags"
Expand Down Expand Up @@ -42,7 +43,7 @@ var containerNodesCmd = &cobra.Command{
for i := range cnrNodes {
cmd.Printf("Descriptor #%d, REP %d:\n", i+1, policy.ReplicaNumberByIndex(i))
for j := range cnrNodes[i] {
common.PrettyPrintNodeInfo(cmd, cnrNodes[i][j], j, "\t", short)
cmdprinter.PrettyPrintNodeInfo(cmd, cnrNodes[i][j], j, "\t", short)
}
}
},
Expand Down
3 changes: 2 additions & 1 deletion cmd/neofs-cli/modules/netmap/snapshot.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package netmap

import (
"github.com/nspcc-dev/neofs-node/cmd/internal/cmdprinter"
internalclient "github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/client"
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/common"
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/commonflags"
Expand All @@ -24,7 +25,7 @@ var snapshotCmd = &cobra.Command{
res, err := internalclient.NetMapSnapshot(ctx, prm)
common.ExitOnErr(cmd, "rpc error: %w", err)

common.PrettyPrintNetMap(cmd, res.NetMap())
cmdprinter.PrettyPrintNetMap(cmd, res.NetMap())
},
}

Expand Down
3 changes: 2 additions & 1 deletion cmd/neofs-cli/modules/object/nodes.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package object

import (
"github.com/nspcc-dev/neofs-node/cmd/internal/cmdprinter"
internalclient "github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/client"
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/common"
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/commonflags"
Expand Down Expand Up @@ -61,7 +62,7 @@ var objectNodesCmd = &cobra.Command{
for i := range placementNodes {
cmd.Printf("Descriptor #%d, REP %d:\n", i+1, policy.ReplicaNumberByIndex(i))
for j := range placementNodes[i] {
common.PrettyPrintNodeInfo(cmd, placementNodes[i][j], j, "\t", short)
cmdprinter.PrettyPrintNodeInfo(cmd, placementNodes[i][j], j, "\t", short)
}
}
},
Expand Down
6 changes: 3 additions & 3 deletions pkg/morph/client/netmap/netmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func (c *Client) GetNetMapByEpoch(epoch uint64) (*netmap.NetMap, error) {
epochSnapshotMethod, err)
}

nm, err := decodeNetMap(res)
nm, err := DecodeNetMap(res)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -61,10 +61,10 @@ func (c *Client) NetMap() (*netmap.NetMap, error) {
netMapMethod, err)
}

return decodeNetMap(res)
return DecodeNetMap(res)
}

func decodeNetMap(resStack []stackitem.Item) (*netmap.NetMap, error) {
func DecodeNetMap(resStack []stackitem.Item) (*netmap.NetMap, error) {
var nm netmap.NetMap

if len(resStack) > 0 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/morph/client/netmap/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ func (c *Client) GetNetMap(diff uint64) (*netmap.NetMap, error) {
return nil, err
}

return decodeNetMap(res)
return DecodeNetMap(res)
}

0 comments on commit 5955244

Please sign in to comment.