adds state restoration to validator

This commit is contained in:
Marcin Czenko 2024-09-26 16:23:29 +02:00
parent f288ba7021
commit 8b100e4bd5
No known key found for this signature in database
GPG Key ID: 33DEA0C8E30937C0
1 changed files with 20 additions and 0 deletions

View File

@ -1,3 +1,4 @@
import std/times
import std/sets
import std/sequtils
import pkg/chronos
@ -23,6 +24,9 @@ type
proofTimeout: UInt256
config: ValidationConfig
const
MaxStorageRequestDuration: times.Duration = initDuration(days = 30)
logScope:
topics = "codex validator"
@ -119,10 +123,26 @@ proc run(validation: Validation) {.async.} =
except CatchableError as e:
error "Validation failed", msg = e.msg
proc epochForDurationBackFromNow(duration: times.Duration): int64 =
let now = getTime().toUnix
return now - duration.inSeconds
proc restoreHistoricalState(validation: Validation) {.async} =
let startTimeEpoch = epochForDurationBackFromNow(MaxStorageRequestDuration)
let slotFilledEvents = await validation.market.queryPastEvents(SlotFilled,
fromTime = startTimeEpoch)
for event in slotFilledEvents:
let slotId = slotId(event.requestId, event.slotIndex)
if validation.shouldValidateSlot(slotId):
trace "Adding slot", slotId
validation.slots.incl(slotId)
await removeSlotsThatHaveEnded(validation)
proc start*(validation: Validation) {.async.} =
validation.periodicity = await validation.market.periodicity()
validation.proofTimeout = await validation.market.proofTimeout()
await validation.subscribeSlotFilled()
await validation.restoreHistoricalState()
validation.running = validation.run()
proc stop*(validation: Validation) {.async.} =