11
2+ import Cli
23import Linleios
4+ import Parser.Char.Numeric
5+ import Parser.Stream
36
7+ open Cli
48
5- def env : Environment := makeEnvironment 0 .05 0 .95 0 .90 600 0 .75 1 4 7
69
7- def sn := simulate env default 1e-6 25
10+ instance : ParseableType Float where
11+ name := "Float"
12+ parse? x := match (Parser.Char.ASCII.parseFloat : SimpleParser Substring Char Float).run x with
13+ | .ok _ y => some y
14+ | _ => none
815
9- def main : IO Unit :=
16+
17+ def runMarkovCmd (p : Parsed) : IO UInt32 :=
1018 do
19+ let activeSlotCoefficient : Float := p.flag! "active-slot-coefficient" |>.as! Float
20+ let Lheader : Nat := p.flag! "l-header" |>.as! Nat
21+ let Lvote : Nat := p.flag! "l-vote" |>.as! Nat
22+ let Ldiff : Nat := p.flag! "l-diff" |>.as! Nat
23+ let committeeSize : Nat := p.flag! "committee-size" |>.as! Nat
24+ let τ : Float := p.flag! "quorum-fraction" |>.as! Float
25+ let pRbHeaderArrives : Float := p.flag! "p-rb-header-arrives" |>.as! Float
26+ let pEbValidates : Float := p.flag! "p-eb-validates" |>.as! Float
27+ let ε : Float := p.flag! "tolerance" |>.as! Float
28+ let rbCount : Nat := p.flag! "rb-count" |>.as! Nat
29+ let env := makeEnvironment activeSlotCoefficient pRbHeaderArrives pEbValidates committeeSize.toFloat τ Lheader Lvote Ldiff
30+ let sn := simulate env default ε rbCount
1131 let print {α : Type } [Repr α] (x : α) : IO Unit := IO.println (reprPrec x 0 ).pretty
1232 IO.println ""
1333 print sn
@@ -17,3 +37,37 @@ def main : IO Unit :=
1737 print $ ebEfficiency sn
1838 IO.println ""
1939 print $ 1 - totalProbability sn
40+ pure 0
41+
42+ def markovCmd : Cmd := `[Cli|
43+ markovCmd VIA runMarkovCmd; ["0.0.1" ]
44+ "Run a Markov simulation of Linear Leios."
45+ FLAGS:
46+ "active-slot-coefficient" : Float ; "The active slot coefficient for RBs, in probability per slot."
47+ "l-header" : Nat ; "L_header protocol parameter, in slots."
48+ "l-vote" : Nat ; "L_vote protocol parameter, in slots."
49+ "l-diff" : Nat ; "L_diff protocol parameter, in slots."
50+ "committee-size" : Nat ; "Expected number of voters in the committee."
51+ "quorum-fraction" : Float ; "τ protocol parameter, in %/100."
52+ "p-rb-header-arrives" : Float ; "Probability that the RB header arrives before L_header."
53+ "p-eb-validates" : Float ; "Probability that the EB is fully validated before 3 L_header + L_vote."
54+ "tolerance" : Float ; "Discard states with less than this probability."
55+ "rb-count" : Nat ; "Number of RBs to simulate."
56+ EXTENSIONS:
57+ author "bwbush" ;
58+ defaultValues! #[
59+ ("active-slot-coefficient" , "0.05" )
60+ , ("l-header" , "1" )
61+ , ("l-vote" , "4" )
62+ , ("l-diff" , "7" )
63+ , ("committee-size" , "600" )
64+ , ("quorum-fraction" , "0.75" )
65+ , ("p-rb-header-arrives" , "0.95" )
66+ , ("p-eb-validates" , "0.90" )
67+ , ("tolerance" , "1e-9" )
68+ , ("rb-count" , "100" )
69+ ]
70+ ]
71+
72+ def main (args : List String) : IO UInt32 :=
73+ markovCmd.validate args
0 commit comments