CommitCertificate telemetry duration excludes root-chain publish work (eager time.Since in defer)
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
- On
main(observed at commit 7d1d955), run:go vet ./controller/... - Observe:
controller/block.go:337:37: call to time.Since is not deferredExpected 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 rungo vetor 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
Source: canopy-network/canopy