From 8efea6e0669e164ddc31c5269eb147033dfe8eec Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Wed, 15 Sep 2021 18:57:43 +0300 Subject: [PATCH] [#792] ir: Support multiple notification endpoints Accept notification endpoints as string slice from config. Work with the first successfully initialized WSClient. Signed-off-by: Leonard Lyubich --- pkg/innerring/innerring.go | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/pkg/innerring/innerring.go b/pkg/innerring/innerring.go index f24560dde..c37946577 100644 --- a/pkg/innerring/innerring.go +++ b/pkg/innerring/innerring.go @@ -879,14 +879,34 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error } func createListener(ctx context.Context, p *chainParams) (event.Listener, error) { - sub, err := subscriber.New(ctx, &subscriber.Params{ - Log: p.log, - Endpoint: p.cfg.GetString(p.name + ".endpoint.notification"), - DialTimeout: p.cfg.GetDuration(p.name + ".dial_timeout"), - StartFromBlock: p.from, - }) - if err != nil { - return nil, err + // config name left unchanged for compatibility, may be its better to rename it to "endpoints" + endpoints := p.cfg.GetStringSlice(p.name + ".endpoint.notification") + if len(endpoints) == 0 { + return nil, errors.New("missing morph notification endpoints") + } + + var ( + sub subscriber.Subscriber + err error + ) + + dialTimeout := p.cfg.GetDuration(p.name + ".dial_timeout") + + for i := range endpoints { + sub, err = subscriber.New(ctx, &subscriber.Params{ + Log: p.log, + Endpoint: endpoints[i], + DialTimeout: dialTimeout, + StartFromBlock: p.from, + }) + if err == nil { + break + } + + p.log.Info("failed to establish websocket neo event listener, trying another", + zap.String("endpoint", endpoints[i]), + zap.String("error", err.Error()), + ) } listener, err := event.NewListener(event.ListenerParams{