Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Changelog for NeoFS Node
- Support for GET of LINK objects in EC containers (#3722)
- Containers can now be locked for deletion via `__NEOFS__LOCK_UNTIL` attribute (#3708)
- SN can respond with `CONTAINER_LOCKED` status now (#3708)
- IR now supports `setAttrbibute` method to Container contract (#3728)

### Fixed
- IR panics at graceful shutdown (#3706)
Expand Down
27 changes: 27 additions & 0 deletions pkg/innerring/processors/container/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,30 @@ func (cp *Processor) handleObjectPut(ev event.Event) {
cp.log.Warn("object pool submission failed", zap.Error(err))
}
}

func (cp *Processor) handleSetAttribute(ev event.Event) {
e := ev.(containerEvent.SetAttribute)

cp.log.Debug("notification",
zap.String("type", "set attribute"),
zap.String("cID", base58.Encode(e.CID)),
)

if !cp.alphabetState.IsAlphabet() {
cp.log.Debug("non alphabet mode, ignore set attribute")
return
}

err := cp.objectPool.Submit(func() {
err := cp.cnrClient.Morph().NotarySignAndInvokeTX(e.NotaryRequest.MainTransaction, false)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so 3rd party can add attribute to my container w/o my approval?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think no. I consider, we will check this with token parameter inside contact setAttribute, when it be done in contracts

if err != nil {
cp.log.Error("could not approve set attribute",
zap.String("cID", base58.Encode(e.CID)),
zap.Error(err),
)
}
})
if err != nil {
cp.log.Warn("object pool submission failed", zap.Error(err))
}
}
9 changes: 9 additions & 0 deletions pkg/innerring/processors/container/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ func (cp *Processor) ListenerNotaryParsers() []event.NotaryParserInfo {
p.SetRequestType(fschaincontracts.AddContainerStructsMethod)
p.SetParser(containerEvent.RestoreAddStructsRequest)

// set attribute
p.SetRequestType(containerEvent.SetAttributeNotaryEvent)
p.SetParser(containerEvent.ParseSetAttribute)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
p.SetParser(containerEvent.ParseSetAttribute)
p.SetParser(containerEvent.ParseSetAttribute)
pp = append(pp, p)


return pp
}

Expand Down Expand Up @@ -240,6 +244,11 @@ func (cp *Processor) ListenerNotaryHandlers() []event.NotaryHandlerInfo {
h.SetHandler(cp.handleObjectPut)
hh = append(hh, h)

// container setAttribute
h.SetRequestType(containerEvent.SetAttributeNotaryEvent)
h.SetHandler(cp.handleSetAttribute)
hh = append(hh, h)

// migrate protobuf->struct
h.SetRequestType(fschaincontracts.AddContainerStructsMethod)
h.SetHandler(func(ev event.Event) {
Expand Down
59 changes: 59 additions & 0 deletions pkg/morph/event/container/attributes.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package container

import (
"github.com/nspcc-dev/neo-go/pkg/network/payload"
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
)

const (
// SetAttributeNotaryEvent is method name for setAttribute operations in `Container` contract.
SetAttributeNotaryEvent = "setAttribute"
)

// SetAttribute represents structure of notification about modified container attributes
// coming from NeoFS Container contract.
type SetAttribute struct {
CID []byte
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can validate it there. currently, any size of CID and any token can be signed by the alphabet and sent to the contract

Name []byte
Value []byte
Token []byte

// For notary notifications only.
// Contains raw transactions of notary request.
NotaryRequest *payload.P2PNotaryRequest
}

// MorphEvent implements [event.Event].
func (r SetAttribute) MorphEvent() {}

// ParseSetAttribute from NotaryEvent into container event structure.
func ParseSetAttribute(ne event.NotaryEvent) (event.Event, error) {
const expectedItemNumAnnounceLoad = 4
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const expectedItemNumAnnounceLoad = 4
const expectedItemNumSetAttribute = 4

args, err := getArgsFromEvent(ne, expectedItemNumAnnounceLoad)
if err != nil {
return nil, err
}
var ev SetAttribute

ev.Token, err = getValueFromArg(args, 0, "session token", stackitem.ByteArrayT, event.BytesFromOpcode)
if err != nil {
return nil, err
}
ev.Value, err = getValueFromArg(args, 1, "attribute value", stackitem.ByteArrayT, event.BytesFromOpcode)
if err != nil {
return nil, err
}
ev.Name, err = getValueFromArg(args, 2, "attribute name", stackitem.ByteArrayT, event.BytesFromOpcode)
if err != nil {
return nil, err
}
ev.CID, err = getValueFromArg(args, 3, "container ID", stackitem.ByteArrayT, event.BytesFromOpcode)
if err != nil {
return nil, err
}

ev.NotaryRequest = ne.Raw()

return ev, nil
}
Loading