From 0a30384dbd3ca7161bab73d53d75632b922b7a43 Mon Sep 17 00:00:00 2001 From: Marcin Czenko Date: Thu, 12 Dec 2024 18:07:08 +0100 Subject: [PATCH] improves performance of the historical state restoration --- codex/validation.nim | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/codex/validation.nim b/codex/validation.nim index ce61cc492..6b5ac447a 100644 --- a/codex/validation.nim +++ b/codex/validation.nim @@ -61,15 +61,15 @@ func maxSlotsConstraintRespected(validation: Validation): bool = validation.slots.len < validation.config.maxSlots func shouldValidateSlot(validation: Validation, slotId: SlotId): bool = - if (validationGroups =? validation.config.groups): - (groupIndexForSlotId(slotId, validationGroups) == - validation.config.groupIndex) and - validation.maxSlotsConstraintRespected - else: - validation.maxSlotsConstraintRespected + without validationGroups =? validation.config.groups: + return true + groupIndexForSlotId(slotId, validationGroups) == + validation.config.groupIndex proc subscribeSlotFilled(validation: Validation) {.async.} = proc onSlotFilled(requestId: RequestId, slotIndex: UInt256) = + if not validation.maxSlotsConstraintRespected: + return let slotId = slotId(requestId, slotIndex) if validation.shouldValidateSlot(slotId): trace "Adding slot", slotId, groups = validation.config.groups, @@ -145,14 +145,14 @@ proc restoreHistoricalState(validation: Validation) {.async.} = let startTimeEpoch = validation.epochForDurationBackFromNow(MaxStorageRequestDuration) let slotFilledEvents = await validation.market.queryPastSlotFilledEvents( fromTime = startTimeEpoch) - trace "Found filled slots", numberOfSlots = slotFilledEvents.len for event in slotFilledEvents: + if not validation.maxSlotsConstraintRespected: + break let slotId = slotId(event.requestId, event.slotIndex) - if validation.shouldValidateSlot(slotId): + let slotState = await validation.market.slotState(slotId) + if slotState == SlotState.Filled and validation.shouldValidateSlot(slotId): trace "Adding slot [historical]", slotId validation.slots.incl(slotId) - trace "Removing slots that have ended..." - await removeSlotsThatHaveEnded(validation) trace "Historical state restored", numberOfSlots = validation.slots.len proc start*(validation: Validation) {.async.} =