Skip to content

Commit

Permalink
Log a warning whenever we don’t do the next validation because we’re …
Browse files Browse the repository at this point in the history
…low on memory
  • Loading branch information
ganeshvanahalli committed Feb 28, 2024
1 parent 5dab604 commit 507b780
Showing 1 changed file with 20 additions and 24 deletions.
44 changes: 20 additions & 24 deletions staker/block_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -577,15 +577,21 @@ func (v *BlockValidator) iterativeValidationEntryCreator(ctx context.Context, ig
return v.config().ValidationPoll
}

func (v *BlockValidator) isMemoryLimitExceeded() bool {
if v.MemoryFreeLimitChecker == nil {
return false
}
exceeded, err := v.MemoryFreeLimitChecker.IsLimitExceeded()
if err != nil {
log.Error("error checking if free-memory limit exceeded using MemoryFreeLimitChecker", "err", err)
}
return exceeded
}

func (v *BlockValidator) sendNextRecordRequests(ctx context.Context) (bool, error) {
if v.MemoryFreeLimitChecker != nil {
exceeded, err := v.MemoryFreeLimitChecker.IsLimitExceeded()
if err != nil {
log.Error("error checking if free-memory limit exceeded using MemoryFreeLimitChecker", "err", err)
}
if exceeded {
return false, nil
}
if v.isMemoryLimitExceeded() {
log.Warn("sendNextRecordRequests: aborting due to running low on memory")
return false, nil
}
v.reorgMutex.RLock()
pos := v.recordSent()
Expand Down Expand Up @@ -616,14 +622,9 @@ func (v *BlockValidator) sendNextRecordRequests(ctx context.Context) (bool, erro
return true, nil
}
for pos <= recordUntil {
if v.MemoryFreeLimitChecker != nil {
exceeded, err := v.MemoryFreeLimitChecker.IsLimitExceeded()
if err != nil {
log.Error("error checking if free-memory limit exceeded using MemoryFreeLimitChecker", "err", err)
}
if exceeded {
return false, nil
}
if v.isMemoryLimitExceeded() {
log.Warn("sendNextRecordRequests: aborting due to running low on memory")
return false, nil
}
validationStatus, found := v.validations.Load(pos)
if !found {
Expand Down Expand Up @@ -778,14 +779,9 @@ validationsLoop:
log.Trace("advanceValidations: no more room", "pos", pos)
return nil, nil
}
if v.MemoryFreeLimitChecker != nil {
exceeded, err := v.MemoryFreeLimitChecker.IsLimitExceeded()
if err != nil {
log.Error("error checking if free-memory limit exceeded using MemoryFreeLimitChecker", "err", err)
}
if exceeded {
return nil, nil
}
if v.isMemoryLimitExceeded() {
log.Warn("advanceValidations: aborting due to running low on memory")
return nil, nil
}
if currentStatus == Prepared {
input, err := validationStatus.Entry.ToInput()
Expand Down

0 comments on commit 507b780

Please sign in to comment.