2020-10-08 13:17:50 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2021-01-15 10:02:59 +00:00
|
|
|
"bytes"
|
2021-08-24 07:43:21 +00:00
|
|
|
"errors"
|
2021-09-20 16:13:17 +00:00
|
|
|
"fmt"
|
2021-01-15 10:02:59 +00:00
|
|
|
|
2020-10-08 13:17:50 +00:00
|
|
|
netmapGRPC "github.com/nspcc-dev/neofs-api-go/v2/netmap/grpc"
|
2021-11-28 12:06:07 +00:00
|
|
|
nodeconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/node"
|
2021-02-19 08:01:37 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/core/netmap"
|
2021-12-28 10:39:42 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/metrics"
|
2022-01-31 11:58:55 +00:00
|
|
|
nmClient "github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap"
|
2020-10-21 09:26:16 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
|
2020-10-21 15:12:31 +00:00
|
|
|
netmapEvent "github.com/nspcc-dev/neofs-node/pkg/morph/event/netmap"
|
2021-06-23 09:50:40 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/network"
|
2020-10-08 13:17:50 +00:00
|
|
|
netmapTransportGRPC "github.com/nspcc-dev/neofs-node/pkg/network/transport/netmap/grpc"
|
2021-01-13 13:46:39 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/services/control"
|
2020-10-08 13:17:50 +00:00
|
|
|
netmapService "github.com/nspcc-dev/neofs-node/pkg/services/netmap"
|
2021-11-10 07:08:33 +00:00
|
|
|
netmapSDK "github.com/nspcc-dev/neofs-sdk-go/netmap"
|
2021-11-28 12:06:07 +00:00
|
|
|
subnetid "github.com/nspcc-dev/neofs-sdk-go/subnet/id"
|
2022-06-08 23:18:26 +00:00
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/version"
|
2020-10-21 15:12:31 +00:00
|
|
|
"go.uber.org/atomic"
|
2020-10-21 16:26:38 +00:00
|
|
|
"go.uber.org/zap"
|
2020-10-08 13:17:50 +00:00
|
|
|
)
|
|
|
|
|
2020-10-21 15:12:31 +00:00
|
|
|
// primary solution of local network state dump.
|
|
|
|
type networkState struct {
|
|
|
|
epoch *atomic.Uint64
|
2021-06-11 10:55:11 +00:00
|
|
|
|
|
|
|
controlNetStatus atomic.Value // control.NetmapStatus
|
|
|
|
|
|
|
|
nodeInfo atomic.Value // *netmapSDK.NodeInfo
|
2021-12-28 10:39:42 +00:00
|
|
|
|
2022-07-19 15:16:42 +00:00
|
|
|
metrics *metrics.NodeMetrics
|
2020-10-21 15:12:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func newNetworkState() *networkState {
|
2022-10-10 19:10:49 +00:00
|
|
|
var nmStatus atomic.Value
|
|
|
|
nmStatus.Store(control.NetmapStatus_STATUS_UNDEFINED)
|
|
|
|
|
2020-10-21 15:12:31 +00:00
|
|
|
return &networkState{
|
2022-10-10 19:10:49 +00:00
|
|
|
epoch: atomic.NewUint64(0),
|
|
|
|
controlNetStatus: nmStatus,
|
2020-10-21 15:12:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *networkState) CurrentEpoch() uint64 {
|
|
|
|
return s.epoch.Load()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *networkState) setCurrentEpoch(v uint64) {
|
|
|
|
s.epoch.Store(v)
|
2021-12-28 10:39:42 +00:00
|
|
|
if s.metrics != nil {
|
|
|
|
s.metrics.SetEpoch(v)
|
|
|
|
}
|
2020-10-21 15:12:31 +00:00
|
|
|
}
|
|
|
|
|
2021-06-11 10:55:11 +00:00
|
|
|
func (s *networkState) setNodeInfo(ni *netmapSDK.NodeInfo) {
|
2022-06-08 23:18:26 +00:00
|
|
|
ctrlNetSt := control.NetmapStatus_STATUS_UNDEFINED
|
2021-06-11 10:55:11 +00:00
|
|
|
|
2022-06-08 23:18:26 +00:00
|
|
|
if ni != nil {
|
|
|
|
s.nodeInfo.Store(*ni)
|
2021-06-11 10:55:11 +00:00
|
|
|
|
2022-06-08 23:18:26 +00:00
|
|
|
switch {
|
|
|
|
case ni.IsOnline():
|
|
|
|
ctrlNetSt = control.NetmapStatus_ONLINE
|
|
|
|
case ni.IsOffline():
|
|
|
|
ctrlNetSt = control.NetmapStatus_OFFLINE
|
2022-10-14 08:33:52 +00:00
|
|
|
case ni.IsMaintenance():
|
|
|
|
ctrlNetSt = control.NetmapStatus_MAINTENANCE
|
2022-06-08 23:18:26 +00:00
|
|
|
}
|
|
|
|
} else {
|
2021-06-11 10:55:11 +00:00
|
|
|
ctrlNetSt = control.NetmapStatus_OFFLINE
|
2022-10-10 20:04:00 +00:00
|
|
|
|
|
|
|
niRaw := s.nodeInfo.Load()
|
|
|
|
if niRaw != nil {
|
|
|
|
niOld := niRaw.(netmapSDK.NodeInfo)
|
|
|
|
|
|
|
|
// nil ni means that the node is not included
|
|
|
|
// in the netmap
|
|
|
|
niOld.SetOffline()
|
|
|
|
|
|
|
|
s.nodeInfo.Store(niOld)
|
|
|
|
}
|
2021-06-11 10:55:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
s.controlNetStatus.Store(ctrlNetSt)
|
|
|
|
}
|
|
|
|
|
2022-10-10 19:10:49 +00:00
|
|
|
func (s *networkState) controlNetmapStatus() (res control.NetmapStatus) {
|
2021-06-11 10:55:11 +00:00
|
|
|
return s.controlNetStatus.Load().(control.NetmapStatus)
|
|
|
|
}
|
2020-10-08 13:17:50 +00:00
|
|
|
|
2022-06-08 23:18:26 +00:00
|
|
|
func (s *networkState) getNodeInfo() (res netmapSDK.NodeInfo, ok bool) {
|
|
|
|
v := s.nodeInfo.Load()
|
|
|
|
if v != nil {
|
|
|
|
res, ok = v.(netmapSDK.NodeInfo)
|
|
|
|
if !ok {
|
|
|
|
panic(fmt.Sprintf("unexpected value in atomic node info state: %T", v))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
2021-06-11 10:55:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func nodeKeyFromNetmap(c *cfg) []byte {
|
2022-06-08 23:18:26 +00:00
|
|
|
ni, ok := c.cfgNetmap.state.getNodeInfo()
|
|
|
|
if ok {
|
|
|
|
return ni.PublicKey()
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
2021-06-11 10:55:11 +00:00
|
|
|
}
|
|
|
|
|
2021-06-22 16:00:00 +00:00
|
|
|
func (c *cfg) iterateNetworkAddresses(f func(string) bool) {
|
2022-06-08 23:18:26 +00:00
|
|
|
ni, ok := c.cfgNetmap.state.getNodeInfo()
|
|
|
|
if ok {
|
|
|
|
ni.IterateNetworkEndpoints(f)
|
|
|
|
}
|
2021-06-22 16:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *cfg) addressNum() int {
|
2022-06-08 23:18:26 +00:00
|
|
|
ni, ok := c.cfgNetmap.state.getNodeInfo()
|
|
|
|
if ok {
|
|
|
|
return ni.NumberOfNetworkEndpoints()
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0
|
2021-06-11 10:55:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func initNetmapService(c *cfg) {
|
2021-06-23 09:50:40 +00:00
|
|
|
network.WriteToNodeInfo(c.localAddr, &c.cfgNodeInfo.localInfo)
|
2021-05-31 08:55:38 +00:00
|
|
|
c.cfgNodeInfo.localInfo.SetPublicKey(c.key.PublicKey().Bytes())
|
2022-06-08 23:18:26 +00:00
|
|
|
parseAttributes(c)
|
|
|
|
c.cfgNodeInfo.localInfo.SetOffline()
|
2020-10-08 13:17:50 +00:00
|
|
|
|
2021-11-28 12:06:07 +00:00
|
|
|
readSubnetCfg(c)
|
|
|
|
|
2021-02-19 08:01:37 +00:00
|
|
|
if c.cfgMorph.client == nil {
|
|
|
|
initMorphComponents(c)
|
|
|
|
}
|
|
|
|
|
2021-10-20 14:28:37 +00:00
|
|
|
initNetmapState(c)
|
|
|
|
|
2021-06-22 17:25:18 +00:00
|
|
|
server := netmapTransportGRPC.New(
|
|
|
|
netmapService.NewSignService(
|
|
|
|
&c.key.PrivateKey,
|
|
|
|
netmapService.NewResponseService(
|
|
|
|
netmapService.NewExecutionService(
|
|
|
|
c,
|
|
|
|
c.apiVersion,
|
|
|
|
&netInfo{
|
2022-06-08 23:18:26 +00:00
|
|
|
netState: c.cfgNetmap.state,
|
|
|
|
magic: c.cfgMorph.client,
|
|
|
|
morphClientNetMap: c.cfgNetmap.wrapper,
|
|
|
|
msPerBlockRdr: c.cfgMorph.client.MsPerBlock,
|
2021-06-22 17:25:18 +00:00
|
|
|
},
|
2020-10-08 13:17:50 +00:00
|
|
|
),
|
2021-06-22 17:25:18 +00:00
|
|
|
c.respSvc,
|
2020-10-08 13:17:50 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|
2020-10-21 15:12:31 +00:00
|
|
|
|
2021-06-22 17:25:18 +00:00
|
|
|
for _, srv := range c.cfgGRPC.servers {
|
|
|
|
netmapGRPC.RegisterNetmapServiceServer(srv, server)
|
|
|
|
}
|
|
|
|
|
2020-10-21 15:12:31 +00:00
|
|
|
addNewEpochNotificationHandler(c, func(ev event.Event) {
|
|
|
|
c.cfgNetmap.state.setCurrentEpoch(ev.(netmapEvent.NewEpoch).EpochNumber())
|
|
|
|
})
|
2020-10-30 12:57:49 +00:00
|
|
|
|
2021-05-12 09:27:12 +00:00
|
|
|
addNewEpochAsyncNotificationHandler(c, func(ev event.Event) {
|
2021-08-24 07:43:21 +00:00
|
|
|
if !c.needBootstrap() || c.cfgNetmap.reBoostrapTurnedOff.Load() { // fixes #470
|
2021-05-12 09:27:12 +00:00
|
|
|
return
|
|
|
|
}
|
2021-04-21 13:26:04 +00:00
|
|
|
|
2021-05-12 09:27:12 +00:00
|
|
|
n := ev.(netmapEvent.NewEpoch).EpochNumber()
|
2020-10-30 12:57:49 +00:00
|
|
|
|
2021-05-12 09:27:12 +00:00
|
|
|
const reBootstrapInterval = 2
|
|
|
|
|
|
|
|
if (n-c.cfgNetmap.startEpoch)%reBootstrapInterval == 0 {
|
2022-10-28 07:02:55 +00:00
|
|
|
err := c.bootstrap()
|
2021-05-12 09:27:12 +00:00
|
|
|
if err != nil {
|
|
|
|
c.log.Warn("can't send re-bootstrap tx", zap.Error(err))
|
2020-10-30 12:57:49 +00:00
|
|
|
}
|
2021-05-12 09:27:12 +00:00
|
|
|
}
|
|
|
|
})
|
2021-01-15 10:02:59 +00:00
|
|
|
|
2021-04-15 10:24:43 +00:00
|
|
|
addNewEpochAsyncNotificationHandler(c, func(ev event.Event) {
|
2021-01-15 10:02:59 +00:00
|
|
|
e := ev.(netmapEvent.NewEpoch).EpochNumber()
|
|
|
|
|
2021-01-25 08:23:06 +00:00
|
|
|
ni, err := c.netmapLocalNodeState(e)
|
2021-01-15 10:02:59 +00:00
|
|
|
if err != nil {
|
2021-01-25 08:23:06 +00:00
|
|
|
c.log.Error("could not update node state on new epoch",
|
2021-01-15 10:02:59 +00:00
|
|
|
zap.Uint64("epoch", e),
|
|
|
|
zap.String("error", err.Error()),
|
|
|
|
)
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-01-25 08:23:06 +00:00
|
|
|
c.handleLocalNodeInfo(ni)
|
2021-01-15 10:02:59 +00:00
|
|
|
})
|
2021-09-30 19:11:20 +00:00
|
|
|
|
|
|
|
if c.cfgMorph.notaryEnabled {
|
|
|
|
addNewEpochAsyncNotificationHandler(c, func(ev event.Event) {
|
|
|
|
_, err := makeNotaryDeposit(c)
|
|
|
|
if err != nil {
|
|
|
|
c.log.Error("could not make notary deposit",
|
|
|
|
zap.String("error", err.Error()),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2020-10-08 13:17:50 +00:00
|
|
|
}
|
|
|
|
|
2021-11-28 12:06:07 +00:00
|
|
|
func readSubnetCfg(c *cfg) {
|
|
|
|
var subnetCfg nodeconfig.SubnetConfig
|
|
|
|
|
|
|
|
subnetCfg.Init(*c.appCfg)
|
|
|
|
|
|
|
|
var (
|
|
|
|
id subnetid.ID
|
|
|
|
err error
|
|
|
|
)
|
|
|
|
|
|
|
|
subnetCfg.IterateSubnets(func(idTxt string) {
|
2022-06-15 08:08:10 +00:00
|
|
|
err = id.DecodeString(idTxt)
|
2021-11-28 12:06:07 +00:00
|
|
|
fatalOnErrDetails("parse subnet entry", err)
|
|
|
|
|
|
|
|
c.cfgNodeInfo.localInfo.EnterSubnet(id)
|
|
|
|
})
|
|
|
|
|
|
|
|
if subnetCfg.ExitZero() {
|
|
|
|
subnetid.MakeZero(&id)
|
|
|
|
c.cfgNodeInfo.localInfo.ExitSubnet(id)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-20 14:28:37 +00:00
|
|
|
// bootstrapNode adds current node to the Network map.
|
|
|
|
// Must be called after initNetmapService.
|
2020-10-08 13:17:50 +00:00
|
|
|
func bootstrapNode(c *cfg) {
|
2021-08-24 07:43:21 +00:00
|
|
|
if c.needBootstrap() {
|
2022-10-28 07:02:55 +00:00
|
|
|
err := c.bootstrap()
|
2021-08-24 07:43:21 +00:00
|
|
|
fatalOnErrDetails("bootstrap error", err)
|
|
|
|
}
|
2020-10-08 13:17:50 +00:00
|
|
|
}
|
2020-10-21 09:26:16 +00:00
|
|
|
|
|
|
|
func addNetmapNotificationHandler(c *cfg, sTyp string, h event.Handler) {
|
|
|
|
typ := event.TypeFromString(sTyp)
|
|
|
|
|
|
|
|
if c.cfgNetmap.subscribers == nil {
|
|
|
|
c.cfgNetmap.subscribers = make(map[event.Type][]event.Handler, 1)
|
|
|
|
}
|
|
|
|
|
|
|
|
c.cfgNetmap.subscribers[typ] = append(c.cfgNetmap.subscribers[typ], h)
|
|
|
|
}
|
|
|
|
|
2021-08-12 15:24:17 +00:00
|
|
|
func setNetmapNotificationParser(c *cfg, sTyp string, p event.NotificationParser) {
|
2020-10-21 09:26:16 +00:00
|
|
|
typ := event.TypeFromString(sTyp)
|
|
|
|
|
|
|
|
if c.cfgNetmap.parsers == nil {
|
2021-08-12 15:24:17 +00:00
|
|
|
c.cfgNetmap.parsers = make(map[event.Type]event.NotificationParser, 1)
|
2020-10-21 09:26:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
c.cfgNetmap.parsers[typ] = p
|
|
|
|
}
|
|
|
|
|
2021-10-20 14:28:37 +00:00
|
|
|
// initNetmapState inits current Network map state.
|
|
|
|
// Must be called after Morph components initialization.
|
|
|
|
func initNetmapState(c *cfg) {
|
2020-10-21 16:26:38 +00:00
|
|
|
epoch, err := c.cfgNetmap.wrapper.Epoch()
|
2021-05-31 05:11:23 +00:00
|
|
|
fatalOnErrDetails("could not initialize current epoch number", err)
|
2020-10-21 16:26:38 +00:00
|
|
|
|
2021-01-25 08:23:06 +00:00
|
|
|
ni, err := c.netmapLocalNodeState(epoch)
|
2021-05-31 05:11:23 +00:00
|
|
|
fatalOnErrDetails("could not init network state", err)
|
2021-01-15 10:02:59 +00:00
|
|
|
|
2022-06-08 23:18:26 +00:00
|
|
|
stateWord := "undefined"
|
|
|
|
|
|
|
|
if ni != nil {
|
|
|
|
switch {
|
|
|
|
case ni.IsOnline():
|
|
|
|
stateWord = "online"
|
|
|
|
case ni.IsOffline():
|
|
|
|
stateWord = "offline"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-15 10:02:59 +00:00
|
|
|
c.log.Info("initial network state",
|
|
|
|
zap.Uint64("epoch", epoch),
|
2022-06-08 23:18:26 +00:00
|
|
|
zap.String("state", stateWord),
|
2020-10-21 16:26:38 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
c.cfgNetmap.state.setCurrentEpoch(epoch)
|
2021-05-12 09:27:12 +00:00
|
|
|
c.cfgNetmap.startEpoch = epoch
|
2022-06-08 23:18:26 +00:00
|
|
|
c.handleLocalNodeInfo(ni)
|
2020-10-21 16:26:38 +00:00
|
|
|
}
|
|
|
|
|
2021-02-19 08:01:37 +00:00
|
|
|
func (c *cfg) netmapLocalNodeState(epoch uint64) (*netmapSDK.NodeInfo, error) {
|
2021-01-15 10:02:59 +00:00
|
|
|
// calculate current network state
|
|
|
|
nm, err := c.cfgNetmap.wrapper.GetNetMapByEpoch(epoch)
|
|
|
|
if err != nil {
|
2021-01-25 08:23:06 +00:00
|
|
|
return nil, err
|
2021-01-15 10:02:59 +00:00
|
|
|
}
|
|
|
|
|
2022-09-17 12:37:01 +00:00
|
|
|
c.netMap.Store(*nm)
|
|
|
|
|
2022-06-08 23:18:26 +00:00
|
|
|
nmNodes := nm.Nodes()
|
|
|
|
for i := range nmNodes {
|
2022-06-16 21:45:32 +00:00
|
|
|
if bytes.Equal(nmNodes[i].PublicKey(), c.binPublicKey) {
|
2022-06-08 23:18:26 +00:00
|
|
|
return &nmNodes[i], nil
|
2021-01-15 10:02:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-08 23:18:26 +00:00
|
|
|
return nil, nil
|
2021-01-15 10:02:59 +00:00
|
|
|
}
|
|
|
|
|
2022-10-17 12:03:55 +00:00
|
|
|
// addNewEpochNotificationHandler adds handler that will be executed synchronously.
|
2020-10-21 09:26:16 +00:00
|
|
|
func addNewEpochNotificationHandler(c *cfg, h event.Handler) {
|
|
|
|
addNetmapNotificationHandler(c, newEpochNotification, h)
|
|
|
|
}
|
2021-01-11 11:57:01 +00:00
|
|
|
|
2022-10-17 12:03:55 +00:00
|
|
|
// addNewEpochAsyncNotificationHandler adds handler that will be executed asynchronously via netmap workerPool.
|
2021-04-13 12:53:58 +00:00
|
|
|
func addNewEpochAsyncNotificationHandler(c *cfg, h event.Handler) {
|
|
|
|
addNetmapNotificationHandler(
|
|
|
|
c,
|
|
|
|
newEpochNotification,
|
|
|
|
event.WorkerPoolHandler(
|
|
|
|
c.cfgNetmap.workerPool,
|
|
|
|
h,
|
|
|
|
c.log,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-08-24 07:43:21 +00:00
|
|
|
var errRelayBootstrap = errors.New("setting netmap status is forbidden in relay mode")
|
|
|
|
|
2021-01-15 11:53:41 +00:00
|
|
|
func (c *cfg) SetNetmapStatus(st control.NetmapStatus) error {
|
2022-09-19 12:41:04 +00:00
|
|
|
switch st {
|
|
|
|
default:
|
|
|
|
return fmt.Errorf("unsupported status %v", st)
|
|
|
|
case control.NetmapStatus_MAINTENANCE:
|
2022-10-18 15:42:14 +00:00
|
|
|
return c.setMaintenanceStatus(false)
|
2022-09-19 12:41:04 +00:00
|
|
|
case control.NetmapStatus_ONLINE, control.NetmapStatus_OFFLINE:
|
2021-11-09 15:54:03 +00:00
|
|
|
}
|
|
|
|
|
2022-10-04 13:01:16 +00:00
|
|
|
c.stopMaintenance()
|
2021-11-09 15:54:03 +00:00
|
|
|
|
2021-08-24 07:43:21 +00:00
|
|
|
if !c.needBootstrap() {
|
|
|
|
return errRelayBootstrap
|
|
|
|
}
|
|
|
|
|
2021-01-15 11:53:41 +00:00
|
|
|
if st == control.NetmapStatus_ONLINE {
|
2021-04-21 13:26:04 +00:00
|
|
|
c.cfgNetmap.reBoostrapTurnedOff.Store(false)
|
2022-10-28 07:02:55 +00:00
|
|
|
return bootstrapOnline(c)
|
2021-01-15 11:53:41 +00:00
|
|
|
}
|
|
|
|
|
2021-04-21 13:26:04 +00:00
|
|
|
c.cfgNetmap.reBoostrapTurnedOff.Store(true)
|
|
|
|
|
2022-09-19 16:59:23 +00:00
|
|
|
return c.updateNetMapState(func(*nmClient.UpdatePeerPrm) {})
|
|
|
|
}
|
2021-11-10 11:05:51 +00:00
|
|
|
|
2022-10-18 15:42:14 +00:00
|
|
|
func (c *cfg) ForceMaintenance() error {
|
|
|
|
return c.setMaintenanceStatus(true)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *cfg) setMaintenanceStatus(force bool) error {
|
|
|
|
netSettings, err := c.cfgNetmap.wrapper.ReadNetworkConfiguration()
|
|
|
|
if err != nil {
|
|
|
|
err = fmt.Errorf("read network settings to check maintenance allowance: %w", err)
|
|
|
|
} else if !netSettings.MaintenanceModeAllowed {
|
|
|
|
err = errors.New("maintenance mode is not allowed by the network")
|
|
|
|
}
|
|
|
|
|
|
|
|
if err == nil || force {
|
|
|
|
c.startMaintenance()
|
|
|
|
|
|
|
|
if err == nil {
|
|
|
|
err = c.updateNetMapState((*nmClient.UpdatePeerPrm).SetMaintenance)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("local maintenance is started, but state is not updated in the network: %w", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-09-19 16:59:23 +00:00
|
|
|
// calls UpdatePeerState operation of Netmap contract's client for the local node.
|
|
|
|
// State setter is used to specify node state to switch to.
|
|
|
|
func (c *cfg) updateNetMapState(stateSetter func(*nmClient.UpdatePeerPrm)) error {
|
|
|
|
var prm nmClient.UpdatePeerPrm
|
2021-11-10 11:05:51 +00:00
|
|
|
prm.SetKey(c.key.PublicKey().Bytes())
|
2022-09-19 16:59:23 +00:00
|
|
|
stateSetter(&prm)
|
2021-11-10 11:05:51 +00:00
|
|
|
|
|
|
|
return c.cfgNetmap.wrapper.UpdatePeerState(prm)
|
2021-01-15 11:53:41 +00:00
|
|
|
}
|
2021-02-19 08:01:37 +00:00
|
|
|
|
|
|
|
type netInfo struct {
|
|
|
|
netState netmap.State
|
|
|
|
|
|
|
|
magic interface {
|
2021-08-26 08:17:31 +00:00
|
|
|
MagicNumber() (uint64, error)
|
2021-02-19 08:01:37 +00:00
|
|
|
}
|
2021-09-20 16:13:17 +00:00
|
|
|
|
2022-06-08 23:18:26 +00:00
|
|
|
morphClientNetMap *nmClient.Client
|
2021-09-20 16:13:17 +00:00
|
|
|
|
|
|
|
msPerBlockRdr func() (int64, error)
|
2021-02-19 08:01:37 +00:00
|
|
|
}
|
|
|
|
|
2022-06-08 23:18:26 +00:00
|
|
|
func (n *netInfo) Dump(ver version.Version) (*netmapSDK.NetworkInfo, error) {
|
2021-08-26 08:17:31 +00:00
|
|
|
magic, err := n.magic.MagicNumber()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2022-06-08 23:18:26 +00:00
|
|
|
var ni netmapSDK.NetworkInfo
|
2021-02-19 08:01:37 +00:00
|
|
|
ni.SetCurrentEpoch(n.netState.CurrentEpoch())
|
2021-08-26 08:17:31 +00:00
|
|
|
ni.SetMagicNumber(magic)
|
2021-02-19 08:01:37 +00:00
|
|
|
|
2022-06-08 23:18:26 +00:00
|
|
|
netInfoMorph, err := n.morphClientNetMap.ReadNetworkConfiguration()
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("read network configuration using netmap contract client: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if mjr := ver.Major(); mjr > 2 || mjr == 2 && ver.Minor() > 9 {
|
2021-09-20 16:13:17 +00:00
|
|
|
msPerBlock, err := n.msPerBlockRdr()
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("ms per block: %w", err)
|
|
|
|
}
|
|
|
|
|
2022-06-08 23:18:26 +00:00
|
|
|
ni.SetMsPerBlock(msPerBlock)
|
2021-09-20 16:13:17 +00:00
|
|
|
|
2022-06-08 23:18:26 +00:00
|
|
|
ni.SetMaxObjectSize(netInfoMorph.MaxObjectSize)
|
|
|
|
ni.SetStoragePrice(netInfoMorph.StoragePrice)
|
|
|
|
ni.SetAuditFee(netInfoMorph.AuditFee)
|
|
|
|
ni.SetEpochDuration(netInfoMorph.EpochDuration)
|
|
|
|
ni.SetContainerFee(netInfoMorph.ContainerFee)
|
|
|
|
ni.SetNamedContainerFee(netInfoMorph.ContainerAliasFee)
|
|
|
|
ni.SetNumberOfEigenTrustIterations(netInfoMorph.EigenTrustIterations)
|
|
|
|
ni.SetEigenTrustAlpha(netInfoMorph.EigenTrustAlpha)
|
|
|
|
ni.SetIRCandidateFee(netInfoMorph.IRCandidateFee)
|
|
|
|
ni.SetWithdrawalFee(netInfoMorph.WithdrawalFee)
|
|
|
|
|
2022-09-19 15:31:56 +00:00
|
|
|
if netInfoMorph.HomomorphicHashingDisabled {
|
|
|
|
ni.DisableHomomorphicHashing()
|
|
|
|
}
|
|
|
|
|
2022-09-19 15:43:53 +00:00
|
|
|
if netInfoMorph.MaintenanceModeAllowed {
|
|
|
|
ni.AllowMaintenanceMode()
|
|
|
|
}
|
|
|
|
|
2022-06-08 23:18:26 +00:00
|
|
|
for i := range netInfoMorph.Raw {
|
|
|
|
ni.SetRawNetworkParameter(netInfoMorph.Raw[i].Name, netInfoMorph.Raw[i].Value)
|
2021-09-20 16:13:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-08 23:18:26 +00:00
|
|
|
return &ni, nil
|
2021-02-19 08:01:37 +00:00
|
|
|
}
|