From d0a0432a51455976e230e222602a9026bf2ec448 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Fri, 30 Dec 2022 12:51:49 +0300 Subject: [PATCH] [#5] innerring: Use generic LRU cache Signed-off-by: Evgenii Stratonikov --- pkg/innerring/processors/neofs/process_assets.go | 4 ++-- pkg/innerring/processors/neofs/processor.go | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pkg/innerring/processors/neofs/process_assets.go b/pkg/innerring/processors/neofs/process_assets.go index 2fdd55ad66..aa752035e8 100644 --- a/pkg/innerring/processors/neofs/process_assets.go +++ b/pkg/innerring/processors/neofs/process_assets.go @@ -42,10 +42,10 @@ func (np *Processor) processDeposit(deposit *frostfsEvent.Deposit) { defer np.mintEmitLock.Unlock() val, ok := np.mintEmitCache.Get(receiver.String()) - if ok && val.(uint64)+np.mintEmitThreshold >= curEpoch { + if ok && val+np.mintEmitThreshold >= curEpoch { np.log.Warn("double mint emission declined", zap.String("receiver", receiver.String()), - zap.Uint64("last_emission", val.(uint64)), + zap.Uint64("last_emission", val), zap.Uint64("current_epoch", curEpoch)) return diff --git a/pkg/innerring/processors/neofs/processor.go b/pkg/innerring/processors/neofs/processor.go index 8435a93155..54c7825394 100644 --- a/pkg/innerring/processors/neofs/processor.go +++ b/pkg/innerring/processors/neofs/processor.go @@ -12,7 +12,7 @@ import ( "github.com/TrueCloudLab/frostfs-node/pkg/morph/event" frostfsEvent "github.com/TrueCloudLab/frostfs-node/pkg/morph/event/neofs" "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/encoding/fixedn" "github.com/nspcc-dev/neo-go/pkg/util" "github.com/panjf2000/ants/v2" @@ -47,7 +47,7 @@ type ( alphabetState AlphabetState converter PrecisionConverter mintEmitLock *sync.Mutex - mintEmitCache *lru.Cache + mintEmitCache *lru.Cache[string, uint64] mintEmitThreshold uint64 mintEmitValue fixedn.Fixed8 gasBalanceThreshold int64 @@ -105,7 +105,7 @@ func New(p *Params) (*Processor, error) { return nil, fmt.Errorf("ir/frostfs: can't create worker pool: %w", err) } - lruCache, err := lru.New(p.MintEmitCacheSize) + lruCache, err := lru.New[string, uint64](p.MintEmitCacheSize) if err != nil { return nil, fmt.Errorf("ir/frostfs: can't create LRU cache for gas emission: %w", err) }