cache

package
v7.1.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 10, 2026 License: GPL-3.0 Imports: 36 Imported by: 0

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.

Code generated by hack/gen-logs.sh; DO NOT EDIT. This file is created and regenerated automatically. Anything added here might get removed.

Index

Constants

This section is empty.

Variables

View Source
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.",
	})
)
View Source
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")

	// ErrNotFoundRegistration when validator registration does not exist in cache.
	ErrNotFoundRegistration = errors.Wrap(ErrNotFound, "no validator registered")

	// 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.
	ErrAlreadyInProgress = errors.New("already in progress")
)
View Source
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.",
	})
)
View Source
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.

View Source
var SubnetIDs = newSubnetIDs()

SubnetIDs for attester and aggregator.

View Source
var SyncSubnetIDs = newSyncSubnetIDs()

SyncSubnetIDs for sync committee participant.

Functions

func GetBySlotAndCommitteeIndex

func GetBySlotAndCommitteeIndex[T ethpb.Att](c *AttestationCache, slot primitives.Slot, committeeIndex primitives.CommitteeIndex) []T

GetBySlotAndCommitteeIndex returns all attestations in the cache that match the provided slot and committee index. Forkchoice attestations are not returned.

NOTE: This function cannot be declared as a method on the AttestationCache because it is a generic function.

Types

type AttestationCache

type AttestationCache struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

AttestationCache holds a map of attGroup items that group together all attestations for a single slot. When we add an attestation to the cache by calling Add, we either create a new group with this attestation (if this is the first attestation for some slot) or two things can happen:

  • If the attestation is unaggregated, we add its attestation bit to attestation bits of the first attestation in the group.
  • If the attestation is aggregated, we append it to the group. There should be no redundancy in the list because we ignore redundant aggregates in gossip.

The first bullet point above means that we keep one aggregate attestation to which we keep appending bits as new single-bit attestations arrive. This means that at any point during seconds 0-4 of a slot we will have only one attestation for this slot in the cache.

NOTE: This design in principle can result in worse aggregates since we lose the ability to aggregate some single bit attestations in case of overlaps with incoming aggregates.

The cache also keeps forkchoice attestations in a separate struct. These attestations are used for forkchoice-related operations.

func NewAttestationCache

func NewAttestationCache() *AttestationCache

NewAttestationCache creates a new cache instance.

func (*AttestationCache) Add

func (c *AttestationCache) Add(att ethpb.Att) error

Add does one of two things:

  • For unaggregated attestations, it adds the attestation bit to attestation bits of the running aggregate, which is the first aggregate for the slot.
  • For aggregated attestations, it appends the attestation to the existing list of attestations for the slot.

func (*AttestationCache) AggregateIsRedundant

func (c *AttestationCache) AggregateIsRedundant(att ethpb.Att) (bool, error)

AggregateIsRedundant checks whether all attestation bits of the passed-in aggregate are already included by any aggregate in the cache.

func (*AttestationCache) Count

func (c *AttestationCache) Count() int

Count returns the number of all attestations in the cache, excluding forkchoice attestations.

func (*AttestationCache) DeleteCovered

func (c *AttestationCache) DeleteCovered(att ethpb.Att) error

DeleteCovered removes all attestations whose attestation bits are a proper subset of the passed-in attestation.

func (*AttestationCache) DeleteForkchoiceAttestation

func (c *AttestationCache) DeleteForkchoiceAttestation(att ethpb.Att) error

DeleteForkchoiceAttestation deletes a forkchoice attestation.

func (*AttestationCache) ForkchoiceAttestations

func (c *AttestationCache) ForkchoiceAttestations() []ethpb.Att

ForkchoiceAttestations returns all forkchoice attestations.

func (*AttestationCache) GetAll

func (c *AttestationCache) GetAll() []ethpb.Att

GetAll returns all attestations in the cache, excluding forkchoice attestations.

func (*AttestationCache) PruneBefore

func (c *AttestationCache) PruneBefore(slot primitives.Slot) uint64

PruneBefore removes all attestations whose slot is earlier than the passed-in slot.

func (*AttestationCache) SaveForkchoiceAttestations

func (c *AttestationCache) SaveForkchoiceAttestations(att []ethpb.Att) error

SaveForkchoiceAttestations saves forkchoice attestations.

type AttestationConsensusData

type AttestationConsensusData struct {
	Slot          primitives.Slot
	HeadRoot      []byte
	Target        forkchoicetypes.Checkpoint
	Source        forkchoicetypes.Checkpoint
	IsPayloadFull bool
}

type AttestationDataCache

type AttestationDataCache struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

AttestationDataCache stores cached results of AttestationData requests.

func NewAttestationDataCache

func NewAttestationDataCache() *AttestationDataCache

NewAttestationDataCache creates a new instance of AttestationDataCache.

func (*AttestationDataCache) Get

Get retrieves cached attestation data, recording a cache hit or miss. This method is lock free.

func (*AttestationDataCache) Put

Put adds a response to the cache. This method is lock free.

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) Clear

func (c *BalanceCache) Clear()

Clear resets the SyncCommitteeCache to its initial state

func (*BalanceCache) Get

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) EvictUpTo added in v7.1.3

func (c *CheckpointStateCache) EvictUpTo(epoch primitives.Epoch) int

EvictUpTo removes all entries from the cache whose state epoch is at or before the given epoch. Returns the number of evicted entries.

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

type CommitteeCache struct {
	Wg             sync.WaitGroup
	Sf             singleflight.Group
	CommitteeCache *lru.Cache
	// contains filtered or unexported fields
}

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) ([]primitives.ValidatorIndex, error)

ActiveIndices returns the active indices of a given seed stored in cache.

func (*CommitteeCache) ActiveIndicesCount

func (c *CommitteeCache) ActiveIndicesCount(seed [32]byte) (int, error)

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) Clear

func (c *CommitteeCache) Clear()

Clear resets the CommitteeCache to its initial state

func (*CommitteeCache) Committee

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) CompressCommitteeCache

func (c *CommitteeCache) CompressCommitteeCache()

CompressCommitteeCache compresses the size of the committee cache.

func (*CommitteeCache) ExpandCommitteeCache

func (c *CommitteeCache) ExpandCommitteeCache()

ExpandCommitteeCache expands the size of the committee cache.

func (*CommitteeCache) HasEntry

func (c *CommitteeCache) HasEntry(seed string) bool

HasEntry returns true if the committee cache has a value.

type Committees

type Committees struct {
	CommitteeCount  uint64
	Seed            [32]byte
	ShuffledIndices []primitives.ValidatorIndex
	SortedIndices   []primitives.ValidatorIndex
}

Committees defines the shuffled committees seed.

type DepositCache

type DepositCache interface {
	DepositFetcher
	DepositInserter
	DepositPruner
}

DepositCache combines the interfaces for retrieving and inserting deposit information.

type DepositFetcher

type DepositFetcher interface {
	AllDeposits(ctx context.Context, untilBlk *big.Int) []*ethpb.Deposit
	AllDepositContainers(ctx context.Context) []*ethpb.DepositContainer
	DepositByPubkey(ctx context.Context, pubKey []byte) (*ethpb.Deposit, *big.Int)
	DepositsNumberAndRootAtHeight(ctx context.Context, blockHeight *big.Int) (uint64, [32]byte)
	InsertPendingDeposit(ctx context.Context, d *ethpb.Deposit, blockNum uint64, index int64, depositRoot [32]byte)
	PendingDeposits(ctx context.Context, untilBlk *big.Int) []*ethpb.Deposit
	PendingContainers(ctx context.Context, untilBlk *big.Int) []*ethpb.DepositContainer
	FinalizedFetcher
}

DepositFetcher defines a struct which can retrieve deposit information from a store.

type DepositInserter

type DepositInserter interface {
	InsertDeposit(ctx context.Context, d *ethpb.Deposit, blockNum uint64, index int64, depositRoot [32]byte) error
	InsertDepositContainers(ctx context.Context, ctrs []*ethpb.DepositContainer)
	InsertFinalizedDeposits(ctx context.Context, eth1DepositIndex int64, executionHash common.Hash, executionNumber uint64) error
}

DepositInserter defines a struct which can insert deposit information from a store.

type DepositPruner

type DepositPruner interface {
	PrunePendingDeposits(ctx context.Context, merkleTreeIndex int64)
	PruneAllPendingDeposits(ctx context.Context)
	PruneProofs(ctx context.Context, untilDepositIndex int64) error
	PruneAllProofs(ctx context.Context)
}

DepositPruner is an interface for pruning deposits and proofs.

type ExecutionPayloadContents added in v7.1.5

type ExecutionPayloadContents struct {
	Envelope    *ethpb.ExecutionPayloadEnvelope
	DataColumns []consensusblocks.RODataColumn
}

ExecutionPayloadContents holds the producer's envelope with precomputed data column sidecars; raw blobs/proofs are derived from the columns at read time so the publish hot path skips the KZG cell extension.

type ExecutionPayloadEnvelopeCache added in v7.1.5

type ExecutionPayloadEnvelopeCache struct {
	// contains filtered or unexported fields
}

ExecutionPayloadEnvelopeCache holds the most recent ExecutionPayloadContents produced by the proposer. Single-entry; Set replaces.

func NewExecutionPayloadEnvelopeCache added in v7.1.5

func NewExecutionPayloadEnvelopeCache() *ExecutionPayloadEnvelopeCache

func (*ExecutionPayloadEnvelopeCache) Contents added in v7.1.5

Contents returns a snapshot of the cached bundle. The struct is freshly allocated; inner slices alias the cache (safe — Set re-assigns whole).

func (*ExecutionPayloadEnvelopeCache) Set added in v7.1.5

Set replaces the cached contents. No-op on nil receiver/contents/envelope so readers can treat Envelope and Envelope.Payload as non-nil on a hit.

type FinalizedDeposits

type FinalizedDeposits interface {
	Deposits() MerkleTree
	MerkleTrieIndex() int64
}

FinalizedDeposits defines a method to access a merkle tree containing deposits and their indexes.

type FinalizedFetcher

type FinalizedFetcher interface {
	FinalizedDeposits(ctx context.Context) (FinalizedDeposits, error)
	NonFinalizedDeposits(ctx context.Context, lastFinalizedIndex int64, untilBlk *big.Int) []*ethpb.Deposit
}

FinalizedFetcher is a smaller interface defined to be the bare minimum to satisfy “Service”. It extends the "DepositFetcher" interface with additional methods for fetching finalized deposits.

type HighestExecutionPayloadBidCache added in v7.1.4

type HighestExecutionPayloadBidCache struct {
	// contains filtered or unexported fields
}

HighestExecutionPayloadBidCache stores the highest bid for each (slot, parent_block_hash, parent_block_root) tuple.

func NewHighestExecutionPayloadBidCache added in v7.1.4

func NewHighestExecutionPayloadBidCache() *HighestExecutionPayloadBidCache

NewHighestExecutionPayloadBidCache initializes a highest-bid cache.

func (*HighestExecutionPayloadBidCache) Get added in v7.1.4

func (c *HighestExecutionPayloadBidCache) Get(
	slot primitives.Slot,
	parentHash [32]byte,
	parentRoot [32]byte,
) (*ethpb.SignedExecutionPayloadBid, bool)

Get returns the highest cached bid for the given tuple.

func (*HighestExecutionPayloadBidCache) PruneBefore added in v7.1.4

func (c *HighestExecutionPayloadBidCache) PruneBefore(slot primitives.Slot)

PruneBefore removes all cached bids for slots before the provided slot.

func (*HighestExecutionPayloadBidCache) SetIfHigher added in v7.1.4

SetIfHigher inserts the bid if absent, or replaces the cached bid only if the incoming value is strictly greater.

type MerkleTree

type MerkleTree interface {
	HashTreeRoot() ([32]byte, error)
	NumOfItems() int
	Insert(item []byte, index int) error
	MerkleProof(index int) ([][]byte, error)
}

MerkleTree defines methods for constructing and manipulating a merkle tree.

type PayloadAttestationCache added in v7.1.4

type PayloadAttestationCache struct {
	// contains filtered or unexported fields
}

PayloadAttestationCache tracks seen payload attestation messages for a single slot.

func (*PayloadAttestationCache) Add added in v7.1.4

Add marks the given slot and validator index as seen. This function assumes that the message has already been validated.

func (*PayloadAttestationCache) Clear added in v7.1.4

func (p *PayloadAttestationCache) Clear()

Clear clears the internal cache.

func (*PayloadAttestationCache) Seen added in v7.1.4

Seen returns true if a vote for the given slot has already been processed for this validator index.

type PayloadIDCache

type PayloadIDCache struct {
	sync.Mutex
	// contains filtered or unexported fields
}

PayloadIDCache is a cache that keeps track of the prepared payload ID for the given slot, head root and parent payload status.

func NewPayloadIDCache

func NewPayloadIDCache() *PayloadIDCache

NewPayloadIDCache returns a new payload ID cache

func (*PayloadIDCache) PayloadID

func (p *PayloadIDCache) PayloadID(slot primitives.Slot, root [32]byte, full bool) (primitives.PayloadID, bool)

PayloadID returns the payload ID for the given slot, parent block root and parent payload status

func (*PayloadIDCache) Set

func (p *PayloadIDCache) Set(slot primitives.Slot, root [32]byte, full bool, pid primitives.PayloadID)

SetPayloadID updates the payload ID for the given slot, head root and parent payload status it also prunes older entries in the cache

type ProposerPreference added in v7.1.4

type ProposerPreference struct {
	DependentRoot  [32]byte
	ValidatorIndex primitives.ValidatorIndex
	FeeRecipient   primitives.ExecutionAddress
	TargetGasLimit uint64
}

ProposerPreference is a proposer fee-recipient / gas-limit preference. When stored in the (slot, dep_root) preferences map it represents a signed SignedProposerPreferences; when stored in the per-validator defaults map it represents a pre-Gloas PrepareBeaconProposer write (no signature, no dependent_root).

func (*ProposerPreference) FeeRecipientOrDefault added in v7.1.6

func (p *ProposerPreference) FeeRecipientOrDefault() primitives.ExecutionAddress

FeeRecipientOrDefault returns the preference's FeeRecipient, or the --suggested-fee-recipient default when it is unset.

func (*ProposerPreference) GasLimitOr added in v7.1.6

func (p *ProposerPreference) GasLimitOr(fallback uint64) uint64

GasLimitOr returns the preference's TargetGasLimit, or fallback when it is unset.

type ProposerPreferencesCache added in v7.1.4

type ProposerPreferencesCache struct {
	// contains filtered or unexported fields
}

ProposerPreferencesCache holds two stores with different lookup keys:

  1. preferences: signed proposer preferences from gossip / our local SubmitSignedProposerPreferences, keyed by (slot, dependent_root). Spec-aligned lookup for bid validation and post-Gloas proposing.

  2. defaults: per-validator fee-recipient defaults written via the pre-Gloas PrepareBeaconProposer endpoint, keyed by validator_index. Branch-independent fallback for proposing when no (slot, dep_root) entry exists.

Lookup order at proposal time: preferences → defaults → DefaultFeeRecipient (the --suggested-fee-recipient flag). "Which validators are attached to this BN" lives in SubscribedValidatorsCache, not here.

func NewProposerPreferencesCache added in v7.1.4

func NewProposerPreferencesCache() *ProposerPreferencesCache

NewProposerPreferencesCache initializes a proposer preferences cache.

func (*ProposerPreferencesCache) Add added in v7.1.4

Add stores a signed proposer preference at the given slot. If an entry with the same (slot, pref.DependentRoot) already exists, the existing value is kept and false is returned.

func (*ProposerPreferencesCache) BestFor added in v7.1.6

func (c *ProposerPreferencesCache) BestFor(dependentRoot [32]byte, slot primitives.Slot, idx primitives.ValidatorIndex) (ProposerPreference, bool)

BestFor returns the best-available preference for proposer `idx` at (slot, dependentRoot): the signed branch-specific entry if present, else the per-validator default, else (zero, false).

func (*ProposerPreferencesCache) Clear added in v7.1.4

func (c *ProposerPreferencesCache) Clear()

Clear removes all cached signed preferences. Does not touch defaults.

func (*ProposerPreferencesCache) DefaultFor added in v7.1.6

DefaultFor returns the per-validator fee-recipient default for the given validator index, if one was set via PrepareBeaconProposer.

func (*ProposerPreferencesCache) Get added in v7.1.4

func (c *ProposerPreferencesCache) Get(dependentRoot [32]byte, slot primitives.Slot) (ProposerPreference, bool)

Get returns the signed proposer preference stored for (slot, dependentRoot).

func (*ProposerPreferencesCache) Has added in v7.1.4

func (c *ProposerPreferencesCache) Has(dependentRoot [32]byte, slot primitives.Slot) bool

Has returns true if a signed preference exists for (slot, dependentRoot).

func (*ProposerPreferencesCache) PruneBefore added in v7.1.4

func (c *ProposerPreferencesCache) PruneBefore(slot primitives.Slot)

PruneBefore removes all signed preferences for slots before the provided slot.

func (*ProposerPreferencesCache) SetDefault added in v7.1.6

func (c *ProposerPreferencesCache) SetDefault(pref ProposerPreference)

SetDefault records a per-validator fee-recipient default, keyed by ValidatorIndex. Populated by the pre-Gloas PrepareBeaconProposer endpoint. DependentRoot on the supplied preference is ignored.

type RegistrationCache

type RegistrationCache struct {
	// contains filtered or unexported fields
}

RegistrationCache is used to store the cached results of an Validator Registration request. beacon api /eth/v1/validator/register_validator

func NewRegistrationCache

func NewRegistrationCache() *RegistrationCache

NewRegistrationCache initializes the map and underlying cache.

func (*RegistrationCache) RegistrationByIndex

func (regCache *RegistrationCache) RegistrationByIndex(id primitives.ValidatorIndex) (*ethpb.ValidatorRegistrationV1, error)

RegistrationByIndex returns the registration by index in the cache and also removes items in the cache if expired.

func (*RegistrationCache) UpdateIndexToRegisteredMap

func (regCache *RegistrationCache) UpdateIndexToRegisteredMap(ctx context.Context, m map[primitives.ValidatorIndex]*ethpb.ValidatorRegistrationV1)

UpdateIndexToRegisteredMap adds or updates values in the cache based on the argument.

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) Disable

func (c *SkipSlotCache) Disable()

Disable the skip slot cache.

func (*SkipSlotCache) Enable

func (c *SkipSlotCache) Enable()

Enable the skip slot 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 SubscribedValidatorsCache added in v7.1.6

type SubscribedValidatorsCache struct {
	// contains filtered or unexported fields
}

SubscribedValidatorsCache tracks validator indices the validator client has posted committee subscriptions for.

func NewSubscribedValidatorsCache added in v7.1.6

func NewSubscribedValidatorsCache() *SubscribedValidatorsCache

NewSubscribedValidatorsCache returns a cache keyed by validator index. The VC re-posts subscriptions each epoch, so a TTL of a few epochs is enough to ride out a missed post without dropping the validator from custody calculations.

func (*SubscribedValidatorsCache) Add added in v7.1.6

Add records the validator as attached. Re-adding extends the TTL.

func (*SubscribedValidatorsCache) Clear added in v7.1.6

func (c *SubscribedValidatorsCache) Clear()

Clear removes all attached validators.

func (*SubscribedValidatorsCache) Has added in v7.1.6

Has returns true if the validator is currently attached.

func (*SubscribedValidatorsCache) Indices added in v7.1.6

Indices returns the set of currently-attached validator indices.

func (*SubscribedValidatorsCache) Validating added in v7.1.6

func (c *SubscribedValidatorsCache) Validating() bool

Validating returns true if at least one validator is attached.

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) Clear

func (s *SyncCommitteeCache) Clear()

Clear resets the SyncCommitteeCache to its initial state

func (*SyncCommitteeCache) CurrentPeriodIndexPosition

func (s *SyncCommitteeCache) CurrentPeriodIndexPosition(root [32]byte, valIdx primitives.ValidatorIndex) ([]primitives.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) CurrentPeriodPositions

func (s *SyncCommitteeCache) CurrentPeriodPositions(root [32]byte, indices []primitives.ValidatorIndex) ([][]primitives.CommitteeIndex, error)

CurrentPeriodPositions returns current period positions of validator indices with respect with sync committee. If any input validator index has no assignment, an empty list will be returned for that validator. 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 primitives.ValidatorIndex) ([]primitives.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.ReadOnlyBeaconState) 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

Get `state` using `slot` as key. Return nil if nothing is found.

func (*SyncCommitteeHeadStateCache) Put

Put `slot` as key and `state` as value onto the cache.

Directories

Path Synopsis
Package depositsnapshot implements the EIP-4881 standard for minimal sparse Merkle tree.
Package depositsnapshot implements the EIP-4881 standard for minimal sparse Merkle tree.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL