removing redundant loop in computeOnChainAggregate (#15108)

* removing redundant loop

* Update beacon-chain/rpc/prysm/v1alpha1/validator/proposer_attestations_electra.go

Co-authored-by: Radosław Kapka <rkapka@wp.pl>

* removing unused import

* replacing with more used function

* resolving Unsafe cast from uint64 to int error

---------

Co-authored-by: Radosław Kapka <rkapka@wp.pl>
This commit is contained in:
james-prysm
2025-03-31 16:22:47 -05:00
committed by GitHub
parent 8be205cf3d
commit a50e981c74
2 changed files with 7 additions and 8 deletions

View File

@@ -1,10 +1,10 @@
package validator
import (
"cmp"
"slices"
"github.com/prysmaticlabs/go-bitfield"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/v5/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/v5/crypto/bls"
ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
@@ -58,11 +58,11 @@ func computeOnChainAggregate(aggregates []ethpb.Att) ([]ethpb.Att, error) {
for _, aggs := range aggsByDataRoot {
slices.SortFunc(aggs, func(a, b ethpb.Att) int {
return a.CommitteeBitsVal().BitIndices()[0] - b.CommitteeBitsVal().BitIndices()[0]
return cmp.Compare(a.GetCommitteeIndex(), b.GetCommitteeIndex())
})
sigs := make([]bls.Signature, len(aggs))
committeeIndices := make([]primitives.CommitteeIndex, len(aggs))
cb := primitives.NewAttestationCommitteeBits()
aggBitsIndices := make([]uint64, 0)
aggBitsOffset := uint64(0)
var err error
@@ -74,7 +74,7 @@ func computeOnChainAggregate(aggregates []ethpb.Att) ([]ethpb.Att, error) {
if err != nil {
return nil, err
}
committeeIndices[i] = helpers.CommitteeIndices(a.CommitteeBitsVal())[0]
cb.SetBitAt(uint64(a.GetCommitteeIndex()), true)
aggBitsOffset += a.GetAggregationBits().Len()
}
@@ -84,16 +84,12 @@ func computeOnChainAggregate(aggregates []ethpb.Att) ([]ethpb.Att, error) {
aggregationBits.SetBitAt(bi, true)
}
cb := primitives.NewAttestationCommitteeBits()
att := &ethpb.AttestationElectra{
AggregationBits: aggregationBits,
Data: aggs[0].GetData(),
CommitteeBits: cb,
Signature: bls.AggregateSignatures(sigs).Marshal(),
}
for _, ci := range committeeIndices {
att.CommitteeBits.SetBitAt(uint64(ci), true)
}
result = append(result, att)
}

View File

@@ -0,0 +1,3 @@
### Ignored
- small optimization on the computeOnChainAggregate function