prysm-pulse/slasher/db/iface/interface.go
Ivan Martinez c44a30672e
Change slasher DB structure to mirror beacon-chains (#4848)
* Add interface and move slashing types to /types package

* WIP restructure to match beacon chain DB

* Fix build

* Fix comment

* Fix comments

* fix comments for sure

* Use wrapper function for evict

* Remove unused

* Update slasher/db/kv/kv.go

* Update slasher/db/testing/BUILD.bazel

* Update slasher/db/types/BUILD.bazel

* Update slasher/db/types/types.go

Co-authored-by: Raul Jordan <raul@prysmaticlabs.com>
2020-02-13 10:19:46 -06:00

88 lines
3.6 KiB
Go

package iface
import (
"io"
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
slashpb "github.com/prysmaticlabs/prysm/proto/slashing"
"github.com/prysmaticlabs/prysm/slasher/db/types"
)
// ReadOnlyDatabase represents a read only database with functions that do not modify the DB.
type ReadOnlyDatabase interface {
// AttesterSlashing related methods.
AttesterSlashings(status types.SlashingStatus) ([]*ethpb.AttesterSlashing, error)
DeleteAttesterSlashing(attesterSlashing *ethpb.AttesterSlashing) error
HasAttesterSlashing(slashing *ethpb.AttesterSlashing) (bool, types.SlashingStatus, error)
GetLatestEpochDetected() (uint64, error)
// BlockHeader related methods.
BlockHeaders(epoch uint64, validatorID uint64) ([]*ethpb.SignedBeaconBlockHeader, error)
HasBlockHeader(epoch uint64, validatorID uint64) bool
// IndexedAttestations related methods.
IdxAttsForTargetFromID(targetEpoch uint64, validatorID uint64) ([]*ethpb.IndexedAttestation, error)
IdxAttsForTarget(targetEpoch uint64) ([]*ethpb.IndexedAttestation, error)
LatestIndexedAttestationsTargetEpoch() (uint64, error)
LatestValidatorIdx() (uint64, error)
DoubleVotes(validatorIdx uint64, dataRoot []byte, origAtt *ethpb.IndexedAttestation) ([]*ethpb.AttesterSlashing, error)
HasIndexedAttestation(targetEpoch uint64, validatorID uint64) (bool, error)
// MinMaxSpan related methods.
ValidatorSpansMap(validatorIdx uint64) (*slashpb.EpochSpanMap, error)
// ProposerSlashing related methods.
ProposalSlashingsByStatus(status types.SlashingStatus) ([]*ethpb.ProposerSlashing, error)
HasProposerSlashing(slashing *ethpb.ProposerSlashing) (bool, types.SlashingStatus, error)
// Validator Index -> Pubkey related methods.
ValidatorPubKey(validatorID uint64) ([]byte, error)
}
// WriteAccessDatabase represents a write access database with only functions that can modify the DB.
type WriteAccessDatabase interface {
// AttesterSlashing related methods.
SaveAttesterSlashing(status types.SlashingStatus, slashing *ethpb.AttesterSlashing) error
SaveAttesterSlashings(status types.SlashingStatus, slashings []*ethpb.AttesterSlashing) error
SetLatestEpochDetected(epoch uint64) error
// BlockHeader related methods.
SaveBlockHeader(epoch uint64, validatorID uint64, blockHeader *ethpb.SignedBeaconBlockHeader) error
DeleteBlockHeader(epoch uint64, validatorID uint64, blockHeader *ethpb.SignedBeaconBlockHeader) error
PruneBlockHistory(currentEpoch uint64, pruningEpochAge uint64) error
// IndexedAttestations related methods.
SaveIndexedAttestation(idxAttestation *ethpb.IndexedAttestation) error
DeleteIndexedAttestation(idxAttestation *ethpb.IndexedAttestation) error
PruneAttHistory(currentEpoch uint64, pruningEpochAge uint64) error
// MinMaxSpan related methods.
SaveValidatorSpansMap(validatorIdx uint64, spanMap *slashpb.EpochSpanMap) error
SaveCachedSpansMaps() error
DeleteValidatorSpanMap(validatorIdx uint64) error
// ProposerSlashing related methods.
DeleteProposerSlashing(slashing *ethpb.ProposerSlashing) error
SaveProposerSlashing(status types.SlashingStatus, slashing *ethpb.ProposerSlashing) error
SaveProposerSlashings(status types.SlashingStatus, slashings []*ethpb.ProposerSlashing) error
// Validator Index -> Pubkey related methods.
SavePubKey(validatorID uint64, pubKey []byte) error
DeletePubKey(validatorID uint64) error
}
// FullAccessDatabase represents a full access database with only DB interaction functions.
type FullAccessDatabase interface {
ReadOnlyDatabase
WriteAccessDatabase
}
// Database represents a full access database with the proper DB helper functions.
type Database interface {
io.Closer
FullAccessDatabase
DatabasePath() string
ClearDB() error
}