[#750] morph: Remove deprecated channel use

Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
Evgenii Stratonikov 2023-10-24 12:34:30 +03:00 committed by Evgenii Stratonikov
parent 559ad58ab1
commit fe1acf9e9a
2 changed files with 4 additions and 20 deletions

View file

@ -527,15 +527,6 @@ func (c *Client) IsValidScript(script []byte, signers []transaction.Signer) (val
return res.State == vmstate.Halt.String(), nil 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 { func (c *Client) Metrics() morphmetrics.Register {
return c.metrics return c.metrics
} }

View file

@ -12,7 +12,6 @@ import (
"github.com/nspcc-dev/neo-go/pkg/core/block" "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/core/state"
"github.com/nspcc-dev/neo-go/pkg/neorpc/result" "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" "github.com/nspcc-dev/neo-go/pkg/util"
"go.uber.org/zap" "go.uber.org/zap"
) )
@ -183,8 +182,6 @@ func New(ctx context.Context, p *Params) (Subscriber, error) {
func (s *subscriber) routeNotifications(ctx context.Context) { func (s *subscriber) routeNotifications(ctx context.Context) {
var ( var (
// TODO: not needed after nspcc-dev/neo-go#2980.
cliCh = s.client.NotificationChannel()
restoreCh = make(chan bool) restoreCh = make(chan bool)
restoreInProgress bool restoreInProgress bool
) )
@ -220,8 +217,6 @@ routeloop:
} else { } else {
connLost = true connLost = true
} }
case _, ok := <-cliCh:
connLost = !ok
case ok := <-restoreCh: case ok := <-restoreCh:
restoreInProgress = false restoreInProgress = false
if !ok { if !ok {
@ -230,7 +225,7 @@ routeloop:
} }
if connLost { if connLost {
if !restoreInProgress { if !restoreInProgress {
restoreInProgress, cliCh = s.switchEndpoint(ctx, restoreCh) restoreInProgress = s.switchEndpoint(ctx, restoreCh)
if !restoreInProgress { if !restoreInProgress {
break routeloop break routeloop
} }
@ -249,15 +244,13 @@ routeloop:
close(s.notaryChan) 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) s.log.Info(logs.RPConnectionLost)
if !s.client.SwitchRPC(ctx) { if !s.client.SwitchRPC(ctx) {
s.log.Error(logs.RPCNodeSwitchFailure) s.log.Error(logs.RPCNodeSwitchFailure)
return false, nil return false
} }
cliCh := s.client.NotificationChannel()
s.Lock() s.Lock()
chs := newSubChannels() chs := newSubChannels()
go func() { go func() {
@ -267,7 +260,7 @@ func (s *subscriber) switchEndpoint(ctx context.Context, finishCh chan<- bool) (
s.Unlock() s.Unlock()
s.client.Metrics().IncSwitchCount() s.client.Metrics().IncSwitchCount()
return true, cliCh return true
} }
func newSubChannels() subChannels { func newSubChannels() subChannels {