Acquire EB closure age - #2249
Conversation
| traceWith ktracer $ TraceLeiosBlockAcquired point | ||
| forM_ completedByBody $ traceWith ktracer . TraceLeiosBlockTxsAcquired | ||
| forM_ completedByBody $ \completedPoint -> do | ||
| age <- ebAge completedPoint.pointSlotNo |
There was a problem hiding this comment.
Getting ahold of the immutable tip each time here just for the sake of logging feels weird. Good enough for a prototype, but we probably could just figure out the wall clock time of the announcement once (we need to judge it coming late anyways) and just take the diff to that here.
There was a problem hiding this comment.
I asked claude:
This is already a known gap, not solved anywhere: InFutureCheck.hs:147-151's judgeHeaderArrival has the identical pattern — recompute
hardForkSummary/runQuery on every header — with a literal -- TODO cache this in the KnownIntersectionState? Or even in the LedgerDB? sitting unresolved. I
checked for a shared "cached interpreter" utility (mkInterpreter call sites, GetInterpreter handling) — the only other place that builds one is the
local-state-query handler (HardFork/Combinator/Ledger/Query.hs:530), which is also on-demand, not cached. So there's nothing to reuse; we'd be writing the
first instance of this pattern.
This can be fixed locally in newSlotAge by reusing the interpreter until it fails, and then caching it again, e.g.
newSlotAge ::
(IOLike m, HasHardForkHistory blk) =>
SystemTime m ->
TopLevelConfig blk ->
m (ExtLedgerState blk EmptyMK) ->
m (SlotNo -> m NominalDiffTime)
newSlotAge systemTime cfg getLedger = do
cacheVar <- StrictSTM.newTVarIO =<< mkInterp
pure $ \slot -> do
now <- systemTimeCurrent systemTime
interp <- StrictSTM.readTVarIO cacheVar
onset <- case interpretQuery interp (HardFork.slotToWallclock slot) of
Right (onset, _slotLength) -> pure onset
Left _pastHorizon -> do
interp' <- mkInterp
StrictSTM.atomically $ StrictSTM.writeTVar cacheVar interp'
fst <$> HardFork.runQueryThrow (HardFork.slotToWallclock slot) -- via interp', see note below
pure $ now `diffRelTime` onset
where
mkInterp = mkInterpreter . hardForkSummary (configLedger cfg) . ledgerState <$> getLedger@nfrisby what do think?
There was a problem hiding this comment.
I feel it doesn't fit into this PR to fix the general problem, but I could do a separate one.
There was a problem hiding this comment.
This is not what I worried about, neither what I suggested.
we probably could just figure out the wall clock time of the announcement once
Was meant to move the slot to wall clock time conversion into where we process (or create) announcements. Then, all the dependent timings we want to trace (when we acquired the corresponding EB body, closure, when we voted on it etc.) would just be relative to that point in time (ideally using a monotonic clock).
Either way, no change needed in this PR.
Added `NominalDiffTime` to `TraceLeiosBlockTxsAcquired`. This will allow us to compute 90, 95 and 99 percentiles of how long it takes to acquire all txs announced in an EB.
00eacfc to
b7e2b75
Compare
Description
Added
NominalDiffTimetoTraceLeiosBlockTxsAcquired. This willallow us to compute 90, 95 and 99 percentiles of how long it takes to acquire
all txs announced in an EB.
WARNING
To update your feature branch if it's stale, please rebase it manually on top of
main. Don't update your feature branch by mergingmaininto it. Your pull request will not pass CI if you do.