Skip to content

Commit

Permalink
extract methods
Browse files Browse the repository at this point in the history
  • Loading branch information
mehdi-aouadi committed Jul 25, 2024
1 parent b9604a8 commit ef962b1
Showing 1 changed file with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,18 +149,11 @@ public Stream<ValidatableAttestation> stream(final Optional<UInt64> committeeInd

public Stream<ValidatableAttestation> stream(
final Optional<UInt64> committeeIndex, final boolean requiresCommitteeBits) {
// Group Attestation type mismatch
if (requiresCommitteeBits != includedValidators.requiresCommitteeBits()) {
if (noMatchingAttestations(committeeIndex, requiresCommitteeBits)) {
return Stream.empty();
} else {
return StreamSupport.stream(spliterator(committeeIndex), false);
}
// Pre electra attestation and committee index not matching
if (committeeIndex.isPresent()
&& !includedValidators.requiresCommitteeBits()
&& !attestationData.getIndex().equals(committeeIndex.get())) {
return Stream.empty();
}
// Filter based on the committee index
return StreamSupport.stream(spliterator(committeeIndex), false);
}

public Spliterator<ValidatableAttestation> spliterator(final Optional<UInt64> committeeIndex) {
Expand Down Expand Up @@ -245,6 +238,18 @@ public boolean matchesCommitteeShufflingSeed(final Set<Bytes32> validSeeds) {
return committeeShufflingSeed.map(validSeeds::contains).orElse(false);
}

private boolean noMatchingAttestations(
Optional<UInt64> committeeIndex, boolean requiresCommitteeBits) {
return requiresCommitteeBits != includedValidators.requiresCommitteeBits()
|| noMatchingPhase0Attestations(committeeIndex);
}

private boolean noMatchingPhase0Attestations(Optional<UInt64> committeeIndex) {
return committeeIndex.isPresent()
&& !includedValidators.requiresCommitteeBits()
&& !attestationData.getIndex().equals(committeeIndex.get());
}

private class AggregatingIterator implements Iterator<ValidatableAttestation> {

private final Optional<UInt64> maybeCommitteeIndex;
Expand Down

0 comments on commit ef962b1

Please sign in to comment.