better use of logScopes to reduce duplication
This commit is contained in:
parent
ba844eed7b
commit
4e83f099e8
|
@ -79,13 +79,15 @@ proc subscribeSlotFilled(validation: Validation) {.async.} =
|
||||||
validation.subscriptions.add(subscription)
|
validation.subscriptions.add(subscription)
|
||||||
|
|
||||||
proc removeSlotsThatHaveEnded(validation: Validation) {.async.} =
|
proc removeSlotsThatHaveEnded(validation: Validation) {.async.} =
|
||||||
|
logScope:
|
||||||
|
groups = validation.config.groups
|
||||||
|
groupIndex = validation.config.groupIndex
|
||||||
var ended: HashSet[SlotId]
|
var ended: HashSet[SlotId]
|
||||||
let slots = validation.slots
|
let slots = validation.slots
|
||||||
for slotId in slots:
|
for slotId in slots:
|
||||||
let state = await validation.market.slotState(slotId)
|
let state = await validation.market.slotState(slotId)
|
||||||
if state != SlotState.Filled:
|
if state != SlotState.Filled:
|
||||||
trace "Removing slot", slotId, groups = validation.config.groups,
|
trace "Removing slot", slotId, slotState = state
|
||||||
groupIndex = validation.config.groupIndex, slotState = state
|
|
||||||
ended.incl(slotId)
|
ended.incl(slotId)
|
||||||
validation.slots.excl(ended)
|
validation.slots.excl(ended)
|
||||||
|
|
||||||
|
@ -94,18 +96,16 @@ proc markProofAsMissing(validation: Validation,
|
||||||
period: Period) {.async.} =
|
period: Period) {.async.} =
|
||||||
logScope:
|
logScope:
|
||||||
currentPeriod = validation.getCurrentPeriod()
|
currentPeriod = validation.getCurrentPeriod()
|
||||||
|
groups = validation.config.groups
|
||||||
|
groupIndex = validation.config.groupIndex
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if await validation.market.canProofBeMarkedAsMissing(slotId, period):
|
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)
|
await validation.market.markProofAsMissing(slotId, period)
|
||||||
else:
|
else:
|
||||||
let inDowntime {.used.} = await validation.market.inDowntime(slotId)
|
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:
|
except CancelledError:
|
||||||
raise
|
raise
|
||||||
except CatchableError as e:
|
except CatchableError as e:
|
||||||
|
@ -118,18 +118,18 @@ proc markProofsAsMissing(validation: Validation) {.async.} =
|
||||||
await validation.markProofAsMissing(slotId, previousPeriod)
|
await validation.markProofAsMissing(slotId, previousPeriod)
|
||||||
|
|
||||||
proc run(validation: Validation) {.async.} =
|
proc run(validation: Validation) {.async.} =
|
||||||
trace "Validation started", groups = validation.config.groups,
|
logScope:
|
||||||
groupIndex = validation.config.groupIndex,
|
groups = validation.config.groups
|
||||||
currentTime = validation.clock.now,
|
groupIndex = validation.config.groupIndex
|
||||||
currentTime = validation.clock.now.fromUnix
|
trace "Validation started", currentTime = validation.clock.now,
|
||||||
|
currentTime = validation.clock.now.fromUnix
|
||||||
try:
|
try:
|
||||||
while true:
|
while true:
|
||||||
await validation.waitUntilNextPeriod()
|
await validation.waitUntilNextPeriod()
|
||||||
await validation.removeSlotsThatHaveEnded()
|
await validation.removeSlotsThatHaveEnded()
|
||||||
await validation.markProofsAsMissing()
|
await validation.markProofsAsMissing()
|
||||||
except CancelledError:
|
except CancelledError:
|
||||||
trace "Validation stopped", groups = validation.config.groups,
|
trace "Validation stopped"
|
||||||
groupIndex = validation.config.groupIndex
|
|
||||||
discard
|
discard
|
||||||
except CatchableError as e:
|
except CatchableError as e:
|
||||||
error "Validation failed", msg = e.msg, groups = validation.config.groups,
|
error "Validation failed", msg = e.msg, groups = validation.config.groups,
|
||||||
|
@ -140,27 +140,22 @@ proc epochForDurationBackFromNow(validation: Validation,
|
||||||
return validation.clock.now - duration.inSeconds
|
return validation.clock.now - duration.inSeconds
|
||||||
|
|
||||||
proc restoreHistoricalState(validation: Validation) {.async} =
|
proc restoreHistoricalState(validation: Validation) {.async} =
|
||||||
trace "Restoring historical state...", groups = validation.config.groups,
|
logScope:
|
||||||
|
groups = validation.config.groups
|
||||||
groupIndex = validation.config.groupIndex
|
groupIndex = validation.config.groupIndex
|
||||||
|
trace "Restoring historical state..."
|
||||||
let startTimeEpoch = validation.epochForDurationBackFromNow(MaxStorageRequestDuration)
|
let startTimeEpoch = validation.epochForDurationBackFromNow(MaxStorageRequestDuration)
|
||||||
let slotFilledEvents = await validation.market.queryPastSlotFilledEvents(
|
let slotFilledEvents = await validation.market.queryPastSlotFilledEvents(
|
||||||
fromTime = startTimeEpoch)
|
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:
|
for event in slotFilledEvents:
|
||||||
let slotId = slotId(event.requestId, event.slotIndex)
|
let slotId = slotId(event.requestId, event.slotIndex)
|
||||||
if validation.shouldValidateSlot(slotId):
|
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)
|
validation.slots.incl(slotId)
|
||||||
trace "Removing slots that have ended...", groups = validation.config.groups,
|
trace "Removing slots that have ended..."
|
||||||
groupIndex = validation.config.groupIndex
|
|
||||||
await removeSlotsThatHaveEnded(validation)
|
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.} =
|
proc start*(validation: Validation) {.async.} =
|
||||||
validation.periodicity = await validation.market.periodicity()
|
validation.periodicity = await validation.market.periodicity()
|
||||||
|
|
Loading…
Reference in New Issue