[#5] morph/client: Use generic LRU cache

Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
Evgenii Stratonikov 2022-12-30 12:47:18 +03:00 committed by fyrchik
parent d8fb9c85eb
commit 55b403e0ee
5 changed files with 7 additions and 5 deletions

2
go.mod
View file

@ -39,6 +39,8 @@ require (
gopkg.in/yaml.v3 v3.0.1 gopkg.in/yaml.v3 v3.0.1
) )
require github.com/hashicorp/golang-lru/v2 v2.0.1
require ( require (
github.com/TrueCloudLab/frostfs-crypto v0.5.0 // indirect github.com/TrueCloudLab/frostfs-crypto v0.5.0 // indirect
github.com/TrueCloudLab/rfc6979 v0.3.0 // indirect github.com/TrueCloudLab/rfc6979 v0.3.0 // indirect

BIN
go.sum

Binary file not shown.

View file

@ -9,7 +9,7 @@ import (
"time" "time"
"github.com/TrueCloudLab/frostfs-node/pkg/util/logger" "github.com/TrueCloudLab/frostfs-node/pkg/util/logger"
lru "github.com/hashicorp/golang-lru" lru "github.com/hashicorp/golang-lru/v2"
"github.com/nspcc-dev/neo-go/pkg/core/native/noderoles" "github.com/nspcc-dev/neo-go/pkg/core/native/noderoles"
"github.com/nspcc-dev/neo-go/pkg/core/transaction" "github.com/nspcc-dev/neo-go/pkg/core/transaction"
"github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/nspcc-dev/neo-go/pkg/crypto/keys"
@ -96,7 +96,7 @@ type cache struct {
nnsHash *util.Uint160 nnsHash *util.Uint160
gKey *keys.PublicKey gKey *keys.PublicKey
txHeights *lru.Cache txHeights *lru.Cache[util.Uint256, uint32]
} }
func (c cache) nns() *util.Uint160 { func (c cache) nns() *util.Uint160 {

View file

@ -8,7 +8,7 @@ import (
"time" "time"
"github.com/TrueCloudLab/frostfs-node/pkg/util/logger" "github.com/TrueCloudLab/frostfs-node/pkg/util/logger"
lru "github.com/hashicorp/golang-lru" lru "github.com/hashicorp/golang-lru/v2"
"github.com/nspcc-dev/neo-go/pkg/core/transaction" "github.com/nspcc-dev/neo-go/pkg/core/transaction"
"github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/nspcc-dev/neo-go/pkg/crypto/keys"
"github.com/nspcc-dev/neo-go/pkg/rpcclient" "github.com/nspcc-dev/neo-go/pkg/rpcclient"
@ -185,7 +185,7 @@ func newActor(ws *rpcclient.WSClient, acc *wallet.Account, cfg cfg) (*actor.Acto
} }
func newClientCache() cache { func newClientCache() cache {
c, _ := lru.New(100) // returns error only if size is negative c, _ := lru.New[util.Uint256, uint32](100) // returns error only if size is negative
return cache{ return cache{
m: &sync.RWMutex{}, m: &sync.RWMutex{},
txHeights: c, txHeights: c,

View file

@ -892,7 +892,7 @@ func (c *Client) CalculateNonceAndVUB(hash util.Uint256) (nonce uint32, vub uint
func (c *Client) getTransactionHeight(h util.Uint256) (uint32, error) { func (c *Client) getTransactionHeight(h util.Uint256) (uint32, error) {
if rh, ok := c.cache.txHeights.Get(h); ok { if rh, ok := c.cache.txHeights.Get(h); ok {
return rh.(uint32), nil return rh, nil
} }
height, err := c.client.GetTransactionHeight(h) height, err := c.client.GetTransactionHeight(h)
if err != nil { if err != nil {