forked from TrueCloudLab/frostfs-node
[#5] morph/client: Use generic LRU cache
Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
parent
d8fb9c85eb
commit
55b403e0ee
5 changed files with 9 additions and 5 deletions
2
go.mod
2
go.mod
|
@ -39,6 +39,8 @@ require (
|
|||
gopkg.in/yaml.v3 v3.0.1
|
||||
)
|
||||
|
||||
require github.com/hashicorp/golang-lru/v2 v2.0.1
|
||||
|
||||
require (
|
||||
github.com/TrueCloudLab/frostfs-crypto v0.5.0 // indirect
|
||||
github.com/TrueCloudLab/rfc6979 v0.3.0 // indirect
|
||||
|
|
2
go.sum
2
go.sum
|
@ -243,6 +243,8 @@ github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ
|
|||
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
|
||||
github.com/hashicorp/golang-lru v0.5.4 h1:YDjusn29QI/Das2iO9M0BHnIbxPeyuCHsjMW+lJfyTc=
|
||||
github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4=
|
||||
github.com/hashicorp/golang-lru/v2 v2.0.1 h1:5pv5N1lT1fjLg2VQ5KWc7kmucp2x/kvFOnxuVTqZ6x4=
|
||||
github.com/hashicorp/golang-lru/v2 v2.0.1/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM=
|
||||
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
|
||||
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
|
||||
github.com/holiman/uint256 v1.2.0 h1:gpSYcPLWGv4sG43I2mVLiDZCNDh/EpGjSk8tmtxitHM=
|
||||
|
|
|
@ -9,7 +9,7 @@ import (
|
|||
"time"
|
||||
|
||||
"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/transaction"
|
||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||
|
@ -96,7 +96,7 @@ type cache struct {
|
|||
|
||||
nnsHash *util.Uint160
|
||||
gKey *keys.PublicKey
|
||||
txHeights *lru.Cache
|
||||
txHeights *lru.Cache[util.Uint256, uint32]
|
||||
}
|
||||
|
||||
func (c cache) nns() *util.Uint160 {
|
||||
|
|
|
@ -8,7 +8,7 @@ import (
|
|||
"time"
|
||||
|
||||
"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/crypto/keys"
|
||||
"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 {
|
||||
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{
|
||||
m: &sync.RWMutex{},
|
||||
txHeights: c,
|
||||
|
|
|
@ -892,7 +892,7 @@ func (c *Client) CalculateNonceAndVUB(hash util.Uint256) (nonce uint32, vub uint
|
|||
|
||||
func (c *Client) getTransactionHeight(h util.Uint256) (uint32, error) {
|
||||
if rh, ok := c.cache.txHeights.Get(h); ok {
|
||||
return rh.(uint32), nil
|
||||
return rh, nil
|
||||
}
|
||||
height, err := c.client.GetTransactionHeight(h)
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in a new issue