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: 41 Imported by: 20

Documentation

Overview

Package kv defines a bolt-db, key-value store implementation of the Database interface defined by a Prysm beacon node.

Index

Constants

View Source
const (
	// VotesCacheSize with 1M validators will be 8MB.
	VotesCacheSize = 1 << 23
	// NumOfVotes specifies the vote cache size.
	NumOfVotes = 1 << 20
	// BeaconNodeDbDirName is the name of the directory containing the beacon node database.
	BeaconNodeDbDirName = "beaconchaindata"
	// DatabaseFileName is the name of the beacon node database.
	DatabaseFileName = "beaconchain.db"
)

Variables

View Source
var BlockCacheSize = int64(1 << 21)

BlockCacheSize specifies 1000 slots worth of blocks cached, which would be approximately 2MB

Functions

func KVStoreDatafilePath added in v1.3.9

func KVStoreDatafilePath(dirPath string) string

KVStoreDatafilePath is the canonical construction of a full database file path from the directory path, so that code outside this package can find the full path in a consistent way.

Types

type Config added in v1.2.2

type Config struct {
	InitialMMapSize int
}

Config for the bolt db kv store.

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 Beacon 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) ArchivedPointRoot added in v0.3.2

func (s *Store) ArchivedPointRoot(ctx context.Context, slot types.Slot) [32]byte

ArchivedPointRoot returns the block root of an archived point from the DB. This is essential for cold state management and to restore a cold state.

func (*Store) AttesterSlashing

func (s *Store) AttesterSlashing(ctx context.Context, slashingRoot [32]byte) (*ethpb.AttesterSlashing, error)

AttesterSlashing retrieval by hash tree root.

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 at slot 345: $DATADIR/backups/prysm_beacondb_at_slot_0000345.backup

func (*Store) Block

func (s *Store) Block(ctx context.Context, blockRoot [32]byte) (interfaces.SignedBeaconBlock, error)

Block retrieval by root.

func (*Store) BlockRoots

func (s *Store) BlockRoots(ctx context.Context, f *filters.QueryFilter) ([][32]byte, error)

BlockRoots retrieves a list of beacon block roots by filter criteria. If the caller requires both the blocks and the block roots for a certain filter they should instead use the Blocks function rather than use BlockRoots. During periods of non finality there are potential race conditions which leads to differing roots when calling the db multiple times for the same filter.

func (*Store) BlockRootsBySlot added in v1.1.0

func (s *Store) BlockRootsBySlot(ctx context.Context, slot types.Slot) (bool, [][32]byte, error)

BlockRootsBySlot retrieves a list of beacon block roots by slot

func (*Store) Blocks

Blocks retrieves a list of beacon blocks and its respective roots by filter criteria.

func (*Store) BlocksBySlot added in v1.1.0

func (s *Store) BlocksBySlot(ctx context.Context, slot types.Slot) (bool, []interfaces.SignedBeaconBlock, error)

BlocksBySlot retrieves a list of beacon blocks and its respective roots by slot.

func (*Store) CleanUpDirtyStates added in v1.0.0

func (s *Store) CleanUpDirtyStates(ctx context.Context, slotsPerArchivedPoint types.Slot) error

CleanUpDirtyStates removes states in DB that falls to under archived point interval rules. Only following states would be kept: 1.) state_slot % archived_interval == 0. (e.g. archived_interval=2048, states with slot 2048, 4096... etc) 2.) archived_interval - archived_interval/3 < state_slot % archived_interval

(e.g. archived_interval=2048, states with slots after 1365).
This is to tolerate skip slots. Not every state lays on the boundary.

3.) state with current finalized root 4.) unfinalized States

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

func (s *Store) DeleteState(ctx context.Context, blockRoot [32]byte) error

DeleteState by block root.

func (*Store) DeleteStates

func (s *Store) DeleteStates(ctx context.Context, blockRoots [][32]byte) error

DeleteStates by block roots.

func (*Store) DepositContractAddress

func (s *Store) DepositContractAddress(ctx context.Context) ([]byte, error)

DepositContractAddress returns contract address is the address of the deposit contract on the proof of work chain.

func (*Store) EnsureEmbeddedGenesis added in v1.3.4

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

EnsureEmbeddedGenesis checks that a genesis block has been generated when an embedded genesis state is used. If a genesis block does not exist, but a genesis state does, then we should call SaveGenesisData on the existing genesis state.

func (*Store) FinalizedCheckpoint

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

FinalizedCheckpoint returns the latest finalized checkpoint in beacon chain.

func (*Store) FinalizedChildBlock added in v1.0.0

func (s *Store) FinalizedChildBlock(ctx context.Context, blockRoot [32]byte) (interfaces.SignedBeaconBlock, error)

FinalizedChildBlock returns the child block of a provided finalized block. If no finalized block or its respective child block exists we return with a nil block.

func (*Store) GenesisBlock added in v0.3.0

func (s *Store) GenesisBlock(ctx context.Context) (interfaces.SignedBeaconBlock, error)

GenesisBlock retrieves the genesis block of the beacon chain.

func (*Store) GenesisState

func (s *Store) GenesisState(ctx context.Context) (iface.BeaconState, error)

GenesisState returns the genesis state in beacon chain.

func (*Store) HasArchivedPoint added in v0.3.2

func (s *Store) HasArchivedPoint(ctx context.Context, slot types.Slot) bool

HasArchivedPoint returns true if an archived point exists in DB.

func (*Store) HasAttesterSlashing

func (s *Store) HasAttesterSlashing(ctx context.Context, slashingRoot [32]byte) bool

HasAttesterSlashing verifies if a slashing is stored in the db.

func (*Store) HasBlock

func (s *Store) HasBlock(ctx context.Context, blockRoot [32]byte) bool

HasBlock checks if a block by root exists in the db.

func (*Store) HasProposerSlashing

func (s *Store) HasProposerSlashing(ctx context.Context, slashingRoot [32]byte) bool

HasProposerSlashing verifies if a slashing is stored in the db.

func (*Store) HasState added in v0.3.2

func (s *Store) HasState(ctx context.Context, blockRoot [32]byte) bool

HasState checks if a state by root exists in the db.

func (*Store) HasStateSummary added in v0.3.2

func (s *Store) HasStateSummary(ctx context.Context, blockRoot [32]byte) bool

HasStateSummary returns true if a state summary exists in DB.

func (*Store) HasVoluntaryExit

func (s *Store) HasVoluntaryExit(ctx context.Context, exitRoot [32]byte) bool

HasVoluntaryExit verifies if a voluntary exit is stored in the db by its signing root.

func (*Store) HeadBlock

func (s *Store) HeadBlock(ctx context.Context) (interfaces.SignedBeaconBlock, error)

HeadBlock returns the latest canonical block in the Ethereum Beacon Chain.

func (*Store) HighestSlotBlocksBelow added in v0.3.8

func (s *Store) HighestSlotBlocksBelow(ctx context.Context, slot types.Slot) ([]interfaces.SignedBeaconBlock, error)

HighestSlotBlocksBelow returns the block with the highest slot below the input slot from the db.

func (*Store) HighestSlotStatesBelow added in v0.3.9

func (s *Store) HighestSlotStatesBelow(ctx context.Context, slot types.Slot) ([]iface.ReadOnlyBeaconState, error)

HighestSlotStatesBelow returns the states with the highest slot below the input slot from the db. Ideally there should just be one state per slot, but given validator can double propose, a single slot could have multiple block roots and results states. This returns a list of states.

func (*Store) IsFinalizedBlock added in v0.2.3

func (s *Store) IsFinalizedBlock(ctx context.Context, blockRoot [32]byte) bool

IsFinalizedBlock returns true if the block root is present in the finalized block root index. A beacon block root contained exists in this index if it is considered finalized and canonical. Note: beacon blocks from the latest finalized epoch return true, whether or not they are considered canonical in the "head view" of the beacon node.

func (*Store) JustifiedCheckpoint

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

JustifiedCheckpoint returns the latest justified checkpoint in beacon chain.

func (*Store) LastArchivedRoot added in v1.0.0

func (s *Store) LastArchivedRoot(ctx context.Context) [32]byte

LastArchivedRoot from the db.

func (*Store) LastArchivedSlot added in v1.0.0

func (s *Store) LastArchivedSlot(ctx context.Context) (types.Slot, error)

LastArchivedSlot from the db.

func (*Store) LoadGenesis added in v1.3.4

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

LoadGenesis loads a genesis state from a given file path, if no genesis exists already.

func (*Store) PowchainData added in v0.3.0

func (s *Store) PowchainData(ctx context.Context) (*db.ETH1ChainData, error)

PowchainData retrieves the powchain data.

func (*Store) ProposerSlashing

func (s *Store) ProposerSlashing(ctx context.Context, slashingRoot [32]byte) (*ethpb.ProposerSlashing, error)

ProposerSlashing retrieval by slashing root.

func (*Store) RunMigrations added in v1.0.0

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

RunMigrations defined in the migrations array.

func (*Store) SaveAttesterSlashing

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

SaveAttesterSlashing to the db by its hash tree root.

func (*Store) SaveBlock

func (s *Store) SaveBlock(ctx context.Context, signed interfaces.SignedBeaconBlock) error

SaveBlock to the db.

func (*Store) SaveBlocks

func (s *Store) SaveBlocks(ctx context.Context, blocks []interfaces.SignedBeaconBlock) error

SaveBlocks via bulk updates to the db.

func (*Store) SaveDepositContractAddress

func (s *Store) SaveDepositContractAddress(ctx context.Context, addr common.Address) error

SaveDepositContractAddress to the db. It returns an error if an address has been previously saved.

func (*Store) SaveFinalizedCheckpoint

func (s *Store) SaveFinalizedCheckpoint(ctx context.Context, checkpoint *ethpb.Checkpoint) error

SaveFinalizedCheckpoint saves finalized checkpoint in beacon chain.

func (*Store) SaveGenesisBlockRoot

func (s *Store) SaveGenesisBlockRoot(ctx context.Context, blockRoot [32]byte) error

SaveGenesisBlockRoot to the db.

func (*Store) SaveGenesisData added in v1.3.4

func (s *Store) SaveGenesisData(ctx context.Context, genesisState iface.BeaconState) error

SaveGenesisData bootstraps the beaconDB with a given genesis state.

func (*Store) SaveHeadBlockRoot

func (s *Store) SaveHeadBlockRoot(ctx context.Context, blockRoot [32]byte) error

SaveHeadBlockRoot to the db.

func (*Store) SaveJustifiedCheckpoint

func (s *Store) SaveJustifiedCheckpoint(ctx context.Context, checkpoint *ethpb.Checkpoint) error

SaveJustifiedCheckpoint saves justified checkpoint in beacon chain.

func (*Store) SavePowchainData added in v0.3.0

func (s *Store) SavePowchainData(ctx context.Context, data *db.ETH1ChainData) error

SavePowchainData saves the pow chain data.

func (*Store) SaveProposerSlashing

func (s *Store) SaveProposerSlashing(ctx context.Context, slashing *ethpb.ProposerSlashing) error

SaveProposerSlashing to the db by its hash tree root.

func (*Store) SaveState

func (s *Store) SaveState(ctx context.Context, st iface.ReadOnlyBeaconState, blockRoot [32]byte) error

SaveState stores a state to the db using block's signing root which was used to generate the state.

func (*Store) SaveStateSummaries added in v0.3.9

func (s *Store) SaveStateSummaries(ctx context.Context, summaries []*pb.StateSummary) error

SaveStateSummaries saves state summary objects to the DB.

func (*Store) SaveStateSummary added in v0.3.2

func (s *Store) SaveStateSummary(ctx context.Context, summary *pb.StateSummary) error

SaveStateSummary saves a state summary object to the DB.

func (*Store) SaveStates added in v0.3.2

func (s *Store) SaveStates(ctx context.Context, states []iface.ReadOnlyBeaconState, blockRoots [][32]byte) error

SaveStates stores multiple states to the db using the provided corresponding roots.

func (*Store) SaveVoluntaryExit

func (s *Store) SaveVoluntaryExit(ctx context.Context, exit *ethpb.VoluntaryExit) error

SaveVoluntaryExit to the db by its signing root.

func (*Store) State

func (s *Store) State(ctx context.Context, blockRoot [32]byte) (iface.BeaconState, error)

State returns the saved state using block's signing root, this particular block was used to generate the state.

func (*Store) StateSummary added in v0.3.2

func (s *Store) StateSummary(ctx context.Context, blockRoot [32]byte) (*pb.StateSummary, error)

StateSummary returns the state summary object from the db using input block root.

func (*Store) VoluntaryExit

func (s *Store) VoluntaryExit(ctx context.Context, exitRoot [32]byte) (*ethpb.VoluntaryExit, error)

VoluntaryExit retrieval by signing root.

Jump to

Keyboard shortcuts

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