From 1c9228350aac4c3deb3f6bad66498d5f36316109 Mon Sep 17 00:00:00 2001 From: Marcin Czenko Date: Mon, 14 Oct 2024 01:49:39 +0200 Subject: [PATCH] adds validation groups and group index in logs of validator --- codex/validation.nim | 44 +++++++++++++++++++++++++++++++------------- 1 file changed, 31 insertions(+), 13 deletions(-) diff --git a/codex/validation.nim b/codex/validation.nim index 6468e6a8..ae9a2737 100644 --- a/codex/validation.nim +++ b/codex/validation.nim @@ -47,7 +47,8 @@ proc getCurrentPeriod(validation: Validation): UInt256 = proc waitUntilNextPeriod(validation: Validation) {.async.} = let period = validation.getCurrentPeriod() let periodEnd = validation.periodicity.periodEnd(period) - trace "Waiting until next period", currentPeriod = period + trace "Waiting until next period", currentPeriod = period, groups = validation.config.groups, + groupIndex = validation.config.groupIndex await validation.clock.waitUntil(periodEnd.truncate(int64) + 1) func groupIndexForSlotId*(slotId: SlotId, @@ -71,7 +72,8 @@ proc subscribeSlotFilled(validation: Validation) {.async.} = proc onSlotFilled(requestId: RequestId, slotIndex: UInt256) = let slotId = slotId(requestId, slotIndex) if validation.shouldValidateSlot(slotId): - trace "Adding slot", slotId + trace "Adding slot", slotId, groups = validation.config.groups, + groupIndex = validation.config.groupIndex validation.slots.incl(slotId) let subscription = await validation.market.subscribeSlotFilled(onSlotFilled) validation.subscriptions.add(subscription) @@ -82,7 +84,8 @@ proc removeSlotsThatHaveEnded(validation: Validation) {.async.} = for slotId in slots: let state = await validation.market.slotState(slotId) if state != SlotState.Filled: - trace "Removing slot", slotId + trace "Removing slot", slotId, groups = validation.config.groups, + groupIndex = validation.config.groupIndex ended.incl(slotId) validation.slots.excl(ended) @@ -94,11 +97,15 @@ proc markProofAsMissing(validation: Validation, try: if await validation.market.canProofBeMarkedAsMissing(slotId, period): - trace "Marking proof as missing", slotId, periodProofMissed = period + trace "Marking proof as missing", slotId, periodProofMissed = period, + groups = validation.config.groups, + groupIndex = validation.config.groupIndex await validation.market.markProofAsMissing(slotId, period) else: let inDowntime {.used.} = await validation.market.inDowntime(slotId) - trace "Proof not missing", checkedPeriod = period, inDowntime + trace "Proof not missing", checkedPeriod = period, inDowntime, + groups = validation.config.groups, + groupIndex = validation.config.groupIndex except CancelledError: raise except CatchableError as e: @@ -111,36 +118,47 @@ proc markProofsAsMissing(validation: Validation) {.async.} = await validation.markProofAsMissing(slotId, previousPeriod) proc run(validation: Validation) {.async.} = - trace "Validation started" + trace "Validation started", groups = validation.config.groups, + groupIndex = validation.config.groupIndex try: while true: await validation.waitUntilNextPeriod() await validation.removeSlotsThatHaveEnded() await validation.markProofsAsMissing() except CancelledError: - trace "Validation stopped" + trace "Validation stopped", groups = validation.config.groups, + groupIndex = validation.config.groupIndex discard except CatchableError as e: - error "Validation failed", msg = e.msg + error "Validation failed", msg = e.msg, groups = validation.config.groups, + groupIndex = validation.config.groupIndex proc epochForDurationBackFromNow(validation: Validation, duration: times.Duration): SecondsSince1970 = return validation.clock.now - duration.inSeconds proc restoreHistoricalState(validation: Validation) {.async} = - trace "Restoring historical state..." + trace "Restoring historical state...", groups = validation.config.groups, + groupIndex = validation.config.groupIndex let startTimeEpoch = validation.epochForDurationBackFromNow(MaxStorageRequestDuration) let slotFilledEvents = await validation.market.queryPastSlotFilledEvents( fromTime = startTimeEpoch) - trace "Found slot filled events", numberOfSlots = slotFilledEvents.len + trace "Found slot filled events", numberOfSlots = slotFilledEvents.len, + groups = validation.config.groups, + groupIndex = validation.config.groupIndex for event in slotFilledEvents: let slotId = slotId(event.requestId, event.slotIndex) if validation.shouldValidateSlot(slotId): - trace "Adding slot [historical]", slotId + trace "Adding slot [historical]", slotId, + groups = validation.config.groups, + groupIndex = validation.config.groupIndex validation.slots.incl(slotId) - trace "Removing slots that have ended..." + trace "Removing slots that have ended...", groups = validation.config.groups, + groupIndex = validation.config.groupIndex await removeSlotsThatHaveEnded(validation) - trace "Historical state restored", numberOfSlots = validation.slots.len + trace "Historical state restored", numberOfSlots = validation.slots.len, + groups = validation.config.groups, + groupIndex = validation.config.groupIndex proc start*(validation: Validation) {.async.} = validation.periodicity = await validation.market.periodicity()