From 35bd869b0482af900ef25eac6d68ec06af0bde63 Mon Sep 17 00:00:00 2001 From: simlecode <69969590+simlecode@users.noreply.github.com> Date: Thu, 23 Nov 2023 13:10:29 +0800 Subject: [PATCH] chore: use github.com/hashicorp/golang-lru/arc/v2 --- go.mod | 3 ++- go.sum | 6 ++++-- pkg/chain/store.go | 6 +++--- pkg/consensus/block_validator.go | 6 +++--- pkg/events/message_cache.go | 6 +++--- pkg/statemanger/state_manger.go | 8 ++++---- venus-devtool/go.mod | 3 ++- venus-devtool/go.sum | 6 ++++-- 8 files changed, 25 insertions(+), 19 deletions(-) diff --git a/go.mod b/go.mod index 9fc98e3d14..cfea1f792f 100644 --- a/go.mod +++ b/go.mod @@ -53,7 +53,8 @@ require ( github.com/hako/durafmt v0.0.0-20200710122514-c0fb7b4da026 github.com/hannahhoward/go-pubsub v0.0.0-20200423002714-8d62886cc36e github.com/hashicorp/go-multierror v1.1.1 - github.com/hashicorp/golang-lru/v2 v2.0.2 + github.com/hashicorp/golang-lru/arc/v2 v2.0.7 + github.com/hashicorp/golang-lru/v2 v2.0.7 github.com/howeyc/gopass v0.0.0-20190910152052-7cb4b85ec19c github.com/ipfs-force-community/metrics v1.0.1-0.20231011024528-8c881d456601 github.com/ipfs-force-community/sophon-auth v1.14.0 diff --git a/go.sum b/go.sum index ce128014cd..cf4b82a6ea 100644 --- a/go.sum +++ b/go.sum @@ -570,8 +570,10 @@ 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.2 h1:Dwmkdr5Nc/oBiXgJS3CDHNhJtIHkuZ3DZF5twqnfBdU= -github.com/hashicorp/golang-lru/v2 v2.0.2/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM= +github.com/hashicorp/golang-lru/arc/v2 v2.0.7 h1:QxkVTxwColcduO+LP7eJO56r2hFiG8zEbfAAzRv52KQ= +github.com/hashicorp/golang-lru/arc/v2 v2.0.7/go.mod h1:Pe7gBlGdc8clY5LJ0LpJXMt5AmgmWNH1g+oFFVUHOEc= +github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k= +github.com/hashicorp/golang-lru/v2 v2.0.7/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/howeyc/gopass v0.0.0-20190910152052-7cb4b85ec19c h1:aY2hhxLhjEAbfXOx2nRJxCXezC6CO2V/yN+OCr1srtk= diff --git a/pkg/chain/store.go b/pkg/chain/store.go index f240da86f9..fe8a86ec8f 100644 --- a/pkg/chain/store.go +++ b/pkg/chain/store.go @@ -10,7 +10,7 @@ import ( "runtime/debug" "sync" - lru "github.com/hashicorp/golang-lru/v2" + "github.com/hashicorp/golang-lru/arc/v2" "github.com/ipld/go-car" carutil "github.com/ipld/go-car/util" carv2 "github.com/ipld/go-car/v2" @@ -128,7 +128,7 @@ type Store struct { reorgCh chan reorg reorgNotifeeCh chan ReorgNotifee - tsCache *lru.ARCCache[types.TipSetKey, *types.TipSet] + tsCache *arc.ARCCache[types.TipSetKey, *types.TipSet] } // NewStore constructs a new default store. @@ -137,7 +137,7 @@ func NewStore(chainDs repo.Datastore, genesisCid cid.Cid, circulatiingSupplyCalculator ICirculatingSupplyCalcualtor, ) *Store { - tsCache, _ := lru.NewARC[types.TipSetKey, *types.TipSet](DefaultTipsetLruCacheSize) + tsCache, _ := arc.NewARC[types.TipSetKey, *types.TipSet](DefaultTipsetLruCacheSize) store := &Store{ stateAndBlockSource: cbor.NewCborStore(bsstore), ds: chainDs, diff --git a/pkg/consensus/block_validator.go b/pkg/consensus/block_validator.go index 0775b38981..692016e2e0 100644 --- a/pkg/consensus/block_validator.go +++ b/pkg/consensus/block_validator.go @@ -10,7 +10,7 @@ import ( "github.com/Gurpartap/async" "github.com/hashicorp/go-multierror" - lru "github.com/hashicorp/golang-lru/v2" + "github.com/hashicorp/golang-lru/arc/v2" "github.com/ipfs/go-cid" cbor "github.com/ipfs/go-ipld-cbor" pubsub "github.com/libp2p/go-libp2p-pubsub" @@ -78,7 +78,7 @@ type BlockValidator struct { // gasprice for vm gasPirceSchedule *gas.PricesSchedule // cache for validate block - validateBlockCache *lru.ARCCache[cid.Cid, struct{}] + validateBlockCache *arc.ARCCache[cid.Cid, struct{}] Stmgr StateTransformer } @@ -97,7 +97,7 @@ func NewBlockValidator(tv TicketValidator, config *config.NetworkParamsConfig, gasPirceSchedule *gas.PricesSchedule, ) *BlockValidator { - validateBlockCache, _ := lru.NewARC[cid.Cid, struct{}](2048) + validateBlockCache, _ := arc.NewARC[cid.Cid, struct{}](2048) return &BlockValidator{ tv: tv, bstore: bstore, diff --git a/pkg/events/message_cache.go b/pkg/events/message_cache.go index e2abf2acbb..ba355b3f8a 100644 --- a/pkg/events/message_cache.go +++ b/pkg/events/message_cache.go @@ -4,7 +4,7 @@ import ( "context" "sync" - lru "github.com/hashicorp/golang-lru/v2" + "github.com/hashicorp/golang-lru/arc/v2" "github.com/ipfs/go-cid" "github.com/filecoin-project/venus/venus-shared/types" @@ -14,11 +14,11 @@ type messageCache struct { api IEvent blockMsgLk sync.Mutex - blockMsgCache *lru.ARCCache[cid.Cid, *types.BlockMessages] + blockMsgCache *arc.ARCCache[cid.Cid, *types.BlockMessages] } func newMessageCache(api IEvent) *messageCache { - blsMsgCache, _ := lru.NewARC[cid.Cid, *types.BlockMessages](500) + blsMsgCache, _ := arc.NewARC[cid.Cid, *types.BlockMessages](500) return &messageCache{ api: api, diff --git a/pkg/statemanger/state_manger.go b/pkg/statemanger/state_manger.go index 30ca8ab615..7c8845140b 100644 --- a/pkg/statemanger/state_manger.go +++ b/pkg/statemanger/state_manger.go @@ -27,7 +27,7 @@ import ( "github.com/filecoin-project/venus/venus-shared/actors/builtin/paych" blockstoreutil "github.com/filecoin-project/venus/venus-shared/blockstore" "github.com/filecoin-project/venus/venus-shared/types" - lru "github.com/hashicorp/golang-lru/v2" + "github.com/hashicorp/golang-lru/arc/v2" "github.com/ipfs/go-cid" logging "github.com/ipfs/go-log/v2" "go.opencensus.io/trace" @@ -78,7 +78,7 @@ type Stmgr struct { // We keep a small cache for calls to ExecutionTrace which helps improve // performance for node operators like exchanges and block explorers - execTraceCache *lru.ARCCache[types.TipSetKey, tipSetCacheEntry] + execTraceCache *arc.ARCCache[types.TipSetKey, tipSetCacheEntry] // We need a lock while making the copy as to prevent other callers // overwrite the cache while making the copy execTraceCacheLock sync.Mutex @@ -94,10 +94,10 @@ func NewStateManager(cs *chain.Store, actorDebugging bool, ) (*Stmgr, error) { log.Debugf("execTraceCache size: %d", execTraceCacheSize) - var execTraceCache *lru.ARCCache[types.TipSetKey, tipSetCacheEntry] + var execTraceCache *arc.ARCCache[types.TipSetKey, tipSetCacheEntry] var err error if execTraceCacheSize > 0 { - execTraceCache, err = lru.NewARC[types.TipSetKey, tipSetCacheEntry](execTraceCacheSize) + execTraceCache, err = arc.NewARC[types.TipSetKey, tipSetCacheEntry](execTraceCacheSize) if err != nil { return nil, err } diff --git a/venus-devtool/go.mod b/venus-devtool/go.mod index bf2086aeeb..b6e35cc111 100644 --- a/venus-devtool/go.mod +++ b/venus-devtool/go.mod @@ -101,7 +101,8 @@ require ( github.com/hashicorp/errwrap v1.1.0 // indirect github.com/hashicorp/go-multierror v1.1.1 // indirect github.com/hashicorp/golang-lru v0.6.0 // indirect - github.com/hashicorp/golang-lru/v2 v2.0.5 // indirect + github.com/hashicorp/golang-lru/arc/v2 v2.0.7 // indirect + github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect github.com/icza/backscanner v0.0.0-20210726202459-ac2ffc679f94 // indirect github.com/ipfs/bbloom v0.0.4 // indirect github.com/ipfs/boxo v0.10.1 // indirect diff --git a/venus-devtool/go.sum b/venus-devtool/go.sum index 6634668ad7..f25625a478 100644 --- a/venus-devtool/go.sum +++ b/venus-devtool/go.sum @@ -407,8 +407,10 @@ github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= github.com/hashicorp/golang-lru v0.6.0 h1:uL2shRDx7RTrOrTCUZEGP/wJUFiUI8QT6E7z5o8jga4= github.com/hashicorp/golang-lru v0.6.0/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= -github.com/hashicorp/golang-lru/v2 v2.0.5 h1:wW7h1TG88eUIJ2i69gaE3uNVtEPIagzhGvHgwfx2Vm4= -github.com/hashicorp/golang-lru/v2 v2.0.5/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM= +github.com/hashicorp/golang-lru/arc/v2 v2.0.7 h1:QxkVTxwColcduO+LP7eJO56r2hFiG8zEbfAAzRv52KQ= +github.com/hashicorp/golang-lru/arc/v2 v2.0.7/go.mod h1:Pe7gBlGdc8clY5LJ0LpJXMt5AmgmWNH1g+oFFVUHOEc= +github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k= +github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/huin/goupnp v1.0.0/go.mod h1:n9v9KO1tAxYH82qOn+UTIFQDmx5n1Zxd/ClZDMX7Bnc=