~/bend-docscommunity

policy/safe.bend checks

raw source on the hub · import cswap-bend-cli@0.1.0.0/policy/safe.bend as Safe

4 imports
import Base
import ./types.bend as T
import ./usage.bend as U
import ./rank.bend as R

Types

type Algo source · line 16 · raw

Data

type Cd source · line 25 · raw

Data

A candidate with its ranking key (smaller wins: k1, then k2) and its headroom. k1 None is infinity.

Definitions

def known source · line 29 · raw

@+m:Maybe<&2, Nat> -> Bool

The reading is decision-grade and carries a headroom.

def exhausted source · line 36 · raw

@+m:Maybe<&2, Nat> -> Bool

def backed_off source · line 43 · raw

@+m:Maybe<&2, 0x0717344745a30ebad1f19045228e8f18/policy/types.Usage> -> @+now:Nat -> Bool

def row.safe source · line 51 · raw

@+m:Maybe<&2, 0x0717344745a30ebad1f19045228e8f18/policy/types.Usage> -> @+now:Nat -> @+ms:List<&2, String> -> Bool

A row with a trusted headroom above zero, not in backoff.

def safe source · line 54 · raw

@+a:0x0717344745a30ebad1f19045228e8f18/policy/types.Account -> @+active:Nat -> @+us:List<&2, 0x0717344745a30ebad1f19045228e8f18/policy/types.Usage> -> @+now:Nat -> @+ms:List<&2, String> -> Bool

def h.of source · line 57 · raw

@+m:Maybe<&2, Nat> -> Nat

def rr.group.at source · line 66 · raw

@+after:Bool -> Nat

def rr.group source · line 73 · raw

@+slot:Nat -> @+active:Nat -> Nat

def key1 source · line 80 · raw

@+algo:Algo -> @+active:Nat -> @+slot:Nat -> @+reset:Maybe<&2, Nat> -> Maybe<&2, Nat>

round-robin: the next slot after the live one, wrapping to the lowest. soonest-reset: the weekly window that resets first (unknown last), then more headroom. drain-first: the least headroom (the most used). best, sticky: the most headroom. Ties go to the first account in sequence order.

def key2 source · line 89 · raw

@+algo:Algo -> @+slot:Nat -> @+h:Nat -> Nat

def key source · line 98 · raw

@+algo:Algo -> @+active:Nat -> @+slot:Nat -> @+h:Nat -> @+reset:Maybe<&2, Nat> -> Cd

def lt1 source · line 101 · raw

@+a:Maybe<&2, Nat> -> @+b:Maybe<&2, Nat> -> Bool

def cd.lt source · line 105 · raw

@+c:Cd -> @+d:Cd -> Bool

c ranks strictly before d.

def cand.need source · line 112 · raw

@+ok:Bool -> @+c:Cd -> Maybe<&2, Cd>

def cand.rows source · line 119 · raw

@+algo:Algo -> @+a:0x0717344745a30ebad1f19045228e8f18/policy/types.Account -> @+active:Nat -> @+us:List<&2, 0x0717344745a30ebad1f19045228e8f18/policy/types.Usage> -> @+now:Nat -> @+ms:List<&2, String> -> @+need:Nat -> @+m:Maybe<&2, 0x0717344745a30ebad1f19045228e8f18/policy/types.Usage> -> Maybe<&2, Cd>

def cand.go source · line 123 · raw

@+sf:Bool -> @+algo:Algo -> @+a:0x0717344745a30ebad1f19045228e8f18/policy/types.Account -> @+active:Nat -> @+us:List<&2, 0x0717344745a30ebad1f19045228e8f18/policy/types.Usage> -> @+now:Nat -> @+ms:List<&2, String> -> @+need:Nat -> Maybe<&2, Cd>

The candidate a is when it is safe and has the headroom the landing needs.

def cand source · line 130 · raw

@+algo:Algo -> @+a:0x0717344745a30ebad1f19045228e8f18/policy/types.Account -> @+active:Nat -> @+us:List<&2, 0x0717344745a30ebad1f19045228e8f18/policy/types.Usage> -> @+now:Nat -> @+ms:List<&2, String> -> @+need:Nat -> Maybe<&2, Cd>

def merge.at source · line 133 · raw

@+tail_first:Bool -> @+c:Cd -> @+d:Cd -> Maybe<&2, Cd>

def merge.some source · line 140 · raw

@+c:Cd -> @+tail:Maybe<&2, Cd> -> Maybe<&2, Cd>

def merge source · line 148 · raw

@+m:Maybe<&2, Cd> -> @+tail:Maybe<&2, Cd> -> Maybe<&2, Cd>

The head's candidate against the best of the rest; the head keeps a tie.

def pick source · line 156 · raw

@+algo:Algo -> @+as:List<&2, 0x0717344745a30ebad1f19045228e8f18/policy/types.Account> -> @+active:Nat -> @+us:List<&2, 0x0717344745a30ebad1f19045228e8f18/policy/types.Usage> -> @+now:Nat -> @+ms:List<&2, String> -> @+need:Nat -> Maybe<&2, Cd>

The best candidate in sequence order.

def name.pick source · line 165 · raw

@+hit:Bool -> @+a:Algo -> @+rest:Maybe<&2, Algo> -> Maybe<&2, Algo>

def parse source · line 173 · raw

@+s:String -> Maybe<&2, Algo>

The strategy a name stands for.

def name source · line 180 · raw

@+algo:Algo -> String

def names source · line 193 · raw

List<&2, String>

def strict source · line 198 · raw

@+algo:Algo -> Bool

best keeps the reference's engine (and its looser eligibility); the rest use pick.