Skip to main content

split_range

Function split_range 

Source
pub fn split_range(
    ranges: &[AvailableRange],
    requested: SlotRange,
    kind: BundleKind,
) -> Result<Vec<(u64, u64)>, String>
Expand description

Split a user-requested [start_slot, end_slot] range across the available bundle ranges, returning a list of contiguous, non-overlapping (start, end) pairs — one per bundle that the server can serve as its own session.

Each emitted start is a real bundle_start_slot and each end is within the max_bundle_end_slot of a bundle that begins exactly at that start (the server requires start_slot == bundle_start_slot and caps end_slot at that bundle’s max_bundle_end_slot). Among all such gap-free splits we pick the one with the most sub-ranges, i.e. the highest parallelism: a fine-grained (e.g. 10k) bundle grid yields one session per fine bundle instead of collapsing onto a coarser series that overlaps the same slots — even when the coarse and fine bundles share a start slot. A coarser bundle is only ridden where no finer grid continues the walk, which still lets us serve a request the coarse data covers even across a hole in the fine grid.

kind picks which bundles the split rides; the walk itself is the same for either, since a recording is read slot by slot exactly as a block bundle is. An unlabelled range, from a server predating AvailableRange::kind, counts as BundleKind::Blocks.

Returns an error if the requested start cannot anchor, or if no gap-free split reaches requested_end.