[#1441] ir: Do not validate subnet removal
It is useless process since subnet owner is able to delete subnet without an Alphabet approval. The Alphabet should only validate netmap state after removal: 1. Update nodes' attributes if they were included in the deleted subnet; 2. Remove nodes without any subnet entrance. Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
parent
feef9a98f7
commit
fdd54b0a03
3 changed files with 1 additions and 127 deletions
|
@ -1,44 +0,0 @@
|
||||||
package subnetevents
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
subnetid "github.com/nspcc-dev/neofs-sdk-go/subnet/id"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Delete represents a notification about NeoFS subnet removal.
|
|
||||||
// Generated by a contract when intending to delete a subnet.
|
|
||||||
type Delete interface {
|
|
||||||
// Contains the ID of the subnet to be removed.
|
|
||||||
eventWithID
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeleteValidator asserts intent to remove a subnet.
|
|
||||||
type DeleteValidator struct{}
|
|
||||||
|
|
||||||
// Assert processes the attempt to remove a subnet. It approves the removal through nil return.
|
|
||||||
//
|
|
||||||
// All read errors of Delete are forwarded.
|
|
||||||
//
|
|
||||||
// It returns an error on:
|
|
||||||
// * zero subnet creation;
|
|
||||||
// * empty ID or different from the one wired into info;
|
|
||||||
// * empty owner ID or different from the one wired into info.
|
|
||||||
func (x DeleteValidator) Assert(event Delete) error {
|
|
||||||
var err error
|
|
||||||
|
|
||||||
// read ID
|
|
||||||
var id subnetid.ID
|
|
||||||
if err = event.ReadID(&id); err != nil {
|
|
||||||
return fmt.Errorf("read ID: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// prevent zero subnet removal
|
|
||||||
if subnetid.IsZero(id) {
|
|
||||||
return zeroSubnetOp{
|
|
||||||
op: "removal",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
|
@ -1,44 +0,0 @@
|
||||||
package subnetevents
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
|
|
||||||
subnetid "github.com/nspcc-dev/neofs-sdk-go/subnet/id"
|
|
||||||
)
|
|
||||||
|
|
||||||
type delete struct {
|
|
||||||
idEvent
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestDeleteValidator_Assert(t *testing.T) {
|
|
||||||
var (
|
|
||||||
v DeleteValidator
|
|
||||||
|
|
||||||
e delete
|
|
||||||
|
|
||||||
err error
|
|
||||||
)
|
|
||||||
|
|
||||||
// read ID error
|
|
||||||
e.idErr = errors.New("id err")
|
|
||||||
|
|
||||||
err = v.Assert(e)
|
|
||||||
require.ErrorIs(t, err, e.idErr)
|
|
||||||
|
|
||||||
e.idErr = nil
|
|
||||||
|
|
||||||
// zero subnet ID
|
|
||||||
subnetid.MakeZero(&e.id)
|
|
||||||
|
|
||||||
err = v.Assert(e)
|
|
||||||
require.ErrorAs(t, err, new(zeroSubnetOp))
|
|
||||||
|
|
||||||
const idNum = 13
|
|
||||||
e.id.SetNumber(idNum)
|
|
||||||
|
|
||||||
err = v.Assert(e)
|
|
||||||
require.NoError(t, err)
|
|
||||||
}
|
|
|
@ -31,8 +31,6 @@ type subnetHandler struct {
|
||||||
morphClient morphsubnet.Client
|
morphClient morphsubnet.Client
|
||||||
|
|
||||||
putValidator irsubnet.PutValidator
|
putValidator irsubnet.PutValidator
|
||||||
|
|
||||||
delValidator irsubnet.DeleteValidator
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// configuration of subnet component.
|
// configuration of subnet component.
|
||||||
|
@ -272,52 +270,16 @@ func (s *Server) catchSubnetRemoval(e event.Event) {
|
||||||
s.handleSubnetRemoval(e)
|
s.handleSubnetRemoval(e)
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.log.Error("subnet removal queue failure",
|
s.log.Error("subnet removal handling failure",
|
||||||
zap.String("error", err.Error()),
|
zap.String("error", err.Error()),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// implements irsubnet.Delete event interface required by irsubnet.DeleteValidator.
|
|
||||||
type deleteSubnetEvent struct {
|
|
||||||
ev subnetevents.Delete
|
|
||||||
}
|
|
||||||
|
|
||||||
// ReadID unmarshals subnet ID from a binary NeoFS API protocol's format.
|
|
||||||
func (x deleteSubnetEvent) ReadID(id *subnetid.ID) error {
|
|
||||||
return id.Unmarshal(x.ev.ID())
|
|
||||||
}
|
|
||||||
|
|
||||||
// handleSubnetRemoval handles event of subnet removal parsed via subnetevents.ParseDelete.
|
// handleSubnetRemoval handles event of subnet removal parsed via subnetevents.ParseDelete.
|
||||||
func (s *Server) handleSubnetRemoval(e event.Event) {
|
func (s *Server) handleSubnetRemoval(e event.Event) {
|
||||||
delEv := e.(subnetevents.Delete) // panic occurs only if we registered handler incorrectly
|
delEv := e.(subnetevents.Delete) // panic occurs only if we registered handler incorrectly
|
||||||
|
|
||||||
err := s.subnetHandler.delValidator.Assert(deleteSubnetEvent{
|
|
||||||
ev: delEv,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
s.log.Info("discard subnet removal",
|
|
||||||
zap.String("reason", err.Error()),
|
|
||||||
)
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// send new transaction
|
|
||||||
var prm morphsubnet.DeletePrm
|
|
||||||
|
|
||||||
prm.SetID(delEv.ID())
|
|
||||||
prm.SetTxHash(delEv.TxHash())
|
|
||||||
|
|
||||||
_, err = s.subnetHandler.morphClient.Delete(prm)
|
|
||||||
if err != nil {
|
|
||||||
s.log.Error("approve subnet removal",
|
|
||||||
zap.String("error", err.Error()),
|
|
||||||
)
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// handle subnet changes in netmap
|
// handle subnet changes in netmap
|
||||||
|
|
||||||
candidates, err := s.netmapClient.GetCandidates()
|
candidates, err := s.netmapClient.GetCandidates()
|
||||||
|
|
Loading…
Reference in a new issue