diff --git a/pkg/innerring/invoke/container.go b/pkg/innerring/invoke/container.go index 350efb0c..874fffd5 100644 --- a/pkg/innerring/invoke/container.go +++ b/pkg/innerring/invoke/container.go @@ -13,10 +13,17 @@ type ( Container []byte Signature []byte } + + // ContainerParams for container put invocation. + RemoveContainerParams struct { + ContainerID []byte + Signature []byte + } ) const ( - putContainerMethod = "put" + putContainerMethod = "put" + deleteContainerMethod = "delete" ) // RegisterContainer invokes Put method. @@ -31,3 +38,15 @@ func RegisterContainer(cli *client.Client, con util.Uint160, p *ContainerParams) p.Key.Bytes(), ) } + +// RegisterContainer invokes Delete method. +func RemoveContainer(cli *client.Client, con util.Uint160, p *RemoveContainerParams) error { + if cli == nil { + return client.ErrNilClient + } + + return cli.Invoke(con, extraFee, deleteContainerMethod, + p.ContainerID, + p.Signature, + ) +} diff --git a/pkg/innerring/invoke/neofs.go b/pkg/innerring/invoke/neofs.go index 543217ab..f8cb2b33 100644 --- a/pkg/innerring/invoke/neofs.go +++ b/pkg/innerring/invoke/neofs.go @@ -26,7 +26,7 @@ const ( // for invocation calculated based on testinvoke which happens at collection // stage. Therefore client has to provide some extra SysFee to operate at // execution stage. Otherwise invocation will fail due to gas limit. - extraFee = 5000_0000 // 0.5 Fixed8 gas + extraFee = 1_5000_0000 // 1.5 Fixed8 gas checkIsInnerRingMethod = "isInnerRing" chequeMethod = "cheque" diff --git a/pkg/innerring/processors/container/handlers.go b/pkg/innerring/processors/container/handlers.go index 0808e168..9e62e266 100644 --- a/pkg/innerring/processors/container/handlers.go +++ b/pkg/innerring/processors/container/handlers.go @@ -26,3 +26,19 @@ func (cp *Processor) handlePut(ev event.Event) { zap.Int("capacity", cp.pool.Cap())) } } + +func (cp *Processor) handleDelete(ev event.Event) { + del := ev.(containerEvent.Delete) // todo: check panic in production + cp.log.Info("notification", + zap.String("type", "container delete"), + zap.String("id", base58.Encode(del.ContainerID()))) + + // send event to the worker pool + + err := cp.pool.Submit(func() { cp.processContainerDelete(&del) }) + if err != nil { + // todo: move into controlled degradation stage + cp.log.Warn("container processor worker pool drained", + zap.Int("capacity", cp.pool.Cap())) + } +} diff --git a/pkg/innerring/processors/container/process_container.go b/pkg/innerring/processors/container/process_container.go index f235e34d..96253e4f 100644 --- a/pkg/innerring/processors/container/process_container.go +++ b/pkg/innerring/processors/container/process_container.go @@ -24,3 +24,21 @@ func (cp *Processor) processContainerPut(put *containerEvent.Put) { cp.log.Error("can't invoke new container", zap.Error(err)) } } + +// Process delete container operation from the user by checking container sanity +// and sending approve tx back to morph. +func (cp *Processor) processContainerDelete(delete *containerEvent.Delete) { + if !cp.activeState.IsActive() { + cp.log.Info("passive mode, ignore container put") + return + } + + err := invoke.RemoveContainer(cp.morphClient, cp.containerContract, + &invoke.RemoveContainerParams{ + ContainerID: delete.ContainerID(), + Signature: delete.Signature(), + }) + if err != nil { + cp.log.Error("can't invoke delete container", zap.Error(err)) + } +} diff --git a/pkg/innerring/processors/container/processor.go b/pkg/innerring/processors/container/processor.go index 5cfe6e80..daa34261 100644 --- a/pkg/innerring/processors/container/processor.go +++ b/pkg/innerring/processors/container/processor.go @@ -36,7 +36,8 @@ type ( ) const ( - putNotification = "containerPut" + putNotification = "containerPut" + deleteNotification = "containerDelete" ) // New creates container contract processor instance. @@ -71,11 +72,18 @@ func (cp *Processor) ListenerParsers() []event.ParserInfo { var parsers []event.ParserInfo // container put event - deposit := event.ParserInfo{} - deposit.SetType(putNotification) - deposit.SetScriptHash(cp.containerContract) - deposit.SetParser(containerEvent.ParsePut) - parsers = append(parsers, deposit) + put := event.ParserInfo{} + put.SetType(putNotification) + put.SetScriptHash(cp.containerContract) + put.SetParser(containerEvent.ParsePut) + parsers = append(parsers, put) + + // container del event + del := event.ParserInfo{} + del.SetType(deleteNotification) + del.SetScriptHash(cp.containerContract) + del.SetParser(containerEvent.ParseDelete) + parsers = append(parsers, del) return parsers } @@ -85,11 +93,17 @@ func (cp *Processor) ListenerHandlers() []event.HandlerInfo { var handlers []event.HandlerInfo // container put handler - deposit := event.HandlerInfo{} - deposit.SetType(putNotification) - deposit.SetScriptHash(cp.containerContract) - deposit.SetHandler(cp.handlePut) - handlers = append(handlers, deposit) + put := event.HandlerInfo{} + put.SetType(putNotification) + put.SetScriptHash(cp.containerContract) + put.SetHandler(cp.handlePut) + handlers = append(handlers, put) + + del := event.HandlerInfo{} + del.SetType(deleteNotification) + del.SetScriptHash(cp.containerContract) + del.SetHandler(cp.handleDelete) + handlers = append(handlers, del) return handlers }