pick
Pick the single child to delegate the next quantum to, or null when no child is both eligible and demanding.
The steps, all in exact rational arithmetic (design §7.3):
Candidates — edges whose
additionalNeed = targetOutstanding − outstandingis positive, each with a quantum trimmed to demand, holdings, and the caps; a zero quantum drops the edge.Parent virtual time — the weighted mean
V = Σ w·ev / Σ wover the fixed candidate set, whereevis effectiveVirtualService.Eligibility — keep candidates with
ev ≤ V. Non-empty by construction:Vis the weighted mean of these same candidates'evover strictly positive weights, somin(ev) ≤ Valways holds, and no rounding can lose the margin — the arithmetic is exact and an overflow throws rather than returning a wrong order. 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).Deadline — among the eligible, the minimum
(ev + q/w, attachmentId); the stable id is the deterministic tie-break.
Parameters
the parent's immediate children.
the round's quantum and caps.
service this peer may itself delegate right now; caps the quantum.
Throws
if step 3's eligible set is empty — a policy bug, not an input the caller can provoke (issue #1737).