From dfa51048a852aa9a8c88a67b6914d671137dc3f7 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Fri, 6 Dec 2024 15:56:41 +0300 Subject: [PATCH] [#1546] morph/event: Remove "is started" checks from event handler registrar This codepath hides possible bugs in code. All initialization function should run before init stage. Signed-off-by: Evgenii Stratonikov --- internal/logs/logs.go | 2 -- pkg/morph/event/listener.go | 17 ----------------- 2 files changed, 19 deletions(-) diff --git a/internal/logs/logs.go b/internal/logs/logs.go index 893be700..535802a2 100644 --- a/internal/logs/logs.go +++ b/internal/logs/logs.go @@ -164,11 +164,9 @@ const ( EventNotaryParserNotSet = "notary parser not set" EventCouldNotParseNotaryEvent = "could not parse notary event" EventNotaryHandlersForParsedNotificationEventWereNotRegistered = "notary handlers for parsed notification event were not registered" - EventListenerHasBeenAlreadyStartedIgnoreParser = "listener has been already started, ignore parser" EventRegisteredNewEventParser = "registered new event parser" EventIgnoreHandlerOfEventWoParser = "ignore handler of event w/o parser" EventRegisteredNewEventHandler = "registered new event handler" - EventListenerHasBeenAlreadyStartedIgnoreNotaryParser = "listener has been already started, ignore notary parser" EventIgnoreHandlerOfNotaryEventWoParser = "ignore handler of notary event w/o parser" StorageOperation = "local object storage operation" BlobovniczaCreatingDirectoryForBoltDB = "creating directory for BoltDB" diff --git a/pkg/morph/event/listener.go b/pkg/morph/event/listener.go index b6754680..64ff205b 100644 --- a/pkg/morph/event/listener.go +++ b/pkg/morph/event/listener.go @@ -100,8 +100,6 @@ type listener struct { startOnce, stopOnce sync.Once - started bool - notificationParsers map[scriptHashWithType]NotificationParser notificationHandlers map[scriptHashWithType][]Handler @@ -171,9 +169,6 @@ func (l *listener) ListenWithError(ctx context.Context, intError chan<- error) { } func (l *listener) listen(ctx context.Context, intError chan<- error) error { - // mark listener as started - l.started = true - subErrCh := make(chan error) go l.subscribe(subErrCh) @@ -462,12 +457,6 @@ func (l *listener) SetNotificationParser(pi NotificationParserInfo) { l.mtx.Lock() defer l.mtx.Unlock() - // check if the listener was started - if l.started { - log.Warn(context.Background(), logs.EventListenerHasBeenAlreadyStartedIgnoreParser) - return - } - // add event parser if _, ok := l.notificationParsers[pi.scriptHashWithType]; !ok { l.notificationParsers[pi.scriptHashWithType] = pi.parser() @@ -546,12 +535,6 @@ func (l *listener) SetNotaryParser(pi NotaryParserInfo) { l.mtx.Lock() defer l.mtx.Unlock() - // check if the listener was started - if l.started { - log.Warn(context.Background(), logs.EventListenerHasBeenAlreadyStartedIgnoreNotaryParser) - return - } - // add event parser if _, ok := l.notaryParsers[pi.notaryRequestTypes]; !ok { l.notaryParsers[pi.notaryRequestTypes] = pi.parser()