Skip to content

Commit

Permalink
Don't use MaxCover for Electra on-chain aggregates (#14925)
Browse files Browse the repository at this point in the history
* Don't use MaxCover for Electra on-chain aggregates

* changelog <3
  • Loading branch information
rkapka authored Feb 18, 2025
1 parent d396a99 commit 961d8e1
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package validator

import (
"bytes"
"cmp"
"context"
"fmt"
"slices"
"sort"

"github.com/pkg/errors"
Expand Down Expand Up @@ -277,7 +279,14 @@ func (a proposerAtts) sortOnChainAggregates() (proposerAtts, error) {
return a, nil
}

return a.sortByProfitabilityUsingMaxCover()
// Sort by slot first, then by bit count.
slices.SortFunc(a, func(a, b ethpb.Att) int {
return cmp.Or(
-cmp.Compare(a.GetData().Slot, b.GetData().Slot),
-cmp.Compare(a.GetAggregationBits().Count(), b.GetAggregationBits().Count()))
})

return a, nil
}

// Separate attestations by slot, as slot number takes higher precedence when sorting.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -794,17 +794,19 @@ func Test_packAttestations_ElectraOnChainAggregates(t *testing.T) {

require.NoError(t, st.SetSlot(params.BeaconConfig().SlotsPerEpoch+1))

atts, err := s.packAttestations(ctx, st, params.BeaconConfig().SlotsPerEpoch)
require.NoError(t, err)
require.Equal(t, 6, len(atts))
assert.Equal(t, true,
atts[0].GetAggregationBits().Count() >= atts[1].GetAggregationBits().Count() &&
atts[1].GetAggregationBits().Count() >= atts[2].GetAggregationBits().Count() &&
atts[2].GetAggregationBits().Count() >= atts[3].GetAggregationBits().Count() &&
atts[3].GetAggregationBits().Count() >= atts[4].GetAggregationBits().Count() &&
atts[4].GetAggregationBits().Count() >= atts[5].GetAggregationBits().Count(),
"on-chain aggregates are not sorted by aggregation bit count",
)
t.Run("ok", func(t *testing.T) {
atts, err := s.packAttestations(ctx, st, params.BeaconConfig().SlotsPerEpoch)
require.NoError(t, err)
require.Equal(t, 6, len(atts))
assert.Equal(t, true,
atts[0].GetAggregationBits().Count() >= atts[1].GetAggregationBits().Count() &&
atts[1].GetAggregationBits().Count() >= atts[2].GetAggregationBits().Count() &&
atts[2].GetAggregationBits().Count() >= atts[3].GetAggregationBits().Count() &&
atts[3].GetAggregationBits().Count() >= atts[4].GetAggregationBits().Count() &&
atts[4].GetAggregationBits().Count() >= atts[5].GetAggregationBits().Count(),
"on-chain aggregates are not sorted by aggregation bit count",
)
})

t.Run("slot takes precedence", func(t *testing.T) {
moreRecentAtt := &ethpb.AttestationElectra{
Expand All @@ -814,7 +816,7 @@ func Test_packAttestations_ElectraOnChainAggregates(t *testing.T) {
Signature: sig.Marshal(),
}
require.NoError(t, pool.SaveUnaggregatedAttestations([]ethpb.Att{moreRecentAtt}))
atts, err = s.packAttestations(ctx, st, params.BeaconConfig().SlotsPerEpoch)
atts, err := s.packAttestations(ctx, st, params.BeaconConfig().SlotsPerEpoch)
require.NoError(t, err)
require.Equal(t, 7, len(atts))
assert.Equal(t, true, atts[0].GetData().Slot == 1)
Expand Down
3 changes: 3 additions & 0 deletions changelog/radek_no-maxcover-for-electra.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### Changed

- Don't use MaxCover for Electra on-chain attestations.

0 comments on commit 961d8e1

Please sign in to comment.