| 941 | } |
| 942 | |
| 943 | fn prune_safe(&mut self, safe_l2_number: u64) { |
| 944 | // Count how many leading blocks are both safe (number <= safe_l2_number) and |
| 945 | // already past the encoding cursor (index < block_cursor). We must not prune |
| 946 | // blocks that haven't been fed into a channel yet or we'd silently skip them. |
| 947 | let prune_count = self |
| 948 | .blocks |
| 949 | .iter() |
| 950 | .take(self.block_cursor) |
| 951 | .take_while(|b| b.header.number <= safe_l2_number) |
| 952 | .count(); |
| 953 | |
| 954 | if prune_count == 0 { |
| 955 | return; |
| 956 | } |
| 957 | |
| 958 | debug!(prune_count, safe_l2_number, "pruning safe blocks from input queue"); |
| 959 | |
| 960 | self.blocks.drain(..prune_count); |
| 961 | self.block_cursor -= prune_count; |
| 962 | BatcherMetrics::pending_blocks().decrement(prune_count as f64); |
| 963 | |
| 964 | // Adjust block_range high-water marks in ready channels so that confirm() |
| 965 | // does not over-prune later. This mirrors the adjustment in confirm(). |
| 966 | for ch in &mut self.ready_channels { |
| 967 | ch.block_range.end = ch.block_range.end.saturating_sub(prune_count); |
| 968 | ch.encoded_block_range.start = ch.encoded_block_range.start.saturating_sub(prune_count); |
| 969 | ch.encoded_block_range.end = ch.encoded_block_range.end.saturating_sub(prune_count); |
| 970 | } |
| 971 | } |
| 972 | |
| 973 | fn da_backlog_bytes(&self) -> u64 { |
| 974 | let pending_blocks = self |