kv

package
v0.0.0-...-ab12051 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2020 License: GPL-3.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// SpanCacheEnabled uses span cache to detect surround slashing.
	SpanCacheEnabled bool
	CacheItems       int64
	MaxCacheSize     int64
}

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, epoch uint64, validatorID uint64) ([]*ethpb.SignedBeaconBlockHeader, error)

BlockHeaders accepts an epoch and validator id and returns the corresponding block header array. Returns nil if the block header for those values does not exist.

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 MinMaxSpans 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, epoch uint64, validatorID uint64, blockHeader *ethpb.SignedBeaconBlockHeader) error

DeleteBlockHeader deletes a block header using the epoch 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) DeleteValidatorSpanMap

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

DeleteValidatorSpanMap deletes a validator span map using a validator index as bucket key.

func (*Store) DoubleVotes

func (db *Store) DoubleVotes(ctx context.Context, validatorIdx uint64, dataRoot []byte, origAtt *ethpb.IndexedAttestation) ([]*ethpb.AttesterSlashing, error)

DoubleVotes looks up db for slashable attesting data that were preformed by the same validator.

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, epoch uint64, validatorID uint64) bool

HasBlockHeader accepts an epoch and validator id and returns true if the block header exists.

func (*Store) HasIndexedAttestation

func (db *Store) HasIndexedAttestation(ctx context.Context, targetEpoch uint64, validatorID uint64) (bool, error)

HasIndexedAttestation accepts an epoch and validator id and returns true if the indexed attestation exists.

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

func (db *Store) IdxAttsForTarget(ctx context.Context, targetEpoch uint64) ([]*ethpb.IndexedAttestation, error)

IdxAttsForTarget 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) IdxAttsForTargetFromID

func (db *Store) IdxAttsForTargetFromID(ctx context.Context, targetEpoch uint64, validatorID uint64) ([]*ethpb.IndexedAttestation, error)

IdxAttsForTargetFromID accepts a epoch and validator index and returns a list of indexed attestations from that validator for the given target epoch. Returns nil if the indexed attestation does not exist.

func (*Store) IndexedAttestationsForEpoch

func (db *Store) IndexedAttestationsForEpoch(ctx context.Context, targetEpoch uint64) ([]*ethpb.IndexedAttestation, error)

IndexedAttestationsForEpoch retrieves all indexed attestations by target epoch by looking into a bucket of attestation roots by epoch first. Then, it retrieves all attestations that match that list of roots.

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

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

LatestValidatorIdx returns latest validator id in db returns 0 if there is no validators 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 uint64, 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 uint64, pruningEpochAge uint64) error

PruneBlockHistory leaves only records younger then history size.

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, epoch uint64, validatorID uint64, blockHeader *ethpb.SignedBeaconBlockHeader) error

SaveBlockHeader accepts a block header and writes it to disk.

func (*Store) SaveCachedSpansMaps

func (db *Store) SaveCachedSpansMaps(ctx context.Context) error

SaveCachedSpansMaps saves all span map from cache to disk if no span maps are in db or cache is disabled it returns nil.

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

func (db *Store) SaveIncomingIndexedAttestationByEpoch(ctx context.Context, att *ethpb.IndexedAttestation) error

SaveIncomingIndexedAttestationByEpoch stores an indexed attestations into the db by storing its root into a bucket and using its target epoch as the key.

func (*Store) SaveIncomingIndexedAttestationsByEpoch

func (db *Store) SaveIncomingIndexedAttestationsByEpoch(ctx context.Context, atts []*ethpb.IndexedAttestation) error

SaveIncomingIndexedAttestationsByEpoch stores a list of indexed attestations into the db by storing their roots into a bucket using their target epoch as the key.

func (*Store) SaveIndexedAttestation

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

SaveIndexedAttestation accepts epoch and indexed attestation and writes it to disk.

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

func (db *Store) SaveValidatorSpansMap(ctx context.Context, validatorIdx uint64, spanMap *slashpb.EpochSpanMap) error

SaveValidatorSpansMap accepts a validator index and span map 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.

func (*Store) ValidatorSpansMap

func (db *Store) ValidatorSpansMap(ctx context.Context, validatorIdx uint64) (*slashpb.EpochSpanMap, error)

ValidatorSpansMap accepts validator index and returns the corresponding spans map for slashing detection. Returns nil if the span map for this validator index does not exist.

Jump to

Keyboard shortcuts

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