kv

package
v5.1.2-mekong Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2024 License: GPL-3.0 Imports: 38 Imported by: 0

Documentation

Overview

Package kv defines a persistent backend for the validator service.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoProposerSettingsFound = errors.New("no proposer settings found in bucket")

ErrNoProposerSettingsFound is an error thrown when no settings are found in bucket

View Source
var (
	ProtectionDbFileName = "validator.db"
)

ProtectionDbFileName Validator slashing protection db file name.

Functions

This section is empty.

Types

type AttestationRecordSaveRequest

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

AttestationRecordSaveRequest includes the attestation record to save along with the appropriate call context.

type Config

type Config struct {
	PubKeys [][fieldparams.BLSPubkeyLength]byte
}

Config represents store's config object.

type QueuedAttestationRecords

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

QueuedAttestationRecords is a thread-safe struct for managing a queue of attestation records to save to validator database.

func NewQueuedAttestationRecords

func NewQueuedAttestationRecords() *QueuedAttestationRecords

NewQueuedAttestationRecords constructor allocates the underlying slice and required attributes for managing pending attestation records.

func (*QueuedAttestationRecords) Append

Append a new attestation record to the queue.

func (*QueuedAttestationRecords) Flush

Flush all records. This method returns the current pending records and resets the pending records slice.

func (*QueuedAttestationRecords) Len

func (p *QueuedAttestationRecords) Len() int

Len returns the current length of records.

type SlashingKind

type SlashingKind int

SlashingKind used for helpful information upon detection.

const (
	NotSlashable SlashingKind = iota
	DoubleVote
	SurroundingVote
	SurroundedVote
)

Enums representing the types of slashable events for attesters.

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

func NewKVStore

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

func (s *Store) AttestationHistoryForPubKey(ctx context.Context, pubKey [fieldparams.BLSPubkeyLength]byte) ([]*common.AttestationRecord, error)

AttestationHistoryForPubKey retrieves a list of attestation records for data we have stored in the database for the given validator public key.

func (*Store) AttestedPublicKeys

func (s *Store) AttestedPublicKeys(ctx context.Context) ([][fieldparams.BLSPubkeyLength]byte, error)

AttestedPublicKeys retrieves all public keys that have attested.

func (*Store) Backup

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

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

func (*Store) CheckSlashableAttestation

func (s *Store) CheckSlashableAttestation(
	ctx context.Context, pubKey [fieldparams.BLSPubkeyLength]byte, signingRoot []byte, att ethpb.IndexedAtt,
) (SlashingKind, error)

CheckSlashableAttestation verifies an incoming attestation is not a double vote for a validator public key nor a surround vote.

func (*Store) ClearDB

func (s *Store) ClearDB() error

ClearDB removes any previously stored data at the configured 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) EIPImportBlacklistedPublicKeys

func (s *Store) EIPImportBlacklistedPublicKeys(ctx context.Context) ([][fieldparams.BLSPubkeyLength]byte, error)

EIPImportBlacklistedPublicKeys returns keys that were marked as blacklisted during EIP-3076 slashing protection imports, ensuring that we can prevent these keys from having duties at runtime.

func (*Store) GenesisValidatorsRoot

func (s *Store) GenesisValidatorsRoot(_ context.Context) ([]byte, error)

GenesisValidatorsRoot retrieves the genesis validators root from db.

func (*Store) GraffitiFileHash added in v5.0.2

func (s *Store) GraffitiFileHash() ([32]byte, bool, error)

GraffitiFileHash fetches the graffiti file hash.

func (*Store) GraffitiOrderedIndex

func (s *Store) GraffitiOrderedIndex(_ context.Context, fileHash [32]byte) (uint64, error)

GraffitiOrderedIndex fetches the ordered index, resetting if the file hash changed

func (*Store) HighestSignedProposal

func (s *Store) HighestSignedProposal(ctx context.Context, publicKey [fieldparams.BLSPubkeyLength]byte) (primitives.Slot, bool, error)

HighestSignedProposal returns the highest signed proposal slot for a validator public key. If no data exists, a boolean of value false is returned.

func (*Store) ImportStandardProtectionJSON added in v5.0.2

func (s *Store) ImportStandardProtectionJSON(ctx context.Context, r io.Reader) error

ImportStandardProtection takes in EIP-3076 compliant JSON file used for slashing protection by Ethereum validators and imports its data into Prysm's internal complete representation of slashing protection in the validator client's database.

func (*Store) LowestSignedProposal

func (s *Store) LowestSignedProposal(ctx context.Context, publicKey [fieldparams.BLSPubkeyLength]byte) (primitives.Slot, bool, error)

LowestSignedProposal returns the lowest signed proposal slot for a validator public key. If no data exists, a boolean of value false is returned.

func (*Store) LowestSignedSourceEpoch

func (s *Store) LowestSignedSourceEpoch(ctx context.Context, publicKey [fieldparams.BLSPubkeyLength]byte) (primitives.Epoch, bool, error)

LowestSignedSourceEpoch returns the lowest signed source epoch for a validator public key. If no data exists, returning 0 is a sensible default.

func (*Store) LowestSignedTargetEpoch

func (s *Store) LowestSignedTargetEpoch(ctx context.Context, publicKey [fieldparams.BLSPubkeyLength]byte) (primitives.Epoch, bool, error)

LowestSignedTargetEpoch returns the lowest signed target epoch for a validator public key. If no data exists, returning 0 is a sensible default.

func (*Store) ProposalHistoryForPubKey

func (s *Store) ProposalHistoryForPubKey(ctx context.Context, publicKey [fieldparams.BLSPubkeyLength]byte) ([]*common.Proposal, error)

ProposalHistoryForPubKey returns the entire proposal history for a given public key.

func (*Store) ProposalHistoryForSlot

func (s *Store) ProposalHistoryForSlot(ctx context.Context, publicKey [fieldparams.BLSPubkeyLength]byte, slot primitives.Slot) ([32]byte, bool, bool, error)

ProposalHistoryForSlot accepts a validator public key and returns the corresponding signing root as well as a boolean that tells us if we have a proposal history stored at the slot and a boolean that tells us if we have a signed root at the slot.

func (*Store) ProposedPublicKeys

func (s *Store) ProposedPublicKeys(ctx context.Context) ([][fieldparams.BLSPubkeyLength]byte, error)

ProposedPublicKeys retrieves all public keys in our proposals history bucket. Warning: A public key in this bucket does not necessarily mean it has signed a block.

func (*Store) ProposerSettings

func (s *Store) ProposerSettings(ctx context.Context) (*proposer.Settings, error)

ProposerSettings gets the current proposer settings

func (*Store) ProposerSettingsExists

func (s *Store) ProposerSettingsExists(ctx context.Context) (bool, error)

ProposerSettingsExists returns true or false if the settings exist or not

func (*Store) PruneAttestations

func (s *Store) PruneAttestations(ctx context.Context) error

PruneAttestations loops through every public key in the public keys bucket and prunes all attestation data that has target epochs older the highest target epoch minus some constant of how many epochs we keep track of for slashing protection. This routine is meant to run on startup.

func (*Store) RunDownMigrations

func (s *Store) RunDownMigrations(ctx context.Context) error

RunDownMigrations defined in the downMigrations list.

func (*Store) RunUpMigrations

func (s *Store) RunUpMigrations(ctx context.Context) error

RunUpMigrations defined in the upMigrations list.

func (*Store) SaveAttestationForPubKey

func (s *Store) SaveAttestationForPubKey(
	ctx context.Context, pubKey [fieldparams.BLSPubkeyLength]byte, signingRoot [fieldparams.RootLength]byte, att ethpb.IndexedAtt,
) error

SaveAttestationForPubKey saves an attestation for a validator public key for local validator slashing protection.

func (*Store) SaveAttestationsForPubKey

func (s *Store) SaveAttestationsForPubKey(
	ctx context.Context, pubKey [fieldparams.BLSPubkeyLength]byte, signingRoots [][]byte, atts []*ethpb.IndexedAttestation,
) error

SaveAttestationsForPubKey stores a batch of attestations all at once.

func (*Store) SaveEIPImportBlacklistedPublicKeys

func (s *Store) SaveEIPImportBlacklistedPublicKeys(ctx context.Context, publicKeys [][fieldparams.BLSPubkeyLength]byte) error

SaveEIPImportBlacklistedPublicKeys stores a list of blacklisted public keys that were determined during EIP-3076 slashing protection imports.

func (*Store) SaveGenesisValidatorsRoot

func (s *Store) SaveGenesisValidatorsRoot(_ context.Context, genValRoot []byte) error

SaveGenesisValidatorsRoot saves the genesis validators root to db.

func (*Store) SaveGraffitiOrderedIndex

func (s *Store) SaveGraffitiOrderedIndex(_ context.Context, index uint64) error

SaveGraffitiOrderedIndex writes the current graffiti index to the db

func (*Store) SaveProposalHistoryForSlot

func (s *Store) SaveProposalHistoryForSlot(ctx context.Context, pubKey [fieldparams.BLSPubkeyLength]byte, slot primitives.Slot, signingRoot []byte) error

SaveProposalHistoryForSlot saves the proposal history for the requested validator public key. We also check if the incoming proposal slot is lower than the lowest signed proposal slot for the validator and override its value on disk.

func (*Store) SaveProposerSettings

func (s *Store) SaveProposerSettings(ctx context.Context, settings *proposer.Settings) error

SaveProposerSettings saves the entire proposer setting overriding the existing settings

func (*Store) SigningRootAtTargetEpoch

func (s *Store) SigningRootAtTargetEpoch(ctx context.Context, pubKey [fieldparams.BLSPubkeyLength]byte, target primitives.Epoch) ([]byte, error)

SigningRootAtTargetEpoch checks for an existing signing root at a specified target epoch for a given validator public key.

func (*Store) Size

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

Size returns the db size in bytes.

func (*Store) SlashableAttestationCheck added in v5.0.2

func (s *Store) SlashableAttestationCheck(
	ctx context.Context,
	indexedAtt ethpb.IndexedAtt,
	pubKey [fieldparams.BLSPubkeyLength]byte,
	signingRoot32 [32]byte,
	emitAccountMetrics bool,
	validatorAttestFailVec *prometheus.CounterVec,
) error

SlashableAttestationCheck checks if an attestation is slashable by comparing it with the attesting history for the given public key in our complete slashing protection database defined by EIP-3076. If it is not, it updates the database.

func (*Store) SlashableProposalCheck added in v5.0.2

func (s *Store) SlashableProposalCheck(
	ctx context.Context,
	pubKey [fieldparams.BLSPubkeyLength]byte,
	signedBlock interfaces.ReadOnlySignedBeaconBlock,
	signingRoot [fieldparams.RootLength]byte,
	emitAccountMetrics bool,
	validatorProposeFailVec *prometheus.CounterVec,
) error

SlashableProposalCheck checks if a block proposal is slashable by comparing it with the block proposals history for the given public key in our complete slashing protection database defined by EIP-3076. If it is not, we then update the history.

func (*Store) UpdatePublicKeysBuckets

func (s *Store) UpdatePublicKeysBuckets(pubKeys [][fieldparams.BLSPubkeyLength]byte) error

UpdatePublicKeysBuckets for a specified list of keys.

Jump to

Keyboard shortcuts

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