From a8d2001b35d7f361d67a88bbd43310e858fa4195 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Tue, 15 Mar 2022 14:33:09 +0300 Subject: [PATCH] [#1213] morph/client: Use a separate cache for every client Signed-off-by: Evgenii Stratonikov --- pkg/morph/client/constructor.go | 14 +++++++------- pkg/morph/client/multi.go | 4 +--- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/pkg/morph/client/constructor.go b/pkg/morph/client/constructor.go index 760bf4a67..8d54d5ef4 100644 --- a/pkg/morph/client/constructor.go +++ b/pkg/morph/client/constructor.go @@ -84,7 +84,7 @@ func New(key *keys.PrivateKey, endpoint string, opts ...Option) (*Client, error) if cfg.singleCli != nil { return &Client{ - cache: initClientCache(), + cache: newClientCache(), singleClient: blankSingleClient(cfg.singleCli, wallet.NewAccountFromPrivateKey(key), cfg), }, nil } @@ -92,17 +92,17 @@ func New(key *keys.PrivateKey, endpoint string, opts ...Option) (*Client, error) endpoints := append(cfg.extraEndpoints, endpoint) return &Client{ + cache: newClientCache(), multiClient: &multiClient{ - cfg: *cfg, - account: wallet.NewAccountFromPrivateKey(key), - endpoints: endpoints, - clients: make(map[string]*Client, len(endpoints)), - sharedCache: initClientCache(), + cfg: *cfg, + account: wallet.NewAccountFromPrivateKey(key), + endpoints: endpoints, + clients: make(map[string]*Client, len(endpoints)), }, }, nil } -func initClientCache() cache { +func newClientCache() cache { c, _ := lru.New(100) // returns error only if size is negative return cache{ txHeights: c, diff --git a/pkg/morph/client/multi.go b/pkg/morph/client/multi.go index 54cf0edda..1534165e4 100644 --- a/pkg/morph/client/multi.go +++ b/pkg/morph/client/multi.go @@ -15,8 +15,6 @@ type multiClient struct { sharedNotary *notary // notary config needed for single client construction - sharedCache cache - endpoints []string clientsMtx sync.Mutex clients map[string]*Client @@ -48,7 +46,7 @@ func (x *multiClient) createForAddress(addr string) (*Client, error) { sCli.notary = x.sharedNotary c = &Client{ - cache: x.sharedCache, + cache: newClientCache(), singleClient: sCli, } x.clients[addr] = c