[#1213] morph/client: Protect cached values with a mutex

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2022-03-15 14:21:24 +03:00 committed by Alex Vanin
parent a8d2001b35
commit 9bbb136e4a
2 changed files with 23 additions and 7 deletions

View file

@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"sync"
"time"
lru "github.com/hashicorp/golang-lru"
@ -43,8 +44,11 @@ type Client struct {
}
type cache struct {
nnsHash util.Uint160
groupKey *keys.PublicKey
// mtx protects primitive values.
mtx sync.RWMutex
nnsHash util.Uint160
groupKey *keys.PublicKey
// txHeights is a thread-safe LRU cache for transaction heights.
txHeights *lru.Cache
}