prysm-pulse/slasher/db/iface/interface.go
Raul Jordan 14b3181e67
Plug-In Attester Slashing Detection Into Slasher Runtime (#4937)
* more spanner additions

* implement iface

* begin implement

* wrapped up spanner functions

* rem interface

* added in necessary comments

* comments on enums

* begin adding tests

* plug in surround vote detection

* saved indexed db implementation

* finally plugin slashing for historical data

* Small fixes

* add in all gazelle

* save incoming new functions

* resolve todo

* fix broken test channel item

* tests passing when fixing certain arguments and setups

* Add comment and change unimplemented

* find surround

* added in gazelle

* gazz

* feedback from shay

* fixed up naming

* Update

* Add tests for detectSurroundVotes

* Remove logs

* Fix slasher test

* formatting

* Remove unneeded condition

* Test indices better

* fixing broken build

* pass tests

* skip tests

* imports

* Update slasher/detection/attestations/attestations_test.go

* Update slasher/beaconclient/historical_data_retrieval_test.go

* Address comments

* Rename function

* Add comment for future optimization

* Fix comment

Co-authored-by: Ivan Martinez <ivanthegreatdev@gmail.com>
2020-02-27 12:22:39 -05:00

98 lines
4.8 KiB
Go

package iface
import (
"context"
"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(ctx context.Context, status types.SlashingStatus) ([]*ethpb.AttesterSlashing, error)
DeleteAttesterSlashing(ctx context.Context, attesterSlashing *ethpb.AttesterSlashing) error
HasAttesterSlashing(ctx context.Context, slashing *ethpb.AttesterSlashing) (bool, types.SlashingStatus, error)
GetLatestEpochDetected(ctx context.Context) (uint64, error)
// BlockHeader related methods.
BlockHeaders(ctx context.Context, epoch uint64, validatorID uint64) ([]*ethpb.SignedBeaconBlockHeader, error)
HasBlockHeader(ctx context.Context, epoch uint64, validatorID uint64) bool
// IndexedAttestationsForEpoch related methods.
IndexedAttestationsForEpoch(ctx context.Context, targetEpoch uint64) ([]*ethpb.IndexedAttestation, error)
IdxAttsForTargetFromID(ctx context.Context, targetEpoch uint64, validatorID uint64) ([]*ethpb.IndexedAttestation, error)
IdxAttsForTarget(ctx context.Context, targetEpoch uint64) ([]*ethpb.IndexedAttestation, error)
LatestIndexedAttestationsTargetEpoch(ctx context.Context) (uint64, error)
LatestValidatorIdx(ctx context.Context) (uint64, error)
DoubleVotes(ctx context.Context, validatorIdx uint64, dataRoot []byte, origAtt *ethpb.IndexedAttestation) ([]*ethpb.AttesterSlashing, error)
HasIndexedAttestation(ctx context.Context, targetEpoch uint64, validatorID uint64) (bool, error)
// MinMaxSpan related methods.
ValidatorSpansMap(ctx context.Context, validatorIdx uint64) (*slashpb.EpochSpanMap, error)
// ProposerSlashing related methods.
ProposalSlashingsByStatus(ctx context.Context, status types.SlashingStatus) ([]*ethpb.ProposerSlashing, error)
HasProposerSlashing(ctx context.Context, slashing *ethpb.ProposerSlashing) (bool, types.SlashingStatus, error)
// Validator Index -> Pubkey related methods.
ValidatorPubKey(ctx context.Context, validatorID uint64) ([]byte, error)
// Chain data related methods.
ChainHead(ctx context.Context) (*ethpb.ChainHead, error)
}
// WriteAccessDatabase represents a write access database with only functions that can modify the DB.
type WriteAccessDatabase interface {
// AttesterSlashing related methods.
SaveAttesterSlashing(ctx context.Context, status types.SlashingStatus, slashing *ethpb.AttesterSlashing) error
SaveAttesterSlashings(ctx context.Context, status types.SlashingStatus, slashings []*ethpb.AttesterSlashing) error
SetLatestEpochDetected(ctx context.Context, epoch uint64) error
// BlockHeader related methods.
SaveBlockHeader(ctx context.Context, epoch uint64, validatorID uint64, blockHeader *ethpb.SignedBeaconBlockHeader) error
DeleteBlockHeader(ctx context.Context, epoch uint64, validatorID uint64, blockHeader *ethpb.SignedBeaconBlockHeader) error
PruneBlockHistory(ctx context.Context, currentEpoch uint64, pruningEpochAge uint64) error
// IndexedAttestationsForEpoch related methods.
SaveIndexedAttestation(ctx context.Context, idxAttestation *ethpb.IndexedAttestation) error
SaveIncomingIndexedAttestationByEpoch(ctx context.Context, idxAttestation *ethpb.IndexedAttestation) error
SaveIncomingIndexedAttestationsByEpoch(ctx context.Context, idxAttestations []*ethpb.IndexedAttestation) error
DeleteIndexedAttestation(ctx context.Context, idxAttestation *ethpb.IndexedAttestation) error
PruneAttHistory(ctx context.Context, currentEpoch uint64, pruningEpochAge uint64) error
// MinMaxSpan related methods.
SaveValidatorSpansMap(ctx context.Context, validatorIdx uint64, spanMap *slashpb.EpochSpanMap) error
SaveCachedSpansMaps(ctx context.Context) error
DeleteValidatorSpanMap(ctx context.Context, validatorIdx uint64) error
// ProposerSlashing related methods.
DeleteProposerSlashing(ctx context.Context, slashing *ethpb.ProposerSlashing) error
SaveProposerSlashing(ctx context.Context, status types.SlashingStatus, slashing *ethpb.ProposerSlashing) error
SaveProposerSlashings(ctx context.Context, status types.SlashingStatus, slashings []*ethpb.ProposerSlashing) error
// Validator Index -> Pubkey related methods.
SavePubKey(ctx context.Context, validatorID uint64, pubKey []byte) error
DeletePubKey(ctx context.Context, validatorID uint64) error
// Chain data related methods.
SaveChainHead(ctx context.Context, head *ethpb.ChainHead) 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
}