slasherkv

package
v0.0.0-...-0064a47 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2024 License: GPL-3.0 Imports: 26 Imported by: 0

Documentation

Overview

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

Index

Constants

View Source
const (
	// DatabaseFileName is the name of the beacon node database.
	DatabaseFileName = "slasher.db"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store defines an implementation of the Prysm Database interface using BoltDB as the underlying persistent kv-store for Ethereum consensus.

func NewKVStore

func NewKVStore(ctx context.Context, dirPath string) (*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) AttestationRecordForValidator

func (s *Store) AttestationRecordForValidator(
	ctx context.Context, validatorIdx primitives.ValidatorIndex, targetEpoch primitives.Epoch,
) (*slashertypes.IndexedAttestationWrapper, error)

AttestationRecordForValidator given a validator index and a target epoch, retrieves an existing attestation record we have stored in the database.

func (*Store) BlockProposalForValidator

func (s *Store) BlockProposalForValidator(
	ctx context.Context, validatorIdx primitives.ValidatorIndex, slot primitives.Slot,
) (*slashertypes.SignedBlockHeaderWrapper, error)

BlockProposalForValidator given a validator index and a slot retrieves an existing proposal record we have stored in the database.

func (*Store) CheckAttesterDoubleVotes

func (s *Store) CheckAttesterDoubleVotes(
	ctx context.Context, attestations []*slashertypes.IndexedAttestationWrapper,
) ([]*slashertypes.AttesterDoubleVote, error)

CheckAttesterDoubleVotes retrieves any slashable double votes that exist for a series of input attestations with respect to the database.

func (*Store) CheckDoubleBlockProposals

func (s *Store) CheckDoubleBlockProposals(
	ctx context.Context, incomingProposals []*slashertypes.SignedBlockHeaderWrapper,
) ([]*ethpb.ProposerSlashing, error)

CheckDoubleBlockProposals takes in a list of proposals and for each, checks if there already exists a proposal at the same slot+validatorIndex combination. If so, it checks if the existing signing root is not-empty and is different than the incoming proposal signing root. If so, it returns a double block proposal object.

func (*Store) ClearDB

func (s *Store) ClearDB() error

ClearDB removes the previously stored database in the data directory.

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

func (s *Store) HighestAttestations(
	_ context.Context,
	indices []primitives.ValidatorIndex,
) ([]*ethpb.HighestAttestation, error)

HighestAttestations retrieves the last attestation data from the database for all indices.

func (*Store) LastEpochWrittenForValidators

func (s *Store) LastEpochWrittenForValidators(
	ctx context.Context, validatorIndexes []primitives.ValidatorIndex,
) ([]*slashertypes.AttestedEpochForValidator, error)

LastEpochWrittenForValidators given a list of validator indices returns the latest epoch we have recorded the validators writing data for.

func (*Store) LoadSlasherChunks

func (s *Store) LoadSlasherChunks(
	ctx context.Context, kind slashertypes.ChunkKind, chunkKeys [][]byte,
) ([][]uint16, []bool, error)

LoadSlasherChunks given a chunk kind and a disk keys, retrieves chunks for a validator min or max span used by slasher from our database.

func (*Store) PruneAttestationsAtEpoch

func (s *Store) PruneAttestationsAtEpoch(
	_ context.Context, maxEpoch primitives.Epoch,
) (numPruned uint, err error)

PruneAttestationsAtEpoch deletes all attestations from the slasher DB with target epoch less than or equal to the specified epoch.

func (*Store) PruneProposalsAtEpoch

func (s *Store) PruneProposalsAtEpoch(
	ctx context.Context, maxEpoch primitives.Epoch,
) (numPruned uint, err error)

PruneProposalsAtEpoch deletes all proposals from the slasher DB with epoch less than or equal to the specified epoch.

func (*Store) SaveAttestationRecordsForValidators

func (s *Store) SaveAttestationRecordsForValidators(
	ctx context.Context,
	attWrappers []*slashertypes.IndexedAttestationWrapper,
) error

SaveAttestationRecordsForValidators saves attestation records for the specified indices. If multiple attestations are provided for the same validator index + target epoch combination, then only the first one is (arbitrarily) saved in the `attestationDataRootsBucket` bucket.

func (*Store) SaveBlockProposals

func (s *Store) SaveBlockProposals(
	ctx context.Context, proposals []*slashertypes.SignedBlockHeaderWrapper,
) error

SaveBlockProposals takes in a list of block proposals and saves them to our proposal records bucket in the database. If multiple proposals are provided for the same slot + validatorIndex combination, then only the last one is saved in the database.

func (*Store) SaveLastEpochWrittenForValidators

func (s *Store) SaveLastEpochWrittenForValidators(
	ctx context.Context, epochByValIndex map[primitives.ValidatorIndex]primitives.Epoch,
) error

SaveLastEpochWrittenForValidators saves the latest epoch that each validator has attested to in the provided map.

func (*Store) SaveSlasherChunks

func (s *Store) SaveSlasherChunks(
	ctx context.Context, kind slashertypes.ChunkKind, chunkKeys [][]byte, chunks [][]uint16,
) error

SaveSlasherChunks given a chunk kind, list of disk keys, and list of chunks, saves the chunks to our database for use by slasher in slashing detection.

Jump to

Keyboard shortcuts

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