Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

7549 aggregating pool filter phase0 att in electra #8303

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,6 @@ default List<UInt64> getCommitteeIndicesRequired() {
return getCommitteeIndices()
.orElseThrow(() -> new IllegalArgumentException("Missing committee indices"));
}

boolean requiresCommitteeBits();
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,6 @@ default Optional<AttestationElectraSchema> toVersionElectra() {
SszBitlistSchema<?> getAggregationBitsSchema();

Optional<SszBitvectorSchema<?>> getCommitteeBitsSchema();

boolean requiresCommitteeBits();
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,9 @@ public Optional<List<UInt64>> getCommitteeIndices() {
return Optional.of(
getCommitteeBitsRequired().getAllSetBits().intStream().mapToObj(UInt64::valueOf).toList());
}

@Override
public boolean requiresCommitteeBits() {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,9 @@ public AttestationElectra create(
public Optional<AttestationElectraSchema> toVersionElectra() {
return Optional.of(this);
}

@Override
public boolean requiresCommitteeBits() {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,9 @@ public AttestationData getData() {
public BLSSignature getAggregateSignature() {
return getField2().getSignature();
}

@Override
public boolean requiresCommitteeBits() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,9 @@ public Attestation create(
final BLSSignature signature) {
return new AttestationPhase0(this, aggregationBits, data, signature);
}

@Override
public boolean requiresCommitteeBits() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -177,11 +178,14 @@ public synchronized SszList<Attestation> getAttestationsForBlock(
final UInt64 currentEpoch = spec.getCurrentEpoch(stateAtBlockSlot);
final int previousEpochLimit = spec.getPreviousEpochAttestationCapacity(stateAtBlockSlot);

final SchemaDefinitions schemaDefinitions =
spec.atSlot(stateAtBlockSlot.getSlot()).getSchemaDefinitions();

final SszListSchema<Attestation, ?> 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
Expand All @@ -196,11 +200,15 @@ public synchronized SszList<Attestation> 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;
}
Expand Down