Skip to content

Commit

Permalink
Fix electra attestation performance tracker (#9012)
Browse files Browse the repository at this point in the history
  • Loading branch information
tbenr authored Jan 17, 2025
1 parent 40b2f8f commit d56ce97
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,10 @@ public void onSlot(final UInt64 slot) {
}

SafeFuture.allOf(reportingTasks.toArray(SafeFuture[]::new))
.handleException(LOG::error)
.handleException(error -> LOG.error("Failed to report performance metrics", error))
.alwaysRun(
() -> {
if (reportingTasks.size() > 0) {
if (!reportingTasks.isEmpty()) {
timingsSettableGauge.set(System.currentTimeMillis() - startTime);
}
})
Expand Down Expand Up @@ -307,10 +307,10 @@ private AttestationPerformance calculateAttestationPerformance(
// data hash to inclusion slot to aggregation bitlist
final Map<Bytes32, NavigableMap<UInt64, AttestationBitsAggregator>>
slotAndBitlistsByAttestationDataHash = new HashMap<>();
for (Map.Entry<UInt64, List<Attestation>> entry : attestationsIncludedOnChain.entrySet()) {
final Optional<Int2IntMap> committeesSize =
Optional.of(spec.getBeaconCommitteesSize(state, entry.getKey()));
for (Attestation attestation : entry.getValue()) {
for (final Map.Entry<UInt64, List<Attestation>> entry :
attestationsIncludedOnChain.entrySet()) {
for (final Attestation attestation : entry.getValue()) {
final Optional<Int2IntMap> committeesSize = getCommitteesSize(attestation, state);
final Bytes32 attestationDataHash = attestation.getData().hashTreeRoot();
final NavigableMap<UInt64, AttestationBitsAggregator> slotToBitlists =
slotAndBitlistsByAttestationDataHash.computeIfAbsent(
Expand All @@ -325,7 +325,7 @@ private AttestationPerformance calculateAttestationPerformance(
}
}

for (Attestation sentAttestation : producedAttestations) {
for (final Attestation sentAttestation : producedAttestations) {
final Bytes32 sentAttestationDataHash = sentAttestation.getData().hashTreeRoot();
final UInt64 sentAttestationSlot = sentAttestation.getData().getSlot();
if (!slotAndBitlistsByAttestationDataHash.containsKey(sentAttestationDataHash)) {
Expand Down Expand Up @@ -359,7 +359,7 @@ private AttestationPerformance calculateAttestationPerformance(
// IntSummaryStatistics returns Integer.MIN and MAX when the summarized integer list
// is empty.
final int numberOfProducedAttestations = producedAttestations.size();
return producedAttestations.size() > 0
return numberOfProducedAttestations > 0
? new AttestationPerformance(
analyzedEpoch,
validatorTracker.getNumberOfValidatorsForEpoch(analyzedEpoch),
Expand All @@ -374,6 +374,14 @@ private AttestationPerformance calculateAttestationPerformance(
analyzedEpoch, validatorTracker.getNumberOfValidatorsForEpoch(analyzedEpoch));
}

private Optional<Int2IntMap> getCommitteesSize(
final Attestation attestation, final BeaconState state) {
if (!attestation.requiresCommitteeBits()) {
return Optional.empty();
}
return Optional.of(spec.getBeaconCommitteesSize(state, attestation.getData().getSlot()));
}

private SafeFuture<Set<BeaconBlock>> getBlocksInEpochs(
final UInt64 startEpochInclusive, final UInt64 endEpochExclusive) {
final UInt64 epochStartSlot = spec.computeStartSlotAtEpoch(startEpochInclusive);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ private SafeFuture<BlockContainer> validateBlock(

if (!blockContainerAndMetaData.consensusBlockValue().isZero()) {
LOG.info(
"Received block for slot {}, block rewards {} ETH, execution payload value {} ETH",
"Validator client received block for slot {}, block rewards {} ETH, execution payload value {} ETH",
slot,
weiToEth(blockContainerAndMetaData.consensusBlockValue()),
weiToEth(blockContainerAndMetaData.executionPayloadValue()));
Expand Down

0 comments on commit d56ce97

Please sign in to comment.