Skip to content

Commit

Permalink
chore: use github.com/hashicorp/golang-lru/arc/v2
Browse files Browse the repository at this point in the history
  • Loading branch information
simlecode committed Nov 23, 2023
1 parent 5254d6c commit 35bd869
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 19 deletions.
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
6 changes: 3 additions & 3 deletions pkg/chain/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.
Expand All @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions pkg/consensus/block_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand All @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions pkg/events/message_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions pkg/statemanger/state_manger.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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
}
Expand Down
3 changes: 2 additions & 1 deletion venus-devtool/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions venus-devtool/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down

0 comments on commit 35bd869

Please sign in to comment.