Documentation ¶
Overview ¶
Package kv defines a bolt-db, key-value store implementation of the slasher database interface.
Index ¶
- type Config
- type Store
- func (db *Store) AttesterSlashings(ctx context.Context, status types.SlashingStatus) ([]*ethpb.AttesterSlashing, error)
- func (db *Store) BlockHeaders(ctx context.Context, slot, validatorID uint64) ([]*ethpb.SignedBeaconBlockHeader, error)
- func (db *Store) CacheLength(ctx context.Context) int
- func (db *Store) ChainHead(ctx context.Context) (*ethpb.ChainHead, error)
- func (db *Store) ClearDB() error
- func (db *Store) ClearSpanCache()
- func (db *Store) Close() error
- func (db *Store) DatabasePath() string
- func (db *Store) DeleteAttesterSlashing(ctx context.Context, attesterSlashing *ethpb.AttesterSlashing) error
- func (db *Store) DeleteBlockHeader(ctx context.Context, blockHeader *ethpb.SignedBeaconBlockHeader) error
- func (db *Store) DeleteIndexedAttestation(ctx context.Context, idxAttestation *ethpb.IndexedAttestation) error
- func (db *Store) DeleteProposerSlashing(ctx context.Context, slashing *ethpb.ProposerSlashing) error
- func (db *Store) DeletePubKey(ctx context.Context, validatorID uint64) error
- func (db *Store) EnableHighestAttestationCache(enable bool)
- func (db *Store) EnableSpanCache(enable bool)
- func (db *Store) EpochSpans(_ context.Context, epoch uint64, fromCache bool) (*types.EpochStore, error)
- func (db *Store) GetLatestEpochDetected(ctx context.Context) (uint64, error)
- func (db *Store) HasAttesterSlashing(ctx context.Context, slashing *ethpb.AttesterSlashing) (bool, types.SlashingStatus, error)
- func (db *Store) HasBlockHeader(ctx context.Context, slot, validatorID uint64) bool
- func (db *Store) HasIndexedAttestation(ctx context.Context, att *ethpb.IndexedAttestation) (bool, error)
- func (db *Store) HasProposerSlashing(ctx context.Context, slashing *ethpb.ProposerSlashing) (bool, types.SlashingStatus, error)
- func (db *Store) HighestAttestation(ctx context.Context, validatorID uint64) (*slashpb.HighestAttestation, error)
- func (db *Store) IndexedAttestationsForTarget(ctx context.Context, targetEpoch uint64) ([]*ethpb.IndexedAttestation, error)
- func (db *Store) IndexedAttestationsWithPrefix(ctx context.Context, targetEpoch uint64, sigBytes []byte) ([]*ethpb.IndexedAttestation, error)
- func (db *Store) LatestIndexedAttestationsTargetEpoch(ctx context.Context) (uint64, error)
- func (db *Store) ProposalSlashingsByStatus(ctx context.Context, status types.SlashingStatus) ([]*ethpb.ProposerSlashing, error)
- func (db *Store) PruneAttHistory(ctx context.Context, currentEpoch, pruningEpochAge uint64) error
- func (db *Store) PruneBlockHistory(ctx context.Context, currentEpoch, pruningEpochAge uint64) error
- func (db *Store) RemoveOldestFromCache(ctx context.Context) uint64
- func (db *Store) SaveAttesterSlashing(ctx context.Context, status types.SlashingStatus, ...) error
- func (db *Store) SaveAttesterSlashings(ctx context.Context, status types.SlashingStatus, ...) error
- func (db *Store) SaveBlockHeader(ctx context.Context, blockHeader *ethpb.SignedBeaconBlockHeader) error
- func (db *Store) SaveChainHead(ctx context.Context, head *ethpb.ChainHead) error
- func (db *Store) SaveEpochSpans(ctx context.Context, epoch uint64, es *types.EpochStore, toCache bool) error
- func (db *Store) SaveHighestAttestation(ctx context.Context, highest *slashpb.HighestAttestation) error
- func (db *Store) SaveIndexedAttestation(ctx context.Context, idxAttestation *ethpb.IndexedAttestation) error
- func (db *Store) SaveIndexedAttestations(ctx context.Context, idxAttestations []*ethpb.IndexedAttestation) error
- func (db *Store) SaveProposerSlashing(ctx context.Context, status types.SlashingStatus, ...) error
- func (db *Store) SaveProposerSlashings(ctx context.Context, status types.SlashingStatus, ...) error
- func (db *Store) SavePubKey(ctx context.Context, validatorID uint64, pubKey []byte) error
- func (db *Store) SetLatestEpochDetected(ctx context.Context, epoch uint64) error
- func (db *Store) Size() (int64, error)
- func (db *Store) ValidatorPubKey(ctx context.Context, validatorID uint64) ([]byte, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { // SpanCacheSize determines the span map cache size. SpanCacheSize int HighestAttestationCacheSize int }
Config options for the slasher db.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store defines an implementation of the slasher Database interface using BoltDB as the underlying persistent kv-store for eth2.
func NewKVStore ¶
NewKVStore initializes a new boltDB key-value store at the directory path specified, creates the kv-buckets based on the schema, and stores an open connection db object as a property of the Store struct.
func (*Store) AttesterSlashings ¶
func (db *Store) AttesterSlashings(ctx context.Context, status types.SlashingStatus) ([]*ethpb.AttesterSlashing, error)
AttesterSlashings accepts a status and returns all slashings with this status. returns empty []*ethpb.AttesterSlashing if no slashing has been found with this status.
func (*Store) BlockHeaders ¶
func (db *Store) BlockHeaders(ctx context.Context, slot, validatorID uint64) ([]*ethpb.SignedBeaconBlockHeader, error)
BlockHeaders accepts an slot and validator id and returns the corresponding block header array. Returns nil if the block header for those values does not exist.
func (*Store) CacheLength ¶ added in v1.0.0
CacheLength returns the number of cached items.
func (*Store) ChainHead ¶
ChainHead retrieves the persisted chain head from the database accordingly.
func (*Store) ClearDB ¶
ClearDB removes any previously stored data at the configured data directory.
func (*Store) ClearSpanCache ¶
func (db *Store) ClearSpanCache()
ClearSpanCache clears the spans cache.
func (*Store) DatabasePath ¶
DatabasePath at which this database writes files.
func (*Store) DeleteAttesterSlashing ¶
func (db *Store) DeleteAttesterSlashing(ctx context.Context, attesterSlashing *ethpb.AttesterSlashing) error
DeleteAttesterSlashing deletes an attester slashing proof from db.
func (*Store) DeleteBlockHeader ¶
func (db *Store) DeleteBlockHeader(ctx context.Context, blockHeader *ethpb.SignedBeaconBlockHeader) error
DeleteBlockHeader deletes a block header using the slot and validator id.
func (*Store) DeleteIndexedAttestation ¶
func (db *Store) DeleteIndexedAttestation(ctx context.Context, idxAttestation *ethpb.IndexedAttestation) error
DeleteIndexedAttestation deletes a indexed attestation using the slot and its root as keys in their respective buckets.
func (*Store) DeleteProposerSlashing ¶
func (db *Store) DeleteProposerSlashing(ctx context.Context, slashing *ethpb.ProposerSlashing) error
DeleteProposerSlashing deletes a proposer slashing proof.
func (*Store) DeletePubKey ¶
DeletePubKey deletes a public key of a validator id.
func (*Store) EnableHighestAttestationCache ¶ added in v1.0.0
EnableHighestAttestationCache used to enable or disable highest attestation cache in tests.
func (*Store) EnableSpanCache ¶ added in v1.0.0
EnableSpanCache used to enable or disable span map cache in tests.
func (*Store) EpochSpans ¶ added in v1.0.0
func (db *Store) EpochSpans(_ context.Context, epoch uint64, fromCache bool) (*types.EpochStore, error)
EpochSpans accepts epoch and returns the corresponding spans byte array for slashing detection. Returns span byte array, and error in case of db error. returns empty byte array if no entry for this epoch exists in db.
func (*Store) GetLatestEpochDetected ¶
GetLatestEpochDetected returns the latest detected epoch from db.
func (*Store) HasAttesterSlashing ¶
func (db *Store) HasAttesterSlashing(ctx context.Context, slashing *ethpb.AttesterSlashing) (bool, types.SlashingStatus, error)
HasAttesterSlashing returns true and slashing status if a slashing is found in the db.
func (*Store) HasBlockHeader ¶
HasBlockHeader accepts a slot and validator id and returns true if the block header exists.
func (*Store) HasIndexedAttestation ¶
func (db *Store) HasIndexedAttestation(ctx context.Context, att *ethpb.IndexedAttestation) (bool, error)
HasIndexedAttestation accepts an attestation and returns true if it exists in the DB.
func (*Store) HasProposerSlashing ¶
func (db *Store) HasProposerSlashing(ctx context.Context, slashing *ethpb.ProposerSlashing) (bool, types.SlashingStatus, error)
HasProposerSlashing returns the slashing key if it is found in db.
func (*Store) HighestAttestation ¶ added in v1.0.0
func (db *Store) HighestAttestation(ctx context.Context, validatorID uint64) (*slashpb.HighestAttestation, error)
HighestAttestation returns the highest calculated attestation for a validatorID
func (*Store) IndexedAttestationsForTarget ¶
func (db *Store) IndexedAttestationsForTarget(ctx context.Context, targetEpoch uint64) ([]*ethpb.IndexedAttestation, error)
IndexedAttestationsForTarget accepts a target epoch and returns a list of indexed attestations. Returns nil if the indexed attestation does not exist with that target epoch.
func (*Store) IndexedAttestationsWithPrefix ¶
func (db *Store) IndexedAttestationsWithPrefix(ctx context.Context, targetEpoch uint64, sigBytes []byte) ([]*ethpb.IndexedAttestation, error)
IndexedAttestationsWithPrefix accepts a target epoch and signature bytes to find all attestations with the requested prefix. Returns nil if the indexed attestation does not exist with that target epoch.
func (*Store) LatestIndexedAttestationsTargetEpoch ¶
LatestIndexedAttestationsTargetEpoch returns latest target epoch in db returns 0 if there is no indexed attestations in db.
func (*Store) ProposalSlashingsByStatus ¶
func (db *Store) ProposalSlashingsByStatus(ctx context.Context, status types.SlashingStatus) ([]*ethpb.ProposerSlashing, error)
ProposalSlashingsByStatus returns all the proposal slashing proofs with a certain status.
func (*Store) PruneAttHistory ¶
PruneAttHistory removes all attestations from the DB older than the pruning epoch age.
func (*Store) PruneBlockHistory ¶
PruneBlockHistory leaves only records younger then history size.
func (*Store) RemoveOldestFromCache ¶ added in v1.0.0
RemoveOldestFromCache clears the oldest key out of the cache only if the cache is at max capacity.
func (*Store) SaveAttesterSlashing ¶
func (db *Store) SaveAttesterSlashing(ctx context.Context, status types.SlashingStatus, slashing *ethpb.AttesterSlashing) error
SaveAttesterSlashing accepts a slashing proof and its status and writes it to disk.
func (*Store) SaveAttesterSlashings ¶
func (db *Store) SaveAttesterSlashings(ctx context.Context, status types.SlashingStatus, slashings []*ethpb.AttesterSlashing) error
SaveAttesterSlashings accepts a slice of slashing proof and its status and writes it to disk.
func (*Store) SaveBlockHeader ¶
func (db *Store) SaveBlockHeader(ctx context.Context, blockHeader *ethpb.SignedBeaconBlockHeader) error
SaveBlockHeader accepts a block header and writes it to disk.
func (*Store) SaveChainHead ¶
SaveChainHead accepts a beacon chain head object and persists it to the DB.
func (*Store) SaveEpochSpans ¶ added in v1.0.0
func (db *Store) SaveEpochSpans(ctx context.Context, epoch uint64, es *types.EpochStore, toCache bool) error
SaveEpochSpans accepts a epoch and span byte array and writes it to disk.
func (*Store) SaveHighestAttestation ¶ added in v1.0.0
func (db *Store) SaveHighestAttestation(ctx context.Context, highest *slashpb.HighestAttestation) error
SaveHighestAttestation saves highest attestation for a validatorID.
func (*Store) SaveIndexedAttestation ¶
func (db *Store) SaveIndexedAttestation(ctx context.Context, idxAttestation *ethpb.IndexedAttestation) error
SaveIndexedAttestation accepts an indexed attestation and writes it to the DB.
func (*Store) SaveIndexedAttestations ¶
func (db *Store) SaveIndexedAttestations(ctx context.Context, idxAttestations []*ethpb.IndexedAttestation) error
SaveIndexedAttestations accepts multiple indexed attestations and writes them to the DB.
func (*Store) SaveProposerSlashing ¶
func (db *Store) SaveProposerSlashing(ctx context.Context, status types.SlashingStatus, slashing *ethpb.ProposerSlashing) error
SaveProposerSlashing accepts a proposer slashing and its status header and writes it to disk.
func (*Store) SaveProposerSlashings ¶
func (db *Store) SaveProposerSlashings(ctx context.Context, status types.SlashingStatus, slashings []*ethpb.ProposerSlashing) error
SaveProposerSlashings accepts a slice of slashing proof and its status and writes it to disk.
func (*Store) SavePubKey ¶
SavePubKey accepts a validator id and its public key and writes it to disk.
func (*Store) SetLatestEpochDetected ¶
SetLatestEpochDetected sets the latest slashing detected epoch in db.