From 507b780bec7cb62465bf6d4bab597b40c1359e6e Mon Sep 17 00:00:00 2001 From: Ganesh Vanahalli Date: Wed, 28 Feb 2024 09:58:20 -0600 Subject: [PATCH] =?UTF-8?q?Log=20a=20warning=20whenever=20we=20don?= =?UTF-8?q?=E2=80=99t=20do=20the=20next=20validation=20because=20we?= =?UTF-8?q?=E2=80=99re=20low=20on=20memory?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- staker/block_validator.go | 44 ++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 24 deletions(-) diff --git a/staker/block_validator.go b/staker/block_validator.go index f71cafec5d..56cd5307d8 100644 --- a/staker/block_validator.go +++ b/staker/block_validator.go @@ -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() @@ -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 { @@ -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()