[#1648] morph: Init endpoints before first client creation

Sort the endpoint by their priority before the first WS client creation to
start the morph client with the highest priority endpoint.

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2022-08-02 13:14:13 +03:00 committed by Pavel Karpy
parent 1c1b5043fc
commit 2467be0117

View file

@ -107,6 +107,8 @@ func New(key *keys.PrivateKey, opts ...Option) (*Client, error) {
closeChan: make(chan struct{}),
}
cli.endpoints.init(cfg.endpoints)
if cfg.singleCli != nil {
// return client in single RPC node mode that uses
// predefined WS client
@ -117,7 +119,7 @@ func New(key *keys.PrivateKey, opts ...Option) (*Client, error) {
// inactive mode will be enabled
cli.client = cfg.singleCli
} else {
ws, err := newWSClient(*cfg, cfg.endpoints[0].Address)
ws, err := newWSClient(*cfg, cli.endpoints.list[0].Address)
if err != nil {
return nil, fmt.Errorf("could not create morph client: %w", err)
}
@ -129,7 +131,6 @@ func New(key *keys.PrivateKey, opts ...Option) (*Client, error) {
cli.client = ws
}
cli.endpoints.init(cfg.endpoints)
go cli.notificationLoop()