[#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 <e.stratonikov@yadro.com>
This commit is contained in:
Evgenii Stratonikov 2024-12-06 15:56:41 +03:00 committed by Evgenii Stratonikov
parent 670305a721
commit dfa51048a8
2 changed files with 0 additions and 19 deletions

View file

@ -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"

View file

@ -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()