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 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
Describe the bug
Controller.CommitCertificaterecords commit-processing telemetry with a deferred call whose duration is evaluated eagerly:Deferred call arguments are evaluated when the
deferstatement runs, not at return. Sotime.Since(start)is computed at line 337, before theblock that follows. That loop calls
FSM.LoadRootChainInfoper 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
CommitCertificateParallelalready does this correctly at line 364 with a closure, and its comment documents the intended semantics.Steps to reproduce
main(observed at commit 7d1d955), run:go vet ./controller/...Expected behavior
The commit telemetry duration should be measured at return time so it covers the full
CommitCertificatebody, including the root-chain publish loop after line 337, andgo vetshould 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
main, commit 7d1d955go vet(standard Go toolchain); repo CI does not currently rungo vetor a linterAdditional context
Suggested fix, matching the sibling
CommitCertificateParallel:This is the only eager
time.Since-in-deferin the repo; every other site already uses the closure form. Happy to open a PR if this looks right.Required Tags