From 858354c120541a2c0b79b3ffaa04d1ddebf6b823 Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Wed, 25 Dec 2024 19:31:57 +0300 Subject: [PATCH] node/object/put: add object type to meta-on-chain It is optional since one of the types (REGULAR) is the most expected, and its missing can be recognizable. Signed-off-by: Pavel Karpy --- pkg/core/object/replicate.go | 8 +++++++- pkg/core/object/replicate_test.go | 9 ++++++++- pkg/network/transport/object/grpc/replication.go | 9 +++++---- pkg/network/transport/object/grpc/replication_test.go | 2 +- pkg/services/object/put/distributed.go | 5 +++-- 5 files changed, 24 insertions(+), 9 deletions(-) diff --git a/pkg/core/object/replicate.go b/pkg/core/object/replicate.go index c6b44b7c2d..1c26956ab6 100644 --- a/pkg/core/object/replicate.go +++ b/pkg/core/object/replicate.go @@ -5,6 +5,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" cid "github.com/nspcc-dev/neofs-sdk-go/container/id" + objectsdk "github.com/nspcc-dev/neofs-sdk-go/object" oid "github.com/nspcc-dev/neofs-sdk-go/object/id" ) @@ -21,6 +22,7 @@ const ( previousPartKey = "previousPart" deletedKey = "deleted" lockedKey = "locked" + typeKey = "type" ) // EncodeReplicationMetaInfo uses NEO's map (strict order) serialized format as a raw @@ -37,7 +39,8 @@ const ( // "previousPart": [OPTIONAL] _raw_ object ID (32 bytes) // "deleted": [OPTIONAL] array of _raw_ object IDs // "locked": [OPTIONAL] array of _raw_ object IDs -func EncodeReplicationMetaInfo(cID cid.ID, oID, firstPart, previousPart oid.ID, pSize uint64, +// "type": [OPTIONAL] object type enumeration +func EncodeReplicationMetaInfo(cID cid.ID, oID, firstPart, previousPart oid.ID, pSize uint64, typ objectsdk.Type, deleted, locked []oid.ID, vub uint64, magicNumber uint32) []byte { kvs := []stackitem.MapElement{ kv(cidKey, cID[:]), @@ -59,6 +62,9 @@ func EncodeReplicationMetaInfo(cID cid.ID, oID, firstPart, previousPart oid.ID, if len(locked) > 0 { kvs = append(kvs, oidsKV(lockedKey, locked)) } + if typ != objectsdk.TypeRegular { + kvs = append(kvs, kv(typeKey, uint32(typ))) + } result, err := stackitem.Serialize(stackitem.NewMapWithValue(kvs)) if err != nil { diff --git a/pkg/core/object/replicate_test.go b/pkg/core/object/replicate_test.go index fb98e748cf..2e256cece2 100644 --- a/pkg/core/object/replicate_test.go +++ b/pkg/core/object/replicate_test.go @@ -8,6 +8,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" cid "github.com/nspcc-dev/neofs-sdk-go/container/id" cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test" + "github.com/nspcc-dev/neofs-sdk-go/object" oid "github.com/nspcc-dev/neofs-sdk-go/object/id" oidtest "github.com/nspcc-dev/neofs-sdk-go/object/id/test" "github.com/stretchr/testify/require" @@ -24,6 +25,7 @@ type m struct { prev oid.ID deleted []oid.ID locked []oid.ID + typ object.Type } func TestMetaInfo(t *testing.T) { @@ -37,6 +39,7 @@ func TestMetaInfo(t *testing.T) { prev: oidtest.ID(), deleted: oidtest.IDs(10), locked: oidtest.IDs(10), + typ: object.TypeTombstone, } t.Run("full", func(t *testing.T) { @@ -49,13 +52,14 @@ func TestMetaInfo(t *testing.T) { meta.deleted = nil meta.deleted = nil meta.locked = nil + meta.typ = object.TypeRegular testMeta(t, meta, false) }) } func testMeta(t *testing.T, m m, full bool) { - raw := EncodeReplicationMetaInfo(m.cID, m.oID, m.first, m.prev, m.size, m.deleted, m.locked, m.vub, m.magic) + raw := EncodeReplicationMetaInfo(m.cID, m.oID, m.first, m.prev, m.size, m.typ, m.deleted, m.locked, m.vub, m.magic) item, err := stackitem.Deserialize(raw) require.NoError(t, err) @@ -94,6 +98,9 @@ func testMeta(t *testing.T, m m, full bool) { require.Equal(t, lockedKey, string(mm[8].Key.Value().([]byte))) require.Equal(t, m.locked, stackItemToOIDs(t, mm[8].Value)) + + require.Equal(t, typeKey, string(mm[9].Key.Value().([]byte))) + require.Equal(t, int(m.typ), int(mm[9].Value.Value().(*big.Int).Uint64())) } func stackItemToOIDs(t *testing.T, value stackitem.Item) []oid.ID { diff --git a/pkg/network/transport/object/grpc/replication.go b/pkg/network/transport/object/grpc/replication.go index 6ece608cb9..8f9f4b1959 100644 --- a/pkg/network/transport/object/grpc/replication.go +++ b/pkg/network/transport/object/grpc/replication.go @@ -215,7 +215,8 @@ func (s *Server) metaInfoSignature(o object.Object) ([]byte, error) { var deleted []oid.ID var locked []oid.ID - switch o.Type() { + typ := o.Type() + switch typ { case object.TypeTombstone: var t object.Tombstone err := t.Unmarshal(o.Payload()) @@ -242,9 +243,9 @@ func (s *Server) metaInfoSignature(o object.Object) ([]byte, error) { secondBlock := firstBlock + currentEpochDuration thirdBlock := secondBlock + currentEpochDuration - firstMeta := objectcore.EncodeReplicationMetaInfo(o.GetContainerID(), o.GetID(), firstObj, prevObj, o.PayloadSize(), deleted, locked, firstBlock, s.mNumber) - secondMeta := objectcore.EncodeReplicationMetaInfo(o.GetContainerID(), o.GetID(), firstObj, prevObj, o.PayloadSize(), deleted, locked, secondBlock, s.mNumber) - thirdMeta := objectcore.EncodeReplicationMetaInfo(o.GetContainerID(), o.GetID(), firstObj, prevObj, o.PayloadSize(), deleted, locked, thirdBlock, s.mNumber) + firstMeta := objectcore.EncodeReplicationMetaInfo(o.GetContainerID(), o.GetID(), firstObj, prevObj, o.PayloadSize(), typ, deleted, locked, firstBlock, s.mNumber) + secondMeta := objectcore.EncodeReplicationMetaInfo(o.GetContainerID(), o.GetID(), firstObj, prevObj, o.PayloadSize(), typ, deleted, locked, secondBlock, s.mNumber) + thirdMeta := objectcore.EncodeReplicationMetaInfo(o.GetContainerID(), o.GetID(), firstObj, prevObj, o.PayloadSize(), typ, deleted, locked, thirdBlock, s.mNumber) var firstSig neofscrypto.Signature var secondSig neofscrypto.Signature diff --git a/pkg/network/transport/object/grpc/replication_test.go b/pkg/network/transport/object/grpc/replication_test.go index 35beec0694..706b8bff7a 100644 --- a/pkg/network/transport/object/grpc/replication_test.go +++ b/pkg/network/transport/object/grpc/replication_test.go @@ -408,7 +408,7 @@ func TestServer_Replicate(t *testing.T) { require.Equal(t, signer.PublicKeyBytes, sig.PublicKeyBytes()) require.True(t, sig.Verify(objectcore.EncodeReplicationMetaInfo( - o.GetContainerID(), o.GetID(), o.GetFirstID(), o.GetPreviousID(), o.PayloadSize(), nil, nil, + o.GetContainerID(), o.GetID(), o.GetFirstID(), o.GetPreviousID(), o.PayloadSize(), o.Type(), nil, nil, uint64((123+1+i)*240), mNumber))) sigsRaw = sigsRaw[:4+l] diff --git a/pkg/services/object/put/distributed.go b/pkg/services/object/put/distributed.go index b83604a417..38648c757e 100644 --- a/pkg/services/object/put/distributed.go +++ b/pkg/services/object/put/distributed.go @@ -150,7 +150,8 @@ func (t *distributedTarget) Close() (oid.ID, error) { var deletedObjs []oid.ID var lockedObjs []oid.ID - switch t.objMeta.Type() { + typ := t.objMeta.Type() + switch typ { case objectSDK.TypeTombstone: deletedObjs = t.objMeta.Objects() case objectSDK.TypeLock: @@ -159,7 +160,7 @@ func (t *distributedTarget) Close() (oid.ID, error) { } expectedVUB := (uint64(t.currentBlock)/t.currentEpochDuration + 2) * t.currentEpochDuration - t.objSharedMeta = object.EncodeReplicationMetaInfo(t.obj.GetContainerID(), t.obj.GetID(), firstObj, prevObj, t.obj.PayloadSize(), deletedObjs, + t.objSharedMeta = object.EncodeReplicationMetaInfo(t.obj.GetContainerID(), t.obj.GetID(), firstObj, prevObj, t.obj.PayloadSize(), typ, deletedObjs, lockedObjs, expectedVUB, t.networkMagicNumber) id := t.obj.GetID() err := t.placementIterator.iterateNodesForObject(id, t.sendObject)