forked from TrueCloudLab/frostfs-node
[#833] services/netmap: Support new fields of netmap.NetworkInfo
Make the implementation of network info source (Netmap V2 service dependency) to read MillisecondsPerBlock sidechain parameter and NeoFS network parameters depending on the client version. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
7582689de4
commit
283ccc04b4
2 changed files with 48 additions and 8 deletions
|
@ -3,10 +3,12 @@ package main
|
|||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
netmapSDK "github.com/nspcc-dev/neofs-api-go/pkg/netmap"
|
||||
netmapV2 "github.com/nspcc-dev/neofs-api-go/v2/netmap"
|
||||
netmapGRPC "github.com/nspcc-dev/neofs-api-go/v2/netmap/grpc"
|
||||
"github.com/nspcc-dev/neofs-api-go/v2/refs"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/core/netmap"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
|
||||
netmapEvent "github.com/nspcc-dev/neofs-node/pkg/morph/event/netmap"
|
||||
|
@ -96,8 +98,10 @@ func initNetmapService(c *cfg) {
|
|||
c,
|
||||
c.apiVersion,
|
||||
&netInfo{
|
||||
netState: c.cfgNetmap.state,
|
||||
magic: c.cfgMorph.client,
|
||||
netState: c.cfgNetmap.state,
|
||||
magic: c.cfgMorph.client,
|
||||
netCfg: c.cfgNetmap.wrapper.IterateConfigParameters,
|
||||
msPerBlockRdr: c.cfgMorph.client.MsPerBlock,
|
||||
},
|
||||
),
|
||||
c.respSvc,
|
||||
|
@ -274,9 +278,13 @@ type netInfo struct {
|
|||
magic interface {
|
||||
MagicNumber() (uint64, error)
|
||||
}
|
||||
|
||||
netCfg func(func(key, value []byte) error) error
|
||||
|
||||
msPerBlockRdr func() (int64, error)
|
||||
}
|
||||
|
||||
func (n *netInfo) Dump() (*netmapV2.NetworkInfo, error) {
|
||||
func (n *netInfo) Dump(ver *refs.Version) (*netmapV2.NetworkInfo, error) {
|
||||
magic, err := n.magic.MagicNumber()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -286,5 +294,35 @@ func (n *netInfo) Dump() (*netmapV2.NetworkInfo, error) {
|
|||
ni.SetCurrentEpoch(n.netState.CurrentEpoch())
|
||||
ni.SetMagicNumber(magic)
|
||||
|
||||
if mjr := ver.GetMajor(); mjr > 2 || mjr == 2 && ver.GetMinor() > 9 {
|
||||
msPerBlock, err := n.msPerBlockRdr()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("ms per block: %w", err)
|
||||
}
|
||||
|
||||
var (
|
||||
ps []*netmapV2.NetworkParameter
|
||||
netCfg netmapV2.NetworkConfig
|
||||
)
|
||||
|
||||
if err := n.netCfg(func(key, value []byte) error {
|
||||
var p netmapV2.NetworkParameter
|
||||
|
||||
p.SetKey(key)
|
||||
p.SetValue(value)
|
||||
|
||||
ps = append(ps, &p)
|
||||
|
||||
return nil
|
||||
}); err != nil {
|
||||
return nil, fmt.Errorf("network config: %w", err)
|
||||
}
|
||||
|
||||
netCfg.SetParameters(ps...)
|
||||
|
||||
ni.SetNetworkConfig(&netCfg)
|
||||
ni.SetMsPerBlock(msPerBlock)
|
||||
}
|
||||
|
||||
return ni, nil
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg"
|
||||
"github.com/nspcc-dev/neofs-api-go/v2/netmap"
|
||||
"github.com/nspcc-dev/neofs-api-go/v2/refs"
|
||||
)
|
||||
|
||||
type executorSvc struct {
|
||||
|
@ -25,9 +26,10 @@ type NodeState interface {
|
|||
// NetworkInfo encapsulates source of the
|
||||
// recent information about the NeoFS network.
|
||||
type NetworkInfo interface {
|
||||
// Must return recent network information.
|
||||
// in NeoFS API v2 NetworkInfo structure.
|
||||
Dump() (*netmap.NetworkInfo, error)
|
||||
// Must return recent network information in NeoFS API v2 NetworkInfo structure.
|
||||
//
|
||||
// If protocol version is <=2.9, MillisecondsPerBlock and network config should be unset.
|
||||
Dump(*refs.Version) (*netmap.NetworkInfo, error)
|
||||
}
|
||||
|
||||
func NewExecutionService(s NodeState, v *pkg.Version, netInfo NetworkInfo) Server {
|
||||
|
@ -78,8 +80,8 @@ func (s *executorSvc) LocalNodeInfo(
|
|||
|
||||
func (s *executorSvc) NetworkInfo(
|
||||
_ context.Context,
|
||||
_ *netmap.NetworkInfoRequest) (*netmap.NetworkInfoResponse, error) {
|
||||
ni, err := s.netInfo.Dump()
|
||||
req *netmap.NetworkInfoRequest) (*netmap.NetworkInfoResponse, error) {
|
||||
ni, err := s.netInfo.Dump(req.GetMetaHeader().GetVersion())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue