-
Notifications
You must be signed in to change notification settings - Fork 985
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
is slashable attestation endpoint implementation (#5209)
* is slashable attestation endpoint implementation * fix todo * comment * Merge refs/heads/master into is_slashable_attestation * Merge refs/heads/master into is_slashable_attestation * Merge refs/heads/master into is_slashable_attestation * Update slasher/rpc/server.go * Update slasher/rpc/server.go * Update slasher/rpc/service.go
- Loading branch information
Showing
6 changed files
with
118 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package rpc | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1" | ||
testDB "github.com/prysmaticlabs/prysm/slasher/db/testing" | ||
"github.com/prysmaticlabs/prysm/slasher/detection" | ||
) | ||
|
||
func Test_DetectionFlow(t *testing.T) { | ||
db := testDB.SetupSlasherDB(t, false) | ||
defer testDB.TeardownSlasherDB(t, db) | ||
|
||
savedAttestation := ðpb.IndexedAttestation{ | ||
AttestingIndices: []uint64{3}, | ||
Data: ðpb.AttestationData{ | ||
Source: ðpb.Checkpoint{Epoch: 3}, | ||
Target: ðpb.Checkpoint{Epoch: 4}, | ||
}, | ||
Signature: []byte{1, 2}, | ||
} | ||
incomingAtt := ðpb.IndexedAttestation{ | ||
AttestingIndices: []uint64{3}, | ||
Data: ðpb.AttestationData{ | ||
Source: ðpb.Checkpoint{Epoch: 2}, | ||
Target: ðpb.Checkpoint{Epoch: 4}, | ||
}, | ||
Signature: []byte{1, 2}, | ||
} | ||
cfg := &detection.Config{ | ||
SlasherDB: db, | ||
} | ||
ctx := context.Background() | ||
ds := detection.NewDetectionService(ctx, cfg) | ||
server := Server{ctx: ctx, detector: ds, slasherDB: db} | ||
slashings, err := server.IsSlashableAttestation(ctx, savedAttestation) | ||
if err != nil { | ||
t.Fatalf("got error while trying to detect slashing: %v", err) | ||
} | ||
if len(slashings.AttesterSlashing) != 0 { | ||
t.Fatalf("Found slashings while no slashing should have been found on first attestation: %v slashing found: %v", savedAttestation, slashings) | ||
} | ||
|
||
slashing, err := server.IsSlashableAttestation(ctx, incomingAtt) | ||
if err != nil { | ||
t.Fatalf("got error while trying to detect slashing: %v", err) | ||
} | ||
if len(slashing.AttesterSlashing) != 1 { | ||
t.Fatalf("only one slashing should have been found. got: %v", len(slashing.AttesterSlashing)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters