Skip to content

Commit

Permalink
chore: improve log information (#656)
Browse files Browse the repository at this point in the history
* Add proof downtime to validator logs

* Add previous state to state machine transition log
  • Loading branch information
emizzle authored Dec 19, 2023
1 parent 39554c8 commit 2c621e0
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 2 deletions.
7 changes: 7 additions & 0 deletions codex/contracts/market.nim
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ method proofTimeout*(market: OnChainMarket): Future[UInt256] {.async.} =
let config = await market.contract.config()
return config.proofs.timeout

method proofDowntime*(market: OnChainMarket): Future[uint8] {.async.} =
let config = await market.contract.config()
return config.proofs.downtime

method getPointer*(market: OnChainMarket, slotId: SlotId): Future[uint8] {.async.} =
return await market.contract.getPointer(slotId)

method myRequests*(market: OnChainMarket): Future[seq[RequestId]] {.async.} =
return await market.contract.myRequests

Expand Down
11 changes: 11 additions & 0 deletions codex/market.nim
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ method periodicity*(market: Market): Future[Periodicity] {.base, async.} =
method proofTimeout*(market: Market): Future[UInt256] {.base, async.} =
raiseAssert("not implemented")

method proofDowntime*(market: Market): Future[uint8] {.base, async.} =
raiseAssert("not implemented")

method getPointer*(market: Market, slotId: SlotId): Future[uint8] {.base, async.} =
raiseAssert("not implemented")

proc inDowntime*(market: Market, slotId: SlotId): Future[bool] {.async.} =
let downtime = await market.proofDowntime
let pntr = await market.getPointer(slotId)
return pntr < downtime

method requestStorage*(market: Market,
request: StorageRequest) {.base, async.} =
raiseAssert("not implemented")
Expand Down
3 changes: 2 additions & 1 deletion codex/utils/asyncstatemachine.nim
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ proc scheduler(machine: Machine) {.async.} =
if next =? event(machine.state):
if not running.isNil and not running.finished:
await running.cancelAndWait()
let fromState = if machine.state.isNil: "<none>" else: $machine.state
machine.state = next
debug "enter state", state = machine.state
debug "enter state", state = machine.state, fromState
running = machine.run(machine.state)
running
.track(machine)
Expand Down
4 changes: 3 additions & 1 deletion codex/validation.nim
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ proc markProofAsMissing(validation: Validation,
if await validation.market.canProofBeMarkedAsMissing(slotId, period):
trace "Marking proof as missing", slotId = $slotId, periodProofMissed = period
await validation.market.markProofAsMissing(slotId, period)
else: trace "Proof not missing", checkedPeriod = period
else:
let inDowntime {.used.} = await validation.market.inDowntime(slotId)
trace "Proof not missing", checkedPeriod = period, inDowntime
except CancelledError:
raise
except CatchableError as e:
Expand Down
6 changes: 6 additions & 0 deletions tests/codex/helpers/mockmarket.nim
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ method periodicity*(mock: MockMarket): Future[Periodicity] {.async.} =
method proofTimeout*(market: MockMarket): Future[UInt256] {.async.} =
return market.config.proofs.timeout

method proofDowntime*(market: MockMarket): Future[uint8] {.async.} =
return market.config.proofs.downtime

method getPointer*(market: MockMarket, slotId: SlotId): Future[uint8] {.async.} =
return 0 # TODO

method requestStorage*(market: MockMarket, request: StorageRequest) {.async.} =
market.requested.add(request)
var subscriptions = market.subscriptions.onRequest
Expand Down

0 comments on commit 2c621e0

Please sign in to comment.