[#1170] pkg/morph: Invalidate cache on RPC switch

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2022-03-31 16:12:42 +03:00 committed by Alex Vanin
parent 6508136204
commit 4ed5b1ceef
5 changed files with 58 additions and 25 deletions

View file

@ -90,7 +90,7 @@ func New(key *keys.PrivateKey, endpoint string, opts ...Option) (*Client, error)
}
cli := &Client{
cache: initClientCache(),
cache: newClientCache(),
logger: cfg.logger,
acc: wallet.NewAccountFromPrivateKey(key),
signer: cfg.signer,
@ -140,9 +140,10 @@ func newWSClient(cfg cfg, endpoint string) (*client.WSClient, error) {
)
}
func initClientCache() cache {
func newClientCache() cache {
c, _ := lru.New(100) // returns error only if size is negative
return cache{
m: &sync.RWMutex{},
txHeights: c,
}
}