[#1213] morph/client: Use a separate cache for every client

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2022-03-15 14:33:09 +03:00 committed by Alex Vanin
parent 61f60b8461
commit a8d2001b35
2 changed files with 8 additions and 10 deletions

View file

@ -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,

View file

@ -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