kv

package
v1.4.4 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2021 License: GPL-3.0 Imports: 26 Imported by: 21

Documentation

Overview

Package kv defines a bolt-db, key-value store implementation of the slasher database interface.

Index

Constants

View Source
const (
	// SlasherDbDirName is the name of the directory containing the slasher database.
	SlasherDbDirName = "slasherdata"
	// DatabaseFileName is the name of the slasher database.
	DatabaseFileName = "slasher.db"
)

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

func NewKVStore

func NewKVStore(dirPath string, cfg *Config) (*Store, error)

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 (s *Store) AttesterSlashings(ctx context.Context, status slashertypes.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) Backup added in v1.0.4

func (s *Store) Backup(ctx context.Context, outputDir string, overridePermission bool) error

Backup the database to the datadir backup directory. Example for backup: $DATADIR/backups/prysm_slasherdb_10291092.backup

func (*Store) BlockHeaders

func (s *Store) BlockHeaders(ctx context.Context, slot types.Slot, validatorIndex types.ValidatorIndex) ([]*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

func (s *Store) CacheLength(ctx context.Context) int

CacheLength returns the number of cached items.

func (*Store) ChainHead

func (s *Store) ChainHead(ctx context.Context) (*ethpb.ChainHead, error)

ChainHead retrieves the persisted chain head from the database accordingly.

func (*Store) ClearDB

func (s *Store) ClearDB() error

ClearDB removes any previously stored data at the configured data directory.

func (*Store) ClearSpanCache

func (s *Store) ClearSpanCache()

ClearSpanCache clears the spans cache.

func (*Store) Close

func (s *Store) Close() error

Close closes the underlying boltdb database.

func (*Store) DatabasePath

func (s *Store) DatabasePath() string

DatabasePath at which this database writes files.

func (*Store) DeleteAttesterSlashing

func (s *Store) DeleteAttesterSlashing(ctx context.Context, attesterSlashing *ethpb.AttesterSlashing) error

DeleteAttesterSlashing deletes an attester slashing proof from db.

func (*Store) DeleteBlockHeader

func (s *Store) DeleteBlockHeader(ctx context.Context, blockHeader *ethpb.SignedBeaconBlockHeader) error

DeleteBlockHeader deletes a block header using the slot and validator id.

func (*Store) DeleteIndexedAttestation

func (s *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 (s *Store) DeleteProposerSlashing(ctx context.Context, slashing *ethpb.ProposerSlashing) error

DeleteProposerSlashing deletes a proposer slashing proof.

func (*Store) DeletePubKey

func (s *Store) DeletePubKey(ctx context.Context, validatorIndex types.ValidatorIndex) error

DeletePubKey deletes a public key of a validator id.

func (*Store) EnableHighestAttestationCache added in v1.0.0

func (s *Store) EnableHighestAttestationCache(enable bool)

EnableHighestAttestationCache used to enable or disable highest attestation cache in tests.

func (*Store) EnableSpanCache added in v1.0.0

func (s *Store) EnableSpanCache(enable bool)

EnableSpanCache used to enable or disable span map cache in tests.

func (*Store) EpochSpans added in v1.0.0

func (s *Store) EpochSpans(_ context.Context, epoch types.Epoch, fromCache bool) (*slashertypes.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

func (s *Store) GetLatestEpochDetected(ctx context.Context) (types.Epoch, error)

GetLatestEpochDetected returns the latest detected epoch from db.

func (*Store) HasAttesterSlashing

func (s *Store) HasAttesterSlashing(ctx context.Context, slashing *ethpb.AttesterSlashing) (bool, slashertypes.SlashingStatus, error)

HasAttesterSlashing returns true and slashing status if a slashing is found in the db.

func (*Store) HasBlockHeader

func (s *Store) HasBlockHeader(ctx context.Context, slot types.Slot, validatorIndex types.ValidatorIndex) bool

HasBlockHeader accepts a slot and validator id and returns true if the block header exists.

func (*Store) HasIndexedAttestation

func (s *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 (s *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 (s *Store) HighestAttestation(ctx context.Context, validatorID uint64) (*slashpb.HighestAttestation, error)

HighestAttestation returns the highest calculated attestation for a validatorID

func (*Store) IndexedAttestationsForTarget

func (s *Store) IndexedAttestationsForTarget(ctx context.Context, targetEpoch types.Epoch) ([]*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 (s *Store) IndexedAttestationsWithPrefix(ctx context.Context, targetEpoch types.Epoch, 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

func (s *Store) LatestIndexedAttestationsTargetEpoch(ctx context.Context) (uint64, error)

LatestIndexedAttestationsTargetEpoch returns latest target epoch in db returns 0 if there is no indexed attestations in db.

func (*Store) ProposalSlashingsByStatus

func (s *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

func (s *Store) PruneAttHistory(ctx context.Context, currentEpoch, pruningEpochAge types.Epoch) error

PruneAttHistory removes all attestations from the DB older than the pruning epoch age.

func (*Store) PruneBlockHistory

func (s *Store) PruneBlockHistory(ctx context.Context, currentEpoch, pruningEpochAge types.Epoch) error

PruneBlockHistory leaves only records younger then history size.

func (*Store) RemoveOldestFromCache added in v1.0.0

func (s *Store) RemoveOldestFromCache(ctx context.Context) uint64

RemoveOldestFromCache clears the oldest key out of the cache only if the cache is at max capacity.

func (*Store) SaveAttesterSlashing

func (s *Store) SaveAttesterSlashing(ctx context.Context, status slashertypes.SlashingStatus, slashing *ethpb.AttesterSlashing) error

SaveAttesterSlashing accepts a slashing proof and its status and writes it to disk.

func (*Store) SaveAttesterSlashings

func (s *Store) SaveAttesterSlashings(ctx context.Context, status slashertypes.SlashingStatus, slashings []*ethpb.AttesterSlashing) error

SaveAttesterSlashings accepts a slice of slashing proof and its status and writes it to disk.

func (*Store) SaveBlockHeader

func (s *Store) SaveBlockHeader(ctx context.Context, blockHeader *ethpb.SignedBeaconBlockHeader) error

SaveBlockHeader accepts a block header and writes it to disk.

func (*Store) SaveChainHead

func (s *Store) SaveChainHead(ctx context.Context, head *ethpb.ChainHead) error

SaveChainHead accepts a beacon chain head object and persists it to the DB.

func (*Store) SaveEpochSpans added in v1.0.0

func (s *Store) SaveEpochSpans(ctx context.Context, epoch types.Epoch, es *slashertypes.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 (s *Store) SaveHighestAttestation(ctx context.Context, highest *slashpb.HighestAttestation) error

SaveHighestAttestation saves highest attestation for a validatorID.

func (*Store) SaveIndexedAttestation

func (s *Store) SaveIndexedAttestation(ctx context.Context, idxAttestation *ethpb.IndexedAttestation) error

SaveIndexedAttestation accepts an indexed attestation and writes it to the DB.

func (*Store) SaveIndexedAttestations

func (s *Store) SaveIndexedAttestations(ctx context.Context, idxAttestations []*ethpb.IndexedAttestation) error

SaveIndexedAttestations accepts multiple indexed attestations and writes them to the DB.

func (*Store) SaveProposerSlashing

func (s *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 (s *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

func (s *Store) SavePubKey(ctx context.Context, validatorIndex types.ValidatorIndex, pubKey []byte) error

SavePubKey accepts a validator id and its public key and writes it to disk.

func (*Store) SetLatestEpochDetected

func (s *Store) SetLatestEpochDetected(ctx context.Context, epoch types.Epoch) error

SetLatestEpochDetected sets the latest slashing detected epoch in db.

func (*Store) Size

func (s *Store) Size() (int64, error)

Size returns the db size in bytes.

func (*Store) ValidatorPubKey

func (s *Store) ValidatorPubKey(ctx context.Context, validatorIndex types.ValidatorIndex) ([]byte, error)

ValidatorPubKey accepts validator id and returns the corresponding pubkey. Returns nil if the pubkey for this validator id does not exist.

Jump to

Keyboard shortcuts

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