2019-12-03 22:04:11 +00:00
|
|
|
package attestations
|
|
|
|
|
|
|
|
import (
|
2019-12-03 23:07:44 +00:00
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/patrickmn/go-cache"
|
2019-12-03 22:04:11 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/params"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Pool defines an implementation of the attestation pool interface
|
|
|
|
// using cache as underlying kv store for various incoming attestations
|
|
|
|
// such are unaggregated, aggregated or within a block.
|
|
|
|
type Pool struct {
|
2019-12-03 23:07:44 +00:00
|
|
|
aggregatedAtt *cache.Cache
|
|
|
|
unAggregatedAtt *cache.Cache
|
|
|
|
attInBlock *cache.Cache
|
2019-12-03 22:04:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewPool initializes a new attestation pool consists of multiple KV store in cache for
|
|
|
|
// various kind of aggregations.
|
|
|
|
func NewPool() *Pool {
|
2019-12-03 23:07:44 +00:00
|
|
|
|
|
|
|
secsInEpoch := time.Duration(params.BeaconConfig().SlotsPerEpoch * params.BeaconConfig().SecondsPerSlot)
|
|
|
|
|
|
|
|
// Create caches with default expiration time of one epoch and which
|
|
|
|
// purges expired items every other epoch.
|
2019-12-03 22:04:11 +00:00
|
|
|
pool := &Pool{
|
2019-12-03 23:07:44 +00:00
|
|
|
unAggregatedAtt: cache.New(secsInEpoch/time.Minute, 2*secsInEpoch/time.Minute),
|
|
|
|
aggregatedAtt: cache.New(secsInEpoch/time.Minute, 2*secsInEpoch/time.Minute),
|
|
|
|
attInBlock: cache.New(secsInEpoch/time.Minute, 2*secsInEpoch/time.Minute),
|
2019-12-03 22:04:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return pool
|
|
|
|
}
|