Documentation ¶
Overview ¶
Package cache includes all important caches for the runtime of an Ethereum Beacon Node, ensuring the node does not spend resources computing duplicate operations such as committee calculations for validators during the same epoch, etc.
Index ¶
- Variables
- type AttestationCache
- func (c *AttestationCache) Get(ctx context.Context, req *ethpb.AttestationDataRequest) (*ethpb.AttestationData, error)
- func (c *AttestationCache) MarkInProgress(req *ethpb.AttestationDataRequest) error
- func (c *AttestationCache) MarkNotInProgress(req *ethpb.AttestationDataRequest) error
- func (c *AttestationCache) Put(_ context.Context, req *ethpb.AttestationDataRequest, ...) error
- type BalanceCache
- type CheckpointStateCache
- type CommitteeCache
- func (c *CommitteeCache) ActiveIndices(ctx context.Context, seed [32]byte) ([]types.ValidatorIndex, error)
- func (c *CommitteeCache) ActiveIndicesCount(ctx context.Context, seed [32]byte) (int, error)
- func (c *CommitteeCache) AddCommitteeShuffledList(ctx context.Context, committees *Committees) error
- func (c *CommitteeCache) Committee(ctx context.Context, slot types.Slot, seed [32]byte, ...) ([]types.ValidatorIndex, error)
- func (c *CommitteeCache) HasEntry(seed string) bool
- func (c *CommitteeCache) MarkInProgress(seed [32]byte) error
- func (c *CommitteeCache) MarkNotInProgress(seed [32]byte) error
- type Committees
- type ProposerIndices
- type ProposerIndicesCache
- type ProposerPayloadIDsCache
- func (f *ProposerPayloadIDsCache) GetProposerPayloadIDs(slot types.Slot, r [32]byte) (types.ValidatorIndex, [8]byte, bool)
- func (f *ProposerPayloadIDsCache) PrunePayloadIDs(slot types.Slot)
- func (f *ProposerPayloadIDsCache) SetProposerAndPayloadIDs(slot types.Slot, vId types.ValidatorIndex, pId [8]byte, r [32]byte)
- type SkipSlotCache
- func (c *SkipSlotCache) Disable()
- func (c *SkipSlotCache) Enable()
- func (c *SkipSlotCache) Get(ctx context.Context, r [32]byte) (state.BeaconState, error)
- func (c *SkipSlotCache) MarkInProgress(r [32]byte) error
- func (c *SkipSlotCache) MarkNotInProgress(r [32]byte)
- func (c *SkipSlotCache) Put(_ context.Context, r [32]byte, state state.BeaconState)
- type SyncCommitteeCache
- func (s *SyncCommitteeCache) CurrentPeriodIndexPosition(root [32]byte, valIdx types.ValidatorIndex) ([]types.CommitteeIndex, error)
- func (s *SyncCommitteeCache) NextPeriodIndexPosition(root [32]byte, valIdx types.ValidatorIndex) ([]types.CommitteeIndex, error)
- func (s *SyncCommitteeCache) UpdatePositionsInCommittee(syncCommitteeBoundaryRoot [32]byte, st state.BeaconState) error
- type SyncCommitteeHeadStateCache
Constants ¶
This section is empty.
Variables ¶
var ( // CommitteeCacheMiss tracks the number of committee requests that aren't present in the cache. CommitteeCacheMiss = promauto.NewCounter(prometheus.CounterOpts{ Name: "committee_cache_miss", Help: "The number of committee requests that aren't present in the cache.", }) // CommitteeCacheHit tracks the number of committee requests that are in the cache. CommitteeCacheHit = promauto.NewCounter(prometheus.CounterOpts{ Name: "committee_cache_hit", Help: "The number of committee requests that are present in the cache.", }) )
var ( // ErrNilValueProvided for when we try to put a nil value in a cache. ErrNilValueProvided = errors.New("nil value provided on Put()") // ErrIncorrectType for when the state is of the incorrect type. ErrIncorrectType = errors.New("incorrect state type provided") // ErrNotFound for cache fetches that return a nil value. ErrNotFound = errors.New("not found in cache") // ErrNonExistingSyncCommitteeKey when sync committee key (root) does not exist in cache. ErrNonExistingSyncCommitteeKey = errors.New("does not exist sync committee key") )
var ( // ProposerIndicesCacheMiss tracks the number of proposerIndices requests that aren't present in the cache. ProposerIndicesCacheMiss = promauto.NewCounter(prometheus.CounterOpts{ Name: "proposer_indices_cache_miss", Help: "The number of proposer indices requests that aren't present in the cache.", }) // ProposerIndicesCacheHit tracks the number of proposerIndices requests that are in the cache. ProposerIndicesCacheHit = promauto.NewCounter(prometheus.CounterOpts{ Name: "proposer_indices_cache_hit", Help: "The number of proposer indices requests that are present in the cache.", }) )
var ( // SyncCommitteeCacheMiss tracks the number of committee requests that aren't present in the cache. SyncCommitteeCacheMiss = promauto.NewCounter(prometheus.CounterOpts{ Name: "sync_committee_index_cache_miss_total", Help: "The number of committee requests that aren't present in the sync committee index cache.", }) // SyncCommitteeCacheHit tracks the number of committee requests that are in the cache. SyncCommitteeCacheHit = promauto.NewCounter(prometheus.CounterOpts{ Name: "sync_committee_index_cache_hit_total", Help: "The number of committee requests that are present in the sync committee index cache.", }) )
var ErrAlreadyInProgress = errors.New("already in progress")
ErrAlreadyInProgress appears when attempting to mark a cache as in progress while it is already in progress. The client should handle this error and wait for the in progress data to resolve via Get.
var ErrNotCommittee = errors.New("object is not a committee struct")
ErrNotCommittee will be returned when a cache object is not a pointer to a Committee struct.
var ErrNotProposerIndices = errors.New("object is not a proposer indices struct")
ErrNotProposerIndices will be returned when a cache object is not a pointer to a ProposerIndices struct.
var SubnetIDs = newSubnetIDs()
SubnetIDs for attester and aggregator.
var SyncSubnetIDs = newSyncSubnetIDs()
SyncSubnetIDs for sync committee participant.
Functions ¶
This section is empty.
Types ¶
type AttestationCache ¶
type AttestationCache struct {
// contains filtered or unexported fields
}
AttestationCache is used to store the cached results of an AttestationData request.
func NewAttestationCache ¶
func NewAttestationCache() *AttestationCache
NewAttestationCache initializes the map and underlying cache.
func (*AttestationCache) Get ¶
func (c *AttestationCache) Get(ctx context.Context, req *ethpb.AttestationDataRequest) (*ethpb.AttestationData, error)
Get waits for any in progress calculation to complete before returning a cached response, if any.
func (*AttestationCache) MarkInProgress ¶
func (c *AttestationCache) MarkInProgress(req *ethpb.AttestationDataRequest) error
MarkInProgress a request so that any other similar requests will block on Get until MarkNotInProgress is called.
func (*AttestationCache) MarkNotInProgress ¶
func (c *AttestationCache) MarkNotInProgress(req *ethpb.AttestationDataRequest) error
MarkNotInProgress will release the lock on a given request. This should be called after put.
func (*AttestationCache) Put ¶
func (c *AttestationCache) Put(_ context.Context, req *ethpb.AttestationDataRequest, res *ethpb.AttestationData) error
Put the response in the cache.
type BalanceCache ¶
type BalanceCache struct {
// contains filtered or unexported fields
}
BalanceCache is a struct with 1 LRU cache for looking up balance by epoch.
func NewEffectiveBalanceCache ¶
func NewEffectiveBalanceCache() *BalanceCache
NewEffectiveBalanceCache creates a new effective balance cache for storing/accessing total balance by epoch.
func (*BalanceCache) AddTotalEffectiveBalance ¶
func (c *BalanceCache) AddTotalEffectiveBalance(st state.ReadOnlyBeaconState, balance uint64) error
AddTotalEffectiveBalance adds a new total effective balance entry for current balance for state `st` into the cache.
func (*BalanceCache) Get ¶
func (c *BalanceCache) Get(st state.ReadOnlyBeaconState) (uint64, error)
Get returns the current epoch's effective balance for state `st` in cache.
type CheckpointStateCache ¶
type CheckpointStateCache struct {
// contains filtered or unexported fields
}
CheckpointStateCache is a struct with 1 queue for looking up state by checkpoint.
func NewCheckpointStateCache ¶
func NewCheckpointStateCache() *CheckpointStateCache
NewCheckpointStateCache creates a new checkpoint state cache for storing/accessing processed state.
func (*CheckpointStateCache) AddCheckpointState ¶
func (c *CheckpointStateCache) AddCheckpointState(cp *ethpb.Checkpoint, s state.ReadOnlyBeaconState) error
AddCheckpointState adds CheckpointState object to the cache. This method also trims the least recently added CheckpointState object if the cache size has ready the max cache size limit.
func (*CheckpointStateCache) StateByCheckpoint ¶
func (c *CheckpointStateCache) StateByCheckpoint(cp *ethpb.Checkpoint) (state.BeaconState, error)
StateByCheckpoint fetches state by checkpoint. Returns true with a reference to the CheckpointState info, if exists. Otherwise returns false, nil.
type CommitteeCache ¶
CommitteeCache is a struct with 1 queue for looking up shuffled indices list by seed.
func NewCommitteesCache ¶
func NewCommitteesCache() *CommitteeCache
NewCommitteesCache creates a new committee cache for storing/accessing shuffled indices of a committee.
func (*CommitteeCache) ActiveIndices ¶
func (c *CommitteeCache) ActiveIndices(ctx context.Context, seed [32]byte) ([]types.ValidatorIndex, error)
ActiveIndices returns the active indices of a given seed stored in cache.
func (*CommitteeCache) ActiveIndicesCount ¶
ActiveIndicesCount returns the active indices count of a given seed stored in cache.
func (*CommitteeCache) AddCommitteeShuffledList ¶
func (c *CommitteeCache) AddCommitteeShuffledList(ctx context.Context, committees *Committees) error
AddCommitteeShuffledList adds Committee shuffled list object to the cache. T his method also trims the least recently list if the cache size has ready the max cache size limit.
func (*CommitteeCache) Committee ¶
func (c *CommitteeCache) Committee(ctx context.Context, slot types.Slot, seed [32]byte, index types.CommitteeIndex) ([]types.ValidatorIndex, error)
Committee fetches the shuffled indices by slot and committee index. Every list of indices represent one committee. Returns true if the list exists with slot and committee index. Otherwise returns false, nil.
func (*CommitteeCache) HasEntry ¶
func (c *CommitteeCache) HasEntry(seed string) bool
HasEntry returns true if the committee cache has a value.
func (*CommitteeCache) MarkInProgress ¶
func (c *CommitteeCache) MarkInProgress(seed [32]byte) error
MarkInProgress a request so that any other similar requests will block on Get until MarkNotInProgress is called.
func (*CommitteeCache) MarkNotInProgress ¶
func (c *CommitteeCache) MarkNotInProgress(seed [32]byte) error
MarkNotInProgress will release the lock on a given request. This should be called after put.
type Committees ¶
type Committees struct { CommitteeCount uint64 Seed [32]byte ShuffledIndices []types.ValidatorIndex SortedIndices []types.ValidatorIndex }
Committees defines the shuffled committees seed.
type ProposerIndices ¶
type ProposerIndices struct { BlockRoot [32]byte ProposerIndices []types.ValidatorIndex }
ProposerIndices defines the cached struct for proposer indices.
type ProposerIndicesCache ¶
type ProposerIndicesCache struct {
// contains filtered or unexported fields
}
ProposerIndicesCache is a struct with 1 queue for looking up proposer indices by root.
func NewProposerIndicesCache ¶
func NewProposerIndicesCache() *ProposerIndicesCache
NewProposerIndicesCache creates a new proposer indices cache for storing/accessing proposer index assignments of an epoch.
func (*ProposerIndicesCache) AddProposerIndices ¶
func (c *ProposerIndicesCache) AddProposerIndices(p *ProposerIndices) error
AddProposerIndices adds ProposerIndices object to the cache. This method also trims the least recently list if the cache size has ready the max cache size limit.
func (*ProposerIndicesCache) HasProposerIndices ¶
func (c *ProposerIndicesCache) HasProposerIndices(r [32]byte) (bool, error)
HasProposerIndices returns the proposer indices of a block root seed.
func (*ProposerIndicesCache) Len ¶
func (c *ProposerIndicesCache) Len() int
Len returns the number of keys in the underlying cache.
func (*ProposerIndicesCache) ProposerIndices ¶
func (c *ProposerIndicesCache) ProposerIndices(r [32]byte) ([]types.ValidatorIndex, error)
ProposerIndices returns the proposer indices of a block root seed.
type ProposerPayloadIDsCache ¶
ProposerPayloadIDsCache is a cache of proposer payload IDs. The key is the slot. The value is the concatenation of the proposer and payload IDs. 8 bytes each.
func NewProposerPayloadIDsCache ¶
func NewProposerPayloadIDsCache() *ProposerPayloadIDsCache
NewProposerPayloadIDsCache creates a new proposer payload IDs cache.
func (*ProposerPayloadIDsCache) GetProposerPayloadIDs ¶
func (f *ProposerPayloadIDsCache) GetProposerPayloadIDs(slot types.Slot, r [32]byte) (types.ValidatorIndex, [8]byte, bool)
GetProposerPayloadIDs returns the proposer and payload IDs for the given slot.
func (*ProposerPayloadIDsCache) PrunePayloadIDs ¶
func (f *ProposerPayloadIDsCache) PrunePayloadIDs(slot types.Slot)
PrunePayloadIDs removes the payload id entries that's current than input slot.
func (*ProposerPayloadIDsCache) SetProposerAndPayloadIDs ¶
func (f *ProposerPayloadIDsCache) SetProposerAndPayloadIDs(slot types.Slot, vId types.ValidatorIndex, pId [8]byte, r [32]byte)
SetProposerAndPayloadIDs sets the proposer and payload IDs for the given slot.
type SkipSlotCache ¶
type SkipSlotCache struct {
// contains filtered or unexported fields
}
SkipSlotCache is used to store the cached results of processing skip slots in transition.ProcessSlots.
func NewSkipSlotCache ¶
func NewSkipSlotCache() *SkipSlotCache
NewSkipSlotCache initializes the map and underlying cache.
func (*SkipSlotCache) Get ¶
func (c *SkipSlotCache) Get(ctx context.Context, r [32]byte) (state.BeaconState, error)
Get waits for any in progress calculation to complete before returning a cached response, if any.
func (*SkipSlotCache) MarkInProgress ¶
func (c *SkipSlotCache) MarkInProgress(r [32]byte) error
MarkInProgress a request so that any other similar requests will block on Get until MarkNotInProgress is called.
func (*SkipSlotCache) MarkNotInProgress ¶
func (c *SkipSlotCache) MarkNotInProgress(r [32]byte)
MarkNotInProgress will release the lock on a given request. This should be called after put.
func (*SkipSlotCache) Put ¶
func (c *SkipSlotCache) Put(_ context.Context, r [32]byte, state state.BeaconState)
Put the response in the cache.
type SyncCommitteeCache ¶
type SyncCommitteeCache struct {
// contains filtered or unexported fields
}
SyncCommitteeCache utilizes a FIFO cache to sufficiently cache validator position within sync committee. It is thread safe with concurrent read write.
func NewSyncCommittee ¶
func NewSyncCommittee() *SyncCommitteeCache
NewSyncCommittee initializes and returns a new SyncCommitteeCache.
func (*SyncCommitteeCache) CurrentPeriodIndexPosition ¶
func (s *SyncCommitteeCache) CurrentPeriodIndexPosition(root [32]byte, valIdx types.ValidatorIndex) ([]types.CommitteeIndex, error)
CurrentPeriodIndexPosition returns current period index position of a validator index with respect with sync committee. If the input validator index has no assignment, an empty list will be returned. If the input root does not exist in cache, `ErrNonExistingSyncCommitteeKey` is returned. Manual checking of state for index position in state is recommended when `ErrNonExistingSyncCommitteeKey` is returned.
func (*SyncCommitteeCache) NextPeriodIndexPosition ¶
func (s *SyncCommitteeCache) NextPeriodIndexPosition(root [32]byte, valIdx types.ValidatorIndex) ([]types.CommitteeIndex, error)
NextPeriodIndexPosition returns next period index position of a validator index in respect with sync committee. If the input validator index has no assignment, an empty list will be returned. If the input root does not exist in cache, `ErrNonExistingSyncCommitteeKey` is returned. Manual checking of state for index position in state is recommended when `ErrNonExistingSyncCommitteeKey` is returned.
func (*SyncCommitteeCache) UpdatePositionsInCommittee ¶
func (s *SyncCommitteeCache) UpdatePositionsInCommittee(syncCommitteeBoundaryRoot [32]byte, st state.BeaconState) error
UpdatePositionsInCommittee updates caching of validators position in sync committee in respect to current epoch and next epoch. This should be called when `current_sync_committee` and `next_sync_committee` change and that happens every `EPOCHS_PER_SYNC_COMMITTEE_PERIOD`.
type SyncCommitteeHeadStateCache ¶
type SyncCommitteeHeadStateCache struct {
// contains filtered or unexported fields
}
SyncCommitteeHeadStateCache for the latest head state requested by a sync committee participant.
func NewSyncCommitteeHeadState ¶
func NewSyncCommitteeHeadState() *SyncCommitteeHeadStateCache
NewSyncCommitteeHeadState initializes a LRU cache for `SyncCommitteeHeadState` with size of 1.
func (*SyncCommitteeHeadStateCache) Get ¶
func (c *SyncCommitteeHeadStateCache) Get(slot types.Slot) (state.BeaconState, error)
Get `state` using `slot` as key. Return nil if nothing is found.
func (*SyncCommitteeHeadStateCache) Put ¶
func (c *SyncCommitteeHeadStateCache) Put(slot types.Slot, st state.BeaconState) error
Put `slot` as key and `state` as value onto the cache.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package depositcache is the source of validator deposits maintained in-memory by the beacon node – deposits processed from the eth1 powchain are then stored in this cache to be accessed by any other service during a beacon node's runtime.
|
Package depositcache is the source of validator deposits maintained in-memory by the beacon node – deposits processed from the eth1 powchain are then stored in this cache to be accessed by any other service during a beacon node's runtime. |