From 5decca9e2a53c65a2117ff3a9d04ef20f2524236 Mon Sep 17 00:00:00 2001 From: Enrico Del Fante Date: Thu, 9 May 2024 18:43:53 +0200 Subject: [PATCH] 7549 aggregating pool filter phase0 att in electra (#8303) --- .../attestation/ValidatableAttestation.java | 2 +- .../operations/Attestation.java | 2 ++ .../operations/AttestationSchema.java | 2 ++ .../versions/electra/AttestationElectra.java | 5 +++++ .../electra/AttestationElectraSchema.java | 5 +++++ .../versions/phase0/AttestationPhase0.java | 5 +++++ .../phase0/AttestationPhase0Schema.java | 5 +++++ .../AggregatingAttestationPool.java | 22 +++++++++++++------ 8 files changed, 40 insertions(+), 8 deletions(-) diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/attestation/ValidatableAttestation.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/attestation/ValidatableAttestation.java index c8d72bedcaf..ac9551366cd 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/attestation/ValidatableAttestation.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/attestation/ValidatableAttestation.java @@ -154,7 +154,7 @@ public void saveCommitteeShufflingSeedAndCommitteesSize(final BeaconState state) saveCommitteeShufflingSeed(state); // The committees size is only required when the committee_bits field is present in the // Attestation - if (attestation.getCommitteeBits().isPresent()) { + if (attestation.requiresCommitteeBits()) { saveCommitteesSize(state); } } diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/Attestation.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/Attestation.java index 383e5c2a8c3..6467298d96e 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/Attestation.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/Attestation.java @@ -62,4 +62,6 @@ default List getCommitteeIndicesRequired() { return getCommitteeIndices() .orElseThrow(() -> new IllegalArgumentException("Missing committee indices")); } + + boolean requiresCommitteeBits(); } diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/AttestationSchema.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/AttestationSchema.java index 31cf4a8e540..43a731634aa 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/AttestationSchema.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/AttestationSchema.java @@ -53,4 +53,6 @@ default Optional toVersionElectra() { SszBitlistSchema getAggregationBitsSchema(); Optional> getCommitteeBitsSchema(); + + boolean requiresCommitteeBits(); } diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/versions/electra/AttestationElectra.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/versions/electra/AttestationElectra.java index ec2b632d4a5..07367183e3c 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/versions/electra/AttestationElectra.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/versions/electra/AttestationElectra.java @@ -86,4 +86,9 @@ public Optional> getCommitteeIndices() { return Optional.of( getCommitteeBitsRequired().getAllSetBits().intStream().mapToObj(UInt64::valueOf).toList()); } + + @Override + public boolean requiresCommitteeBits() { + return true; + } } diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/versions/electra/AttestationElectraSchema.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/versions/electra/AttestationElectraSchema.java index d777a1babe2..0ffa872ebd6 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/versions/electra/AttestationElectraSchema.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/versions/electra/AttestationElectraSchema.java @@ -83,4 +83,9 @@ public AttestationElectra create( public Optional toVersionElectra() { return Optional.of(this); } + + @Override + public boolean requiresCommitteeBits() { + return true; + } } diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/versions/phase0/AttestationPhase0.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/versions/phase0/AttestationPhase0.java index 816b431b2e4..557f9694dd8 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/versions/phase0/AttestationPhase0.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/versions/phase0/AttestationPhase0.java @@ -71,4 +71,9 @@ public AttestationData getData() { public BLSSignature getAggregateSignature() { return getField2().getSignature(); } + + @Override + public boolean requiresCommitteeBits() { + return false; + } } diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/versions/phase0/AttestationPhase0Schema.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/versions/phase0/AttestationPhase0Schema.java index bf431b94146..77f3af7f762 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/versions/phase0/AttestationPhase0Schema.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/versions/phase0/AttestationPhase0Schema.java @@ -63,4 +63,9 @@ public Attestation create( final BLSSignature signature) { return new AttestationPhase0(this, aggregationBits, data, signature); } + + @Override + public boolean requiresCommitteeBits() { + return false; + } } diff --git a/ethereum/statetransition/src/main/java/tech/pegasys/teku/statetransition/attestation/AggregatingAttestationPool.java b/ethereum/statetransition/src/main/java/tech/pegasys/teku/statetransition/attestation/AggregatingAttestationPool.java index ef5e2ce95e4..252a1a19c1a 100644 --- a/ethereum/statetransition/src/main/java/tech/pegasys/teku/statetransition/attestation/AggregatingAttestationPool.java +++ b/ethereum/statetransition/src/main/java/tech/pegasys/teku/statetransition/attestation/AggregatingAttestationPool.java @@ -41,6 +41,7 @@ import tech.pegasys.teku.spec.datastructures.operations.Attestation; import tech.pegasys.teku.spec.datastructures.operations.AttestationData; import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState; +import tech.pegasys.teku.spec.schemas.SchemaDefinitions; /** * Maintains a pool of attestations. Attestations can be retrieved either for inclusion in a block @@ -177,11 +178,14 @@ public synchronized SszList getAttestationsForBlock( final UInt64 currentEpoch = spec.getCurrentEpoch(stateAtBlockSlot); final int previousEpochLimit = spec.getPreviousEpochAttestationCapacity(stateAtBlockSlot); + final SchemaDefinitions schemaDefinitions = + spec.atSlot(stateAtBlockSlot.getSlot()).getSchemaDefinitions(); + final SszListSchema attestationsSchema = - spec.atSlot(stateAtBlockSlot.getSlot()) - .getSchemaDefinitions() - .getBeaconBlockBodySchema() - .getAttestationsSchema(); + schemaDefinitions.getBeaconBlockBodySchema().getAttestationsSchema(); + + final boolean blockRequiresAttestationsWithCommitteeBits = + schemaDefinitions.getAttestationSchema().requiresCommitteeBits(); final AtomicInteger prevEpochCount = new AtomicInteger(0); return dataHashBySlot @@ -196,11 +200,15 @@ public synchronized SszList getAttestationsForBlock( .filter(group -> isValid(stateAtBlockSlot, group.getAttestationData())) .filter(forkChecker::areAttestationsFromCorrectFork) .flatMap(MatchingDataAttestationGroup::stream) - .limit(attestationsSchema.getMaxLength()) .map(ValidatableAttestation::getAttestation) .filter( - att -> { - if (spec.computeEpochAtSlot(att.getData().getSlot()).isLessThan(currentEpoch)) { + attestation -> + attestation.requiresCommitteeBits() == blockRequiresAttestationsWithCommitteeBits) + .limit(attestationsSchema.getMaxLength()) + .filter( + attestation -> { + if (spec.computeEpochAtSlot(attestation.getData().getSlot()) + .isLessThan(currentEpoch)) { final int currentCount = prevEpochCount.getAndIncrement(); return currentCount < previousEpochLimit; }