mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-09 03:01:19 +00:00
a069738c20
* update shared/params * update eth2-types deps * update protobufs * update shared/* * fix testutil/state * update beacon-chain/state * update beacon-chain/db * update tests * fix test * update beacon-chain/core * update beacon-chain/blockchain * update beacon-chain/cache * beacon-chain/forkchoice * update beacon-chain/operations * update beacon-chain/p2p * update beacon-chain/rpc * update sync/initial-sync * update deps * update deps * go fmt * update beacon-chain/sync * update endtoend/ * bazel build //beacon-chain - works w/o issues * update slasher code * udpate tools/ * update validator/ * update fastssz * fix build * fix test building * update tests * update ethereumapis deps * fix tests * update state/stategen * fix build * fix test * add FarFutureSlot * go imports * Radek's suggestions * Ivan's suggestions * type conversions * Nishant's suggestions * add more tests to rpc_send_request * fix test * clean up * fix conflicts Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com> Co-authored-by: nisdas <nishdas93@gmail.com>
48 lines
1.6 KiB
Go
48 lines
1.6 KiB
Go
// Package kv includes a key-value store implementation
|
|
// of an attestation cache used to satisfy important use-cases
|
|
// such as aggregation in a beacon node runtime.
|
|
package kv
|
|
|
|
import (
|
|
"sync"
|
|
"time"
|
|
|
|
"github.com/patrickmn/go-cache"
|
|
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
|
"github.com/prysmaticlabs/prysm/shared/hashutil"
|
|
"github.com/prysmaticlabs/prysm/shared/params"
|
|
)
|
|
|
|
var hashFn = hashutil.HashProto
|
|
|
|
// 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 {
|
|
aggregatedAttLock sync.RWMutex
|
|
aggregatedAtt map[[32]byte][]*ethpb.Attestation
|
|
unAggregateAttLock sync.RWMutex
|
|
unAggregatedAtt map[[32]byte]*ethpb.Attestation
|
|
forkchoiceAttLock sync.RWMutex
|
|
forkchoiceAtt map[[32]byte]*ethpb.Attestation
|
|
blockAttLock sync.RWMutex
|
|
blockAtt map[[32]byte][]*ethpb.Attestation
|
|
seenAtt *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.Mul(params.BeaconConfig().SecondsPerSlot))
|
|
c := cache.New(secsInEpoch*time.Second, 2*secsInEpoch*time.Second)
|
|
pool := &AttCaches{
|
|
unAggregatedAtt: make(map[[32]byte]*ethpb.Attestation),
|
|
aggregatedAtt: make(map[[32]byte][]*ethpb.Attestation),
|
|
forkchoiceAtt: make(map[[32]byte]*ethpb.Attestation),
|
|
blockAtt: make(map[[32]byte][]*ethpb.Attestation),
|
|
seenAtt: c,
|
|
}
|
|
|
|
return pool
|
|
}
|