From 670305a7216bf3a5304b6256eed8dc1efe285f9f Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Fri, 6 Dec 2024 15:50:57 +0300 Subject: [PATCH] [#1546] morph/event: Remove nil checks from event handler registrar This codepath hides possible bugs in code. We would rather panic then silently fail. Signed-off-by: Evgenii Stratonikov --- internal/logs/logs.go | 5 ----- pkg/morph/event/listener.go | 29 ----------------------------- 2 files changed, 34 deletions(-) diff --git a/internal/logs/logs.go b/internal/logs/logs.go index d0bac4d11..893be7006 100644 --- a/internal/logs/logs.go +++ b/internal/logs/logs.go @@ -164,17 +164,12 @@ const ( EventNotaryParserNotSet = "notary parser not set" EventCouldNotParseNotaryEvent = "could not parse notary event" EventNotaryHandlersForParsedNotificationEventWereNotRegistered = "notary handlers for parsed notification event were not registered" - EventIgnoreNilEventParser = "ignore nil event parser" EventListenerHasBeenAlreadyStartedIgnoreParser = "listener has been already started, ignore parser" EventRegisteredNewEventParser = "registered new event parser" - EventIgnoreNilEventHandler = "ignore nil event handler" EventIgnoreHandlerOfEventWoParser = "ignore handler of event w/o parser" EventRegisteredNewEventHandler = "registered new event handler" - EventIgnoreNilNotaryEventParser = "ignore nil notary event parser" EventListenerHasBeenAlreadyStartedIgnoreNotaryParser = "listener has been already started, ignore notary parser" - EventIgnoreNilNotaryEventHandler = "ignore nil notary event handler" EventIgnoreHandlerOfNotaryEventWoParser = "ignore handler of notary event w/o parser" - EventIgnoreNilBlockHandler = "ignore nil block handler" StorageOperation = "local object storage operation" BlobovniczaCreatingDirectoryForBoltDB = "creating directory for BoltDB" BlobovniczaOpeningBoltDB = "opening BoltDB" diff --git a/pkg/morph/event/listener.go b/pkg/morph/event/listener.go index 6e6184e77..b67546804 100644 --- a/pkg/morph/event/listener.go +++ b/pkg/morph/event/listener.go @@ -459,12 +459,6 @@ func (l *listener) SetNotificationParser(pi NotificationParserInfo) { zap.Stringer("event_type", pi.getType()), ) - parser := pi.parser() - if parser == nil { - log.Info(context.Background(), logs.EventIgnoreNilEventParser) - return - } - l.mtx.Lock() defer l.mtx.Unlock() @@ -492,12 +486,6 @@ func (l *listener) RegisterNotificationHandler(hi NotificationHandlerInfo) { zap.Stringer("event_type", hi.GetType()), ) - handler := hi.Handler() - if handler == nil { - log.Warn(context.Background(), logs.EventIgnoreNilEventHandler) - return - } - // check if parser was set l.mtx.RLock() _, ok := l.notificationParsers[hi.scriptHashWithType] @@ -555,12 +543,6 @@ func (l *listener) SetNotaryParser(pi NotaryParserInfo) { zap.Stringer("notary_type", pi.RequestType()), ) - parser := pi.parser() - if parser == nil { - log.Info(context.Background(), logs.EventIgnoreNilNotaryEventParser) - return - } - l.mtx.Lock() defer l.mtx.Unlock() @@ -593,12 +575,6 @@ func (l *listener) RegisterNotaryHandler(hi NotaryHandlerInfo) { zap.Stringer("notary type", hi.RequestType()), ) - handler := hi.Handler() - if handler == nil { - log.Warn(context.Background(), logs.EventIgnoreNilNotaryEventHandler) - return - } - // check if parser was set l.mtx.RLock() _, ok := l.notaryParsers[hi.notaryRequestTypes] @@ -627,11 +603,6 @@ func (l *listener) Stop() { } func (l *listener) RegisterBlockHandler(handler BlockHandler) { - if handler == nil { - l.log.Warn(context.Background(), logs.EventIgnoreNilBlockHandler) - return - } - l.blockHandlers = append(l.blockHandlers, handler) }