Skip to content

Commit 0037e5d

Browse files
committed
Implemented quorum propagation
1 parent f4d8649 commit 0037e5d

File tree

2 files changed

+14
-17
lines changed

2 files changed

+14
-17
lines changed

analysis/markov/Linleios/Evolve.lean

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -63,27 +63,23 @@ def pQuorum (pSuccessfulVote committeeSize τ : Float) : Float :=
6363
let ⟨ μ , σ ⟩ := committeeDistribution pSuccessfulVote committeeSize
6464
1 - cdfGaussian (τ * committeeSize) μ σ
6565

66-
#eval pQuorum 0.90 600 0.75
67-
6866

6967
structure Environment where
7068
activeSlotCoefficient : Probability
7169
Lheader : Nat
7270
Lvote : Nat
7371
Ldiff : Nat
7472
pSpacingOkay : Probability
75-
pRbHeaderArrives : Probability
76-
pEbValidates : Probability
73+
pQuorum : Probability
7774

78-
def makeEnvironment (activeSlotCoefficient pRbHeaderArrives pEbValidates : Float) (Lheader Lvote Ldiff : Nat) : Environment :=
75+
def makeEnvironment (activeSlotCoefficient pRbHeaderArrives pEbValidates committeeSize τ : Float) (Lheader Lvote Ldiff : Nat) : Environment :=
7976
{
8077
activeSlotCoefficient := activeSlotCoefficient
8178
Lheader := Lheader
8279
Lvote := Lvote
8380
Ldiff := Ldiff
8481
pSpacingOkay := (1 - activeSlotCoefficient).pow (3 * Lheader + Lvote + Ldiff - 1).toFloat
85-
pRbHeaderArrives := pRbHeaderArrives
86-
pEbValidates := pEbValidates
82+
pQuorum := pQuorum (pRbHeaderArrives * pEbValidates) committeeSize τ
8783
}
8884

8985

@@ -93,9 +89,10 @@ structure State where
9389
canCertify : Bool
9490
deriving Repr, BEq, Hashable, Inhabited
9591

96-
example : (default : State).rbCount = 0 := rfl
97-
98-
example : (default : State).ebCount = 0 := rfl
92+
theorem genesis : (default : State).rbCount = 0 ∧ (default : State).ebCount = 0 := by
93+
constructor
94+
rfl
95+
rfl
9996

10097

10198
def Probabilities := HashMap State Probability
@@ -108,7 +105,7 @@ instance : Inhabited Probabilities where
108105
abbrev Outcomes := List (State × Probability)
109106

110107

111-
def forge {env : Environment} (state : State) : Outcomes :=
108+
def certify {env : Environment} (state : State) : Outcomes :=
112109
let state' :=
113110
{
114111
state with
@@ -122,14 +119,14 @@ def forge {env : Environment} (state : State) : Outcomes :=
122119
]
123120
else [(state', 1)]
124121

125-
def validate {env : Environment} (state : State) : Outcomes :=
122+
def vote {env : Environment} (state : State) : Outcomes :=
126123
[
127-
(state, env.pRbHeaderArrives * env.pEbValidates)
128-
, ({state with canCertify := false}, 1 - env.pRbHeaderArrives * env.pEbValidates)
124+
(state, env.pQuorum)
125+
, ({state with canCertify := false}, 1 - env.pQuorum)
129126
]
130127

131128
def step {env : Environment} : List (State → Outcomes) :=
132-
[@forge env, @validate env]
129+
[@certify env, @vote env]
133130

134131

135132
def evolve (transition : State → Outcomes) : Probabilities → Probabilities :=

analysis/markov/Main.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
import Linleios
33

44

5-
def env : Environment := makeEnvironment 0.05 0.95 0.90 1 4 7
5+
def env : Environment := makeEnvironment 0.05 0.95 0.90 600 0.75 1 4 7
66

77
def s0 : Probabilities := default
8-
def sn := simulate env s0 10
8+
def sn := simulate env s0 2
99
def pn := totalProbability sn
1010

1111
def main : IO Unit :=

0 commit comments

Comments
 (0)