Skip to content

Acquire EB closure age - #2249

Open
coot wants to merge 1 commit into
leios-prototypefrom
coot/acquire-eb-closure-age
Open

Acquire EB closure age#2249
coot wants to merge 1 commit into
leios-prototypefrom
coot/acquire-eb-closure-age

Conversation

@coot

@coot coot commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Description

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.

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 merging main into it. Your pull request will not pass CI if you do.

Comment thread ouroboros-consensus/src/ouroboros-consensus/LeiosDemoTypes.hs Outdated
traceWith ktracer $ TraceLeiosBlockAcquired point
forM_ completedByBody $ traceWith ktracer . TraceLeiosBlockTxsAcquired
forM_ completedByBody $ \completedPoint -> do
age <- ebAge completedPoint.pointSlotNo

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel it doesn't fit into this PR to fix the general problem, but I could do a separate one.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@coot
coot force-pushed the coot/acquire-eb-closure-age branch from 00eacfc to b7e2b75 Compare August 28, 2026 12:16
@ch1bo

ch1bo commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

Seems like @nfrisby did the same in his #2237 work in 831a3c0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants