-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of github.com:input-output-hk/ouroboros-leios int…
…o feat/large-data
- Loading branch information
Showing
59 changed files
with
5,774 additions
and
835 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{-# OPTIONS --safe #-} | ||
|
||
-------------------------------------------------------------------------------- | ||
-- Variant of `Computational` for relations with two inputs and outputs | ||
-------------------------------------------------------------------------------- | ||
|
||
module Class.Computational22 where | ||
|
||
open import Leios.Prelude | ||
open import Class.Computational | ||
|
||
private variable | ||
S I O Err : Type | ||
|
||
module _ (STS : S → I → O → S → Type) where | ||
record Computational22 Err : Type₁ where | ||
constructor MkComputational | ||
field | ||
computeProof : (s : S) (i : I) → ComputationResult Err (∃[ (o , s') ] STS s i o s') | ||
|
||
compute : S → I → ComputationResult Err (O × S) | ||
compute s i = map proj₁ $ computeProof s i | ||
|
||
field | ||
completeness : ∀ s i o s' → STS s i o s' → compute s i ≡ success (o , s') | ||
|
||
STS' : S × I → O × S → Type | ||
STS' (s , i) (o , s') = STS s i o s' | ||
|
||
module _ ⦃ _ : Computational22 Err ⦄ where | ||
open Computational22 it | ||
instance | ||
comp22⇒comp : Computational STS' Err | ||
comp22⇒comp .Computational.computeProof (s , i) = computeProof s i | ||
comp22⇒comp .Computational.completeness (s , i) (o , s') = completeness s i o s' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
{-# OPTIONS --safe #-} | ||
|
||
open import Leios.Prelude hiding (id) | ||
open import Leios.FFD | ||
|
||
import Data.List as L | ||
import Data.List.Relation.Unary.Any as A | ||
|
||
open import Leios.SpecStructure | ||
|
||
module Leios.Protocol (⋯ : SpecStructure) (let open SpecStructure ⋯) (SlotUpkeep : Type) where | ||
|
||
open BaseAbstract B' using (Cert; V-chkCerts; VTy; initSlot) | ||
open GenFFD | ||
|
||
-- High level structure: | ||
|
||
|
||
-- (simple) Leios | ||
-- / | | ||
-- +-------------------------------------+ | | ||
-- | Header Diffusion Body Diffusion | | | ||
-- +-------------------------------------+ Base Protocol | ||
-- \ / | ||
-- Network | ||
|
||
data LeiosInput : Type where | ||
INIT : VTy → LeiosInput | ||
SUBMIT : EndorserBlock ⊎ List Tx → LeiosInput | ||
SLOT : LeiosInput | ||
FTCH-LDG : LeiosInput | ||
|
||
data LeiosOutput : Type where | ||
FTCH-LDG : List Tx → LeiosOutput | ||
EMPTY : LeiosOutput | ||
|
||
record LeiosState : Type where | ||
field V : VTy | ||
SD : StakeDistr | ||
FFDState : FFD.State | ||
Ledger : List Tx | ||
ToPropose : List Tx | ||
IBs : List InputBlock | ||
EBs : List EndorserBlock | ||
Vs : List (List Vote) | ||
slot : ℕ | ||
IBHeaders : List IBHeader | ||
IBBodies : List IBBody | ||
Upkeep : ℙ SlotUpkeep | ||
BaseState : B.State | ||
|
||
lookupEB : EBRef → Maybe EndorserBlock | ||
lookupEB r = find (λ b → getEBRef b ≟ r) EBs | ||
|
||
lookupIB : IBRef → Maybe InputBlock | ||
lookupIB r = find (λ b → getIBRef b ≟ r) IBs | ||
|
||
lookupTxs : EndorserBlock → List Tx | ||
lookupTxs eb = do | ||
eb′ ← mapMaybe lookupEB $ ebRefs eb | ||
ib ← mapMaybe lookupIB $ ibRefs eb′ | ||
txs $ body ib | ||
where open EndorserBlockOSig | ||
open IBBody | ||
open InputBlock | ||
|
||
constructLedger : List EndorserBlock → List Tx | ||
constructLedger = concatMap lookupTxs | ||
|
||
needsUpkeep : SlotUpkeep → Set | ||
needsUpkeep = _∉ Upkeep | ||
|
||
addUpkeep : LeiosState → SlotUpkeep → LeiosState | ||
addUpkeep s u = let open LeiosState s in record s { Upkeep = Upkeep ∪ ❴ u ❵ } | ||
|
||
initLeiosState : VTy → StakeDistr → B.State → LeiosState | ||
initLeiosState V SD bs = record | ||
{ V = V | ||
; SD = SD | ||
; FFDState = FFD.initFFDState | ||
; Ledger = [] | ||
; ToPropose = [] | ||
; IBs = [] | ||
; EBs = [] | ||
; Vs = [] | ||
; slot = initSlot V | ||
; IBHeaders = [] | ||
; IBBodies = [] | ||
; Upkeep = ∅ | ||
; BaseState = bs | ||
} | ||
|
||
-- some predicates about EBs | ||
module _ (s : LeiosState) (eb : EndorserBlock) where | ||
open EndorserBlockOSig eb | ||
open LeiosState s | ||
|
||
allIBRefsKnown : Type | ||
allIBRefsKnown = ∀[ ref ∈ fromList ibRefs ] ref ∈ˡ map getIBRef IBs | ||
|
||
stake : LeiosState → ℕ | ||
stake record { SD = SD } = case lookupᵐ? SD id of λ where | ||
(just s) → s | ||
nothing → 0 | ||
|
||
module _ (s : LeiosState) where | ||
|
||
open LeiosState s | ||
|
||
upd : Header ⊎ Body → LeiosState | ||
upd (inj₁ (ebHeader eb)) = record s { EBs = eb ∷ EBs } | ||
upd (inj₁ (vHeader vs)) = record s { Vs = vs ∷ Vs } | ||
upd (inj₁ (ibHeader h)) with A.any? (matchIB? h) IBBodies | ||
... | yes p = | ||
record s | ||
{ IBs = record { header = h ; body = A.lookup p } ∷ IBs | ||
; IBBodies = IBBodies A.─ p | ||
} | ||
... | no _ = | ||
record s | ||
{ IBHeaders = h ∷ IBHeaders | ||
} | ||
upd (inj₂ (ibBody b)) with A.any? (flip matchIB? b) IBHeaders | ||
... | yes p = | ||
record s | ||
{ IBs = record { header = A.lookup p ; body = b } ∷ IBs | ||
; IBHeaders = IBHeaders A.─ p | ||
} | ||
... | no _ = | ||
record s | ||
{ IBBodies = b ∷ IBBodies | ||
} | ||
|
||
infix 25 _↑_ | ||
_↑_ : LeiosState → List (Header ⊎ Body) → LeiosState | ||
_↑_ = foldr (flip upd) |
Oops, something went wrong.