diff --git a/cmd/neofs-node/config.go b/cmd/neofs-node/config.go index 8d7e2ced..582bafd7 100644 --- a/cmd/neofs-node/config.go +++ b/cmd/neofs-node/config.go @@ -163,6 +163,8 @@ type cfgNetmap struct { parsers map[event.Type]event.Parser subscribers map[event.Type][]event.Handler + + state *networkState } type BootstrapType uint32 diff --git a/cmd/neofs-node/netmap.go b/cmd/neofs-node/netmap.go index 5f79fdfd..25036e9a 100644 --- a/cmd/neofs-node/netmap.go +++ b/cmd/neofs-node/netmap.go @@ -5,11 +5,32 @@ import ( netmapGRPC "github.com/nspcc-dev/neofs-api-go/v2/netmap/grpc" crypto "github.com/nspcc-dev/neofs-crypto" "github.com/nspcc-dev/neofs-node/pkg/morph/event" + netmapEvent "github.com/nspcc-dev/neofs-node/pkg/morph/event/netmap" netmapTransportGRPC "github.com/nspcc-dev/neofs-node/pkg/network/transport/netmap/grpc" netmapService "github.com/nspcc-dev/neofs-node/pkg/services/netmap" "github.com/pkg/errors" + "go.uber.org/atomic" ) +// primary solution of local network state dump. +type networkState struct { + epoch *atomic.Uint64 +} + +func newNetworkState() *networkState { + return &networkState{ + epoch: atomic.NewUint64(0), + } +} + +func (s *networkState) CurrentEpoch() uint64 { + return s.epoch.Load() +} + +func (s *networkState) setCurrentEpoch(v uint64) { + s.epoch.Store(v) +} + func initNetmapService(c *cfg) { peerInfo := new(netmap.NodeInfo) peerInfo.SetAddress(c.localAddr.String()) @@ -29,6 +50,11 @@ func initNetmapService(c *cfg) { ), ), ) + + c.cfgNetmap.state = newNetworkState() + addNewEpochNotificationHandler(c, func(ev event.Event) { + c.cfgNetmap.state.setCurrentEpoch(ev.(netmapEvent.NewEpoch).EpochNumber()) + }) } func bootstrapNode(c *cfg) { diff --git a/cmd/neofs-node/object.go b/cmd/neofs-node/object.go index 88dbdc37..76b4dfa3 100644 --- a/cmd/neofs-node/object.go +++ b/cmd/neofs-node/object.go @@ -233,6 +233,7 @@ func initObjectService(c *cfg) { putsvc.WithFormatValidatorOpts( objectCore.WithDeleteHandler(objGC), ), + putsvc.WithNetworkState(c.cfgNetmap.state), ) sPutV2 := putsvcV2.NewService(