pick

fun pick(edges: List<PolicyEdge>, config: PolicyConfig, localHoldings: Long): Grant?

Pick the single child to delegate the next quantum to, or null when no child is both eligible and demanding.

The steps, on each edge's position p — whole ticks of its own service, its virtual time being p / (G · w) (design §7.1, TICKS_PER_UNIT):

  1. Candidates — edges whose additionalNeed = targetOutstanding − outstanding is positive, each with a quantum trimmed to demand, holdings, and the caps; a zero quantum drops the edge.

  2. Parent virtual time — the weighted mean V = Σ w·ev / Σ w over the fixed candidate set, kept unreduced as Σ p / (G · Σ w) (VirtualTime.mean).

  3. Eligibility — keep candidates with p ≤ ⌈V · w · G⌉: ev ≤ V read on the edge's own grid, V rounded the way a seat rounds it. Non-empty by construction: V is the weighted mean of these same candidates over strictly positive weights, so the candidate with the least ev has p ≤ V · w · G, and the ceiling only widens that. An empty set would mean step 2 averaged a different set than this filter, or admitted a non-positive weight; either makes the round's whole ordering untrustworthy, so it fails loudly instead of scheduling against it (design §7.3 step 3).

  4. Deadline — among the eligible, the minimum (ev + q/w, attachmentId), compared by 128-bit cross-multiplication; the stable id is the deterministic tie-break.

Parameters

edges

the parent's immediate children.

config

the round's quantum and caps.

localHoldings

service this peer may itself delegate right now; caps the quantum. Every position here is the full 128-bit one and nothing narrows it: the mean, the eligibility bound and the deadline p + q · G are all compared wide (compareVirtualWide), so a pick orders exactly however far a child has climbed, and there is no position past which it refuses. What bounds a parent's life instead is the Long lifetime counters the positions are read from, each edge's issuance among them.

Throws

if step 3's eligible set is empty — a policy bug, not an input the caller can provoke (issue #1737).