diff --git a/pkg/morph/client/constructor.go b/pkg/morph/client/constructor.go index 45de2e9060..8db9ff5230 100644 --- a/pkg/morph/client/constructor.go +++ b/pkg/morph/client/constructor.go @@ -44,11 +44,14 @@ type cfg struct { singleCli *rpcclient.WSClient // neo-go client for single client mode inactiveModeCb Callback + + switchInterval time.Duration } const ( - defaultDialTimeout = 5 * time.Second - defaultWaitInterval = 500 * time.Millisecond + defaultDialTimeout = 5 * time.Second + defaultWaitInterval = 500 * time.Millisecond + defaultSwitchInterval = 2 * time.Minute ) func defaultConfig() *cfg { @@ -60,6 +63,7 @@ func defaultConfig() *cfg { signer: &transaction.Signer{ Scopes: transaction.Global, }, + switchInterval: defaultSwitchInterval, } } @@ -289,3 +293,12 @@ func WithConnLostCallback(cb Callback) Option { c.inactiveModeCb = cb } } + +// WithSwitchInterval returns a client constructor option +// that specifies a wait interval b/w attempts to reconnect +// to an RPC node with the highest priority. +func WithSwitchInterval(i time.Duration) Option { + return func(c *cfg) { + c.switchInterval = i + } +} diff --git a/pkg/morph/client/multi.go b/pkg/morph/client/multi.go index 711c73f97a..8d9e0bd5b1 100644 --- a/pkg/morph/client/multi.go +++ b/pkg/morph/client/multi.go @@ -133,9 +133,7 @@ func (c *Client) notificationLoop() { } func (c *Client) switchToMostPrioritized() { - const period = 2 * time.Minute - - t := time.NewTicker(period) + t := time.NewTicker(c.cfg.switchInterval) defer t.Stop() defer c.switchIsActive.Store(false)