Skip to content

Commit

Permalink
checkSlashableAttestations: Simplify duration computation.
Browse files Browse the repository at this point in the history
  • Loading branch information
nalepae committed Feb 8, 2024
1 parent bd02048 commit 7acbc4d
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions beacon-chain/slasher/detect_attestations.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (
func (s *Service) checkSlashableAttestations(
ctx context.Context, currentEpoch primitives.Epoch, atts []*slashertypes.IndexedAttestationWrapper,
) ([]*ethpb.AttesterSlashing, error) {
totalStart := time.Now()

slashings := make([]*ethpb.AttesterSlashing, 0)

// Double votes
Expand All @@ -36,11 +38,10 @@ func (s *Service) checkSlashableAttestations(
groupedByValidatorChunkIndexAtts := s.groupByValidatorChunkIndex(atts)
log.WithField("numBatches", len(groupedByValidatorChunkIndexAtts)).Debug("Batching attestations by validator chunk index")
groupsCount := len(groupedByValidatorChunkIndexAtts)
batchDurations := make([]time.Duration, 0, len(groupedByValidatorChunkIndexAtts))

for validatorChunkIndex, attestations := range groupedByValidatorChunkIndexAtts {
innerStart := time.Now()
surroundStart := time.Now()

for validatorChunkIndex, attestations := range groupedByValidatorChunkIndexAtts {
// The fact that we use always slashertypes.MinSpan is probably the root cause of
// https://github.com/prysmaticlabs/prysm/issues/13591
attSlashings, err := s.checkSurrounds(ctx, attestations, slashertypes.MinSpan, currentEpoch, validatorChunkIndex)
Expand All @@ -54,24 +55,19 @@ func (s *Service) checkSlashableAttestations(
for _, idx := range indices {
s.latestEpochWrittenForValidator[idx] = currentEpoch
}

batchDurations = append(batchDurations, time.Since(innerStart))
}

// Elapsed time computation
totalBatchDuration := time.Duration(0)
for _, batchDuration := range batchDurations {
totalBatchDuration += batchDuration
}
surroundElapsed := time.Since(surroundStart)
totalElapsed := time.Since(totalStart)

fields := logrus.Fields{
"numAttestations": len(atts),
"numBatchesByValidatorChunkIndex": groupsCount,
"elapsed": totalBatchDuration,
"elapsed": totalElapsed,
}

if groupsCount > 0 {
avgProcessingTimePerBatch := totalBatchDuration / time.Duration(groupsCount)
avgProcessingTimePerBatch := surroundElapsed / time.Duration(groupsCount)
fields["avgBatchProcessingTime"] = avgProcessingTimePerBatch
}

Expand Down

0 comments on commit 7acbc4d

Please sign in to comment.