policy/pick.bend checks
raw source on the hub · import cswap-bend-cli@0.1.0.0/policy/pick.bend as Pick
4 imports
import Base import ./types.bend as T import ./usage.bend as U import ./rank.bend as R
Types
type Fam source · line 11 · raw
Data
The family a candidate is judged in: weekly reset (consume-first), the recovery tiers (back soon, back late, one-way fallback).
FResetFam
FRec0Fam
FRec1Fam
FFallFam
type RH source · line 18 · raw
Data
A candidate's ranking time (reset or recovery; None is inf) and headroom.
RH@r:Maybe<&2, Nat> -> @h:Nat -> RH
type Pm source · line 23 · raw
Data
A pick before it is tagged with its ranking mode: nothing, or a slot with the key it won on.
PmNonePm
PmAt@slot:Nat -> @r:Maybe<&2, Nat> -> @h:Nat -> Pm
type Pk source · line 28 · raw
Data
The tagged pick.
PkNonePk
PkAt@slot:Nat -> @r:Maybe<&2, Nat> -> @h:Nat -> @mode:0x0717344745a30ebad1f19045228e8f18/policy/types.Mode -> Pk
type Rk source · line 36 · raw
Data
Everything the pickers read: the trigger, whether the strategy is consume-first, whether this is recovery mode, the active headroom (0 when unknown), the best candidate headroom, the active account's binding recovery and weekly reset, the threshold, and the selection context.
Rk@t:0x0717344745a30ebad1f19045228e8f18/policy/types.Trigger -> @cf:Bool -> @rm:Bool -> @ah0:Nat -> @best:Nat -> @ar:Maybe<&2, Nat> -> @ars:Maybe<&2, Nat> -> @thr:Nat -> @s:0x0717344745a30ebad1f19045228e8f18/policy/rank.Sel -> Rk
type Mn source · line 40 · raw
Data
The best ranking time so far among the family's candidates.
MnNoneMn
MnAt@r:Maybe<&2, Nat> -> Mn
Definitions
def need.of source · line 47 · raw
@+t:0x0717344745a30ebad1f19045228e8f18/policy/types.Trigger -> @+ah:Nat -> @+hy:Nat -> @+thr:Nat -> Nat
The least headroom a target needs: at-limit and failover take any headroom; proactive must land below the threshold and beat the active account by the hysteresis margin.
def trig.pc source · line 54 · raw
@+t:0x0717344745a30ebad1f19045228e8f18/policy/types.Trigger -> Bool
def strat.cf source · line 63 · raw
@+st:0x0717344745a30ebad1f19045228e8f18/policy/types.Strategy -> Bool
def ah.or0 source · line 70 · raw
@+ah:Maybe<&2, Nat> -> Nat
def rk.mk source · line 77 · raw
@+t:0x0717344745a30ebad1f19045228e8f18/policy/types.Trigger -> @+ah:Maybe<&2, Nat> -> @+ab:Bool -> @+best:Nat -> @+ar:Maybe<&2, Nat> -> @+ars:Maybe<&2, Nat> -> @+thr:Nat -> @+hy:Nat -> @+cf:Bool -> @+active:Nat -> @+bar:Maybe<&2, Nat> -> @+us:List<&2, 0x0717344745a30ebad1f19045228e8f18/policy/types.Usage> -> @+now:Nat -> @+ms:List<&2, String> -> Rk
def rk.bar source · line 80 · raw
@+rk:Rk -> @+bar:Maybe<&2, Nat> -> Rk
def land.gate source · line 89 · raw
@+t:0x0717344745a30ebad1f19045228e8f18/policy/types.Trigger -> @+h:Nat -> @+thr:Nat -> Bool
def reset.sooner source · line 98 · raw
@+rc:Maybe<&2, Nat> -> @+ars:Maybe<&2, Nat> -> Bool
def reset.gate source · line 105 · raw
@+t:0x0717344745a30ebad1f19045228e8f18/policy/types.Trigger -> @+rc:Maybe<&2, Nat> -> @+ars:Maybe<&2, Nat> -> Bool
def rh.if source · line 112 · raw
@+ok:Bool -> @+rc:Maybe<&2, Nat> -> @+h:Nat -> Maybe<&2, RH>
def by_recovery source · line 120 · raw
@+rc:Maybe<&2, Nat> -> @+ar:Maybe<&2, Nat> -> @+ah0:Nat -> @+best:Nat -> @+now:Nat -> Bool
Is this candidate ranked by recovery rather than by headroom?
def cdn.rec0 source · line 123 · raw
@+h:Nat -> @+rc:Maybe<&2, Nat> -> @+rk:Rk -> Maybe<&2, RH>
def cdn.rec1 source · line 130 · raw
@+h:Nat -> @+rc:Maybe<&2, Nat> -> @+rk:Rk -> Maybe<&2, RH>
def cdn.fall source · line 137 · raw
@+h:Nat -> @+rc:Maybe<&2, Nat> -> @+rk:Rk -> Maybe<&2, RH>
def cdn.reset source · line 144 · raw
@+h:Nat -> @+rc:Maybe<&2, Nat> -> @+rk:Rk -> Maybe<&2, RH>
def cdn.fam source · line 149 · raw
@+rk:Rk -> @+f:Fam -> @+h:Nat -> @+a:0x0717344745a30ebad1f19045228e8f18/policy/types.Account -> Maybe<&2, RH>
def cdn.at source · line 164 · raw
@+m:Maybe<&2, Nat> -> @+f:Fam -> @+a:0x0717344745a30ebad1f19045228e8f18/policy/types.Account -> @+rk:Rk -> Maybe<&2, RH>
def rk.sel source · line 171 · raw
@+rk:Rk -> 0x0717344745a30ebad1f19045228e8f18/policy/rank.Sel
def cdn source · line 177 · raw
@+a:0x0717344745a30ebad1f19045228e8f18/policy/types.Account -> @+rk:Rk -> @+f:Fam -> Maybe<&2, RH>
A candidate of family f, with its ranking time and headroom.
def top.step source · line 182 · raw
@+c:Maybe<&2, Nat> -> @+acc:Nat -> Nat
def top source · line 190 · raw
@+as:List<&2, 0x0717344745a30ebad1f19045228e8f18/policy/types.Account> -> @+s:0x0717344745a30ebad1f19045228e8f18/policy/rank.Sel -> @+acc:Nat -> Nat
The most headroom any candidate offers (0 when there is none).
def first.hit source · line 197 · raw
@+c:Maybe<&2, Nat> -> @+h:Nat -> Bool
def first.pick source · line 204 · raw
@+hit:Bool -> @+slot:Nat -> @+rest:Maybe<&2, Nat> -> Maybe<&2, Nat>
def first source · line 212 · raw
@+as:List<&2, 0x0717344745a30ebad1f19045228e8f18/policy/types.Account> -> @+s:0x0717344745a30ebad1f19045228e8f18/policy/rank.Sel -> @+h:Nat -> Maybe<&2, Nat>
The first account (sequence order breaks ties) whose candidate headroom is h.
def pk.slot source · line 219 · raw
@+m:Maybe<&2, Nat> -> @+r:Maybe<&2, Nat> -> @+h:Nat -> Pm
def pick.head.at source · line 226 · raw
@+h0:Nat -> @+as:List<&2, 0x0717344745a30ebad1f19045228e8f18/policy/types.Account> -> @+s:0x0717344745a30ebad1f19045228e8f18/policy/rank.Sel -> Pm
def pick.head source · line 233 · raw
@+as:List<&2, 0x0717344745a30ebad1f19045228e8f18/policy/types.Account> -> @+s:0x0717344745a30ebad1f19045228e8f18/policy/rank.Sel -> Pm
def mn.min source · line 238 · raw
@+m:Mn -> @+r:Maybe<&2, Nat> -> Mn
def minr.step source · line 245 · raw
@+c:Maybe<&2, RH> -> @+m:Mn -> Mn
def minr source · line 255 · raw
@+as:List<&2, 0x0717344745a30ebad1f19045228e8f18/policy/types.Account> -> @+rk:Rk -> @+f:Fam -> @+m:Mn -> Mn
The earliest ranking time among the family's candidates.
def maxh.pick source · line 262 · raw
@+hit:Bool -> @+h:Nat -> @+acc:Nat -> Nat
def maxh.step source · line 269 · raw
@+c:Maybe<&2, RH> -> @+r0:Maybe<&2, Nat> -> @+acc:Nat -> Nat
def maxh source · line 279 · raw
@+as:List<&2, 0x0717344745a30ebad1f19045228e8f18/policy/types.Account> -> @+rk:Rk -> @+f:Fam -> @+r0:Maybe<&2, Nat> -> @+acc:Nat -> Nat
The most headroom among the family's candidates whose time is r0.
def maxall.step source · line 286 · raw
@+c:Maybe<&2, RH> -> @+acc:Nat -> Nat
def maxall source · line 296 · raw
@+as:List<&2, 0x0717344745a30ebad1f19045228e8f18/policy/types.Account> -> @+rk:Rk -> @+f:Fam -> @+acc:Nat -> Nat
The most headroom among the family's candidates.
def minat.pick source · line 303 · raw
@+hit:Bool -> @+r:Maybe<&2, Nat> -> @+m:Mn -> Mn
def minat.step source · line 310 · raw
@+c:Maybe<&2, RH> -> @+h0:Nat -> @+m:Mn -> Mn
def minat source · line 320 · raw
@+as:List<&2, 0x0717344745a30ebad1f19045228e8f18/policy/types.Account> -> @+rk:Rk -> @+f:Fam -> @+h0:Nat -> @+m:Mn -> Mn
The earliest time among the family's candidates with headroom h0.
def firstrh.hit source · line 327 · raw
@+c:Maybe<&2, RH> -> @+r0:Maybe<&2, Nat> -> @+h0:Nat -> Bool
def firstrh source · line 337 · raw
@+as:List<&2, 0x0717344745a30ebad1f19045228e8f18/policy/types.Account> -> @+rk:Rk -> @+f:Fam -> @+r0:Maybe<&2, Nat> -> @+h0:Nat -> Maybe<&2, Nat>
The first account whose key is exactly (r0, h0).
def pick.rh.go source · line 344 · raw
@+h0:Nat -> @+r0:Maybe<&2, Nat> -> @+as:List<&2, 0x0717344745a30ebad1f19045228e8f18/policy/types.Account> -> @+rk:Rk -> @+f:Fam -> Pm
def pick.rh.at source · line 347 · raw
@+m:Mn -> @+as:List<&2, 0x0717344745a30ebad1f19045228e8f18/policy/types.Account> -> @+rk:Rk -> @+f:Fam -> Pm
def pick.rh source · line 355 · raw
@+as:List<&2, 0x0717344745a30ebad1f19045228e8f18/policy/types.Account> -> @+rk:Rk -> @+f:Fam -> Pm
Earliest time first, then most headroom, then sequence order.
def pick.hr.go source · line 358 · raw
@+m:Mn -> @+h0:Nat -> @+as:List<&2, 0x0717344745a30ebad1f19045228e8f18/policy/types.Account> -> @+rk:Rk -> @+f:Fam -> Pm
def pick.hr.at source · line 365 · raw
@+h0:Nat -> @+as:List<&2, 0x0717344745a30ebad1f19045228e8f18/policy/types.Account> -> @+rk:Rk -> @+f:Fam -> Pm
def pick.hr source · line 373 · raw
@+as:List<&2, 0x0717344745a30ebad1f19045228e8f18/policy/types.Account> -> @+rk:Rk -> @+f:Fam -> Pm
Most headroom first, then earliest time, then sequence order.
def pk.of source · line 376 · raw
@+mode:0x0717344745a30ebad1f19045228e8f18/policy/types.Mode -> @+p:Pm -> Pk
def pick.rec.late source · line 383 · raw
@+p1:Pm -> @+as:List<&2, 0x0717344745a30ebad1f19045228e8f18/policy/types.Account> -> @+rk:Rk -> Pk
def pick.rec.mid source · line 390 · raw
@+p0:Pm -> @+as:List<&2, 0x0717344745a30ebad1f19045228e8f18/policy/types.Account> -> @+rk:Rk -> Pk
def pick.rec source · line 399 · raw
@+as:List<&2, 0x0717344745a30ebad1f19045228e8f18/policy/types.Account> -> @+rk:Rk -> Pk
Recovery mode: back-soon candidates by soonest recovery, else back-late ones by headroom, else the one-way fallback.
def rk.cf source · line 402 · raw
@+rk:Rk -> Bool
def rk.rm source · line 407 · raw
@+rk:Rk -> Bool
def pick.cf source · line 412 · raw
@+cf:Bool -> @+as:List<&2, 0x0717344745a30ebad1f19045228e8f18/policy/types.Account> -> @+rk:Rk -> Pk
def pick.fam source · line 419 · raw
@+rm:Bool -> @+as:List<&2, 0x0717344745a30ebad1f19045228e8f18/policy/types.Account> -> @+rk:Rk -> Pk
def pick source · line 427 · raw
@+as:List<&2, 0x0717344745a30ebad1f19045228e8f18/policy/types.Account> -> @+rk:Rk -> Pk
The oauth pick for one ranking context.
def rk.active source · line 430 · raw
@+rk:Rk -> Nat
def rk.us source · line 437 · raw
@+rk:Rk -> List<&2, 0x0717344745a30ebad1f19045228e8f18/policy/types.Usage>
def rk.now source · line 444 · raw
@+rk:Rk -> Nat
def rk.ms source · line 451 · raw
@+rk:Rk -> List<&2, String>
def rk.bar_of source · line 458 · raw
@+rk:Rk -> Maybe<&2, Nat>