mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-10 11:41:21 +00:00
7cc32c4dda
* remove unused code * remove defer use in loop * Remove unused methods and constants * gofmt and gaz * nilness check * remove unused args * Add TODO for refactoring subscribeWithBase to remove unused arg. It seems too involved to include in this sweeping PR. https://github.com/prysmaticlabs/prysm/issues/7437 * replace empty slice declaration * Remove unnecessary type conversions * remove redundant type declaration * rename receivers to be consistent * Remove bootnode query tool. It is now obsolete by discv5 * Remove relay node. It is no longer used or supported * Revert "Remove relay node. It is no longer used or supported" This reverts commit 4bd7717334dad85ef4766ed9bc4da711fb5fa810. * Delete unused test directory * Delete unsupported gcp startup script * Delete old k8s script * build fixes * fix build * go mod tidy * revert slasher/db/kv/block_header.go * fix build * remove redundant nil check * combine func args Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com> Co-authored-by: Victor Farazdagi <simple.square@gmail.com>
79 lines
3.0 KiB
Go
79 lines
3.0 KiB
Go
package attestations
|
|
|
|
import (
|
|
"context"
|
|
|
|
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
|
"github.com/prysmaticlabs/prysm/slasher/detection/attestations/iface"
|
|
"github.com/prysmaticlabs/prysm/slasher/detection/attestations/types"
|
|
)
|
|
|
|
var _ iface.SpanDetector = (*MockSpanDetector)(nil)
|
|
|
|
// MockSpanDetector defines a struct which can detect slashable
|
|
// attestation offenses by tracking validator min-max
|
|
// spans from validators.
|
|
type MockSpanDetector struct{}
|
|
|
|
// DetectSlashingsForAttestation mocks a detected slashing, if the sent attestation data
|
|
// has a source epoch of 0, nothing will be detected. If the sent attestation data has a target
|
|
// epoch equal to or greater than 6, it will "detect" a surrounded vote for the target epoch + 1.
|
|
// If the target epoch is greater than 12, it will "detect" a surrounding vote for target epoch - 1.
|
|
// Lastly, if it has a target epoch less than 6, it will "detect" a double vote for the target epoch.
|
|
func (s *MockSpanDetector) DetectSlashingsForAttestation(
|
|
_ context.Context,
|
|
att *ethpb.IndexedAttestation,
|
|
) ([]*types.DetectionResult, error) {
|
|
var detections []*types.DetectionResult
|
|
switch {
|
|
// If the source epoch is 0, don't find a slashing.
|
|
case att.Data.Source.Epoch == 0:
|
|
return nil, nil
|
|
// If the target epoch is > 12, it will "detect" a surrounded saved attestation.
|
|
case att.Data.Target.Epoch > 12:
|
|
detections = append(detections, &types.DetectionResult{
|
|
Kind: types.SurroundVote,
|
|
SlashableEpoch: att.Data.Target.Epoch - 1,
|
|
SigBytes: [2]byte{1, 2},
|
|
})
|
|
return detections, nil
|
|
// If the target epoch is >= 6 < 12, it will "detect" a surrounding saved attestation.
|
|
case att.Data.Target.Epoch >= 6:
|
|
detections = append(detections, &types.DetectionResult{
|
|
Kind: types.SurroundVote,
|
|
SlashableEpoch: att.Data.Target.Epoch + 1,
|
|
SigBytes: [2]byte{1, 2},
|
|
})
|
|
return detections, nil
|
|
// If the target epoch is less than 6, it will "detect" a double vote.
|
|
default:
|
|
detections = append(detections, &types.DetectionResult{
|
|
Kind: types.DoubleVote,
|
|
SlashableEpoch: att.Data.Target.Epoch,
|
|
SigBytes: [2]byte{1, 2},
|
|
})
|
|
}
|
|
return detections, nil
|
|
}
|
|
|
|
// SpanForEpochByValidator returns the specific min-max span for a
|
|
// validator index in a given epoch.
|
|
func (s *MockSpanDetector) SpanForEpochByValidator(_ context.Context, _, _ uint64) (types.Span, error) {
|
|
return types.Span{MinSpan: 0, MaxSpan: 0, SigBytes: [2]byte{}, HasAttested: false}, nil
|
|
}
|
|
|
|
// ValidatorSpansByEpoch returns a list of all validator spans in a given epoch.
|
|
func (s *MockSpanDetector) ValidatorSpansByEpoch(_ context.Context, _ uint64) map[uint64]types.Span {
|
|
return make(map[uint64]types.Span)
|
|
}
|
|
|
|
// DeleteValidatorSpansByEpoch mocks the delete spans by epoch function.
|
|
func (s *MockSpanDetector) DeleteValidatorSpansByEpoch(_ context.Context, _, _ uint64) error {
|
|
return nil
|
|
}
|
|
|
|
// UpdateSpans is a mock for updating the spans for a given attestation..
|
|
func (s *MockSpanDetector) UpdateSpans(_ context.Context, _ *ethpb.IndexedAttestation) error {
|
|
return nil
|
|
}
|