mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-04 00:44:27 +00:00
3043d4722f
* initiate cache * imports fix * add in feature config flag * utilize a dynamic set of subnets * Merge branch 'master' into att-subnets * add in feature config flag * Merge branch 'att-subnets' of github.com:prysmaticlabs/prysm into att-subnets * Merge branch 'master' of https://github.com/prysmaticlabs/geth-sharding into att-subnets * shift * more changes * gaz * Update beacon-chain/rpc/validator/assignments.go * Update beacon-chain/rpc/validator/assignments.go * add flag * Merge branch 'att-subnets' of https://github.com/prysmaticlabs/geth-sharding into att-subnets * Merge branch 'master' into att-subnets * Merge refs/heads/master into att-subnets * no double flag * Merge branch 'att-subnets' of github.com:prysmaticlabs/prysm into att-subnets * amend committee ids to better name * gaz
45 lines
932 B
Go
45 lines
932 B
Go
package cache
|
|
|
|
import (
|
|
"sync"
|
|
|
|
lru "github.com/hashicorp/golang-lru"
|
|
"github.com/prysmaticlabs/prysm/shared/sliceutil"
|
|
)
|
|
|
|
type committeeIDs struct {
|
|
cache *lru.Cache
|
|
lock sync.RWMutex
|
|
}
|
|
|
|
// CommitteeIDs for attestations.
|
|
var CommitteeIDs = newCommitteeIDs()
|
|
|
|
func newCommitteeIDs() *committeeIDs {
|
|
cache, err := lru.New(8)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return &committeeIDs{cache: cache}
|
|
}
|
|
|
|
// AddIDs to the cache for attestation committees by epoch.
|
|
func (t *committeeIDs) AddIDs(indices []uint64, epoch uint64) {
|
|
t.lock.Lock()
|
|
defer t.lock.Unlock()
|
|
val, exists := t.cache.Get(epoch)
|
|
if exists {
|
|
indices = sliceutil.UnionUint64(append(indices, val.([]uint64)...))
|
|
}
|
|
t.cache.Add(epoch, indices)
|
|
}
|
|
|
|
// GetIDs from the cache for attestation committees by epoch.
|
|
func (t *committeeIDs) GetIDs(epoch uint64) []uint64 {
|
|
val, exists := t.cache.Get(epoch)
|
|
if !exists {
|
|
return []uint64{}
|
|
}
|
|
return val.([]uint64)
|
|
}
|