From b3e1e90c01abea2d70348fd2e15fb890db0b54f7 Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Fri, 13 May 2022 21:37:59 +0300 Subject: [PATCH] [#1224] ir: Listen to subnet removal events IR must listen to subnet removal notifications always (regardless of notary mode). Signed-off-by: Pavel Karpy --- CHANGELOG.md | 1 + pkg/innerring/subnet.go | 35 +++++++++++++++++++---------------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7456d004f..ac2e54c65 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ Changelog for NeoFS Node - Do not update NNS group if the key is the same (#1375) - Make LOCODE messages more descriptive (#1394) - Basic income transfer's incorrect log message (#1374) +- Listen to subnet removal events in notary-enabled env (#1224) ## [0.28.1] - 2022-05-05 diff --git a/pkg/innerring/subnet.go b/pkg/innerring/subnet.go index cd0ddada0..be5a3d56d 100644 --- a/pkg/innerring/subnet.go +++ b/pkg/innerring/subnet.go @@ -100,6 +100,7 @@ const ( // // Events (notary): // * put (parser: subnetevents.ParseNotaryPut, handler: catchSubnetCreation); +// * Delete (parser: subnetevents.ParseDelete, handler: catchSubnetCreation). // // Events (non-notary): // * Put (parser: subnetevents.ParsePut, handler: catchSubnetCreation); @@ -118,7 +119,7 @@ func (s *Server) listenSubnet() { parserInfo.SetScriptHash(s.contracts.subnet) handlerInfo.SetScriptHash(s.contracts.subnet) - listenEvent := func(notifyName string, parser event.NotaryParser, handler event.Handler) { + listenNotaryEvent := func(notifyName string, parser event.NotaryParser, handler event.Handler) { notifyTyp := event.NotaryTypeFromString(notifyName) parserInfo.SetMempoolType(mempoolevent.TransactionAdded) @@ -135,10 +136,19 @@ func (s *Server) listenSubnet() { } // subnet creation - listenEvent(notarySubnetCreateEvName, subnetevents.ParseNotaryPut, s.onlyAlphabetEventHandler(s.catchSubnetCreation)) + listenNotaryEvent(notarySubnetCreateEvName, subnetevents.ParseNotaryPut, s.onlyAlphabetEventHandler(s.catchSubnetCreation)) + // subnet removal + listenNotifySubnetEvent(s, subnetRemoveEvName, subnetevents.ParseDelete, s.onlyAlphabetEventHandler(s.catchSubnetRemoval)) } func (s *Server) listenSubnetWithoutNotary() { + // subnet creation + listenNotifySubnetEvent(s, subnetCreateEvName, subnetevents.ParsePut, s.onlyAlphabetEventHandler(s.catchSubnetCreation)) + // subnet removal + listenNotifySubnetEvent(s, subnetRemoveEvName, subnetevents.ParseDelete, s.onlyAlphabetEventHandler(s.catchSubnetRemoval)) +} + +func listenNotifySubnetEvent(s *Server, notifyName string, parser event.NotificationParser, handler event.Handler) { var ( parserInfo event.NotificationParserInfo handlerInfo event.NotificationHandlerInfo @@ -147,23 +157,16 @@ func (s *Server) listenSubnetWithoutNotary() { parserInfo.SetScriptHash(s.contracts.subnet) handlerInfo.SetScriptHash(s.contracts.subnet) - listenEvent := func(notifyName string, parser event.NotificationParser, handler event.Handler) { - notifyTyp := event.TypeFromString(notifyName) + notifyTyp := event.TypeFromString(notifyName) - parserInfo.SetType(notifyTyp) - handlerInfo.SetType(notifyTyp) + parserInfo.SetType(notifyTyp) + handlerInfo.SetType(notifyTyp) - parserInfo.SetParser(parser) - handlerInfo.SetHandler(handler) + parserInfo.SetParser(parser) + handlerInfo.SetHandler(handler) - s.morphListener.SetNotificationParser(parserInfo) - s.morphListener.RegisterNotificationHandler(handlerInfo) - } - - // subnet creation - listenEvent(subnetCreateEvName, subnetevents.ParsePut, s.onlyAlphabetEventHandler(s.catchSubnetCreation)) - // subnet removal - listenEvent(subnetRemoveEvName, subnetevents.ParseDelete, s.onlyAlphabetEventHandler(s.catchSubnetRemoval)) + s.morphListener.SetNotificationParser(parserInfo) + s.morphListener.RegisterNotificationHandler(handlerInfo) } // catchSubnetCreation catches event of subnet creation from listener and queues the processing.