forked from TrueCloudLab/frostfs-node
[#971] morph/netmap: Add optional parameters
Add optional parameters to the client call signature. Group parameters of a client call into struct to improve future codebase support. Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
parent
3114be39d0
commit
c25f5a86ae
11 changed files with 224 additions and 90 deletions
|
@ -10,6 +10,8 @@ import (
|
|||
// of add peer invocation call.
|
||||
type AddPeerArgs struct {
|
||||
info []byte
|
||||
|
||||
client.InvokePrmOptional
|
||||
}
|
||||
|
||||
// SetInfo sets the peer information.
|
||||
|
@ -24,6 +26,7 @@ func (c *Client) AddPeer(args AddPeerArgs) error {
|
|||
|
||||
prm.SetMethod(c.addPeerMethod)
|
||||
prm.SetArgs(args.info)
|
||||
prm.InvokePrmOptional = args.InvokePrmOptional
|
||||
|
||||
if err := c.client.Invoke(prm); err != nil {
|
||||
return fmt.Errorf("could not invoke method (%s): %w", c.addPeerMethod, err)
|
||||
|
|
|
@ -13,17 +13,17 @@ type ConfigArgs struct {
|
|||
key []byte
|
||||
}
|
||||
|
||||
// SetKey sets binary key to configuration parameter.
|
||||
func (c *ConfigArgs) SetKey(v []byte) {
|
||||
c.key = v
|
||||
}
|
||||
|
||||
// ConfigValues groups the stack parameters
|
||||
// returned by get config test invoke.
|
||||
type ConfigValues struct {
|
||||
val interface{}
|
||||
}
|
||||
|
||||
// SetKey sets binary key to configuration parameter.
|
||||
func (c *ConfigArgs) SetKey(v []byte) {
|
||||
c.key = v
|
||||
}
|
||||
|
||||
// Value returns configuration value.
|
||||
func (c ConfigValues) Value() interface{} {
|
||||
return c.val
|
||||
|
@ -58,12 +58,37 @@ func (c *Client) Config(args ConfigArgs, assert func(stackitem.Item) (interface{
|
|||
}, nil
|
||||
}
|
||||
|
||||
// SetConfigPrm groups parameters of SetConfig operation.
|
||||
type SetConfigPrm struct {
|
||||
id []byte
|
||||
key []byte
|
||||
value interface{}
|
||||
|
||||
client.InvokePrmOptional
|
||||
}
|
||||
|
||||
// SetID sets ID of the config value.
|
||||
func (s *SetConfigPrm) SetID(id []byte) {
|
||||
s.id = id
|
||||
}
|
||||
|
||||
// SetKey sets key of the config value.
|
||||
func (s *SetConfigPrm) SetKey(key []byte) {
|
||||
s.key = key
|
||||
}
|
||||
|
||||
// SetValue sets value of the config value.
|
||||
func (s *SetConfigPrm) SetValue(value interface{}) {
|
||||
s.value = value
|
||||
}
|
||||
|
||||
// SetConfig invokes `setConfig` method of NeoFS Netmap contract.
|
||||
func (c *Client) SetConfig(id, key []byte, value interface{}) error {
|
||||
func (c *Client) SetConfig(args SetConfigPrm) error {
|
||||
prm := client.InvokePrm{}
|
||||
|
||||
prm.SetMethod(c.setConfigMethod)
|
||||
prm.SetArgs(id, key, value)
|
||||
prm.SetArgs(args.id, args.key, args.value)
|
||||
prm.InvokePrmOptional = args.InvokePrmOptional
|
||||
|
||||
return c.client.Invoke(prm)
|
||||
}
|
||||
|
@ -120,7 +145,7 @@ func (x ListConfigValues) IterateRecords(f func(key, value []byte) error) error
|
|||
}
|
||||
|
||||
// ListConfig performs the test invoke of config listing method of NeoFS Netmap contract.
|
||||
func (c *Client) ListConfig(args ListConfigArgs) (*ListConfigValues, error) {
|
||||
func (c *Client) ListConfig(_ ListConfigArgs) (*ListConfigValues, error) {
|
||||
prm := client.TestInvokePrm{}
|
||||
|
||||
prm.SetMethod(c.configListMethod)
|
||||
|
|
|
@ -8,8 +8,7 @@ import (
|
|||
|
||||
// EpochArgs groups the arguments
|
||||
// of get epoch number test invoke call.
|
||||
type EpochArgs struct {
|
||||
}
|
||||
type EpochArgs struct{}
|
||||
|
||||
// EpochValues groups the stack parameters
|
||||
// returned by get epoch number test invoke.
|
||||
|
@ -22,22 +21,6 @@ func (e EpochValues) Number() int64 {
|
|||
return e.num
|
||||
}
|
||||
|
||||
// EpochBlockArgs groups the arguments of
|
||||
// get epoch block number test invoke call.
|
||||
type EpochBlockArgs struct {
|
||||
}
|
||||
|
||||
// EpochBlockValues groups the stack parameters
|
||||
// returned by get epoch block number test invoke.
|
||||
type EpochBlockValues struct {
|
||||
block int64
|
||||
}
|
||||
|
||||
// Block return the block number of NeoFS epoch.
|
||||
func (e EpochBlockValues) Block() int64 {
|
||||
return e.block
|
||||
}
|
||||
|
||||
// Epoch performs the test invoke of get epoch number
|
||||
// method of NeoFS Netmap contract.
|
||||
func (c *Client) Epoch(_ EpochArgs) (*EpochValues, error) {
|
||||
|
@ -65,6 +48,21 @@ func (c *Client) Epoch(_ EpochArgs) (*EpochValues, error) {
|
|||
}, nil
|
||||
}
|
||||
|
||||
// EpochBlockArgs groups the arguments of
|
||||
// get epoch block number test invoke call.
|
||||
type EpochBlockArgs struct{}
|
||||
|
||||
// EpochBlockValues groups the stack parameters
|
||||
// returned by get epoch block number test invoke.
|
||||
type EpochBlockValues struct {
|
||||
block int64
|
||||
}
|
||||
|
||||
// Block return the block number of NeoFS epoch.
|
||||
func (e EpochBlockValues) Block() int64 {
|
||||
return e.block
|
||||
}
|
||||
|
||||
// LastEpochBlock performs the test invoke of get epoch block number
|
||||
// method of NeoFS Netmap contract.
|
||||
func (c *Client) LastEpochBlock(_ EpochBlockArgs) (*EpochBlockValues, error) {
|
||||
|
|
|
@ -9,17 +9,32 @@ import (
|
|||
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
|
||||
)
|
||||
|
||||
// UpdateIRPrm groups parameters of UpdateInnerRing
|
||||
// invocation.
|
||||
type UpdateIRPrm struct {
|
||||
keys keys.PublicKeys
|
||||
|
||||
client.InvokePrmOptional
|
||||
}
|
||||
|
||||
// SetKeys sets new inner ring keys.
|
||||
func (u *UpdateIRPrm) SetKeys(keys keys.PublicKeys) {
|
||||
u.keys = keys
|
||||
}
|
||||
|
||||
// UpdateInnerRing updates inner ring members in netmap contract.
|
||||
func (c *Client) UpdateInnerRing(keys keys.PublicKeys) error {
|
||||
args := make([][]byte, len(keys))
|
||||
func (c *Client) UpdateInnerRing(p UpdateIRPrm) error {
|
||||
args := make([][]byte, len(p.keys))
|
||||
|
||||
for i := range args {
|
||||
args[i] = keys[i].Bytes()
|
||||
args[i] = p.keys[i].Bytes()
|
||||
}
|
||||
|
||||
prm := client.InvokePrm{}
|
||||
|
||||
prm.SetMethod(c.updateInnerRing)
|
||||
prm.SetArgs(args)
|
||||
prm.InvokePrmOptional = p.InvokePrmOptional
|
||||
|
||||
return c.client.Invoke(prm)
|
||||
}
|
||||
|
|
|
@ -7,50 +7,12 @@ import (
|
|||
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
|
||||
)
|
||||
|
||||
// GetNetMapArgs groups the arguments
|
||||
// of get network map test invoke call.
|
||||
type GetNetMapArgs struct {
|
||||
}
|
||||
|
||||
// GetSnapshotArgs groups the arguments
|
||||
// of get netmap snapshot test invoke call.
|
||||
type GetSnapshotArgs struct {
|
||||
diff uint64
|
||||
}
|
||||
|
||||
// GetNetMapValues groups the stack parameters
|
||||
// returned by get network map test invoke.
|
||||
type GetNetMapValues struct {
|
||||
peers [][]byte
|
||||
}
|
||||
|
||||
// EpochSnapshotArgs groups the arguments
|
||||
// of snapshot by epoch test invoke call.
|
||||
type EpochSnapshotArgs struct {
|
||||
epoch uint64
|
||||
}
|
||||
|
||||
// EpochSnapshotValues groups the stack parameters
|
||||
// returned by snapshot by epoch test invoke.
|
||||
type EpochSnapshotValues struct {
|
||||
*GetNetMapValues
|
||||
}
|
||||
|
||||
// GetNetMapCandidatesArgs groups the arguments
|
||||
// of get network map candidates test invoke call.
|
||||
type GetNetMapCandidatesArgs struct {
|
||||
}
|
||||
|
||||
// GetNetMapCandidatesValues groups the stack parameters
|
||||
// returned by get network map candidates test invoke.
|
||||
type GetNetMapCandidatesValues struct {
|
||||
netmapNodes []*PeerWithState
|
||||
}
|
||||
|
||||
func (g GetNetMapCandidatesValues) NetmapNodes() []*PeerWithState {
|
||||
return g.netmapNodes
|
||||
}
|
||||
|
||||
// State is an enumeration of various states of the NeoFS node.
|
||||
type State int64
|
||||
|
||||
|
@ -86,23 +48,16 @@ const (
|
|||
peerWithStateFixedPrmNumber = 2
|
||||
)
|
||||
|
||||
// SetDiff sets argument for snapshot method of
|
||||
// netmap contract.
|
||||
func (g *GetSnapshotArgs) SetDiff(d uint64) {
|
||||
g.diff = d
|
||||
}
|
||||
|
||||
// SetEpoch sets epoch number to get snapshot.
|
||||
func (a *EpochSnapshotArgs) SetEpoch(d uint64) {
|
||||
a.epoch = d
|
||||
}
|
||||
|
||||
// Peers return the list of peers from
|
||||
// network map in a binary format.
|
||||
func (g GetNetMapValues) Peers() [][]byte {
|
||||
return g.peers
|
||||
}
|
||||
|
||||
// GetNetMapArgs groups the arguments
|
||||
// of get network map test invoke call.
|
||||
type GetNetMapArgs struct{}
|
||||
|
||||
// NetMap performs the test invoke of get network map
|
||||
// method of NeoFS Netmap contract.
|
||||
func (c *Client) NetMap(_ GetNetMapArgs) (*GetNetMapValues, error) {
|
||||
|
@ -118,6 +73,18 @@ func (c *Client) NetMap(_ GetNetMapArgs) (*GetNetMapValues, error) {
|
|||
return peersFromStackItems(prms, c.netMapMethod)
|
||||
}
|
||||
|
||||
// GetSnapshotArgs groups the arguments
|
||||
// of get netmap snapshot test invoke call.
|
||||
type GetSnapshotArgs struct {
|
||||
diff uint64
|
||||
}
|
||||
|
||||
// SetDiff sets argument for snapshot method of
|
||||
// netmap contract.
|
||||
func (g *GetSnapshotArgs) SetDiff(d uint64) {
|
||||
g.diff = d
|
||||
}
|
||||
|
||||
// Snapshot performs the test invoke of get snapshot of network map
|
||||
// from NeoFS Netmap contract. Contract saves only one previous epoch,
|
||||
// so all invokes with diff > 1 return error.
|
||||
|
@ -136,6 +103,23 @@ func (c *Client) Snapshot(a GetSnapshotArgs) (*GetNetMapValues, error) {
|
|||
return peersFromStackItems(prms, c.snapshotMethod)
|
||||
}
|
||||
|
||||
// EpochSnapshotArgs groups the arguments
|
||||
// of snapshot by epoch test invoke call.
|
||||
type EpochSnapshotArgs struct {
|
||||
epoch uint64
|
||||
}
|
||||
|
||||
// SetEpoch sets epoch number to get snapshot.
|
||||
func (a *EpochSnapshotArgs) SetEpoch(d uint64) {
|
||||
a.epoch = d
|
||||
}
|
||||
|
||||
// EpochSnapshotValues groups the stack parameters
|
||||
// returned by snapshot by epoch test invoke.
|
||||
type EpochSnapshotValues struct {
|
||||
*GetNetMapValues
|
||||
}
|
||||
|
||||
// EpochSnapshot performs the test invoke of get snapshot of network map by epoch
|
||||
// from NeoFS Netmap contract.
|
||||
func (c *Client) EpochSnapshot(args EpochSnapshotArgs) (*EpochSnapshotValues, error) {
|
||||
|
@ -160,6 +144,20 @@ func (c *Client) EpochSnapshot(args EpochSnapshotArgs) (*EpochSnapshotValues, er
|
|||
}, nil
|
||||
}
|
||||
|
||||
// GetNetMapCandidatesArgs groups the arguments
|
||||
// of get network map candidates test invoke call.
|
||||
type GetNetMapCandidatesArgs struct{}
|
||||
|
||||
// GetNetMapCandidatesValues groups the stack parameters
|
||||
// returned by get network map candidates test invoke.
|
||||
type GetNetMapCandidatesValues struct {
|
||||
netmapNodes []*PeerWithState
|
||||
}
|
||||
|
||||
func (g GetNetMapCandidatesValues) NetmapNodes() []*PeerWithState {
|
||||
return g.netmapNodes
|
||||
}
|
||||
|
||||
func (c *Client) Candidates(_ GetNetMapCandidatesArgs) (*GetNetMapCandidatesValues, error) {
|
||||
invokePrm := client.TestInvokePrm{}
|
||||
invokePrm.SetMethod(c.netMapCandidatesMethod)
|
||||
|
|
|
@ -10,6 +10,8 @@ import (
|
|||
// of new epoch invocation call.
|
||||
type NewEpochArgs struct {
|
||||
number int64 // new epoch number
|
||||
|
||||
client.InvokePrmOptional
|
||||
}
|
||||
|
||||
// SetEpochNumber sets the new epoch number.
|
||||
|
@ -24,6 +26,7 @@ func (c *Client) NewEpoch(args NewEpochArgs) error {
|
|||
|
||||
prm.SetMethod(c.newEpochMethod)
|
||||
prm.SetArgs(args.number)
|
||||
prm.InvokePrmOptional = args.InvokePrmOptional
|
||||
|
||||
if err := c.client.Invoke(prm); err != nil {
|
||||
return fmt.Errorf("could not invoke method (%s): %w", c.newEpochMethod, err)
|
||||
|
|
|
@ -12,6 +12,8 @@ type UpdateStateArgs struct {
|
|||
key []byte // peer public key
|
||||
|
||||
state int64 // new peer state
|
||||
|
||||
client.InvokePrmOptional
|
||||
}
|
||||
|
||||
// SetPublicKey sets peer public key
|
||||
|
@ -32,9 +34,9 @@ func (c *Client) UpdateState(args UpdateStateArgs) error {
|
|||
|
||||
prm.SetMethod(c.updateStateMethod)
|
||||
prm.SetArgs(args.state, args.key)
|
||||
prm.InvokePrmOptional = args.InvokePrmOptional
|
||||
|
||||
err := c.client.Invoke(prm)
|
||||
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not invoke method (%s): %w", c.updateStateMethod, err)
|
||||
}
|
||||
|
|
|
@ -4,23 +4,37 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap"
|
||||
)
|
||||
|
||||
// AddPeerPrm groups parameters of AddPeer operation.
|
||||
type AddPeerPrm struct {
|
||||
nodeInfo *netmap.NodeInfo
|
||||
|
||||
client.InvokePrmOptional
|
||||
}
|
||||
|
||||
// SetNodeInfo sets new peer NodeInfo.
|
||||
func (a *AddPeerPrm) SetNodeInfo(nodeInfo *netmap.NodeInfo) {
|
||||
a.nodeInfo = nodeInfo
|
||||
}
|
||||
|
||||
// AddPeer registers peer in NeoFS network through
|
||||
// Netmap contract call.
|
||||
func (w *Wrapper) AddPeer(nodeInfo *netmap.NodeInfo) error {
|
||||
if nodeInfo == nil {
|
||||
func (w *Wrapper) AddPeer(prm AddPeerPrm) error {
|
||||
if prm.nodeInfo == nil {
|
||||
return errors.New("nil node info")
|
||||
}
|
||||
|
||||
rawNodeInfo, err := nodeInfo.Marshal()
|
||||
rawNodeInfo, err := prm.nodeInfo.Marshal()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
args := netmap.AddPeerArgs{}
|
||||
args.SetInfo(rawNodeInfo)
|
||||
args.InvokePrmOptional = prm.InvokePrmOptional
|
||||
|
||||
if err := w.client.AddPeer(args); err != nil {
|
||||
return fmt.Errorf("could not invoke smart contract: %w", err)
|
||||
|
|
|
@ -4,6 +4,8 @@ import (
|
|||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
|
||||
|
||||
"github.com/nspcc-dev/neo-go/pkg/encoding/bigint"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap"
|
||||
)
|
||||
|
@ -168,9 +170,40 @@ func (w *Wrapper) readStringConfig(key string) (string, error) {
|
|||
return str, nil
|
||||
}
|
||||
|
||||
// SetConfigPrm groups parameters of SetConfig operation.
|
||||
type SetConfigPrm struct {
|
||||
id []byte
|
||||
key []byte
|
||||
value interface{}
|
||||
|
||||
client.InvokePrmOptional
|
||||
}
|
||||
|
||||
// SetID sets ID of the config value.
|
||||
func (s *SetConfigPrm) SetID(id []byte) {
|
||||
s.id = id
|
||||
}
|
||||
|
||||
// SetKey sets key of the config value.
|
||||
func (s *SetConfigPrm) SetKey(key []byte) {
|
||||
s.key = key
|
||||
}
|
||||
|
||||
// SetValue sets value of the config value.
|
||||
func (s *SetConfigPrm) SetValue(value interface{}) {
|
||||
s.value = value
|
||||
}
|
||||
|
||||
// SetConfig sets config field.
|
||||
func (w *Wrapper) SetConfig(id, key []byte, value interface{}) error {
|
||||
return w.client.SetConfig(id, key, value)
|
||||
func (w *Wrapper) SetConfig(prm SetConfigPrm) error {
|
||||
args := netmap.SetConfigPrm{}
|
||||
|
||||
args.SetID(prm.id)
|
||||
args.SetKey(prm.key)
|
||||
args.SetValue(prm.value)
|
||||
args.InvokePrmOptional = prm.InvokePrmOptional
|
||||
|
||||
return w.client.SetConfig(args)
|
||||
}
|
||||
|
||||
// IterateConfigParameters iterates over configuration parameters stored in Netmap contract and passes them to f.
|
||||
|
|
|
@ -1,10 +1,32 @@
|
|||
package wrapper
|
||||
|
||||
import "github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||
import (
|
||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap"
|
||||
)
|
||||
|
||||
// UpdateIRPrm groups parameters of UpdateInnerRing
|
||||
// invocation.
|
||||
type UpdateIRPrm struct {
|
||||
keys keys.PublicKeys
|
||||
|
||||
client.InvokePrmOptional
|
||||
}
|
||||
|
||||
// SetKeys sets new inner ring keys.
|
||||
func (u *UpdateIRPrm) SetKeys(keys keys.PublicKeys) {
|
||||
u.keys = keys
|
||||
}
|
||||
|
||||
// UpdateInnerRing updates inner ring keys.
|
||||
func (w *Wrapper) UpdateInnerRing(keys keys.PublicKeys) error {
|
||||
return w.client.UpdateInnerRing(keys)
|
||||
func (w *Wrapper) UpdateInnerRing(prm UpdateIRPrm) error {
|
||||
args := netmap.UpdateIRPrm{}
|
||||
|
||||
args.SetKeys(prm.keys)
|
||||
args.InvokePrmOptional = prm.InvokePrmOptional
|
||||
|
||||
return w.client.UpdateInnerRing(args)
|
||||
}
|
||||
|
||||
// GetInnerRingList return current IR list.
|
||||
|
|
|
@ -3,16 +3,37 @@ package wrapper
|
|||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
|
||||
contract "github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap"
|
||||
"github.com/nspcc-dev/neofs-sdk-go/netmap"
|
||||
)
|
||||
|
||||
// UpdatePeerPrm groups parameters of UpdatePeerState operation.
|
||||
type UpdatePeerPrm struct {
|
||||
key []byte
|
||||
state netmap.NodeState
|
||||
|
||||
client.InvokePrmOptional
|
||||
}
|
||||
|
||||
// SetKey sets public key.
|
||||
func (u *UpdatePeerPrm) SetKey(key []byte) {
|
||||
u.key = key
|
||||
}
|
||||
|
||||
// SetState sets node state.
|
||||
func (u *UpdatePeerPrm) SetState(state netmap.NodeState) {
|
||||
u.state = state
|
||||
}
|
||||
|
||||
// UpdatePeerState changes peer status through Netmap contract
|
||||
// call.
|
||||
func (w *Wrapper) UpdatePeerState(key []byte, state netmap.NodeState) error {
|
||||
func (w *Wrapper) UpdatePeerState(prm UpdatePeerPrm) error {
|
||||
args := contract.UpdateStateArgs{}
|
||||
args.SetPublicKey(key)
|
||||
args.SetState(int64(state.ToV2()))
|
||||
|
||||
args.SetPublicKey(prm.key)
|
||||
args.SetState(int64(prm.state.ToV2()))
|
||||
args.InvokePrmOptional = prm.InvokePrmOptional
|
||||
|
||||
// invoke smart contract call
|
||||
if err := w.client.UpdateState(args); err != nil {
|
||||
|
|
Loading…
Reference in a new issue