Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
domiwei committed Nov 9, 2024
1 parent b0adf3f commit b955aa3
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions cl/phase1/network/services/attestation_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ func (s *attestationService) ProcessMessage(ctx context.Context, subnet *uint64,
targetEpoch uint64
signature [96]byte
data *solid.AttestationData
attestation *solid.Attestation
attHashKey [32]byte
)
if att.Attestation != nil {
Expand All @@ -135,7 +134,6 @@ func (s *attestationService) ProcessMessage(ctx context.Context, subnet *uint64,
if err != nil {
return err
}
attestation = att.SingleAttestation.ToAttestation(memberIndexInCommittee)
} else {
// deneb and before case
root = att.Attestation.Data.BeaconBlockRoot
Expand All @@ -148,7 +146,6 @@ func (s *attestationService) ProcessMessage(ctx context.Context, subnet *uint64,
if err != nil {
return err
}
attestation = att.Attestation
}

if _, ok := s.attestationProcessed.Get(attHashKey); ok {
Expand All @@ -168,8 +165,9 @@ func (s *attestationService) ProcessMessage(ctx context.Context, subnet *uint64,
}

var (
domain []byte
pubKey common.Bytes48
domain []byte
pubKey common.Bytes48
attestation *solid.Attestation // SingleAttestation will be transformed to Attestation struct with given member index in committee
)
if err := s.syncedDataManager.ViewHeadState(func(headState *state.CachingBeaconState) error {
// [REJECT] The committee index is within the expected range
Expand Down Expand Up @@ -220,17 +218,20 @@ func (s *attestationService) ProcessMessage(ctx context.Context, subnet *uint64,
return errors.New("on bit index out of committee range")
}
vIndex = beaconCommittee[onBitIndex]
attestation = att.Attestation
} else {
// electra and after
// [REJECT] attestation.data.index == 0
if att.SingleAttestation.Data.CommitteeIndex != 0 {
return errors.New("committee index must be 0")
}
// [REJECT] The attester is a member of the committee -- i.e. attestation.attester_index in get_beacon_committee(state, attestation.data.slot, index).
if !contains(att.SingleAttestation.AttesterIndex, beaconCommittee) {
memIndexInCommittee := contains(att.SingleAttestation.AttesterIndex, beaconCommittee)
if memIndexInCommittee < 0 {
return errors.New("attester is not a member of the committee")
}
vIndex = att.SingleAttestation.AttesterIndex
attestation = att.SingleAttestation.ToAttestation(memIndexInCommittee)
}
// [IGNORE] There has been no other valid attestation seen on an attestation subnet that has an identical attestation.data.target.epoch and participating validator index.
// mark the validator as seen
Expand Down Expand Up @@ -360,11 +361,11 @@ func (a *attestationService) loop(ctx context.Context) {
}
}

func contains[T comparable](target T, slices []T) bool {
for _, s := range slices {
func contains[T comparable](target T, slices []T) int {
for i, s := range slices {
if s == target {
return true
return i
}
}
return false
return -1
}

0 comments on commit b955aa3

Please sign in to comment.