Skip to content

Commit

Permalink
get_attesting_indices
Browse files Browse the repository at this point in the history
  • Loading branch information
rkapka committed Apr 19, 2024
1 parent 6a0e4e1 commit dd27897
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 5 deletions.
2 changes: 1 addition & 1 deletion beacon-chain/core/helpers/beacon_committee.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ func ShuffledIndices(s state.ReadOnlyBeaconState, epoch primitives.Epoch) ([]pri
}

// TODO: doc
func GetCommitteeIndices(committeeBits bitfield.Bitlist) []primitives.CommitteeIndex {
func CommitteeIndices(committeeBits bitfield.Bitlist) []primitives.CommitteeIndex {
indices := committeeBits.BitIndices()
committeeIndices := make([]primitives.CommitteeIndex, len(indices))
for i, ix := range indices {
Expand Down
33 changes: 29 additions & 4 deletions beacon-chain/monitor/process_attestation.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,36 @@ func (s *Service) canUpdateAttestedValidator(idx primitives.ValidatorIndex, slot

// attestingIndices returns the indices of validators that participated in the given aggregated attestation.
func attestingIndices(ctx context.Context, state state.BeaconState, att interfaces.Attestation) ([]uint64, error) {
committee, err := helpers.BeaconCommitteeFromState(ctx, state, att.GetData().Slot, att.GetData().CommitteeIndex)
if err != nil {
return nil, err
aggBits := att.GetAggregationBits()

if att.Version() < version.Electra {
committee, err := helpers.BeaconCommitteeFromState(ctx, state, att.GetData().Slot, att.GetData().CommitteeIndex)
if err != nil {
return nil, err
}
return attestation.AttestingIndices(aggBits, committee)
}

attesters := make([]uint64, 0, len(att.GetAggregationBits()))
committeeIndices := helpers.CommitteeIndices(att.GetCommitteeBits())
committeeOffset := 0
for _, ci := range committeeIndices {
committee, err := helpers.BeaconCommitteeFromState(ctx, state, att.GetData().Slot, ci)
if err != nil {
return nil, err
}
committeeAttesters := make([]uint64, 0, len(committee))
for i, vi := range committee {
if aggBits[committeeOffset+i] == 1 {
committeeAttesters = append(committeeAttesters, uint64(committee[vi]))
}
}
attesters = append(attesters, committeeAttesters...)

committeeOffset += len(committee)
}
return attestation.AttestingIndices(att.GetAggregationBits(), committee)

return attesters, nil
}

// logMessageTimelyFlagsForIndex returns the log message with performance info for the attestation (head, source, target)
Expand Down
1 change: 1 addition & 0 deletions consensus-types/interfaces/beacon_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ type Attestation interface {
ssz.Marshaler
ssz.Unmarshaler
ssz.HashRoot
Version() int
GetAggregationBits() bitfield.Bitlist
SetAggregationBits(bits bitfield.Bitlist)
GetData() *ethpb.AttestationData
Expand Down
9 changes: 9 additions & 0 deletions proto/prysm/v1alpha1/attestation.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@ package eth

import (
"github.com/prysmaticlabs/go-bitfield"
"github.com/prysmaticlabs/prysm/v5/runtime/version"
)

func (a *Attestation) Version() int {
return version.Phase0
}

func (a *Attestation) GetCommitteeBits() bitfield.Bitlist {
return nil
}
Expand All @@ -24,6 +29,10 @@ func (a *Attestation) SetSignature(sig []byte) {
a.Signature = sig
}

func (a *AttestationElectra) Version() int {
return version.Electra
}

func (a *AttestationElectra) SetAggregationBits(bits bitfield.Bitlist) {
a.AggregationBits = bits
}
Expand Down
2 changes: 2 additions & 0 deletions runtime/version/fork.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const (
Bellatrix
Capella
Deneb
Electra
)

var versionToString = map[int]string{
Expand All @@ -16,6 +17,7 @@ var versionToString = map[int]string{
Bellatrix: "bellatrix",
Capella: "capella",
Deneb: "deneb",
Electra: "electra",
}

// stringToVersion and allVersions are populated in init()
Expand Down

0 comments on commit dd27897

Please sign in to comment.