Skip to content

Commit ba5a1ba

Browse files
authored
Fix divide by zero in log_basic_stats (#3633)
1 parent 655dff0 commit ba5a1ba

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

crates/hotshot/task-impls/src/stats.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,13 @@ impl<TYPES: NodeType> StatsTaskState<TYPES> {
186186

187187
fn log_basic_stats(&self, now: i128, epoch: &TYPES::Epoch) {
188188
let num_views = self.latencies_by_view.len();
189+
let total_size = self.sizes_by_view.values().sum::<i128>();
190+
191+
// Either we have no views logged yet, no TXNs or we are not in the DA committee and don't know block sizes
192+
if num_views == 0 || total_size == 0 {
193+
return;
194+
}
195+
189196
let total_latency = self.latencies_by_view.values().sum::<i128>();
190197
let average_latency = total_latency / num_views as i128;
191198
tracing::warn!("Average latency: {}ms", average_latency);
@@ -194,11 +201,6 @@ impl<TYPES: NodeType> StatsTaskState<TYPES> {
194201
epoch,
195202
self.timeouts.len()
196203
);
197-
let total_size = self.sizes_by_view.values().sum::<i128>();
198-
if total_size == 0 {
199-
// Either no TXNs or we are not in the DA committee and don't know block sizes
200-
return;
201-
}
202204
if let Some(epoch_start_time) = self.epoch_start_times.get(epoch) {
203205
let elapsed_time = now - epoch_start_time;
204206
// multiply by 1000 to convert to seconds

0 commit comments

Comments
 (0)