From 6a2ec21641c93849f86605ec0dd781b454512491 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Mon, 19 Sep 2022 20:34:53 +0400 Subject: [PATCH] [#1681] ir/netmap: Check MAINTENANCE state in `UpdateState` Storage node can be requested to be switched into `MAINTENANCE` state. Inner Ring should accept such requests only if network configuration allows it. Make `Processor` of Netmap contract's notifications to depend on `state.NetworkSettings`. Make `Processor.processUpdatePeer` to call `MaintenanceModeAllowed` if notification event relates to `MAINTENANCE` mode`. Share singe `state.NetworkSettings` provider in Inner Ring application. Signed-off-by: Leonard Lyubich --- pkg/innerring/innerring.go | 6 +++++- .../processors/netmap/process_peers.go | 17 ++++++++++++++++- pkg/innerring/processors/netmap/processor.go | 9 +++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/pkg/innerring/innerring.go b/pkg/innerring/innerring.go index 51386c16e..3dd31622f 100644 --- a/pkg/innerring/innerring.go +++ b/pkg/innerring/innerring.go @@ -690,8 +690,10 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper, errChan chan<- } } + netSettings := (*networkSettings)(server.netmapClient) + var netMapCandidateStateValidator statevalidation.NetMapCandidateValidator - netMapCandidateStateValidator.SetNetworkSettings((*networkSettings)(server.netmapClient)) + netMapCandidateStateValidator.SetNetworkSettings(netSettings) // create netmap processor server.netmapProcessor, err = netmap.New(&netmap.Params{ @@ -722,6 +724,8 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper, errChan chan<- ), NotaryDisabled: server.sideNotaryConfig.disabled, SubnetContract: &server.contracts.subnet, + + NodeStateSettings: netSettings, }) if err != nil { return nil, err diff --git a/pkg/innerring/processors/netmap/process_peers.go b/pkg/innerring/processors/netmap/process_peers.go index c6849661d..dfa8e1eb4 100644 --- a/pkg/innerring/processors/netmap/process_peers.go +++ b/pkg/innerring/processors/netmap/process_peers.go @@ -107,14 +107,29 @@ func (np *Processor) processUpdatePeer(ev netmapEvent.UpdatePeer) { var err error + if ev.Maintenance() { + err = np.nodeStateSettings.MaintenanceModeAllowed() + if err != nil { + np.log.Info("prevent switching node to maintenance state", + zap.Error(err), + ) + + return + } + } + if nr := ev.NotaryRequest(); nr != nil { err = np.netmapClient.Morph().NotarySignAndInvokeTX(nr.MainTransaction) } else { prm := netmapclient.UpdatePeerPrm{} - if ev.Online() { + switch { + case ev.Online(): prm.SetOnline() + case ev.Maintenance(): + prm.SetMaintenance() } + prm.SetKey(ev.PublicKey().Bytes()) err = np.netmapClient.UpdatePeerState(prm) diff --git a/pkg/innerring/processors/netmap/processor.go b/pkg/innerring/processors/netmap/processor.go index 430a68199..533bd30f2 100644 --- a/pkg/innerring/processors/netmap/processor.go +++ b/pkg/innerring/processors/netmap/processor.go @@ -6,6 +6,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/core/mempoolevent" "github.com/nspcc-dev/neo-go/pkg/util" + "github.com/nspcc-dev/neofs-node/pkg/innerring/processors/netmap/nodevalidation/state" "github.com/nspcc-dev/neofs-node/pkg/morph/client/container" nmClient "github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap" "github.com/nspcc-dev/neofs-node/pkg/morph/event" @@ -74,6 +75,8 @@ type ( nodeValidator NodeValidator notaryDisabled bool + + nodeStateSettings state.NetworkSettings } // Params of the processor constructor. @@ -97,6 +100,8 @@ type ( NodeValidator NodeValidator NotaryDisabled bool + + NodeStateSettings state.NetworkSettings } ) @@ -132,6 +137,8 @@ func New(p *Params) (*Processor, error) { return nil, errors.New("ir/netmap: node validator is not set") case p.SubnetContract == nil: return nil, errors.New("ir/netmap: subnet contract script hash is not set") + case p.NodeStateSettings == nil: + return nil, errors.New("ir/netmap: node state settings is not set") } p.Log.Debug("netmap worker pool", zap.Int("size", p.PoolSize)) @@ -162,6 +169,8 @@ func New(p *Params) (*Processor, error) { nodeValidator: p.NodeValidator, notaryDisabled: p.NotaryDisabled, + + nodeStateSettings: p.NodeStateSettings, }, nil }