[#798] morph/subscriber: Remove RPC Init timeout

More convenient way is to fail straight away and
expect external restart.

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
support/v0.27
Alex Vanin 2021-09-07 13:15:56 +03:00 committed by Alex Vanin
parent 4874b4ae92
commit 1edf40f4d6
3 changed files with 11 additions and 19 deletions

View File

@ -190,7 +190,6 @@ func listenMorphNotifications(c *cfg) {
Log: c.log,
Endpoint: endpoints[i],
DialTimeout: timeout,
RPCInitTimeout: 10 * time.Second,
StartFromBlock: fromSideChainBlock,
})
if err == nil {

View File

@ -7,7 +7,6 @@ import (
"fmt"
"io"
"net"
"time"
"github.com/nspcc-dev/neo-go/pkg/core/block"
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
@ -895,7 +894,6 @@ func createListener(ctx context.Context, p *chainParams) (event.Listener, error)
Log: p.log,
Endpoint: p.cfg.GetString(p.name + ".endpoint.notification"),
DialTimeout: p.cfg.GetDuration(p.name + ".dial_timeout"),
RPCInitTimeout: 10 * time.Second,
StartFromBlock: p.from,
})
if err != nil {

View File

@ -43,7 +43,6 @@ type (
Log *zap.Logger
Endpoint string
DialTimeout time.Duration
RPCInitTimeout time.Duration
StartFromBlock uint32
}
)
@ -198,7 +197,7 @@ func New(ctx context.Context, p *Params) (Subscriber, error) {
zap.String("endpoint", p.Endpoint),
zap.Uint32("min_block_height", p.StartFromBlock))
err = awaitHeight(wsClient, p.StartFromBlock, p.RPCInitTimeout)
err = awaitHeight(wsClient, p.StartFromBlock)
if err != nil {
return nil, err
}
@ -226,23 +225,19 @@ func New(ctx context.Context, p *Params) (Subscriber, error) {
// This function is required to avoid connections to unsynced RPC nodes, because
// they can produce events from the past that should not be processed by
// NeoFS nodes.
func awaitHeight(wsClient *client.WSClient, startFrom uint32, timeout time.Duration) error {
func awaitHeight(wsClient *client.WSClient, startFrom uint32) error {
if startFrom == 0 {
return nil
}
for ch := time.After(timeout); ; {
select {
case <-ch:
return fmt.Errorf("could not init ws client: didn't reach expected height %d", startFrom)
default:
}
height, err := wsClient.GetBlockCount()
if err != nil {
return fmt.Errorf("could not get block height: %w", err)
} else if height >= startFrom {
return nil
}
time.Sleep(100 * time.Millisecond)
height, err := wsClient.GetBlockCount()
if err != nil {
return fmt.Errorf("could not get block height: %w", err)
}
if height < startFrom {
return fmt.Errorf("RPC block counter %d didn't reach expected height %d", height, startFrom)
}
return nil
}