From 0a6845b05108a8975e1a59293d6a15165978efa7 Mon Sep 17 00:00:00 2001 From: joshieDo <93316087+joshieDo@users.noreply.github.com> Date: Sun, 22 Sep 2024 18:47:37 +0200 Subject: [PATCH] fix(cli): handle case when first transaction range is `None` on `reth db stats` (#11107) --- crates/cli/commands/src/db/stats.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/crates/cli/commands/src/db/stats.rs b/crates/cli/commands/src/db/stats.rs index 31af95c81e0f..76fb69b4a956 100644 --- a/crates/cli/commands/src/db/stats.rs +++ b/crates/cli/commands/src/db/stats.rs @@ -263,10 +263,18 @@ impl Command { let block_range = SegmentRangeInclusive::new(first_ranges.0.start(), last_ranges.0.end()); - let tx_range = first_ranges - .1 - .zip(last_ranges.1) - .map(|(first, last)| SegmentRangeInclusive::new(first.start(), last.end())); + + // Transaction ranges can be empty, so we need to find the first and last which are + // not. + let tx_range = { + let start = ranges + .iter() + .find_map(|(_, tx_range)| tx_range.map(|r| r.start())) + .unwrap_or_default(); + let end = + ranges.iter().rev().find_map(|(_, tx_range)| tx_range.map(|r| r.end())); + end.map(|end| SegmentRangeInclusive::new(start, end)) + }; let mut row = Row::new(); row.add_cell(Cell::new(segment))