2022-01-26 14:48:20 +00:00
|
|
|
package mock
|
2021-09-29 18:17:37 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2022-08-16 12:20:13 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/v3/config/params"
|
2023-01-26 14:40:12 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
2022-08-16 12:20:13 +00:00
|
|
|
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
2021-09-29 18:17:37 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type MockSlashingChecker struct {
|
|
|
|
AttesterSlashingFound bool
|
|
|
|
ProposerSlashingFound bool
|
2023-01-26 14:40:12 +00:00
|
|
|
HighestAtts map[primitives.ValidatorIndex]*ethpb.HighestAttestation
|
2021-09-30 02:33:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *MockSlashingChecker) HighestAttestations(
|
2023-01-26 14:40:12 +00:00
|
|
|
_ context.Context, indices []primitives.ValidatorIndex,
|
2021-09-30 02:33:28 +00:00
|
|
|
) ([]*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
|
2021-09-29 18:17:37 +00:00
|
|
|
}
|
|
|
|
|
2021-12-01 18:56:07 +00:00
|
|
|
func (s *MockSlashingChecker) IsSlashableBlock(_ context.Context, _ *ethpb.SignedBeaconBlockHeader) (*ethpb.ProposerSlashing, error) {
|
2021-09-29 18:17:37 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2021-12-01 18:56:07 +00:00
|
|
|
func (s *MockSlashingChecker) IsSlashableAttestation(_ context.Context, _ *ethpb.IndexedAttestation) ([]*ethpb.AttesterSlashing, error) {
|
2021-09-29 18:17:37 +00:00
|
|
|
if s.AttesterSlashingFound {
|
|
|
|
return []*ethpb.AttesterSlashing{
|
|
|
|
{
|
|
|
|
Attestation_1: ðpb.IndexedAttestation{
|
|
|
|
Data: ðpb.AttestationData{},
|
|
|
|
},
|
|
|
|
Attestation_2: ðpb.IndexedAttestation{
|
|
|
|
Data: ðpb.AttestationData{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
return nil, nil
|
|
|
|
}
|