Skip to content

Commit 70fe09c

Browse files
committed
ir/container: De-struct method parameters
Passing explicit parameters is easier to understand. Signed-off-by: Leonard Lyubich <leonard@morphbits.io>
1 parent ac376b7 commit 70fe09c

File tree

1 file changed

+26
-37
lines changed

1 file changed

+26
-37
lines changed

pkg/innerring/processors/container/process_container.go

Lines changed: 26 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"strings"
77

8+
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
89
"github.com/nspcc-dev/neo-go/pkg/network/payload"
910
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
1011
containerEvent "github.com/nspcc-dev/neofs-node/pkg/morph/event/container"
@@ -24,13 +25,6 @@ type putEvent interface {
2425
NotaryRequest() *payload.P2PNotaryRequest
2526
}
2627

27-
type putContainerContext struct {
28-
e containerEvent.CreateContainerRequest
29-
30-
// must be filled when verifying raw data from e
31-
cnr containerSDK.Container
32-
}
33-
3428
// Process a new container from the user by checking the container sanity
3529
// and sending approve tx back to the FS chain.
3630
func (cp *Processor) processContainerPut(req containerEvent.CreateContainerRequest, id cid.ID) {
@@ -39,11 +33,15 @@ func (cp *Processor) processContainerPut(req containerEvent.CreateContainerReque
3933
return
4034
}
4135

42-
ctx := &putContainerContext{
43-
e: req,
36+
var cnr containerSDK.Container
37+
if err := cnr.Unmarshal(req.Container); err != nil {
38+
cp.log.Error("put container check failed",
39+
zap.Error(fmt.Errorf("invalid binary container: %w", err)),
40+
)
41+
return
4442
}
4543

46-
err := cp.checkPutContainer(ctx)
44+
err := cp.checkPutContainer(req, cnr)
4745
if err != nil {
4846
cp.log.Error("put container check failed",
4947
zap.Error(err),
@@ -52,7 +50,7 @@ func (cp *Processor) processContainerPut(req containerEvent.CreateContainerReque
5250
return
5351
}
5452

55-
cp.approvePutContainer(ctx, id)
53+
cp.approvePutContainer(req.MainTransaction, cnr, id)
5654
}
5755

5856
const (
@@ -67,15 +65,8 @@ var allowedSystemAttributes = map[string]struct{}{
6765
sysAttrChainMeta: {},
6866
}
6967

70-
func (cp *Processor) checkPutContainer(ctx *putContainerContext) error {
71-
binCnr := ctx.e.Container
72-
73-
err := ctx.cnr.Unmarshal(binCnr)
74-
if err != nil {
75-
return fmt.Errorf("invalid binary container: %w", err)
76-
}
77-
78-
for k := range ctx.cnr.Attributes() {
68+
func (cp *Processor) checkPutContainer(req containerEvent.CreateContainerRequest, cnr containerSDK.Container) error {
69+
for k := range cnr.Attributes() {
7970
if strings.HasPrefix(k, sysAttrPrefix) {
8071
if _, ok := allowedSystemAttributes[k]; !ok {
8172
return fmt.Errorf("system attribute %s is not allowed", k)
@@ -87,38 +78,38 @@ func (cp *Processor) checkPutContainer(ctx *putContainerContext) error {
8778
}
8879
}
8980

90-
ecRules := ctx.cnr.PlacementPolicy().ECRules()
81+
ecRules := cnr.PlacementPolicy().ECRules()
9182
if !cp.allowEC && len(ecRules) > 0 {
9283
return errors.New("EC rules are not supported yet")
9384
}
94-
if len(ecRules) > 0 && ctx.cnr.PlacementPolicy().NumberOfReplicas() > 0 {
85+
if len(ecRules) > 0 && cnr.PlacementPolicy().NumberOfReplicas() > 0 {
9586
return errors.New("REP+EC rules are not supported yet")
9687
}
9788

98-
err = cp.verifySignature(signatureVerificationData{
99-
ownerContainer: ctx.cnr.Owner(),
89+
err := cp.verifySignature(signatureVerificationData{
90+
ownerContainer: cnr.Owner(),
10091
verb: session.VerbContainerPut,
101-
binTokenSession: ctx.e.SessionToken,
102-
verifScript: ctx.e.VerificationScript,
103-
invocScript: ctx.e.InvocationScript,
104-
signedData: binCnr,
92+
binTokenSession: req.SessionToken,
93+
verifScript: req.VerificationScript,
94+
invocScript: req.InvocationScript,
95+
signedData: req.Container,
10596
})
10697
if err != nil {
10798
return fmt.Errorf("auth container creation: %w", err)
10899
}
109100

110-
if err = ctx.cnr.PlacementPolicy().Verify(); err != nil {
101+
if err = cnr.PlacementPolicy().Verify(); err != nil {
111102
return fmt.Errorf("invalid storage policy: %w", err)
112103
}
113104

114105
// check homomorphic hashing setting
115-
err = checkHomomorphicHashing(cp.netState, ctx.cnr)
106+
err = checkHomomorphicHashing(cp.netState, cnr)
116107
if err != nil {
117108
return fmt.Errorf("incorrect homomorphic hashing setting: %w", err)
118109
}
119110

120-
if ctx.e.DomainName != "" { // if PutNamed event => check if values in-container domain name and zone correspond to args
121-
err = checkNNS(ctx.cnr, ctx.e.DomainName, ctx.e.DomainZone)
111+
if req.DomainName != "" { // if PutNamed event => check if values in-container domain name and zone correspond to args
112+
err = checkNNS(cnr, req.DomainName, req.DomainZone)
122113
if err != nil {
123114
return fmt.Errorf("NNS: %w", err)
124115
}
@@ -127,15 +118,13 @@ func (cp *Processor) checkPutContainer(ctx *putContainerContext) error {
127118
return nil
128119
}
129120

130-
func (cp *Processor) approvePutContainer(ctx *putContainerContext, id cid.ID) {
121+
func (cp *Processor) approvePutContainer(mainTx transaction.Transaction, cnr containerSDK.Container, id cid.ID) {
131122
l := cp.log.With(zap.Stringer("cID", id))
132123
l.Debug("approving new container...")
133124

134-
e := ctx.e
135-
136125
var err error
137126

138-
err = cp.cnrClient.Morph().NotarySignAndInvokeTX(&e.MainTransaction, true)
127+
err = cp.cnrClient.Morph().NotarySignAndInvokeTX(&mainTx, true)
139128

140129
if err != nil {
141130
l.Error("could not approve put container",
@@ -150,7 +139,7 @@ func (cp *Processor) approvePutContainer(ctx *putContainerContext, id cid.ID) {
150139
return
151140
}
152141

153-
policy := ctx.cnr.PlacementPolicy()
142+
policy := cnr.PlacementPolicy()
154143
vectors, err := nm.ContainerNodes(policy, id)
155144
if err != nil {
156145
l.Error("could not build placement for Container contract update", zap.Error(err))

0 commit comments

Comments
 (0)