From d916a56cda4c2e44b63ca814641240a40539d44a Mon Sep 17 00:00:00 2001 From: Mehdi AOUADI Date: Mon, 9 Dec 2024 16:43:31 +0100 Subject: [PATCH] refactoring --- .../electra/block/BlockProcessorElectra.java | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/electra/block/BlockProcessorElectra.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/electra/block/BlockProcessorElectra.java index 49d63c1b4a7..89dc366260a 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/electra/block/BlockProcessorElectra.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/electra/block/BlockProcessorElectra.java @@ -726,26 +726,25 @@ private Optional checkCommittees( final BeaconState state, final UInt64 slot, final SszBitlist aggregationBits) { - int participantsCount = 0; + int committeeOffset = 0; for (final UInt64 committeeIndex : committeeIndices) { if (committeeIndex.isGreaterThanOrEqualTo(committeeCountPerSlot)) { return Optional.of(AttestationInvalidReason.COMMITTEE_INDEX_TOO_HIGH); } final IntList committee = beaconStateAccessorsElectra.getBeaconCommittee(state, slot, committeeIndex); - final int committeeOffset = participantsCount; - final long committeeAttesterCount = + int currentCommitteeOffset = committeeOffset; + final boolean hasAtLeastOneParticipant = IntStream.range(0, committee.size()) - .filter( + .anyMatch( committeeParticipantIndex -> - aggregationBits.isSet(committeeOffset + committeeParticipantIndex)) - .count(); - if (committeeAttesterCount == 0) { + aggregationBits.isSet(currentCommitteeOffset + committeeParticipantIndex)); + if (!hasAtLeastOneParticipant) { return Optional.of(AttestationInvalidReason.PARTICIPANTS_COUNT_MISMATCH); } - participantsCount += committee.size(); + committeeOffset += committee.size(); } - if (participantsCount != aggregationBits.size()) { + if (committeeOffset != aggregationBits.size()) { return Optional.of(AttestationInvalidReason.PARTICIPANTS_COUNT_MISMATCH); } return Optional.empty();