[#1224] ir: Listen to subnet removal events

IR must listen to subnet removal notifications always (regardless of notary
mode).

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2022-05-13 21:37:59 +03:00 committed by LeL
parent 71f18ba9ec
commit b3e1e90c01
2 changed files with 20 additions and 16 deletions

View file

@ -12,6 +12,7 @@ Changelog for NeoFS Node
- Do not update NNS group if the key is the same (#1375) - Do not update NNS group if the key is the same (#1375)
- Make LOCODE messages more descriptive (#1394) - Make LOCODE messages more descriptive (#1394)
- Basic income transfer's incorrect log message (#1374) - Basic income transfer's incorrect log message (#1374)
- Listen to subnet removal events in notary-enabled env (#1224)
## [0.28.1] - 2022-05-05 ## [0.28.1] - 2022-05-05

View file

@ -100,6 +100,7 @@ const (
// //
// Events (notary): // Events (notary):
// * put (parser: subnetevents.ParseNotaryPut, handler: catchSubnetCreation); // * put (parser: subnetevents.ParseNotaryPut, handler: catchSubnetCreation);
// * Delete (parser: subnetevents.ParseDelete, handler: catchSubnetCreation).
// //
// Events (non-notary): // Events (non-notary):
// * Put (parser: subnetevents.ParsePut, handler: catchSubnetCreation); // * Put (parser: subnetevents.ParsePut, handler: catchSubnetCreation);
@ -118,7 +119,7 @@ func (s *Server) listenSubnet() {
parserInfo.SetScriptHash(s.contracts.subnet) parserInfo.SetScriptHash(s.contracts.subnet)
handlerInfo.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) notifyTyp := event.NotaryTypeFromString(notifyName)
parserInfo.SetMempoolType(mempoolevent.TransactionAdded) parserInfo.SetMempoolType(mempoolevent.TransactionAdded)
@ -135,10 +136,19 @@ func (s *Server) listenSubnet() {
} }
// subnet creation // 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() { 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 ( var (
parserInfo event.NotificationParserInfo parserInfo event.NotificationParserInfo
handlerInfo event.NotificationHandlerInfo handlerInfo event.NotificationHandlerInfo
@ -147,7 +157,6 @@ func (s *Server) listenSubnetWithoutNotary() {
parserInfo.SetScriptHash(s.contracts.subnet) parserInfo.SetScriptHash(s.contracts.subnet)
handlerInfo.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) parserInfo.SetType(notifyTyp)
@ -160,12 +169,6 @@ func (s *Server) listenSubnetWithoutNotary() {
s.morphListener.RegisterNotificationHandler(handlerInfo) s.morphListener.RegisterNotificationHandler(handlerInfo)
} }
// subnet creation
listenEvent(subnetCreateEvName, subnetevents.ParsePut, s.onlyAlphabetEventHandler(s.catchSubnetCreation))
// subnet removal
listenEvent(subnetRemoveEvName, subnetevents.ParseDelete, s.onlyAlphabetEventHandler(s.catchSubnetRemoval))
}
// catchSubnetCreation catches event of subnet creation from listener and queues the processing. // catchSubnetCreation catches event of subnet creation from listener and queues the processing.
func (s *Server) catchSubnetCreation(e event.Event) { func (s *Server) catchSubnetCreation(e event.Event) {
err := s.subnetHandler.workerPool.Submit(func() { err := s.subnetHandler.workerPool.Submit(func() {