From 0e0a675f3518915b58a802d58be2f1c77850cc2e Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Thu, 3 Mar 2022 16:34:08 +0300 Subject: [PATCH] [#1212] morph: Fix NPE in multi client Share multi cache between single clients. Signed-off-by: Pavel Karpy --- pkg/morph/client/constructor.go | 10 +++++----- pkg/morph/client/multi.go | 3 +++ 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/pkg/morph/client/constructor.go b/pkg/morph/client/constructor.go index 410c6383..760bf4a6 100644 --- a/pkg/morph/client/constructor.go +++ b/pkg/morph/client/constructor.go @@ -92,12 +92,12 @@ func New(key *keys.PrivateKey, endpoint string, opts ...Option) (*Client, error) endpoints := append(cfg.extraEndpoints, endpoint) return &Client{ - cache: initClientCache(), multiClient: &multiClient{ - cfg: *cfg, - account: wallet.NewAccountFromPrivateKey(key), - endpoints: endpoints, - clients: make(map[string]*Client, len(endpoints)), + cfg: *cfg, + account: wallet.NewAccountFromPrivateKey(key), + endpoints: endpoints, + clients: make(map[string]*Client, len(endpoints)), + sharedCache: initClientCache(), }, }, nil } diff --git a/pkg/morph/client/multi.go b/pkg/morph/client/multi.go index 56b08633..1a14fb96 100644 --- a/pkg/morph/client/multi.go +++ b/pkg/morph/client/multi.go @@ -15,6 +15,8 @@ type multiClient struct { sharedNotary *notary // notary config needed for single client construction + sharedCache cache + endpoints []string clientsMtx sync.Mutex clients map[string]*Client @@ -41,6 +43,7 @@ func (x *multiClient) createForAddress(addr string) (*Client, error) { sCli.notary = x.sharedNotary c := &Client{ + cache: x.sharedCache, singleClient: sCli, }