From 44c899b5603f6fc14ce4b08cc569e1bebf816405 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Mon, 25 Jan 2021 16:45:59 +0300 Subject: [PATCH] [#324] morph/listener: Do not subscribe on new blocks without handlers Signed-off-by: Leonard Lyubich --- pkg/morph/event/listener.go | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/pkg/morph/event/listener.go b/pkg/morph/event/listener.go index 833c6558a..615bd8048 100644 --- a/pkg/morph/event/listener.go +++ b/pkg/morph/event/listener.go @@ -4,6 +4,7 @@ import ( "context" "sync" + "github.com/nspcc-dev/neo-go/pkg/core/block" "github.com/nspcc-dev/neo-go/pkg/core/state" "github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neofs-node/pkg/morph/client" @@ -153,17 +154,23 @@ func (s listener) listen(ctx context.Context, intError chan<- error) error { } func (s listener) listenLoop(ctx context.Context, chEvent <-chan *state.NotificationEvent, intErr chan<- error) { - blockChan, err := s.subscriber.BlockNotifications() - if err != nil { - if intErr != nil { - intErr <- errors.Wrap(err, "could not open block notifications channel") - } else { - s.log.Debug("could not open block notifications channel", - zap.String("error", err.Error()), - ) - } + var blockChan <-chan *block.Block - return + if len(s.blockHandlers) > 0 { + var err error + if blockChan, err = s.subscriber.BlockNotifications(); err != nil { + if intErr != nil { + intErr <- errors.Wrap(err, "could not open block notifications channel") + } else { + s.log.Debug("could not open block notifications channel", + zap.String("error", err.Error()), + ) + } + + return + } + } else { + blockChan = make(chan *block.Block) } loop: