[#324] morph/listener: Do not subscribe on new blocks without handlers

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2021-01-25 16:45:59 +03:00 committed by Alex Vanin
parent 96f750d9c8
commit 44c899b560

View file

@ -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,8 +154,11 @@ 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 {
var blockChan <-chan *block.Block
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 {
@ -165,6 +169,9 @@ func (s listener) listenLoop(ctx context.Context, chEvent <-chan *state.Notifica
return
}
} else {
blockChan = make(chan *block.Block)
}
loop:
for {