From fe1acf9e9a42367ae78e411f8124aaeed5fb707d Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Tue, 24 Oct 2023 12:34:30 +0300 Subject: [PATCH] [#750] morph: Remove deprecated channel use Signed-off-by: Evgenii Stratonikov --- pkg/morph/client/client.go | 9 --------- pkg/morph/subscriber/subscriber.go | 15 ++++----------- 2 files changed, 4 insertions(+), 20 deletions(-) diff --git a/pkg/morph/client/client.go b/pkg/morph/client/client.go index 606f3bd6..290e651f 100644 --- a/pkg/morph/client/client.go +++ b/pkg/morph/client/client.go @@ -527,15 +527,6 @@ func (c *Client) IsValidScript(script []byte, signers []transaction.Signer) (val return res.State == vmstate.Halt.String(), nil } -// NotificationChannel returns channel than receives subscribed -// notification from the connected RPC node. -// Channel is closed when connection to the RPC node is lost. -func (c *Client) NotificationChannel() <-chan rpcclient.Notification { - c.switchLock.RLock() - defer c.switchLock.RUnlock() - return c.client.Notifications //lint:ignore SA1019 waits for neo-go v0.102.0 https://github.com/nspcc-dev/neo-go/pull/2980 -} - func (c *Client) Metrics() morphmetrics.Register { return c.metrics } diff --git a/pkg/morph/subscriber/subscriber.go b/pkg/morph/subscriber/subscriber.go index c2d8494f..7f3c9138 100644 --- a/pkg/morph/subscriber/subscriber.go +++ b/pkg/morph/subscriber/subscriber.go @@ -12,7 +12,6 @@ import ( "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/neorpc/result" - "github.com/nspcc-dev/neo-go/pkg/rpcclient" "github.com/nspcc-dev/neo-go/pkg/util" "go.uber.org/zap" ) @@ -183,8 +182,6 @@ func New(ctx context.Context, p *Params) (Subscriber, error) { func (s *subscriber) routeNotifications(ctx context.Context) { var ( - // TODO: not needed after nspcc-dev/neo-go#2980. - cliCh = s.client.NotificationChannel() restoreCh = make(chan bool) restoreInProgress bool ) @@ -220,8 +217,6 @@ routeloop: } else { connLost = true } - case _, ok := <-cliCh: - connLost = !ok case ok := <-restoreCh: restoreInProgress = false if !ok { @@ -230,7 +225,7 @@ routeloop: } if connLost { if !restoreInProgress { - restoreInProgress, cliCh = s.switchEndpoint(ctx, restoreCh) + restoreInProgress = s.switchEndpoint(ctx, restoreCh) if !restoreInProgress { break routeloop } @@ -249,15 +244,13 @@ routeloop: close(s.notaryChan) } -func (s *subscriber) switchEndpoint(ctx context.Context, finishCh chan<- bool) (bool, <-chan rpcclient.Notification) { +func (s *subscriber) switchEndpoint(ctx context.Context, finishCh chan<- bool) bool { s.log.Info(logs.RPConnectionLost) if !s.client.SwitchRPC(ctx) { s.log.Error(logs.RPCNodeSwitchFailure) - return false, nil + return false } - cliCh := s.client.NotificationChannel() - s.Lock() chs := newSubChannels() go func() { @@ -267,7 +260,7 @@ func (s *subscriber) switchEndpoint(ctx context.Context, finishCh chan<- bool) ( s.Unlock() s.client.Metrics().IncSwitchCount() - return true, cliCh + return true } func newSubChannels() subChannels {