mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2025-01-07 03:22:18 +00:00
3ab373787e
we need to extract this interface from the struct. i need to also break down the interface more, to better show what parts the caching is used, move some functions from the cache state to the underlying. don't merge
51 lines
1.5 KiB
Go
51 lines
1.5 KiB
Go
package forkchoice
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/ledgerwatch/erigon/cl/cltypes/solid"
|
|
"github.com/ledgerwatch/erigon/cl/phase1/core/state"
|
|
|
|
"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
|
|
s, _, err := f.forkGraph.GetState(f.justifiedCheckpoint.BlockRoot(), false)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if s == nil {
|
|
return fmt.Errorf("justified checkpoint state not accessible")
|
|
}
|
|
// Verify validity of slashings
|
|
valid, err := state.IsValidIndexedAttestation(s, attestation1)
|
|
if err != nil {
|
|
return fmt.Errorf("error calculating indexed attestation 1 validity: %v", err)
|
|
}
|
|
if !valid {
|
|
return fmt.Errorf("invalid indexed attestation 1")
|
|
}
|
|
|
|
valid, err = state.IsValidIndexedAttestation(s, attestation2)
|
|
if err != nil {
|
|
return fmt.Errorf("error calculating indexed attestation 2 validity: %v", err)
|
|
}
|
|
if !valid {
|
|
return fmt.Errorf("invalid indexed attestation 2")
|
|
}
|
|
for _, index := range solid.IntersectionOfSortedSets(attestation1.AttestingIndices, attestation2.AttestingIndices) {
|
|
f.equivocatingIndicies[index] = struct{}{}
|
|
}
|
|
// add attestation indicies to equivocating indicies.
|
|
return nil
|
|
}
|