Skip to content

Commit

Permalink
improves performance of the historical state restoration
Browse files Browse the repository at this point in the history
  • Loading branch information
marcinczenko committed Dec 12, 2024
1 parent be02eab commit 0a30384
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions codex/validation.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.} =
Expand Down

0 comments on commit 0a30384

Please sign in to comment.