|
| 1 | +{-# OPTIONS --safe #-} |
| 2 | + |
| 3 | +open import Leios.Prelude hiding (id) |
| 4 | +open import Leios.FFD |
| 5 | +open import Leios.SpecStructure |
| 6 | +open import Data.Fin.Patterns |
| 7 | + |
| 8 | +module Leios.UniformShort (⋯ : SpecStructure 1) |
| 9 | + (let open SpecStructure ⋯ renaming (isVoteCertified to isVoteCertified')) where |
| 10 | + |
| 11 | +data SlotUpkeep : Type where |
| 12 | + Base IB-Role EB-Role V-Role : SlotUpkeep |
| 13 | + |
| 14 | +allUpkeep : ℙ SlotUpkeep |
| 15 | +allUpkeep = fromList (Base ∷ IB-Role ∷ EB-Role ∷ V-Role ∷ []) |
| 16 | + |
| 17 | +open import Leios.Protocol (⋯) SlotUpkeep public |
| 18 | + |
| 19 | +open BaseAbstract B' using (Cert; V-chkCerts; VTy; initSlot) |
| 20 | +open FFD hiding (_-⟦_/_⟧⇀_) |
| 21 | +open GenFFD |
| 22 | + |
| 23 | +isVoteCertified : LeiosState → EndorserBlock → Type |
| 24 | +isVoteCertified s eb = isVoteCertified' (LeiosState.votingState s) (0F , eb) |
| 25 | + |
| 26 | +module Protocol where |
| 27 | + |
| 28 | + private variable s s' : LeiosState |
| 29 | + ffds' : FFD.State |
| 30 | + π : VrfPf |
| 31 | + bs' : B.State |
| 32 | + ks ks' : K.State |
| 33 | + msgs : List (FFDAbstract.Header ffdAbstract ⊎ FFDAbstract.Body ffdAbstract) |
| 34 | + eb : EndorserBlock |
| 35 | + rbs : List RankingBlock |
| 36 | + txs : List Tx |
| 37 | + V : VTy |
| 38 | + SD : StakeDistr |
| 39 | + pks : List PubKey |
| 40 | + |
| 41 | + -- Uniform Short Pipeline: |
| 42 | + -- |
| 43 | + -- 1. If elected, propose IB |
| 44 | + -- 2. Wait |
| 45 | + -- 3. Wait |
| 46 | + -- 4. If elected, propose EB |
| 47 | + -- 5. If elected, vote |
| 48 | + -- If elected, propose RB |
| 49 | + |
| 50 | + data _↝_ : LeiosState → LeiosState → Type where |
| 51 | + |
| 52 | + IB-Role : let open LeiosState s renaming (FFDState to ffds) |
| 53 | + b = ibBody (record { txs = ToPropose }) |
| 54 | + h = ibHeader (mkIBHeader slot id π sk-IB ToPropose) |
| 55 | + in |
| 56 | + ∙ needsUpkeep IB-Role |
| 57 | + ∙ canProduceIB slot sk-IB (stake s) π |
| 58 | + ∙ ffds FFD.-⟦ Send h (just b) / SendRes ⟧⇀ ffds' |
| 59 | + ───────────────────────────────────────────────────────────────────────── |
| 60 | + s ↝ addUpkeep record s { FFDState = ffds' } IB-Role |
| 61 | + |
| 62 | + EB-Role : let open LeiosState s renaming (FFDState to ffds) |
| 63 | + LI = map getIBRef $ filter (_∈ᴮ slice L slot 3) IBs |
| 64 | + h = mkEB slot id π sk-EB LI [] |
| 65 | + in |
| 66 | + ∙ needsUpkeep EB-Role |
| 67 | + ∙ canProduceEB slot sk-EB (stake s) π |
| 68 | + ∙ ffds FFD.-⟦ Send (ebHeader h) nothing / SendRes ⟧⇀ ffds' |
| 69 | + ───────────────────────────────────────────────────────────────────────── |
| 70 | + s ↝ addUpkeep record s { FFDState = ffds' } EB-Role |
| 71 | + |
| 72 | + V-Role : let open LeiosState s renaming (FFDState to ffds) |
| 73 | + EBs' = filter (allIBRefsKnown s) $ filter (_∈ᴮ slice L slot 1) EBs |
| 74 | + votes = map (vote sk-V ∘ hash) EBs' |
| 75 | + in |
| 76 | + ∙ needsUpkeep V-Role |
| 77 | + ∙ canProduceV slot sk-V (stake s) |
| 78 | + ∙ ffds FFD.-⟦ Send (vHeader votes) nothing / SendRes ⟧⇀ ffds' |
| 79 | + ───────────────────────────────────────────────────────────────────────── |
| 80 | + s ↝ addUpkeep record s { FFDState = ffds' } V-Role |
| 81 | + |
| 82 | + No-IB-Role : let open LeiosState s in |
| 83 | + ∙ needsUpkeep IB-Role |
| 84 | + ∙ ¬ canProduceIB slot sk-IB (stake s) π |
| 85 | + ───────────────────────────────────────────── |
| 86 | + s ↝ addUpkeep s IB-Role |
| 87 | + |
| 88 | + No-EB-Role : let open LeiosState s in |
| 89 | + ∙ needsUpkeep EB-Role |
| 90 | + ∙ ¬ canProduceEB slot sk-EB (stake s) π |
| 91 | + ───────────────────────────────────────────── |
| 92 | + s ↝ addUpkeep s EB-Role |
| 93 | + |
| 94 | + No-V-Role : let open LeiosState s in |
| 95 | + ∙ needsUpkeep V-Role |
| 96 | + ∙ ¬ canProduceV slot sk-V (stake s) |
| 97 | + ───────────────────────────────────────────── |
| 98 | + s ↝ addUpkeep s V-Role |
| 99 | + |
| 100 | + data _-⟦_/_⟧⇀_ : Maybe LeiosState → LeiosInput → LeiosOutput → LeiosState → Type where |
| 101 | + |
| 102 | + -- Initialization |
| 103 | + |
| 104 | + Init : |
| 105 | + ∙ ks K.-⟦ K.INIT pk-IB pk-EB pk-V / K.PUBKEYS pks ⟧⇀ ks' |
| 106 | + ∙ initBaseState B.-⟦ B.INIT (V-chkCerts pks) / B.STAKE SD ⟧⇀ bs' |
| 107 | + ──────────────────────────────────────────────────────────────── |
| 108 | + nothing -⟦ INIT V / EMPTY ⟧⇀ initLeiosState V SD bs' |
| 109 | + |
| 110 | + -- Network and Ledger |
| 111 | + |
| 112 | + Slot : let open LeiosState s renaming (FFDState to ffds; BaseState to bs) in |
| 113 | + ∙ Upkeep ≡ᵉ allUpkeep |
| 114 | + ∙ bs B.-⟦ B.FTCH-LDG / B.BASE-LDG rbs ⟧⇀ bs' |
| 115 | + ∙ ffds FFD.-⟦ Fetch / FetchRes msgs ⟧⇀ ffds' |
| 116 | + ─────────────────────────────────────────────────────────────────────── |
| 117 | + just s -⟦ SLOT / EMPTY ⟧⇀ record s |
| 118 | + { FFDState = ffds' |
| 119 | + ; BaseState = bs' |
| 120 | + ; Ledger = constructLedger rbs |
| 121 | + ; slot = suc slot |
| 122 | + ; Upkeep = ∅ |
| 123 | + } ↑ L.filter isValid? msgs |
| 124 | + |
| 125 | + Ftch : |
| 126 | + ──────────────────────────────────────────────────────── |
| 127 | + just s -⟦ FTCH-LDG / FTCH-LDG (LeiosState.Ledger s) ⟧⇀ s |
| 128 | + |
| 129 | + -- Base chain |
| 130 | + -- |
| 131 | + -- Note: Submitted data to the base chain is only taken into account |
| 132 | + -- if the party submitting is the block producer on the base chain |
| 133 | + -- for the given slot |
| 134 | + |
| 135 | + Base₁ : |
| 136 | + ─────────────────────────────────────────────────────────────────── |
| 137 | + just s -⟦ SUBMIT (inj₂ txs) / EMPTY ⟧⇀ record s { ToPropose = txs } |
| 138 | + |
| 139 | + Base₂a : let open LeiosState s renaming (BaseState to bs) in |
| 140 | + ∙ needsUpkeep Base |
| 141 | + ∙ eb ∈ filter (λ eb → isVoteCertified s eb × eb ∈ᴮ slice L slot 2) EBs |
| 142 | + ∙ bs B.-⟦ B.SUBMIT (this eb) / B.EMPTY ⟧⇀ bs' |
| 143 | + ─────────────────────────────────────────────────────────────────────── |
| 144 | + just s -⟦ SLOT / EMPTY ⟧⇀ addUpkeep record s { BaseState = bs' } Base |
| 145 | + |
| 146 | + Base₂b : let open LeiosState s renaming (BaseState to bs) in |
| 147 | + ∙ needsUpkeep Base |
| 148 | + ∙ [] ≡ filter (λ eb → isVoteCertified s eb × eb ∈ᴮ slice L slot 2) EBs |
| 149 | + ∙ bs B.-⟦ B.SUBMIT (that ToPropose) / B.EMPTY ⟧⇀ bs' |
| 150 | + ─────────────────────────────────────────────────────────────────────── |
| 151 | + just s -⟦ SLOT / EMPTY ⟧⇀ addUpkeep record s { BaseState = bs' } Base |
| 152 | + |
| 153 | + -- Protocol rules |
| 154 | + |
| 155 | + Roles : ∙ s ↝ s' |
| 156 | + ───────────────────────────── |
| 157 | + just s -⟦ SLOT / EMPTY ⟧⇀ s' |
0 commit comments