forked from TrueCloudLab/frostfs-node
[#1680] morph/netmap: Adopt to recent contract changes
After recent Netmap contract changes all read methods which return network map (either candidates or snapshots) encode node descriptors into same structure. Decode `netmap.Node` contract-side structure from the call results. Replace node state with the value from the `netmap.Node.State` field. Signed-off-by: Leonard Lyubich <ctulhurider@gmail.com>
This commit is contained in:
parent
d6c01199c8
commit
eb1fba5182
14 changed files with 135 additions and 221 deletions
|
@ -1,28 +1,12 @@
|
|||
package netmap
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
|
||||
"github.com/nspcc-dev/neofs-sdk-go/netmap"
|
||||
)
|
||||
|
||||
// GetNetMap receives information list about storage nodes
|
||||
// through the Netmap contract call, composes network map
|
||||
// from them and returns it. With diff == 0 returns current
|
||||
// network map, else return snapshot of previous network map.
|
||||
// GetNetMap calls "snapshot" method and decodes netmap.NetMap from the response.
|
||||
func (c *Client) GetNetMap(diff uint64) (*netmap.NetMap, error) {
|
||||
return c.getNetMap(diff)
|
||||
}
|
||||
|
||||
// Snapshot returns current netmap node infos.
|
||||
// Consider using pkg/morph/client/netmap for this.
|
||||
func (c *Client) Snapshot() (*netmap.NetMap, error) {
|
||||
return c.getNetMap(0)
|
||||
}
|
||||
|
||||
func (c *Client) getNetMap(diff uint64) (*netmap.NetMap, error) {
|
||||
prm := client.TestInvokePrm{}
|
||||
prm.SetMethod(snapshotMethod)
|
||||
prm.SetArgs(diff)
|
||||
|
@ -32,24 +16,5 @@ func (c *Client) getNetMap(diff uint64) (*netmap.NetMap, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
return unmarshalNetmap(res, snapshotMethod)
|
||||
}
|
||||
|
||||
func unmarshalNetmap(items []stackitem.Item, method string) (*netmap.NetMap, error) {
|
||||
rawPeers, err := peersFromStackItems(items, method)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
result := make([]netmap.NodeInfo, len(rawPeers))
|
||||
for i := range rawPeers {
|
||||
if err := result[i].Unmarshal(rawPeers[i]); err != nil {
|
||||
return nil, fmt.Errorf("can't unmarshal node info (%s): %w", method, err)
|
||||
}
|
||||
}
|
||||
|
||||
var nm netmap.NetMap
|
||||
nm.SetNodes(result)
|
||||
|
||||
return &nm, nil
|
||||
return decodeNetMap(res)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue