-
Notifications
You must be signed in to change notification settings - Fork 986
/
mock_slashing_checker.go
73 lines (67 loc) · 2.08 KB
/
mock_slashing_checker.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package mock
import (
"context"
"github.com/prysmaticlabs/prysm/v3/config/params"
"github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
)
type MockSlashingChecker struct {
AttesterSlashingFound bool
ProposerSlashingFound bool
HighestAtts map[primitives.ValidatorIndex]*ethpb.HighestAttestation
}
func (s *MockSlashingChecker) HighestAttestations(
_ context.Context, indices []primitives.ValidatorIndex,
) ([]*ethpb.HighestAttestation, error) {
atts := make([]*ethpb.HighestAttestation, 0, len(indices))
for _, valIdx := range indices {
att, ok := s.HighestAtts[valIdx]
if !ok {
continue
}
atts = append(atts, att)
}
return atts, nil
}
func (s *MockSlashingChecker) IsSlashableBlock(_ context.Context, _ *ethpb.SignedBeaconBlockHeader) (*ethpb.ProposerSlashing, error) {
if s.ProposerSlashingFound {
return ðpb.ProposerSlashing{
Header_1: ðpb.SignedBeaconBlockHeader{
Header: ðpb.BeaconBlockHeader{
Slot: 0,
ProposerIndex: 0,
ParentRoot: params.BeaconConfig().ZeroHash[:],
StateRoot: params.BeaconConfig().ZeroHash[:],
BodyRoot: params.BeaconConfig().ZeroHash[:],
},
Signature: params.BeaconConfig().EmptySignature[:],
},
Header_2: ðpb.SignedBeaconBlockHeader{
Header: ðpb.BeaconBlockHeader{
Slot: 0,
ProposerIndex: 0,
ParentRoot: params.BeaconConfig().ZeroHash[:],
StateRoot: params.BeaconConfig().ZeroHash[:],
BodyRoot: params.BeaconConfig().ZeroHash[:],
},
Signature: params.BeaconConfig().EmptySignature[:],
},
}, nil
}
return nil, nil
}
func (s *MockSlashingChecker) IsSlashableAttestation(_ context.Context, _ *ethpb.IndexedAttestation) ([]*ethpb.AttesterSlashing, error) {
if s.AttesterSlashingFound {
return []*ethpb.AttesterSlashing{
{
Attestation_1: ðpb.IndexedAttestation{
Data: ðpb.AttestationData{},
},
Attestation_2: ðpb.IndexedAttestation{
Data: ðpb.AttestationData{},
},
},
}, nil
}
return nil, nil
}