From 1c0150587c6e76bc9691d11089b04db25abcbaba Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Wed, 11 Dec 2024 19:15:43 +0300 Subject: [PATCH] morph: support overload for container.Put contract method It now may have additional arg that enables meta-on-chain support. Closes #2877. Signed-off-by: Pavel Karpy --- CHANGELOG.md | 1 + pkg/morph/client/container/put.go | 33 +++++++++++++++++++------ pkg/morph/event/container/put_notary.go | 5 ++++ 3 files changed, 32 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0c27196377..9d52da6242 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ Changelog for NeoFS Node ## [Unreleased] ### Added +- Initial support for meta-on-chain for objects (#2877) ### Fixed diff --git a/pkg/morph/client/container/put.go b/pkg/morph/client/container/put.go index aec2665fd2..b0025ab168 100644 --- a/pkg/morph/client/container/put.go +++ b/pkg/morph/client/container/put.go @@ -5,6 +5,7 @@ import ( containercore "github.com/nspcc-dev/neofs-node/pkg/core/container" "github.com/nspcc-dev/neofs-node/pkg/morph/client" + containerSDK "github.com/nspcc-dev/neofs-sdk-go/container" cid "github.com/nspcc-dev/neofs-sdk-go/container/id" ) @@ -21,6 +22,10 @@ func Put(c *Client, cnr containercore.Container) (*cid.ID, error) { prm.SetContainer(data) prm.SetName(d.Name()) prm.SetZone(d.Zone()) + switch metaAttribute(cnr.Value) { + case "optimistic", "strict": + prm.EnableMeta() + } if cnr.Session != nil { prm.SetToken(cnr.Session.Marshal()) @@ -41,12 +46,13 @@ func Put(c *Client, cnr containercore.Container) (*cid.ID, error) { // PutPrm groups parameters of Put operation. type PutPrm struct { - cnr []byte - key []byte - sig []byte - token []byte - name string - zone string + cnr []byte + key []byte + sig []byte + token []byte + name string + zone string + enableMetaOnChain bool client.InvokePrmOptional } @@ -81,6 +87,11 @@ func (p *PutPrm) SetZone(zone string) { p.zone = zone } +// EnableMeta enables meta-on-chain. +func (p *PutPrm) EnableMeta() { + p.enableMetaOnChain = true +} + // Put saves binary container with its session token, key and signature // in NeoFS system through Container contract call. // @@ -101,7 +112,11 @@ func (c *Client) Put(p PutPrm) error { prm.SetArgs(p.cnr, p.sig, p.key, p.token, p.name, p.zone) } else { method = putMethod - prm.SetArgs(p.cnr, p.sig, p.key, p.token) + if p.enableMetaOnChain { + prm.SetArgs(p.cnr, p.sig, p.key, p.token, true) + } else { + prm.SetArgs(p.cnr, p.sig, p.key, p.token) + } } prm.SetMethod(method) @@ -118,3 +133,7 @@ func (c *Client) Put(p PutPrm) error { } return nil } + +func metaAttribute(cnr containerSDK.Container) string { + return cnr.Attribute("__NEOFS__METAINFO_CONSISTENCY") +} diff --git a/pkg/morph/event/container/put_notary.go b/pkg/morph/event/container/put_notary.go index bf5d186464..4921f58031 100644 --- a/pkg/morph/event/container/put_notary.go +++ b/pkg/morph/event/container/put_notary.go @@ -56,6 +56,11 @@ func parsePutNotary(ev *Put, raw *payload.P2PNotaryRequest, ops []event.Op) erro fieldNum = 0 ) + // it can have one more arg due to overload with meta-on-chain + if len(ops) == expectedItemNumPut+1 && (ops[0].Code() == opcode.PUSHT || ops[0].Code() == opcode.PUSHF) { + ops = ops[1:] + } + for _, op := range ops { currentOp = op.Code()