From 0ec8f529abbb4e6e7dd179e7135432575ec69455 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Mon, 8 Nov 2021 15:10:49 +0300 Subject: [PATCH] [#842] object/delete: Set tombstone local node as tombstone owner All objects in NeoFS must have owner ID. In previous implementation Object Delete service handler set owner ID from request session token. If removal was executed w/o a session, object with tombstone was prepared incorrectly. In order to fix this node should set its own ID and become an owner of the tombstone object. Extend `NetworkInfo` interface required by Object.Delete handler with `LocalNodeID` method which returns `owner.ID` of the local node. Implement the method on `networkState` component of storage node application which is updated on each node state change in NeoFS network map. Set owner returned by `LocalNodeID` call as tombstone object's owner in Delete handler. Signed-off-by: Leonard Lyubich --- cmd/neofs-node/config.go | 13 ++++++++++++- cmd/neofs-node/object.go | 12 +++++++++++- pkg/services/object/delete/exec.go | 8 +++++++- pkg/services/object/delete/service.go | 5 +++++ 4 files changed, 35 insertions(+), 3 deletions(-) diff --git a/cmd/neofs-node/config.go b/cmd/neofs-node/config.go index c4adeff2b..e33b8b385 100644 --- a/cmd/neofs-node/config.go +++ b/cmd/neofs-node/config.go @@ -13,6 +13,7 @@ import ( "github.com/nspcc-dev/neofs-api-go/pkg" apiclient "github.com/nspcc-dev/neofs-api-go/pkg/client" "github.com/nspcc-dev/neofs-api-go/pkg/netmap" + "github.com/nspcc-dev/neofs-api-go/pkg/owner" netmapV2 "github.com/nspcc-dev/neofs-api-go/v2/netmap" "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config" apiclientconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/apiclient" @@ -77,6 +78,8 @@ type cfg struct { key *keys.PrivateKey + ownerIDFromKey *owner.ID // owner ID calculated from key + apiVersion *pkg.Version cfgGRPC cfgGRPC @@ -221,9 +224,15 @@ func initCfg(path string) *cfg { key := nodeconfig.Key(appCfg) + neo3Wallet, err := owner.NEO3WalletFromPublicKey(&key.PrivateKey.PublicKey) + fatalOnErr(err) + + ownerIDFromKey := owner.NewID() + ownerIDFromKey.SetNeo3Wallet(neo3Wallet) + var logPrm logger.Prm - err := logPrm.SetLevelString( + err = logPrm.SetLevelString( loggerconfig.Level(appCfg), ) fatalOnErr(err) @@ -297,6 +306,8 @@ func initCfg(path string) *cfg { apiclient.WithDialTimeout(apiclientconfig.DialTimeout(appCfg)), ), persistate: persistate, + + ownerIDFromKey: ownerIDFromKey, } if metricsconfig.Address(c.appCfg) != "" { diff --git a/cmd/neofs-node/object.go b/cmd/neofs-node/object.go index c27f666a4..91f4821f3 100644 --- a/cmd/neofs-node/object.go +++ b/cmd/neofs-node/object.go @@ -120,14 +120,22 @@ func (r *localObjectInhumer) DeleteObjects(ts *objectSDK.Address, addr ...*objec type delNetInfo struct { netmap.State - tsLifetime uint64 + + cfg *cfg } func (i *delNetInfo) TombstoneLifetime() (uint64, error) { return i.tsLifetime, nil } +// returns node owner ID calculated from configured private key. +// +// Implements method needed for Object.Delete service. +func (i *delNetInfo) LocalNodeID() *owner.ID { + return i.cfg.ownerIDFromKey +} + type innerRingFetcherWithNotary struct { sidechain *morphClient.Client } @@ -334,6 +342,8 @@ func initObjectService(c *cfg) { deletesvc.WithNetworkInfo(&delNetInfo{ State: c.cfgNetmap.state, tsLifetime: 5, + + cfg: c, }), ) diff --git a/pkg/services/object/delete/exec.go b/pkg/services/object/delete/exec.go index 07bea7123..094e81b2b 100644 --- a/pkg/services/object/delete/exec.go +++ b/pkg/services/object/delete/exec.go @@ -232,9 +232,15 @@ func (exec *execCtx) initTombstoneObject() bool { return false } + tombOwnerID := exec.commonParameters().SessionToken().OwnerID() + if tombOwnerID == nil { + // make local node a tombstone object owner + tombOwnerID = exec.svc.netInfo.LocalNodeID() + } + exec.tombstoneObj = object.NewRaw() exec.tombstoneObj.SetContainerID(exec.containerID()) - exec.tombstoneObj.SetOwnerID(exec.commonParameters().SessionToken().OwnerID()) + exec.tombstoneObj.SetOwnerID(tombOwnerID) exec.tombstoneObj.SetType(objectSDK.TypeTombstone) exec.tombstoneObj.SetPayload(payload) diff --git a/pkg/services/object/delete/service.go b/pkg/services/object/delete/service.go index bb1017972..81f943ea6 100644 --- a/pkg/services/object/delete/service.go +++ b/pkg/services/object/delete/service.go @@ -2,6 +2,7 @@ package deletesvc import ( objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object" + "github.com/nspcc-dev/neofs-api-go/pkg/owner" "github.com/nspcc-dev/neofs-node/pkg/core/netmap" getsvc "github.com/nspcc-dev/neofs-node/pkg/services/object/get" putsvc "github.com/nspcc-dev/neofs-node/pkg/services/object/put" @@ -25,6 +26,10 @@ type NetworkInfo interface { // Must return the lifespan of the tombstones // in the NeoFS epochs. TombstoneLifetime() (uint64, error) + + // Returns user ID of the local storage node. Result must not be nil. + // New tombstone objects will have the result as an owner ID if removal is executed w/o a session. + LocalNodeID() *owner.ID } type cfg struct {