Skip to main content

prune_for_consistency

Function prune_for_consistency 

Source
pub fn prune_for_consistency(
    candidates: Vec<PathWithMetrics>,
    floor: usize,
    hops: usize,
) -> Vec<PathWithMetrics>
Expand description

Trim the candidate set to lower median latency and minimise variance while preserving an anonymity floor.

Behaviour:

  • If candidates.len() <= floor, returns all candidates unchanged (min(found_count, floor) semantics — the floor is never a minimum to fabricate).
  • Sorts candidates with a known total_latency_ms ascending.
  • Drops from the high-latency tail until the total count equals floor, or until no populated candidates remain.
  • If still over the floor with no populated candidates left, drops unpopulated candidates from the input-order tail.

A path is “fully measured” — and therefore preferred over unmeasured alternatives — when total_latency_ms is known AND either hops == 0 (direct path, no channel expected) OR capacity_floor is also known. This prevents 0-hop direct paths from being demoted simply because they carry no channel-capacity data.