canopy icon indicating copy to clipboard operation
canopy copied to clipboard

CommitCertificate telemetry duration excludes root-chain publish work (eager time.Since in defer)

Open midasbal opened this issue 3 months ago • 2 comments

Describe the bug

Controller.CommitCertificate records commit-processing telemetry with a deferred call whose duration is evaluated eagerly:

// controller/block.go:337
defer c.UpdateTelemetry(qc, block, time.Since(start))

Deferred call arguments are evaluated when the defer statement runs, not at return. So time.Since(start) is computed at line 337, before the

if !syncing { for _, id := range c.RCManager.ChainIds() { ... } }

block that follows. That loop calls FSM.LoadRootChainInfo per root chain, which the codebase itself treats as potentially slow (lib.TimeTrack(..., 750*time.Millisecond)), so its duration is excluded from the recorded telemetry. The effect scales with the number of registered root chains and is nil for a node with none.

The sibling CommitCertificateParallel already does this correctly at line 364 with a closure, and its comment documents the intended semantics.

Steps to reproduce

  1. On main (observed at commit 7d1d955), run: go vet ./controller/...
  2. Observe:
controller/block.go:337:37: call to time.Since is not deferred

Expected behavior

The commit telemetry duration should be measured at return time so it covers the full CommitCertificate body, including the root-chain publish loop after line 337, and go vet should report nothing on that line. Currently the duration is captured at line 337 and the trailing work is excluded.

Screenshots

N/A (static-analysis finding, no UI).

Environment

  • OS: N/A (source-level, platform-independent)
  • Software Version: main, commit 7d1d955
  • Other relevant environment info: found via go vet (standard Go toolchain); repo CI does not currently run go vet or a linter

Additional context

Suggested fix, matching the sibling CommitCertificateParallel:

defer func() { c.UpdateTelemetry(qc, block, time.Since(start)) }()

This is the only eager time.Since-in-defer in the repo; every other site already uses the closure form. Happy to open a PR if this looks right.

Required Tags

  • Priority: Low
  • Module: Consensus

midasbal avatar Aug 27 '26 22:08 midasbal

Clean catch. One operational note: anything downstream treating this duration as total commit latency has been reading a number that excludes the publish loop, and the gap grows with root-chain count. When the closure fix lands, the metric's meaning changes overnight. Worth a heads-up wherever this feeds dashboards or alerts, or the fix looks like a latency regression.

exocognosis avatar Oct 15 '26 12:10 exocognosis

Agreed. The fix raises the reported duration on nodes with registered root chains since it now includes the publish loop, so it is a measurement correction rather than a regression. I will note that continuity caveat in the PR so anyone keying alerts off this value sees it. PR incoming.

midasbal avatar Oct 15 '26 19:10 midasbal