2838 | - LogPrint(BCLog::BENCH, " - Load block from disk: %.2fms [%.2fs (%.2fms/blk)]\n",
2839 | - Ticks<MillisecondsDouble>(time_2 - time_1),
2840 | - Ticks<SecondsDouble>(time_read_from_disk_total),
2841 | - Ticks<MillisecondsDouble>(time_read_from_disk_total) / num_blocks_total);
2842 | + // When adding aggregate statistics in the future, keep in mind that
2843 | + // num_blocks_total may be zero until the ConnectBlock() call below.
Fwiw I think this warning is useful because many of the bench logs use / num_blocks_total and there's a assert(num_blocks_total > 0) just a few lines down.
I'd say it would be fine to move the ++num_blocks_total; to this line instead, and the assert as well. Self-documenting code is better than potentially outdated docs.
We also call ConnectTip() from TestBlockValidity() and VerifyDB(). Do you know how the counter is supposed to behave in those cases?
Maybe all globals can be moved to function scope and the num_blocks_total can be duplicated to both functions where it is used?
This would ensure that the counts in one function do not affect the counts in another, given that they are not guaranteed to be equal.
Happy to review such a change, but I barely remember making the original PR and am not very familiar with the bench logging.