erigon-pulse/cmd/erigon-cl/forkchoice/on_attester_slashing.go
a 30430d585a
begin refactor of beacon state (#7433)
this first major move separates the transient beacon state cache from
the underlying tree.

leaf updates are enforced in the setters, which should make programming
easier.

all exported methods of the raw.BeaconState should be safe to call
(without disrupting internal state)

changes many functions to consume *raw.BeaconState in perparation for
interface


beyond refactor it also:

adds a pool for the leaves of the validator ssz hash 

adds a pool for the snappy writers
  
removed the parallel hash experiment (high memory use)
2023-05-04 15:18:42 +02:00

50 lines
1.5 KiB
Go

package forkchoice
import (
"fmt"
"github.com/ledgerwatch/erigon/cl/cltypes"
"github.com/ledgerwatch/erigon/cl/utils"
"github.com/ledgerwatch/erigon/cmd/erigon-cl/core/state"
)
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.Root, 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.BeaconState, 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.BeaconState, 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 utils.IntersectionOfSortedSets(attestation1.AttestingIndices, attestation2.AttestingIndices) {
f.equivocatingIndicies[index] = struct{}{}
}
// add attestation indicies to equivocating indicies.
return nil
}