prysm-pulse/beacon-chain/operations/attestations/kv/kv.go
terence tsao 15b649d760
Fix aggregated attestation pool grows large in size (#4932)
* Add metrics

* Use it

* Use it

* Fixed exp time and tests

* Update on save too

* Expose getters

* One epoch purge time

* Fixed a timing issue

* Clean up

* Gazelle

* Interface

* Prune every epoch

* Aggregate twice per slot

* Revert attsToBeAggregated

* Delete expired atts

Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
2020-02-24 10:18:34 -06:00

36 lines
1.2 KiB
Go

package kv
import (
"time"
"github.com/patrickmn/go-cache"
"github.com/prysmaticlabs/prysm/shared/params"
)
// AttCaches defines the caches used to satisfy attestation pool interface.
// These caches are KV store for various attestations
// such are unaggregated, aggregated or attestations within a block.
type AttCaches struct {
aggregatedAtt *cache.Cache
unAggregatedAtt *cache.Cache
forkchoiceAtt *cache.Cache
blockAtt *cache.Cache
}
// NewAttCaches initializes a new attestation pool consists of multiple KV store in cache for
// various kind of attestations.
func NewAttCaches() *AttCaches {
secsInEpoch := time.Duration(params.BeaconConfig().SlotsPerEpoch * params.BeaconConfig().SecondsPerSlot)
// Create caches with default expiration time of one epoch and which
// purges expired items every epoch.
pool := &AttCaches{
unAggregatedAtt: cache.New(secsInEpoch*time.Second, secsInEpoch*time.Second),
aggregatedAtt: cache.New(secsInEpoch*time.Second, secsInEpoch*time.Second),
forkchoiceAtt: cache.New(secsInEpoch*time.Second, secsInEpoch*time.Second),
blockAtt: cache.New(secsInEpoch*time.Second, secsInEpoch*time.Second),
}
return pool
}