2018-10-05 17:14:50 +00:00
|
|
|
package db
|
|
|
|
|
|
|
|
import (
|
2019-08-09 19:17:18 +00:00
|
|
|
"context"
|
2019-08-15 21:41:51 +00:00
|
|
|
"io"
|
2018-12-17 18:34:28 +00:00
|
|
|
|
2019-08-21 21:11:50 +00:00
|
|
|
"github.com/ethereum/go-ethereum/common"
|
2019-08-11 00:50:10 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/db/filters"
|
2019-08-14 18:48:28 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/db/kv"
|
2019-08-09 19:17:18 +00:00
|
|
|
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
|
|
|
ethpb "github.com/prysmaticlabs/prysm/proto/eth/v1alpha1"
|
2018-10-05 17:14:50 +00:00
|
|
|
)
|
|
|
|
|
2019-08-09 19:17:18 +00:00
|
|
|
// Database defines the necessary methods for Prysm's eth2 backend which may
|
|
|
|
// be implemented by any key-value or relational database in practice.
|
|
|
|
type Database interface {
|
2019-08-15 21:41:51 +00:00
|
|
|
io.Closer
|
|
|
|
DatabasePath() string
|
2019-08-09 19:17:18 +00:00
|
|
|
ClearDB() error
|
2019-08-21 20:21:04 +00:00
|
|
|
// Attestation related methods.
|
2019-08-09 19:17:18 +00:00
|
|
|
Attestation(ctx context.Context, attRoot [32]byte) (*ethpb.Attestation, error)
|
2019-08-11 00:50:10 +00:00
|
|
|
Attestations(ctx context.Context, f *filters.QueryFilter) ([]*ethpb.Attestation, error)
|
2019-08-09 19:17:18 +00:00
|
|
|
HasAttestation(ctx context.Context, attRoot [32]byte) bool
|
|
|
|
DeleteAttestation(ctx context.Context, attRoot [32]byte) error
|
|
|
|
SaveAttestation(ctx context.Context, att *ethpb.Attestation) error
|
|
|
|
SaveAttestations(ctx context.Context, atts []*ethpb.Attestation) error
|
2019-08-21 20:21:04 +00:00
|
|
|
// Block related methods.
|
2019-08-09 19:17:18 +00:00
|
|
|
Block(ctx context.Context, blockRoot [32]byte) (*ethpb.BeaconBlock, error)
|
2019-08-12 16:13:30 +00:00
|
|
|
HeadBlock(ctx context.Context) (*ethpb.BeaconBlock, error)
|
2019-08-11 00:50:10 +00:00
|
|
|
Blocks(ctx context.Context, f *filters.QueryFilter) ([]*ethpb.BeaconBlock, error)
|
|
|
|
BlockRoots(ctx context.Context, f *filters.QueryFilter) ([][]byte, error)
|
2019-08-09 19:17:18 +00:00
|
|
|
HasBlock(ctx context.Context, blockRoot [32]byte) bool
|
|
|
|
DeleteBlock(ctx context.Context, blockRoot [32]byte) error
|
|
|
|
SaveBlock(ctx context.Context, block *ethpb.BeaconBlock) error
|
|
|
|
SaveBlocks(ctx context.Context, blocks []*ethpb.BeaconBlock) error
|
2019-08-12 16:13:30 +00:00
|
|
|
SaveHeadBlockRoot(ctx context.Context, blockRoot [32]byte) error
|
2019-08-29 22:32:35 +00:00
|
|
|
SaveGenesisBlockRoot(ctx context.Context, blockRoot [32]byte) error
|
2019-08-21 20:21:04 +00:00
|
|
|
// Validator related methods.
|
2019-08-09 19:17:18 +00:00
|
|
|
ValidatorLatestVote(ctx context.Context, validatorIdx uint64) (*pb.ValidatorLatestVote, error)
|
|
|
|
HasValidatorLatestVote(ctx context.Context, validatorIdx uint64) bool
|
2019-08-22 15:04:13 +00:00
|
|
|
DeleteValidatorLatestVote(ctx context.Context, validatorIdx uint64) error
|
2019-08-11 00:50:10 +00:00
|
|
|
SaveValidatorLatestVote(ctx context.Context, validatorIdx uint64, vote *pb.ValidatorLatestVote) error
|
2019-08-12 19:33:07 +00:00
|
|
|
ValidatorIndex(ctx context.Context, publicKey [48]byte) (uint64, bool, error)
|
2019-08-09 19:17:18 +00:00
|
|
|
HasValidatorIndex(ctx context.Context, publicKey [48]byte) bool
|
|
|
|
DeleteValidatorIndex(ctx context.Context, publicKey [48]byte) error
|
|
|
|
SaveValidatorIndex(ctx context.Context, publicKey [48]byte, validatorIdx uint64) error
|
2019-08-21 20:21:04 +00:00
|
|
|
// State related methods.
|
|
|
|
State(ctx context.Context, blockRoot [32]byte) (*pb.BeaconState, error)
|
|
|
|
HeadState(ctx context.Context) (*pb.BeaconState, error)
|
2019-08-29 22:32:35 +00:00
|
|
|
GenesisState(ctx context.Context) (*pb.BeaconState, error)
|
2019-08-21 20:21:04 +00:00
|
|
|
SaveState(ctx context.Context, state *pb.BeaconState, blockRoot [32]byte) error
|
|
|
|
// Slashing operations.
|
|
|
|
ProposerSlashing(ctx context.Context, slashingRoot [32]byte) (*ethpb.ProposerSlashing, error)
|
|
|
|
AttesterSlashing(ctx context.Context, slashingRoot [32]byte) (*ethpb.AttesterSlashing, error)
|
|
|
|
SaveProposerSlashing(ctx context.Context, slashing *ethpb.ProposerSlashing) error
|
|
|
|
SaveAttesterSlashing(ctx context.Context, slashing *ethpb.AttesterSlashing) error
|
|
|
|
HasProposerSlashing(ctx context.Context, slashingRoot [32]byte) bool
|
|
|
|
HasAttesterSlashing(ctx context.Context, slashingRoot [32]byte) bool
|
|
|
|
DeleteProposerSlashing(ctx context.Context, slashingRoot [32]byte) error
|
|
|
|
DeleteAttesterSlashing(ctx context.Context, slashingRoot [32]byte) error
|
2019-08-21 21:32:44 +00:00
|
|
|
// Block operations.
|
|
|
|
VoluntaryExit(ctx context.Context, exitRoot [32]byte) (*ethpb.VoluntaryExit, error)
|
|
|
|
SaveVoluntaryExit(ctx context.Context, exit *ethpb.VoluntaryExit) error
|
|
|
|
HasVoluntaryExit(ctx context.Context, exitRoot [32]byte) bool
|
|
|
|
DeleteVoluntaryExit(ctx context.Context, exitRoot [32]byte) error
|
2019-08-30 13:58:02 +00:00
|
|
|
// Checkpoint operations.
|
|
|
|
JustifiedCheckpoint(ctx context.Context) (*ethpb.Checkpoint, error)
|
|
|
|
FinalizedCheckpoint(ctx context.Context) (*ethpb.Checkpoint, error)
|
|
|
|
SaveJustifiedCheckpoint(ctx context.Context, checkpoint *ethpb.Checkpoint) error
|
|
|
|
SaveFinalizedCheckpoint(ctx context.Context, checkpoint *ethpb.Checkpoint) error
|
2019-08-21 21:11:50 +00:00
|
|
|
// Deposit contract related handlers.
|
|
|
|
DepositContractAddress(ctx context.Context) ([]byte, error)
|
|
|
|
SaveDepositContractAddress(ctx context.Context, addr common.Address) error
|
2019-08-09 19:17:18 +00:00
|
|
|
}
|
|
|
|
|
2019-08-14 18:48:28 +00:00
|
|
|
// NewDB initializes a new DB.
|
|
|
|
func NewDB(dirPath string) (Database, error) {
|
|
|
|
return kv.NewKVStore(dirPath)
|
|
|
|
}
|