From 5b20352ac6f55b985fdfe53ee05771ef5e353ce5 Mon Sep 17 00:00:00 2001 From: james-prysm <90280386+james-prysm@users.noreply.github.com> Date: Wed, 8 Oct 2025 13:34:32 -0500 Subject: [PATCH] cleaning up processAggregate (#15823) * cleaning up some code * kasey feedback * further simplifying * kasey's suggestion --- .../sync/pending_attestations_queue.go | 45 +++++++------------ .../james-prysm_cleanup-process-aggregate.md | 3 ++ 2 files changed, 20 insertions(+), 28 deletions(-) create mode 100644 changelog/james-prysm_cleanup-process-aggregate.md diff --git a/beacon-chain/sync/pending_attestations_queue.go b/beacon-chain/sync/pending_attestations_queue.go index 3153ec6ed3..7073a058aa 100644 --- a/beacon-chain/sync/pending_attestations_queue.go +++ b/beacon-chain/sync/pending_attestations_queue.go @@ -241,6 +241,9 @@ func (s *Service) saveAttestation(att ethpb.Att) error { if features.Get().EnableExperimentalAttestationPool { return s.cfg.attestationCache.Add(att) } + if att.IsAggregated() { + return s.cfg.attPool.SaveAggregatedAttestation(att) + } return s.cfg.attPool.SaveUnaggregatedAttestation(att) } @@ -300,40 +303,26 @@ func (s *Service) processVerifiedAttestation( } func (s *Service) processAggregate(ctx context.Context, aggregate ethpb.SignedAggregateAttAndProof) { - att := aggregate.AggregateAttestationAndProof().AggregateVal() - - // Save the pending aggregated attestation to the pool if it passes the aggregated - // validation steps. - valRes, err := s.validateAggregatedAtt(ctx, aggregate) + res, err := s.validateAggregatedAtt(ctx, aggregate) if err != nil { log.WithError(err).Debug("Pending aggregated attestation failed validation") return } - aggValid := pubsub.ValidationAccept == valRes - if aggValid && s.validateBlockInAttestation(ctx, aggregate) { - if features.Get().EnableExperimentalAttestationPool { - if err = s.cfg.attestationCache.Add(att); err != nil { - log.WithError(err).Debug("Could not save aggregated attestation") - return - } - } else { - if att.IsAggregated() { - if err = s.cfg.attPool.SaveAggregatedAttestation(att); err != nil { - log.WithError(err).Debug("Could not save aggregated attestation") - return - } - } else if err = s.cfg.attPool.SaveUnaggregatedAttestation(att); err != nil { - log.WithError(err).Debug("Could not save unaggregated attestation") - return - } - } + if res != pubsub.ValidationAccept || !s.validateBlockInAttestation(ctx, aggregate) { + log.Debug("Pending aggregated attestation failed validation") + return + } - s.setAggregatorIndexEpochSeen(att.GetData().Target.Epoch, aggregate.AggregateAttestationAndProof().GetAggregatorIndex()) + att := aggregate.AggregateAttestationAndProof().AggregateVal() + if err := s.saveAttestation(att); err != nil { + log.WithError(err).Debug("Could not save aggregated attestation") + return + } - // Broadcasting the signed attestation again once a node is able to process it. - if err := s.cfg.p2p.Broadcast(ctx, aggregate); err != nil { - log.WithError(err).Debug("Could not broadcast") - } + s.setAggregatorIndexEpochSeen(att.GetData().Target.Epoch, aggregate.AggregateAttestationAndProof().GetAggregatorIndex()) + + if err := s.cfg.p2p.Broadcast(ctx, aggregate); err != nil { + log.WithError(err).Debug("Could not broadcast aggregated attestation") } } diff --git a/changelog/james-prysm_cleanup-process-aggregate.md b/changelog/james-prysm_cleanup-process-aggregate.md new file mode 100644 index 0000000000..b41b7f4fb4 --- /dev/null +++ b/changelog/james-prysm_cleanup-process-aggregate.md @@ -0,0 +1,3 @@ +### Ignored + +- Small code changes for reusability and readability to processAggregate. \ No newline at end of file