Skip to content

Commit

Permalink
Merge pull request #2163 from OffchainLabs/blockvalidator-lowonmemory…
Browse files Browse the repository at this point in the history
…-warning

Log a warning whenever we don’t do the next validation because we’re low on memory
  • Loading branch information
ganeshvanahalli authored Feb 29, 2024
2 parents 8a52c76 + 51c3cf5 commit 7bc9a6e
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 7bc9a6e

Please sign in to comment.