Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change detection and updating in Slasher to per attestation #5043

Merged
merged 21 commits into from
Mar 9, 2020
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
8b7e70b
Change span updates to update multiple validators at once
0xKiwi Mar 8, 2020
4d65d53
Change detection to perform on multiple validators at once
0xKiwi Mar 8, 2020
1528e78
Merge branch 'master' of https://github.com/prysmaticlabs/Prysm into …
0xKiwi Mar 8, 2020
4174408
Fix minspan issue
0xKiwi Mar 9, 2020
7c188a5
Fix indices
0xKiwi Mar 9, 2020
6b152cf
Fix test
0xKiwi Mar 9, 2020
c1bd0e5
Remove logs
0xKiwi Mar 9, 2020
4b8df97
Remove more logs
0xKiwi Mar 9, 2020
c32b962
Merge branch 'master' of https://github.com/prysmaticlabs/Prysm into …
0xKiwi Mar 9, 2020
3a03b15
Merge branch 'master' into slasher-batch-updating
0xKiwi Mar 9, 2020
f19032b
Merge branch 'master' into slasher-batch-updating
rauljordan Mar 9, 2020
c6f623b
Update slasher/detection/attestations/spanner_test.go
rauljordan Mar 9, 2020
5423dbd
Update slasher/detection/attestations/spanner_test.go
rauljordan Mar 9, 2020
5c19c71
Update slasher/detection/attestations/spanner_test.go
rauljordan Mar 9, 2020
4674c4d
Update slasher/detection/detect.go
rauljordan Mar 9, 2020
c28b75d
Merge branch 'master' into slasher-batch-updating
rauljordan Mar 9, 2020
ca9ebc1
Merge branch 'slasher-batch-updating' of github.com:0xKiwi/prysm into…
rauljordan Mar 9, 2020
22723b0
Merge branch 'master' into slasher-batch-updating
rauljordan Mar 9, 2020
32a39dc
nil check
rauljordan Mar 9, 2020
334eee4
Merge branch 'slasher-batch-updating' of github.com:0xKiwi/prysm into…
rauljordan Mar 9, 2020
cd80b7f
fix ununsed import
rauljordan Mar 9, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion slasher/detection/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ go_library(
visibility = ["//slasher:__subpackages__"],
deps = [
"//shared/event:go_default_library",
"//shared/hashutil:go_default_library",
"//shared/sliceutil:go_default_library",
"//slasher/beaconclient:go_default_library",
"//slasher/db:go_default_library",
Expand Down
2 changes: 1 addition & 1 deletion slasher/detection/attestations/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ go_library(
importpath = "github.com/prysmaticlabs/prysm/slasher/detection/attestations",
visibility = ["//slasher:__subpackages__"],
deps = [
"//shared/hashutil:go_default_library",
"//shared/params:go_default_library",
"//slasher/db:go_default_library",
"//slasher/detection/attestations/iface:go_default_library",
Expand All @@ -23,7 +24,6 @@ go_test(
srcs = ["spanner_test.go"],
embed = [":go_default_library"],
deps = [
"//shared/sliceutil:go_default_library",
"//slasher/db/testing:go_default_library",
"//slasher/detection/attestations/types:go_default_library",
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library",
Expand Down
7 changes: 3 additions & 4 deletions slasher/detection/attestations/iface/iface.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ import (
// SpanDetector defines an interface for Spanners to follow to allow mocks.
type SpanDetector interface {
// Read functions.
DetectSlashingForValidator(
DetectSlashingsForAttestation(
ctx context.Context,
validatorIdx uint64,
attData *ethpb.AttestationData,
) (*types.DetectionResult, error)
att *ethpb.IndexedAttestation,
) ([]*types.DetectionResult, error)

// Write functions.
UpdateSpans(ctx context.Context, att *ethpb.IndexedAttestation) error
Expand Down
37 changes: 20 additions & 17 deletions slasher/detection/attestations/mock_spanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,42 +20,45 @@ type MockSpanDetector struct {
lock sync.RWMutex
}

// DetectSlashingForValidator mocks a detected slashing, if the sent attestation data
// 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) DetectSlashingForValidator(
func (s *MockSpanDetector) DetectSlashingsForAttestation(
ctx context.Context,
validatorIdx uint64,
attData *ethpb.AttestationData,
) (*types.DetectionResult, error) {
att *ethpb.IndexedAttestation,
) ([]*types.DetectionResult, error) {
var detections []*types.DetectionResult
switch {
// If the source epoch is 0, don't find a slashing.
case attData.Source.Epoch == 0:
case att.Data.Source.Epoch == 0:
return nil, nil
// If the target epoch is > 12, it will "detect" a surrounded saved attestation.
case attData.Target.Epoch > 12:
return &types.DetectionResult{
case att.Data.Target.Epoch > 12:
detections = append(detections, &types.DetectionResult{
Kind: types.SurroundVote,
SlashableEpoch: attData.Target.Epoch - 1,
SlashableEpoch: att.Data.Target.Epoch - 1,
SigBytes: [2]byte{1, 2},
}, nil
})
return detections, nil
// If the target epoch is >= 6 < 12, it will "detect" a surrounding saved attestation.
case attData.Target.Epoch >= 6:
return &types.DetectionResult{
case att.Data.Target.Epoch >= 6:
detections = append(detections, &types.DetectionResult{
Kind: types.SurroundVote,
SlashableEpoch: attData.Target.Epoch + 1,
SlashableEpoch: att.Data.Target.Epoch + 1,
SigBytes: [2]byte{1, 2},
}, nil
})
return detections, nil
// If the target epoch is less than 6, it will "detect" a double vote.
default:
return &types.DetectionResult{
detections = append(detections, &types.DetectionResult{
Kind: types.DoubleVote,
SlashableEpoch: attData.Target.Epoch,
SlashableEpoch: att.Data.Target.Epoch,
SigBytes: [2]byte{1, 2},
}, nil
})
}
return detections, nil
}

// SpanForEpochByValidator returns the specific min-max span for a
Expand Down