Skip to content

Commit d7cb215

Browse files
committed
lru/v2
1 parent 95e0448 commit d7cb215

File tree

3 files changed

+10
-13
lines changed

3 files changed

+10
-13
lines changed

go.mod

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ require (
77
github.com/CortexFoundation/merkletree v0.0.0-20230724124840-b6e80265a137
88
github.com/CortexFoundation/torrentfs v1.0.52-0.20230711131012-594cb55f6538
99
github.com/google/uuid v1.3.0
10-
github.com/hashicorp/golang-lru v0.5.5-0.20221011183528-d4900dc688bf
10+
github.com/hashicorp/golang-lru/v2 v2.0.5-0.20230705200825-f4cd393e7b29
1111
github.com/ucwong/golang-kv v1.0.22-0.20230711090627-455356f3db9c
1212
go.etcd.io/bbolt v1.3.7
1313
)
@@ -37,7 +37,6 @@ require (
3737
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect
3838
github.com/google/flatbuffers v23.5.26+incompatible // indirect
3939
github.com/gorilla/websocket v1.5.0 // indirect
40-
github.com/hashicorp/golang-lru/v2 v2.0.4 // indirect
4140
github.com/holiman/uint256 v1.2.3 // indirect
4241
github.com/klauspost/compress v1.16.7 // indirect
4342
github.com/kr/pretty v0.3.1 // indirect

go.sum

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,8 @@ github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+
109109
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
110110
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
111111
github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/Co8=
112-
github.com/hashicorp/golang-lru v0.5.5-0.20221011183528-d4900dc688bf h1:BQyif+/dqmbIGXyGhe5bDx/3grIchislVu5pK7j/bMQ=
113-
github.com/hashicorp/golang-lru v0.5.5-0.20221011183528-d4900dc688bf/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4=
114-
github.com/hashicorp/golang-lru/v2 v2.0.4 h1:7GHuZcgid37q8o5i3QI9KMT4nCWQQ3Kx3Ov6bb9MfK0=
115-
github.com/hashicorp/golang-lru/v2 v2.0.4/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM=
112+
github.com/hashicorp/golang-lru/v2 v2.0.5-0.20230705200825-f4cd393e7b29 h1:ms53+xNey/RHASahOxI1AdzSm5snVNH8xQGTDc1xV2I=
113+
github.com/hashicorp/golang-lru/v2 v2.0.5-0.20230705200825-f4cd393e7b29/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM=
116114
github.com/holiman/uint256 v1.2.3 h1:K8UWO1HUJpRMXBxbmaY1Y8IAMZC/RsKB+ArEnnK4l5o=
117115
github.com/holiman/uint256 v1.2.3/go.mod h1:SC8Ryt4n+UBbPbIBKaG9zbbDlp4jOru9xFZmPzLUTxw=
118116
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=

monitor.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import (
3030
"github.com/CortexFoundation/robot/backend"
3131
"github.com/CortexFoundation/torrentfs/params"
3232
"github.com/CortexFoundation/torrentfs/types"
33-
lru "github.com/hashicorp/golang-lru"
33+
lru "github.com/hashicorp/golang-lru/v2"
3434
"github.com/ucwong/golang-kv"
3535
"math"
3636
"math/big"
@@ -77,8 +77,8 @@ type Monitor struct {
7777
taskCh chan *types.Block
7878
errCh chan error
7979
//newTaskHook func(*types.Block)
80-
blockCache *lru.Cache
81-
sizeCache *lru.Cache
80+
blockCache *lru.Cache[uint64, string]
81+
sizeCache *lru.Cache[string, uint64]
8282
ckp *params.TrustedCheckpoint
8383
start mclock.AbsTime
8484

@@ -143,8 +143,8 @@ func New(flag *params.Config, cache, compress, listen bool, callback chan any) (
143143
m.startNumber.Store(0)
144144

145145
m.terminated.Store(false)
146-
m.blockCache, _ = lru.New(delay)
147-
m.sizeCache, _ = lru.New(batch)
146+
m.blockCache, _ = lru.New[uint64, string](delay)
147+
m.sizeCache, _ = lru.New[string, uint64](batch)
148148
m.listen = listen
149149
m.callback = callback
150150

@@ -380,8 +380,8 @@ func (m *Monitor) rpcBatchBlockByNumber(from, to uint64) (result []*types.Block,
380380
}
381381

382382
func (m *Monitor) getRemainingSize(address string) (uint64, error) {
383-
if size, suc := m.sizeCache.Get(address); suc && size.(uint64) == 0 {
384-
return size.(uint64), nil
383+
if size, suc := m.sizeCache.Get(address); suc && size == 0 {
384+
return size, nil
385385
}
386386
var remainingSize hexutil.Uint64
387387
rpcUploadMeter.Mark(1)

0 commit comments

Comments
 (0)