Skip to content

Commit

Permalink
switched to golang-lru
Browse files Browse the repository at this point in the history
  • Loading branch information
Sidu28 committed Feb 28, 2024
1 parent b36d56b commit 2c67b10
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 28 deletions.
9 changes: 4 additions & 5 deletions eigen_pod_proofs.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ import (

"strconv"

cache "github.com/Code-Hex/go-generics-cache"
"github.com/Code-Hex/go-generics-cache/policy/lru"
"github.com/attestantio/go-eth2-client/spec"
"github.com/attestantio/go-eth2-client/spec/deneb"
"github.com/attestantio/go-eth2-client/spec/phase0"
expirable "github.com/hashicorp/golang-lru/v2/expirable"

beacon "github.com/Layr-Labs/eigenpod-proofs-generation/beacon"
"github.com/Layr-Labs/eigenpod-proofs-generation/common"
Expand All @@ -26,7 +25,7 @@ const (

type EigenPodProofs struct {
chainID uint64
oracleStateCache *cache.Cache[string, interface{}]
oracleStateCache *expirable.LRU[string, interface{}]
oracleStateCacheExpirySeconds int
}

Expand All @@ -37,7 +36,7 @@ func NewEigenPodProofs(chainID uint64, oracleStateCacheExpirySeconds int) (*Eige
// note that TTL applies equally to each entry
// oracleStateCache := expirable.NewLRU[string, []byte](MAX_ORACLE_STATE_CACHE_SIZE, nil, time.Duration(oracleStateCacheExpirySeconds)*time.Second)

oracleStateCache := cache.New(cache.AsLRU[string, interface{}](lru.WithCapacity(MAX_ORACLE_STATE_CACHE_SIZE)))
oracleStateCache := expirable.NewLRU[string, interface{}](MAX_ORACLE_STATE_CACHE_SIZE, nil, time.Duration(oracleStateCacheExpirySeconds)*time.Second)

return &EigenPodProofs{
chainID: chainID,
Expand Down Expand Up @@ -158,7 +157,7 @@ func (epp *EigenPodProofs) loadOrComputeBeaconData(prefix string, slot phase0.Sl
}

// cache the beacon state root
epp.oracleStateCache.Set(key(prefix, uint64(slot)), data, cache.WithExpiration(time.Duration(epp.oracleStateCacheExpirySeconds)*time.Second))
epp.oracleStateCache.Add(key(prefix, uint64(slot)), data)
return data, nil
}

Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ require (
)

require (
github.com/Code-Hex/go-generics-cache v1.3.1 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/StackExchange/wmi v1.2.1 // indirect
github.com/bits-and-blooms/bitset v1.10.0 // indirect
Expand Down
Loading

0 comments on commit 2c67b10

Please sign in to comment.