Skip to content

Commit dd6aac7

Browse files
committed
Decompose Electra block attestations
1 parent 44ff0b1 commit dd6aac7

File tree

3 files changed

+50
-9
lines changed

3 files changed

+50
-9
lines changed

beacon-chain/blockchain/BUILD.bazel

+3
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ go_library(
9696
"@com_github_pkg_errors//:go_default_library",
9797
"@com_github_prometheus_client_golang//prometheus:go_default_library",
9898
"@com_github_prometheus_client_golang//prometheus/promauto:go_default_library",
99+
"@com_github_prysmaticlabs_go_bitfield//:go_default_library",
99100
"@com_github_sirupsen_logrus//:go_default_library",
100101
"@org_golang_x_sync//errgroup:go_default_library",
101102
],
@@ -154,6 +155,7 @@ go_test(
154155
"//beacon-chain/forkchoice/doubly-linked-tree:go_default_library",
155156
"//beacon-chain/forkchoice/types:go_default_library",
156157
"//beacon-chain/operations/attestations:go_default_library",
158+
"//beacon-chain/operations/attestations/kv:go_default_library",
157159
"//beacon-chain/operations/blstoexec:go_default_library",
158160
"//beacon-chain/operations/slashings:go_default_library",
159161
"//beacon-chain/operations/voluntaryexits:go_default_library",
@@ -185,6 +187,7 @@ go_test(
185187
"@com_github_ethereum_go_ethereum//core/types:go_default_library",
186188
"@com_github_holiman_uint256//:go_default_library",
187189
"@com_github_pkg_errors//:go_default_library",
190+
"@com_github_prysmaticlabs_go_bitfield//:go_default_library",
188191
"@com_github_sirupsen_logrus//:go_default_library",
189192
"@com_github_sirupsen_logrus//hooks/test:go_default_library",
190193
"@org_golang_google_protobuf//proto:go_default_library",

beacon-chain/blockchain/forkchoice_update_execution.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ func (s *Service) forkchoiceUpdateWithExecution(ctx context.Context, args *fcuCo
103103
}
104104

105105
// Only need to prune attestations from pool if the head has changed.
106-
if err := s.pruneAttsFromPool(args.headBlock); err != nil {
106+
if err := s.pruneAttsFromPool(s.ctx, args.headState, args.headBlock); err != nil {
107107
log.WithError(err).Error("could not prune attestations from pool")
108108
}
109109
return nil

beacon-chain/blockchain/process_block.go

+46-8
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"time"
77

88
"github.com/pkg/errors"
9+
"github.com/prysmaticlabs/go-bitfield"
910
"github.com/prysmaticlabs/prysm/v5/beacon-chain/core/blocks"
1011
"github.com/prysmaticlabs/prysm/v5/beacon-chain/core/helpers"
1112
coreTime "github.com/prysmaticlabs/prysm/v5/beacon-chain/core/time"
@@ -420,21 +421,58 @@ func (s *Service) savePostStateInfo(ctx context.Context, r [32]byte, b interface
420421
}
421422

422423
// This removes the attestations in block `b` from the attestation mem pool.
423-
func (s *Service) pruneAttsFromPool(headBlock interfaces.ReadOnlySignedBeaconBlock) error {
424+
func (s *Service) pruneAttsFromPool(ctx context.Context, headState state.BeaconState, headBlock interfaces.ReadOnlySignedBeaconBlock) error {
424425
atts := headBlock.Block().Body().Attestations()
425426
for _, att := range atts {
426-
if features.Get().EnableExperimentalAttestationPool {
427-
if err := s.cfg.AttestationCache.DeleteCovered(att); err != nil {
428-
return errors.Wrap(err, "could not delete attestation")
427+
if !att.IsAggregated() {
428+
if err := s.cfg.AttPool.DeleteUnaggregatedAttestation(att); err != nil {
429+
return err
429430
}
430-
} else if att.IsAggregated() {
431-
if err := s.cfg.AttPool.DeleteAggregatedAttestation(att); err != nil {
431+
continue
432+
}
433+
434+
if att.Version() == version.Phase0 {
435+
if features.Get().EnableExperimentalAttestationPool {
436+
if err := s.cfg.AttestationCache.DeleteCovered(att); err != nil {
437+
return err
438+
}
439+
} else if err := s.cfg.AttPool.DeleteAggregatedAttestation(att); err != nil {
432440
return err
433441
}
434-
} else {
435-
if err := s.cfg.AttPool.DeleteUnaggregatedAttestation(att); err != nil {
442+
continue
443+
}
444+
445+
offset := uint64(0)
446+
447+
committeeIndices := att.CommitteeBitsVal().BitIndices()
448+
committees, err := helpers.AttestationCommittees(ctx, headState, att)
449+
if err != nil {
450+
return err
451+
}
452+
for i, c := range committees {
453+
ab := bitfield.NewBitlist(uint64(len(c)))
454+
for j := uint64(0); j < uint64(len(c)); j++ {
455+
ab.SetBitAt(j, att.GetAggregationBits().BitAt(j+offset) == true)
456+
}
457+
458+
cb := primitives.NewAttestationCommitteeBits()
459+
cb.SetBitAt(uint64(committeeIndices[i]), true)
460+
461+
a := &ethpb.AttestationElectra{
462+
AggregationBits: ab,
463+
Data: att.GetData(),
464+
CommitteeBits: cb,
465+
}
466+
467+
if features.Get().EnableExperimentalAttestationPool {
468+
if err := s.cfg.AttestationCache.DeleteCovered(a); err != nil {
469+
return err
470+
}
471+
} else if err := s.cfg.AttPool.DeleteAggregatedAttestation(a); err != nil {
436472
return err
437473
}
474+
475+
offset += uint64(len(c))
438476
}
439477
}
440478
return nil

0 commit comments

Comments
 (0)