Skip to content

Commit d5c071c

Browse files
committed
sn/container: Try new createV2 method for contract creation
Will become available with nspcc-dev/neofs-contract#534 upgrade. If new method is missing, SN falls back to old methods. Signed-off-by: Leonard Lyubich <leonard@morphbits.io>
1 parent 2736003 commit d5c071c

File tree

4 files changed

+44
-8
lines changed

4 files changed

+44
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Changelog for NeoFS Node
88
- IR `experimental.allow_ec` config option (#3570)
99
- SN `pprof.enable_block` and `pprof.enable_mutex` options (#3655)
1010
- `neofs-adm fschain load-report` command (#3649)
11-
- SN now supports new `getInfo` method of the Container contract (#3670)
11+
- SN now supports new `getInfo` and `createV2` methods of the Container contract (#3670)
1212

1313
### Fixed
1414
- Write cache using too much CPU (#3642)

pkg/morph/client/container/put.go

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,21 +50,32 @@ func (c *Client) Put(p PutPrm) (cid.ID, error) {
5050
}
5151

5252
var prm client.InvokePrm
53-
prm.SetMethod(fschaincontracts.CreateContainerMethod)
53+
prm.SetMethod(fschaincontracts.CreateContainerV2Method)
5454
prm.InvokePrmOptional = p.InvokePrmOptional
55-
56-
domain := p.cnr.ReadDomain()
57-
metaAttr := p.cnr.Attribute("__NEOFS__METAINFO_CONSISTENCY")
58-
metaEnabled := metaAttr == "optimistic" || metaAttr == "strict"
59-
cnrBytes := p.cnr.Marshal()
60-
prm.SetArgs(cnrBytes, p.sig, p.key, p.token, domain.Name(), domain.Zone(), metaEnabled)
55+
prm.SetArgs(fschaincontracts.ContainerToStackItem(p.cnr), p.sig, p.key, p.token)
6156

6257
// no magic bugs with notary requests anymore, this operation should
6358
// _always_ be notary signed so make it one more time even if it is
6459
// a repeated flag setting
6560
prm.RequireAlphabetSignature()
6661

6762
err := c.client.Invoke(prm)
63+
if err == nil {
64+
return cid.NewFromMarshalledContainer(p.cnr.Marshal()), nil
65+
}
66+
if !isMethodNotFoundError(err, fschaincontracts.CreateContainerV2Method) {
67+
return cid.ID{}, fmt.Errorf("could not invoke method (%s): %w", fschaincontracts.CreateContainerV2Method, err)
68+
}
69+
70+
prm.SetMethod(fschaincontracts.CreateContainerMethod)
71+
72+
domain := p.cnr.ReadDomain()
73+
metaAttr := p.cnr.Attribute("__NEOFS__METAINFO_CONSISTENCY")
74+
metaEnabled := metaAttr == "optimistic" || metaAttr == "strict"
75+
cnrBytes := p.cnr.Marshal()
76+
prm.SetArgs(cnrBytes, p.sig, p.key, p.token, domain.Name(), domain.Zone(), metaEnabled)
77+
78+
err = c.client.Invoke(prm)
6879
if err != nil {
6980
if isMethodNotFoundError(err, fschaincontracts.CreateContainerMethod) {
7081
prm.SetMethod(putMethod)

pkg/morph/contracts/methods.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package fschaincontracts
33
// Various methods of FS chain Container contract.
44
const (
55
CreateContainerMethod = "create"
6+
CreateContainerV2Method = "createV2"
67
RemoveContainerMethod = "remove"
78
PutContainerEACLMethod = "putEACL"
89
PutContainerReportMethod = "putReport"

pkg/morph/contracts/models.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package fschaincontracts
33
import (
44
"errors"
55
"fmt"
6+
"math/big"
67

78
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
89
containerrpc "github.com/nspcc-dev/neofs-contract/rpc/container"
@@ -86,3 +87,26 @@ func containerVersionFromStruct(src *containerrpc.ContainerAPIVersion) (uint32,
8687

8788
return mjr, mnr, nil
8889
}
90+
91+
// ContainerToStackItem encodes container to instance convertible to stack item.
92+
func ContainerToStackItem(cnr container.Container) stackitem.Convertible {
93+
ver := cnr.Version()
94+
owner := cnr.Owner()
95+
96+
var attrs []*containerrpc.ContainerAttribute
97+
for k, v := range cnr.Attributes() {
98+
attrs = append(attrs, &containerrpc.ContainerAttribute{Key: k, Value: v})
99+
}
100+
101+
return &containerrpc.ContainerInfo{
102+
Version: &containerrpc.ContainerAPIVersion{
103+
Major: big.NewInt(int64(ver.Major())),
104+
Minor: big.NewInt(int64(ver.Minor())),
105+
},
106+
Owner: owner.ScriptHash(),
107+
Nonce: cnr.ProtoMessage().Nonce, // TODO: provide and use nonce getter
108+
BasicACL: big.NewInt(int64(cnr.BasicACL().Bits())),
109+
Attributes: attrs,
110+
StoragePolicy: cnr.PlacementPolicy().Marshal(),
111+
}
112+
}

0 commit comments

Comments
 (0)