github.com/prysmaticlabs/prysm@v1.4.4/slasher/db/iface/interface.go (about)

     1  // Package iface defines an interface for the slasher database,
     2  // providing more advanced interfaces such as a
     3  // ReadOnlyDatabase.
     4  package iface
     5  
     6  import (
     7  	"context"
     8  	"io"
     9  
    10  	types "github.com/prysmaticlabs/eth2-types"
    11  	ethpb "github.com/prysmaticlabs/prysm/proto/eth/v1alpha1"
    12  	slashpb "github.com/prysmaticlabs/prysm/proto/slashing"
    13  	"github.com/prysmaticlabs/prysm/shared/backuputil"
    14  	dbtypes "github.com/prysmaticlabs/prysm/slasher/db/types"
    15  	slashertypes "github.com/prysmaticlabs/prysm/slasher/detection/attestations/types"
    16  )
    17  
    18  // ReadOnlyDatabase represents a read only database with functions that do not modify the DB.
    19  type ReadOnlyDatabase interface {
    20  	// AttesterSlashing related methods.
    21  	AttesterSlashings(ctx context.Context, status dbtypes.SlashingStatus) ([]*ethpb.AttesterSlashing, error)
    22  	DeleteAttesterSlashing(ctx context.Context, attesterSlashing *ethpb.AttesterSlashing) error
    23  	HasAttesterSlashing(ctx context.Context, slashing *ethpb.AttesterSlashing) (bool, dbtypes.SlashingStatus, error)
    24  	GetLatestEpochDetected(ctx context.Context) (types.Epoch, error)
    25  
    26  	// BlockHeader related methods.
    27  	BlockHeaders(ctx context.Context, slot types.Slot, validatorIndex types.ValidatorIndex) ([]*ethpb.SignedBeaconBlockHeader, error)
    28  	HasBlockHeader(ctx context.Context, slot types.Slot, validatorIndex types.ValidatorIndex) bool
    29  
    30  	// IndexedAttestations related methods.
    31  	HasIndexedAttestation(ctx context.Context, att *ethpb.IndexedAttestation) (bool, error)
    32  	IndexedAttestationsForTarget(ctx context.Context, targetEpoch types.Epoch) ([]*ethpb.IndexedAttestation, error)
    33  	IndexedAttestationsWithPrefix(ctx context.Context, targetEpoch types.Epoch, sigBytes []byte) ([]*ethpb.IndexedAttestation, error)
    34  	LatestIndexedAttestationsTargetEpoch(ctx context.Context) (uint64, error)
    35  
    36  	// Highest Attestation related methods.
    37  	HighestAttestation(ctx context.Context, validatorID uint64) (*slashpb.HighestAttestation, error)
    38  
    39  	// MinMaxSpan related methods.
    40  	EpochSpans(ctx context.Context, epoch types.Epoch, fromCache bool) (*slashertypes.EpochStore, error)
    41  
    42  	// ProposerSlashing related methods.
    43  	ProposalSlashingsByStatus(ctx context.Context, status dbtypes.SlashingStatus) ([]*ethpb.ProposerSlashing, error)
    44  	HasProposerSlashing(ctx context.Context, slashing *ethpb.ProposerSlashing) (bool, dbtypes.SlashingStatus, error)
    45  
    46  	// Validator Index -> Pubkey related methods.
    47  	ValidatorPubKey(ctx context.Context, validatorIndex types.ValidatorIndex) ([]byte, error)
    48  
    49  	// Chain data related methods.
    50  	ChainHead(ctx context.Context) (*ethpb.ChainHead, error)
    51  
    52  	// Cache management methods.
    53  	RemoveOldestFromCache(ctx context.Context) uint64
    54  }
    55  
    56  // WriteAccessDatabase represents a write access database with only functions that can modify the DB.
    57  type WriteAccessDatabase interface {
    58  	// AttesterSlashing related methods.
    59  	SaveAttesterSlashing(ctx context.Context, status dbtypes.SlashingStatus, slashing *ethpb.AttesterSlashing) error
    60  	SaveAttesterSlashings(ctx context.Context, status dbtypes.SlashingStatus, slashings []*ethpb.AttesterSlashing) error
    61  	SetLatestEpochDetected(ctx context.Context, epoch types.Epoch) error
    62  
    63  	// BlockHeader related methods.
    64  	SaveBlockHeader(ctx context.Context, blockHeader *ethpb.SignedBeaconBlockHeader) error
    65  	DeleteBlockHeader(ctx context.Context, blockHeader *ethpb.SignedBeaconBlockHeader) error
    66  	PruneBlockHistory(ctx context.Context, currentEpoch, pruningEpochAge types.Epoch) error
    67  
    68  	// IndexedAttestations related methods.
    69  	SaveIndexedAttestation(ctx context.Context, idxAttestation *ethpb.IndexedAttestation) error
    70  	SaveIndexedAttestations(ctx context.Context, idxAttestations []*ethpb.IndexedAttestation) error
    71  	DeleteIndexedAttestation(ctx context.Context, idxAttestation *ethpb.IndexedAttestation) error
    72  	PruneAttHistory(ctx context.Context, currentEpoch, pruningEpochAge types.Epoch) error
    73  
    74  	// Highest Attestation related methods.
    75  	SaveHighestAttestation(ctx context.Context, highest *slashpb.HighestAttestation) error
    76  
    77  	// MinMaxSpan related methods.
    78  	SaveEpochSpans(ctx context.Context, epoch types.Epoch, spans *slashertypes.EpochStore, toCache bool) error
    79  
    80  	// ProposerSlashing related methods.
    81  	DeleteProposerSlashing(ctx context.Context, slashing *ethpb.ProposerSlashing) error
    82  	SaveProposerSlashing(ctx context.Context, status dbtypes.SlashingStatus, slashing *ethpb.ProposerSlashing) error
    83  	SaveProposerSlashings(ctx context.Context, status dbtypes.SlashingStatus, slashings []*ethpb.ProposerSlashing) error
    84  
    85  	// Validator Index -> Pubkey related methods.
    86  	SavePubKey(ctx context.Context, validatorIndex types.ValidatorIndex, pubKey []byte) error
    87  	DeletePubKey(ctx context.Context, validatorIndex types.ValidatorIndex) error
    88  
    89  	// Chain data related methods.
    90  	SaveChainHead(ctx context.Context, head *ethpb.ChainHead) error
    91  }
    92  
    93  // FullAccessDatabase represents a full access database with only DB interaction functions.
    94  type FullAccessDatabase interface {
    95  	ReadOnlyDatabase
    96  	WriteAccessDatabase
    97  }
    98  
    99  // Database represents a full access database with the proper DB helper functions.
   100  type Database interface {
   101  	io.Closer
   102  	backuputil.BackupExporter
   103  	FullAccessDatabase
   104  	DatabasePath() string
   105  	ClearDB() error
   106  }
   107  
   108  // EpochSpansStore represents a data access layer for marshaling and unmarshaling validator spans for each validator per epoch.
   109  type EpochSpansStore interface {
   110  	SetValidatorSpan(ctx context.Context, idx types.ValidatorIndex, newSpan slashertypes.Span) error
   111  	GetValidatorSpan(ctx context.Context, idx types.ValidatorIndex) (slashertypes.Span, error)
   112  }