Skip to content

Commit

Permalink
chore: add check for transient count exceeded key
Browse files Browse the repository at this point in the history
  • Loading branch information
anomit committed Sep 30, 2024
1 parent 869f134 commit 9683e11
Showing 1 changed file with 27 additions and 18 deletions.
45 changes: 27 additions & 18 deletions pkgs/dequeuer/submissionHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,33 @@ func (s *SubmissionHandler) verifyAndStoreSubmission(details SubmissionDetails)
if snapshotterAddr.Hex() != slotInfo.SnapshotterAddress.Hex() {
errMsg = "Incorrect snapshotter address extracted" + string(snapshotterAddr.Hex()) + "for specified slot " + strconv.FormatUint(details.submission.Request.SlotId, 10) + " : " + string(slotInfo.SnapshotterAddress.Hex())
} else {
exists, err := redis.RedisClient.Exists(context.Background(), redis.SlotEpochSubmissionCountExceeded(strconv.FormatUint(details.submission.Request.SlotId, 10), details.submission.Request.EpochId)).Result()
if err != nil {
log.Errorf("Failed to check if slot epoch submission count exceeded exists: %v", err)
return fmt.Errorf("redis client failure: %s", err.Error())
} else if exists > 0 {
errMsg = fmt.Sprintf("Slot epoch submission count exceeded for slot ID %s and epoch ID %d", strconv.FormatUint(details.submission.Request.SlotId, 10), details.submission.Request.EpochId)
log.Errorln("Slot epoch submission count exceeded: ", errMsg)
return errors.New(errMsg)
}
slotEpochCounterKey := redis.SlotEpochSubmissionsKey(strconv.FormatUint(details.submission.Request.SlotId, 10), details.submission.Request.EpochId)
count, err := redis.Incr(context.Background(), slotEpochCounterKey)
if err != nil {
log.Errorf("Failed to increment slot epoch counter: %v", err)
return fmt.Errorf("redis client failure: %s", err.Error())
} else {
if count > 2 {
errMsg := fmt.Sprintf("Slot epoch submission count exceeded for slot ID %s", strconv.FormatUint(details.submission.Request.SlotId, 10))
log.Errorln("Slot epoch submission count exceeded: ", errMsg)
redis.Set(
context.Background(),
redis.SlotEpochSubmissionCountExceeded(strconv.FormatUint(details.submission.Request.SlotId, 10), details.submission.Request.EpochId),
"true",
5*time.Minute,
)
return errors.New(errMsg)
}
}
currentEpochStr, _ := redis.Get(context.Background(), pkgs.CurrentEpoch)
if currentEpochStr == "" {
reporting.SendFailureNotification("verifyAndStoreSubmission", fmt.Sprintf("Current epochId not stored in redis: %s", err.Error()), time.Now().String(), "High")
Expand All @@ -200,24 +227,6 @@ func (s *SubmissionHandler) verifyAndStoreSubmission(details SubmissionDetails)
}
}
}
slotEpochCounterKey := redis.SlotEpochSubmissionsKey(strconv.FormatUint(details.submission.Request.SlotId, 10), details.submission.Request.EpochId)
count, err := redis.Incr(context.Background(), slotEpochCounterKey)
if err != nil {
log.Errorf("Failed to increment slot epoch counter: %v", err)
return fmt.Errorf("redis client failure: %s", err.Error())
} else {
if count > 2 {
errMsg := fmt.Sprintf("Slot epoch submission count exceeded for slot ID %s", strconv.FormatUint(details.submission.Request.SlotId, 10))
log.Errorln("Slot epoch submission count exceeded: ", errMsg)
redis.Set(
context.Background(),
redis.SlotEpochSubmissionCountExceeded(strconv.FormatUint(details.submission.Request.SlotId, 10), details.submission.Request.EpochId),
"true",
5*time.Minute,
)
return errors.New(errMsg)
}
}

key := redis.SubmissionKey(details.submission.Request.EpochId, details.submission.Request.ProjectId, new(big.Int).SetUint64(details.submission.Request.SlotId).String())
value := fmt.Sprintf("%s.%s", details.submissionId.String(), protojson.Format(details.submission))
Expand Down

0 comments on commit 9683e11

Please sign in to comment.