From 2c621e0421810c655a7584d2bd10f0faa7137284 Mon Sep 17 00:00:00 2001 From: Eric <5089238+emizzle@users.noreply.github.com> Date: Tue, 19 Dec 2023 15:29:18 +1100 Subject: [PATCH] chore: improve log information (#656) * Add proof downtime to validator logs * Add previous state to state machine transition log --- codex/contracts/market.nim | 7 +++++++ codex/market.nim | 11 +++++++++++ codex/utils/asyncstatemachine.nim | 3 ++- codex/validation.nim | 4 +++- tests/codex/helpers/mockmarket.nim | 6 ++++++ 5 files changed, 29 insertions(+), 2 deletions(-) diff --git a/codex/contracts/market.nim b/codex/contracts/market.nim index 413262cc..538b44ac 100644 --- a/codex/contracts/market.nim +++ b/codex/contracts/market.nim @@ -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 diff --git a/codex/market.nim b/codex/market.nim index b9a7651a..bf78ddeb 100644 --- a/codex/market.nim +++ b/codex/market.nim @@ -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") diff --git a/codex/utils/asyncstatemachine.nim b/codex/utils/asyncstatemachine.nim index 27d09b64..512617ee 100644 --- a/codex/utils/asyncstatemachine.nim +++ b/codex/utils/asyncstatemachine.nim @@ -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: "" 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) diff --git a/codex/validation.nim b/codex/validation.nim index a3f69296..2be39975 100644 --- a/codex/validation.nim +++ b/codex/validation.nim @@ -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: diff --git a/tests/codex/helpers/mockmarket.nim b/tests/codex/helpers/mockmarket.nim index 22d62e1d..f0d8e967 100644 --- a/tests/codex/helpers/mockmarket.nim +++ b/tests/codex/helpers/mockmarket.nim @@ -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