kv

package
v1.0.0-beta.1 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2020 License: GPL-3.0 Imports: 21 Imported by: 24

Documentation

Overview

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

Index

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

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 (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

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

CacheLength returns the number of cached items.

func (*Store) ChainHead

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

ChainHead retrieves the persisted chain head from the database accordingly.

func (*Store) ClearDB

func (db *Store) ClearDB() error

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

func (db *Store) Close() error

Close closes the underlying boltdb database.

func (*Store) DatabasePath

func (db *Store) DatabasePath() string

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

func (db *Store) DeletePubKey(ctx context.Context, validatorID uint64) error

DeletePubKey deletes a public key of a validator id.

func (*Store) EnableHighestAttestationCache added in v1.0.0

func (db *Store) EnableHighestAttestationCache(enable bool)

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

func (*Store) EnableSpanCache added in v1.0.0

func (db *Store) EnableSpanCache(enable bool)

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

func (db *Store) GetLatestEpochDetected(ctx context.Context) (uint64, error)

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

func (db *Store) HasBlockHeader(ctx context.Context, slot, validatorID uint64) bool

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

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

func (db *Store) PruneAttHistory(ctx context.Context, currentEpoch, pruningEpochAge uint64) error

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

func (*Store) PruneBlockHistory

func (db *Store) PruneBlockHistory(ctx context.Context, currentEpoch, pruningEpochAge uint64) error

PruneBlockHistory leaves only records younger then history size.

func (*Store) RemoveOldestFromCache added in v1.0.0

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

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

func (db *Store) SavePubKey(ctx context.Context, validatorID uint64, pubKey []byte) error

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

func (*Store) SetLatestEpochDetected

func (db *Store) SetLatestEpochDetected(ctx context.Context, epoch uint64) error

SetLatestEpochDetected sets the latest slashing detected epoch in db.

func (*Store) Size

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

Size returns the db size in bytes.

func (*Store) ValidatorPubKey

func (db *Store) ValidatorPubKey(ctx context.Context, validatorID uint64) ([]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