2023-04-08 01:01:10 +00:00
|
|
|
package forkchoice
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2023-05-14 22:12:24 +00:00
|
|
|
|
2023-05-23 18:58:34 +00:00
|
|
|
"github.com/ledgerwatch/erigon/cl/cltypes/solid"
|
2023-05-13 21:44:07 +00:00
|
|
|
"github.com/ledgerwatch/erigon/cl/phase1/core/state"
|
2023-04-08 01:01:10 +00:00
|
|
|
|
|
|
|
"github.com/ledgerwatch/erigon/cl/cltypes"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (f *ForkChoiceStore) OnAttesterSlashing(attesterSlashing *cltypes.AttesterSlashing) error {
|
|
|
|
f.mu.Lock()
|
|
|
|
defer f.mu.Unlock()
|
|
|
|
// Check if these attestation is even slashable.
|
|
|
|
attestation1 := attesterSlashing.Attestation_1
|
|
|
|
attestation2 := attesterSlashing.Attestation_2
|
|
|
|
if !cltypes.IsSlashableAttestationData(attestation1.Data, attestation2.Data) {
|
|
|
|
return fmt.Errorf("attestation data is not slashable")
|
|
|
|
}
|
|
|
|
// Retrieve justified state
|
2023-06-02 12:54:40 +00:00
|
|
|
s, _, err := f.forkGraph.GetState(f.justifiedCheckpoint.BlockRoot(), false)
|
2023-04-08 01:01:10 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2023-05-04 13:18:42 +00:00
|
|
|
if s == nil {
|
2023-04-08 01:01:10 +00:00
|
|
|
return fmt.Errorf("justified checkpoint state not accessible")
|
|
|
|
}
|
|
|
|
// Verify validity of slashings
|
2023-07-19 22:20:33 +00:00
|
|
|
valid, err := state.IsValidIndexedAttestation(s, attestation1)
|
2023-04-08 01:01:10 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("error calculating indexed attestation 1 validity: %v", err)
|
|
|
|
}
|
|
|
|
if !valid {
|
|
|
|
return fmt.Errorf("invalid indexed attestation 1")
|
|
|
|
}
|
|
|
|
|
2023-07-19 22:20:33 +00:00
|
|
|
valid, err = state.IsValidIndexedAttestation(s, attestation2)
|
2023-04-08 01:01:10 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("error calculating indexed attestation 2 validity: %v", err)
|
|
|
|
}
|
|
|
|
if !valid {
|
|
|
|
return fmt.Errorf("invalid indexed attestation 2")
|
|
|
|
}
|
2023-05-23 18:58:34 +00:00
|
|
|
for _, index := range solid.IntersectionOfSortedSets(attestation1.AttestingIndices, attestation2.AttestingIndices) {
|
2023-04-08 01:01:10 +00:00
|
|
|
f.equivocatingIndicies[index] = struct{}{}
|
|
|
|
}
|
|
|
|
// add attestation indicies to equivocating indicies.
|
|
|
|
return nil
|
|
|
|
}
|