From fdd54b0a03562a8ae2f21c504c461d4604f72c89 Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Fri, 27 May 2022 12:35:41 +0300 Subject: [PATCH] [#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 --- pkg/innerring/processors/subnet/delete.go | 44 ------------------- .../processors/subnet/delete_test.go | 44 ------------------- pkg/innerring/subnet.go | 40 +---------------- 3 files changed, 1 insertion(+), 127 deletions(-) delete mode 100644 pkg/innerring/processors/subnet/delete.go delete mode 100644 pkg/innerring/processors/subnet/delete_test.go diff --git a/pkg/innerring/processors/subnet/delete.go b/pkg/innerring/processors/subnet/delete.go deleted file mode 100644 index 1a2ac49a6..000000000 --- a/pkg/innerring/processors/subnet/delete.go +++ /dev/null @@ -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 -} diff --git a/pkg/innerring/processors/subnet/delete_test.go b/pkg/innerring/processors/subnet/delete_test.go deleted file mode 100644 index 04db0e34a..000000000 --- a/pkg/innerring/processors/subnet/delete_test.go +++ /dev/null @@ -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) -} diff --git a/pkg/innerring/subnet.go b/pkg/innerring/subnet.go index 81aeac9fc..5d040ab23 100644 --- a/pkg/innerring/subnet.go +++ b/pkg/innerring/subnet.go @@ -31,8 +31,6 @@ type subnetHandler struct { morphClient morphsubnet.Client putValidator irsubnet.PutValidator - - delValidator irsubnet.DeleteValidator } // configuration of subnet component. @@ -272,52 +270,16 @@ func (s *Server) catchSubnetRemoval(e event.Event) { s.handleSubnetRemoval(e) }) if err != nil { - s.log.Error("subnet removal queue failure", + s.log.Error("subnet removal handling failure", 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. func (s *Server) handleSubnetRemoval(e event.Event) { 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 candidates, err := s.netmapClient.GetCandidates()