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

Fix SingleAttestation in PerformanceTracker bug #8902

Merged
Merged
Changes from 1 commit
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
Next Next commit
fix
tbenr committed Dec 9, 2024
commit 2fcf666b5b90119f0fdeb353bf92ebbba1829fc7
Original file line number Diff line number Diff line change
@@ -586,16 +586,22 @@ public SafeFuture<List<SubmitDataError>> sendSignedAttestations(
}

private SafeFuture<InternalValidationResult> processAttestation(final Attestation attestation) {
final ValidatableAttestation validatableAttestation =
ValidatableAttestation.fromValidator(spec, attestation);
return attestationManager
.addAttestation(ValidatableAttestation.fromValidator(spec, attestation), Optional.empty())
.addAttestation(validatableAttestation, Optional.empty())
.thenPeek(
result -> {
// when saving the attestation in performance tracker, we want to make sure we save
// the converted attestation
// conversion happens during processing and is saved in the validatable attestation
final Attestation convertedAttestation = validatableAttestation.getAttestation();
if (!result.isReject()) {
dutyMetrics.onAttestationPublished(attestation.getData().getSlot());
performanceTracker.saveProducedAttestation(attestation);
dutyMetrics.onAttestationPublished(convertedAttestation.getData().getSlot());
performanceTracker.saveProducedAttestation(convertedAttestation);
} else {
VALIDATOR_LOGGER.producedInvalidAttestation(
attestation.getData().getSlot(),
convertedAttestation.getData().getSlot(),
result.getDescription().orElse("Unknown reason"));
}
})
Original file line number Diff line number Diff line change
@@ -14,6 +14,7 @@
package tech.pegasys.teku.validator.coordinator.performance;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkState;

import com.google.common.annotations.VisibleForTesting;
import it.unimi.dsi.fastutil.ints.Int2IntMap;
@@ -424,6 +425,7 @@ private SafeFuture<Map<UInt64, List<Attestation>>> getAttestationsIncludedInEpoc

@Override
public void saveProducedAttestation(final Attestation attestation) {
checkState(!attestation.isSingleAttestation(), "Single attestation is not supported");
final UInt64 epoch = spec.computeEpochAtSlot(attestation.getData().getSlot());
final Set<Attestation> attestationsInEpoch =
producedAttestationsByEpoch.computeIfAbsent(epoch, __ -> concurrentSet());
Original file line number Diff line number Diff line change
@@ -819,6 +819,53 @@ public void sendSignedAttestations_shouldAddAttestationToAttestationManager() {
.addAttestation(ValidatableAttestation.from(spec, attestation), Optional.empty());
}

@Test
void sendSignedAttestations_shouldSaveConvertedAttestationFromSingleAttestation() {
spec = TestSpecFactory.createMinimalElectra();
dataStructureUtil = new DataStructureUtil(spec);
validatorApiHandler =
new ValidatorApiHandler(
chainDataProvider,
nodeDataProvider,
networkDataProvider,
chainDataClient,
syncStateProvider,
blockFactory,
attestationPool,
attestationManager,
attestationTopicSubscriptions,
activeValidatorTracker,
dutyMetrics,
performanceTracker,
spec,
forkChoiceTrigger,
proposersDataManager,
syncCommitteeMessagePool,
syncCommitteeContributionPool,
syncCommitteeSubscriptionManager,
blockProductionPerformanceFactory,
blockPublisher);

final Attestation attestation = dataStructureUtil.randomSingleAttestation();
final Attestation convertedAttestation = dataStructureUtil.randomAttestation();
doAnswer(
invocation -> {
invocation
.getArgument(0, ValidatableAttestation.class)
.convertToAggregatedFormatFromSingleAttestation(convertedAttestation);
return completedFuture(InternalValidationResult.ACCEPT);
})
.when(attestationManager)
.addAttestation(any(ValidatableAttestation.class), any());

final SafeFuture<List<SubmitDataError>> result =
validatorApiHandler.sendSignedAttestations(List.of(attestation));
assertThat(result).isCompletedWithValue(emptyList());

verify(dutyMetrics).onAttestationPublished(convertedAttestation.getData().getSlot());
verify(performanceTracker).saveProducedAttestation(convertedAttestation);
}

@Test
void sendSignedAttestations_shouldAddToDutyMetricsAndPerformanceTrackerWhenNotInvalid() {
final Attestation attestation = dataStructureUtil.randomAttestation();