Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Changelog for NeoFS Node
### Changed
- SNs exchange TLS certificates on inter-node connections (#4097)
- SN no longer adds origin signature to EC requests sent to remote nodes with API >= v2.25 (#4118)
- SN requests network map only when it has been changed (#4121)

### Removed

Expand Down
13 changes: 12 additions & 1 deletion cmd/neofs-node/morph.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import (
)

const (
newEpochNotification = "NewEpoch"
newEpochNotification = "NewEpoch"
newNetmapVersionNotification = "NewNetmapVersion"
)

func initMorphComponents(c *cfg) {
Expand Down Expand Up @@ -82,6 +83,16 @@ func listenMorphNotifications(c *cfg) {

return res, err
})
setNetmapNotificationParser(c, newNetmapVersionNotification, func(src *state.ContainedNotificationEvent) (event.Event, error) {
res, err := netmapEvent.ParseNewNetmapVersion(src)
if err == nil {
c.log.Info("new netmap version event from FS chain",
zap.Int("versionNumber", res.(netmapEvent.NetmapChanged).NetmapVersion()),
)
}

return res, err
})
registerNotificationHandlers(c.netmapSH, lis, c.cfgNetmap.parsers, c.cfgNetmap.subscribers)
registerNotificationHandlers(c.containerSH, lis, c.cfgContainer.parsers, c.cfgContainer.subscribers)
registerNotificationHandlers(c.balanceSH, lis, c.cfgBalance.parsers, c.cfgBalance.subscribers)
Expand Down
34 changes: 19 additions & 15 deletions cmd/neofs-node/netmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ func initNetmapService(c *cfg) {
c.cfgNetmap.state.setCurrentEpoch(ev.(netmapEvent.NewEpoch).EpochNumber())
})

addNewEpochAsyncNotificationHandler(c, func(ev event.Event) {
e := ev.(netmapEvent.NewEpoch).EpochNumber()
addNetmapChangedNotificationHandler(c, func(ev event.Event) {
v := ev.(netmapEvent.NetmapChanged).NetmapVersion()

var (
ni *netmap.NodeInfo
Expand All @@ -176,19 +176,19 @@ func initNetmapService(c *cfg) {
err = backoff.RetryNotify(
func() error {
retries++
ni, err = c.netmapLocalNodeState(e)
ni, err = c.netmapLocalNodeState()
if errors.Is(err, rpcclient.ErrWSConnLost) {
return backoff.Permanent(err)
}
return err
},
expBackoff,
func(err error, d time.Duration) {
c.log.Info("retrying due to error", zap.Uint64("epoch", e), zap.Error(err), zap.Duration("retry-after", d))
c.log.Info("retrying due to error", zap.Error(err), zap.Duration("retry-after", d))
})
if err != nil {
c.log.Error("could not update node state on new epoch after retries",
zap.Uint64("epoch", e),
c.log.Error("could not update node state on netmap change after retries",
zap.Int("version", v),
zap.Uint64("retries", retries),
zap.Error(err),
)
Expand Down Expand Up @@ -223,14 +223,14 @@ func initNetmapService(c *cfg) {
}
})

addNewEpochAsyncNotificationHandler(c, func(ev event.Event) {
epoch := ev.(netmapEvent.NewEpoch).EpochNumber()
l := c.log.With(zap.Uint64("epoch", epoch))
l.Info("new epoch event, requesting new network map to sync SN connection caches...")
addNetmapChangedNotificationHandler(c, func(ev event.Event) {
version := ev.(netmapEvent.NetmapChanged).NetmapVersion()
l := c.log.With(zap.Int("netmapVersion", version))
l.Info("new network map event, requesting it to sync SN connection caches...")

nm, err := c.netMapSource.GetNetMapByEpoch(epoch)
nm, err := c.netMapSource.NetMap()
if err != nil {
l.Info("failed to get network map by new epoch from event to sync SN connection cache", zap.Error(err))
l.Info("failed to get network map to sync SN connection cache", zap.Error(err))
return
}

Expand Down Expand Up @@ -333,7 +333,7 @@ func getNetworkState(c *cfg) (uint64, *netmap.NodeInfo, error) {
return 0, nil, fmt.Errorf("could not get current epoch number: %w", err)
}

ni, err := c.netmapLocalNodeState(epoch)
ni, err := c.netmapLocalNodeState()
if err != nil {
return 0, nil, fmt.Errorf("could not init network state: %w", err)
}
Expand All @@ -347,9 +347,9 @@ func updateLocalState(c *cfg, epoch uint64, ni *netmap.NodeInfo) {
c.handleLocalNodeInfoFromNetwork(ni)
}

func (c *cfg) netmapLocalNodeState(epoch uint64) (*netmap.NodeInfo, error) {
func (c *cfg) netmapLocalNodeState() (*netmap.NodeInfo, error) {
// calculate current network state
nm, err := c.nCli.GetNetMapByEpoch(epoch)
nm, err := c.nCli.NetMap()
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -384,6 +384,10 @@ func addNewEpochAsyncNotificationHandler(c *cfg, h event.Handler) {
)
}

func addNetmapChangedNotificationHandler(c *cfg, h event.Handler) {
addNetmapNotificationHandler(c, newNetmapVersionNotification, h)
}

var errRelayBootstrap = errors.New("setting netmap status is forbidden in relay mode")

func (c *cfg) SetNetmapStatus(st control.NetmapStatus) error {
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ require (
github.com/nspcc-dev/bbolt v0.0.0-20260404200350-24f70ceb2bd9
github.com/nspcc-dev/hrw/v2 v2.0.4
github.com/nspcc-dev/locode-db v0.8.2
github.com/nspcc-dev/neo-go v0.121.0
github.com/nspcc-dev/neo-go v0.122.0
github.com/nspcc-dev/neofs-api-go/v2 v2.14.1-0.20240827150555-5ce597aa14ea
github.com/nspcc-dev/neofs-contract v0.26.1
github.com/nspcc-dev/neofs-contract v0.26.2-0.20260807135332-b157a9b215bb
github.com/nspcc-dev/neofs-sdk-go v1.0.0-rc.21
github.com/nspcc-dev/tzhash v1.8.4
github.com/panjf2000/ants/v2 v2.11.5
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,14 @@ github.com/nspcc-dev/hrw/v2 v2.0.4 h1:o3Zh/2aF+IgGpvt414f46Ya20WG9u9vWxVd16ErFI8
github.com/nspcc-dev/hrw/v2 v2.0.4/go.mod h1:dUjOx27zTTvoPmT5EG25vSSWL2tKS7ndAa2TPTiZwFo=
github.com/nspcc-dev/locode-db v0.8.2 h1:+9+1Z7ppG+ISDLHzMND7PZ8+R4H3d04doVRyNevOpz0=
github.com/nspcc-dev/locode-db v0.8.2/go.mod h1:PtAASXSG4D4Oz0js9elzTyTr8GLpOJO20qFL881Nims=
github.com/nspcc-dev/neo-go v0.121.0 h1:PRBY7V2LUSrJCRriMwtpE1/KDSEYlDaZgDrTyzgfeTY=
github.com/nspcc-dev/neo-go v0.121.0/go.mod h1:sa78wYlbBY0bLGKRquUGhGcZdHrUxPm7TKLFoVgV94Q=
github.com/nspcc-dev/neo-go v0.122.0 h1:EMVM5qoyUlVvbcgg3nsDR8O1yYtuqABRkRzCodJ4jYc=
github.com/nspcc-dev/neo-go v0.122.0/go.mod h1:AHsMQ8xbcEkY4NYFmlWe7vrLLTG1bmjDrbejMkvIQcM=
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20260609115526-14bc7067ea2e h1:oSMvPnO83Tgy4q1GC5szZzuHuMBHWbO7vySDEyyg2ww=
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20260609115526-14bc7067ea2e/go.mod h1:+nqk9W9KbuvjqA2bQfGTuRKn7FQwcVyhlIDz8hB3f2c=
github.com/nspcc-dev/neofs-api-go/v2 v2.14.1-0.20240827150555-5ce597aa14ea h1:mK0EMGLvunXcFyq7fBURS/CsN4MH+4nlYiqn6pTwWAU=
github.com/nspcc-dev/neofs-api-go/v2 v2.14.1-0.20240827150555-5ce597aa14ea/go.mod h1:YzhD4EZmC9Z/PNyd7ysC7WXgIgURc9uCG1UWDeV027Y=
github.com/nspcc-dev/neofs-contract v0.26.1 h1:7Ii7Q4L3au408LOsIWKiSgfnT1g8G9jo3W7381d41T8=
github.com/nspcc-dev/neofs-contract v0.26.1/go.mod h1:pevVF9OWdEN5bweKxOu6ryZv9muCEtS1ppzYM4RfBIo=
github.com/nspcc-dev/neofs-contract v0.26.2-0.20260807135332-b157a9b215bb h1:7Ow6Wbs7QH5+2FDDcB2nfn/1J/Jpx4jHoXRwoQAIKOY=
github.com/nspcc-dev/neofs-contract v0.26.2-0.20260807135332-b157a9b215bb/go.mod h1:Gn6CqqixGMEjTdzAx846el6T5bJR4WgzlZkD2SkZrtI=
github.com/nspcc-dev/neofs-sdk-go v1.0.0-rc.21 h1:6LPpzMvEn8Y3mdOFHFtcrWC5GU1QGr5I8A701YufMt0=
github.com/nspcc-dev/neofs-sdk-go v1.0.0-rc.21/go.mod h1:cdLGU2E3f13UVE9nkHus171POaf2O4YyeXenUxQnGyQ=
github.com/nspcc-dev/rfc6979 v0.2.4 h1:NBgsdCjhLpEPJZqmC9rciMZDcSY297po2smeaRjw57k=
Expand Down
33 changes: 33 additions & 0 deletions pkg/morph/event/netmap/netmap_changed.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package netmap

import (
"fmt"

"github.com/nspcc-dev/neo-go/pkg/core/state"
netmaprpc "github.com/nspcc-dev/neofs-contract/rpc/netmap"
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
)

// NetmapChanged contains addNode method parameters.
type NetmapChanged netmaprpc.NewNetmapVersionEvent

// NetmapVersion returns new network map version number.
func (n NetmapChanged) NetmapVersion() int {
return int(n.Version.Int64())
}

// MorphEvent implements Neo:Morph Event interface.
func (NetmapChanged) MorphEvent() {}

// ParseNewNetmapVersion is a parser of new netmap version notification event.
//
// The result is of NetmapChanged type.
func ParseNewNetmapVersion(e *state.ContainedNotificationEvent) (event.Event, error) {
var ev netmaprpc.NewNetmapVersionEvent
err := ev.FromStackItem(e.Item)
if err != nil {
return nil, fmt.Errorf("failed to parse new netmap version event: %w", err)
}

return NetmapChanged(ev), nil
}
Loading