Skip to content

Commit

Permalink
morph: support overload for container.Put contract method
Browse files Browse the repository at this point in the history
It now may have additional arg that enables meta-on-chain support. Closes #2877.

Signed-off-by: Pavel Karpy <[email protected]>
  • Loading branch information
carpawell committed Dec 11, 2024
1 parent 87dd88d commit 1c01505
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Changelog for NeoFS Node
## [Unreleased]

### Added
- Initial support for meta-on-chain for objects (#2877)

### Fixed

Expand Down
33 changes: 26 additions & 7 deletions pkg/morph/client/container/put.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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()

Check warning on line 27 in pkg/morph/client/container/put.go

View check run for this annotation

Codecov / codecov/patch

pkg/morph/client/container/put.go#L25-L27

Added lines #L25 - L27 were not covered by tests
}

if cnr.Session != nil {
prm.SetToken(cnr.Session.Marshal())
Expand All @@ -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
}
Expand Down Expand Up @@ -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

Check warning on line 92 in pkg/morph/client/container/put.go

View check run for this annotation

Codecov / codecov/patch

pkg/morph/client/container/put.go#L91-L92

Added lines #L91 - L92 were not covered by tests
}

// Put saves binary container with its session token, key and signature
// in NeoFS system through Container contract call.
//
Expand All @@ -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)
}

Check warning on line 119 in pkg/morph/client/container/put.go

View check run for this annotation

Codecov / codecov/patch

pkg/morph/client/container/put.go#L115-L119

Added lines #L115 - L119 were not covered by tests
}

prm.SetMethod(method)
Expand All @@ -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")

Check warning on line 138 in pkg/morph/client/container/put.go

View check run for this annotation

Codecov / codecov/patch

pkg/morph/client/container/put.go#L137-L138

Added lines #L137 - L138 were not covered by tests
}
5 changes: 5 additions & 0 deletions pkg/morph/event/container/put_notary.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:]
}

Check warning on line 62 in pkg/morph/event/container/put_notary.go

View check run for this annotation

Codecov / codecov/patch

pkg/morph/event/container/put_notary.go#L59-L62

Added lines #L59 - L62 were not covered by tests

for _, op := range ops {
currentOp = op.Code()

Expand Down

0 comments on commit 1c01505

Please sign in to comment.