cache

package
v5.0.4-rc.1 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2024 License: GPL-3.0 Imports: 31 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.

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 (
	// 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.",
	})
)
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

This section is empty.

Types

type AttestationCache

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

AttestationCache stores cached results of AttestationData requests.

func NewAttestationCache

func NewAttestationCache() *AttestationCache

NewAttestationCache creates a new instance of AttestationCache.

func (*AttestationCache) Get

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

func (*AttestationCache) Put

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

type AttestationConsensusData

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

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) 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 {
	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(ctx context.Context, 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 added in v5.0.2

func (c *CommitteeCache) CompressCommitteeCache()

CompressCommitteeCache compresses the size of the committee cache.

func (*CommitteeCache) ExpandCommitteeCache added in v5.0.2

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.

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 []primitives.ValidatorIndex
	SortedIndices   []primitives.ValidatorIndex
}

Committees defines the shuffled committees seed.

type DepositCache

type DepositCache interface {
	DepositFetcher
	DepositInserter
}

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
	PrunePendingDeposits(ctx context.Context, merkleTreeIndex int64)
	PruneProofs(ctx context.Context, untilDepositIndex int64) error
	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 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 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 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 and with the given head root.

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) (primitives.PayloadID, bool)

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

func (*PayloadIDCache) Set

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

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

type ProposerIndices

type ProposerIndices struct {
	BlockRoot       [32]byte
	ProposerIndices []primitives.ValidatorIndex
}

ProposerIndices defines the cached struct for proposer indices.

type ProposerIndicesCache

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

ProposerIndicesCache keeps track of the proposer indices in the next two epochs. It is keyed by the state root of the last epoch before. That is, for blocks during epoch 2, for example slot 65, it will be keyed by the state root of slot 63 (last slot in epoch 1). The cache keeps two sets of indices computed, the "safe" set is computed right before the epoch transition into the current epoch. For example for epoch 2 we will compute this list after importing block 63. The "unsafe" version is computed an epoch in advance, for example for epoch 3, it will be computed after importing block 63.

The cache also keeps a map from checkpoints to state roots so that one is able to access the proposer indices list from a checkpoint instead. The checkpoint is the checkpoint for the epoch previous to the requested proposer indices. That is, for a slot in epoch 2 (eg. 65), the checkpoint root would be for slot 32 if present.

func NewProposerIndicesCache

func NewProposerIndicesCache() *ProposerIndicesCache

NewProposerIndicesCache returns a newly created cache

func (*ProposerIndicesCache) IndicesFromCheckpoint

IndicesFromCheckpoint returns the proposer indices from a checkpoint rather than the state root

func (*ProposerIndicesCache) ProposerIndices

ProposerIndices returns the proposer indices (safe) for the given root

func (*ProposerIndicesCache) Prune

func (p *ProposerIndicesCache) Prune(epoch primitives.Epoch)

Prune resets the ProposerIndicesCache to its initial state

func (*ProposerIndicesCache) Set

Set sets the proposer indices for the given root as key

func (*ProposerIndicesCache) SetCheckpoint

func (p *ProposerIndicesCache) SetCheckpoint(c forkchoicetypes.Checkpoint, root [32]byte)

SetCheckpoint updates the map from checkpoints to state roots

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 RootToPayloadIDMap

type RootToPayloadIDMap map[[32]byte]primitives.PayloadID

RootToPayloadIDMap is a map with keys the head root and values the corresponding PayloadID

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

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.

type TrackedValidator

type TrackedValidator struct {
	Active       bool
	FeeRecipient primitives.ExecutionAddress
	Index        primitives.ValidatorIndex
}

type TrackedValidatorsCache

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

func NewTrackedValidatorsCache

func NewTrackedValidatorsCache() *TrackedValidatorsCache

func (*TrackedValidatorsCache) Prune

func (t *TrackedValidatorsCache) Prune()

func (*TrackedValidatorsCache) Set

func (*TrackedValidatorsCache) Validating added in v5.0.2

func (t *TrackedValidatorsCache) Validating() bool

func (*TrackedValidatorsCache) Validator

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