Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
ac4baad
LeiosNotify: add the pure abstract logic of the EbAnnouncement diffusion
nfrisby Jul 15, 2026
9e3eda8
LeiosNotify: "AntiPipeline" the server typed-protocol's `Peer`
nfrisby Jul 15, 2026
c239424
LeiosNotify: enforce the credits as a bound
nfrisby Jul 15, 2026
33b9b3b
LeiosNotify: use optimized AntiPipelining
nfrisby Jul 15, 2026
b4bf4a2
LeiosNotify: prepare to validate announcements
nfrisby Jul 15, 2026
f2bfba7
LeiosNotify: enforce limit on pipelining depth
nfrisby Jul 15, 2026
cd269e5
LeiosNotify: validate incoming announcements
nfrisby Jul 15, 2026
2480b86
LeiosNotify: also validate announcements against previous messages
nfrisby Jul 15, 2026
d75471d
LeiosNotify: bugfix and refactor in onAnnouncementCentral
nfrisby Jul 16, 2026
f908d29
LeiosNotify: record the Announcements bug, hoping to simplify it away…
nfrisby Jul 16, 2026
9331f5e
LeiosNotify: simpler OCIN story, see ErrAnnouncement Haddock
nfrisby Jul 16, 2026
ead0b8b
LeiosNotify: slight refactor of MsgLeiosBlockAnnouncement handler
nfrisby Jul 16, 2026
82337d5
LeiosNotify: add Announcements.CentralState to NodeKernel
nfrisby Jul 16, 2026
df190a9
LeiosNotify: now relaying announcements
nfrisby Jul 16, 2026
19140e0
ElBimap: avoid warnings on 9.12 about Prelude exporting foldl'
nfrisby Jul 30, 2026
1d4e7e0
LeiosNotify: immtip pruning and forge loop input
nfrisby Jul 16, 2026
d46c281
LeiosNotify: tracers and slight refactoring/renaming
nfrisby Jul 16, 2026
f47eac7
cabal.project: add typed-protocol s-r-p for AntiPipelining
nfrisby Jul 17, 2026
25e8ebf
LeiosNotify: add Test.LeiosDemoLogic.Announcements
nfrisby Jul 17, 2026
85449ea
LeiosNotify: add the easy test suite
nfrisby Jul 17, 2026
19a3f77
LeiosNotify: improve some comments
nfrisby Jul 27, 2026
0a47900
LeiosNotify: decouple EbAnnouncement verification from RbHeader valid…
nfrisby Jul 27, 2026
a8c4f0b
leiosNotifyServerPeerAntiPipelined: replace bare Bool
nfrisby Jul 27, 2026
1f9271b
LeiosNotify: still enforce the RbHeader size limit
nfrisby Jul 27, 2026
1670149
validateAnnouncementChainDepState @DijkstraEra: add some internal com…
nfrisby Jul 27, 2026
7a3663d
LeiosDemoTypes: include identifying information in MsgLeiosBlockAnnou…
nfrisby Jul 27, 2026
92d74e7
LeiosNotify: add lateness to TraceLeiosAnnouncementAccepted
nfrisby Jul 27, 2026
fc9b6f5
LeiosNotify: update from AntiPipelined to Lookahead in typed-protocols
nfrisby Jul 28, 2026
e7d8907
LeiosNotify: try announcing EB concurrently with processing new RB
nfrisby Jul 28, 2026
827e083
LeiosNotify: add an announcement age check more strict than necessary
nfrisby Jul 29, 2026
293200a
LeiosNotify: update typed-protocols SRP to get merged PR 93 LookAhead
nfrisby Jul 30, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ source-repository-package
cardano-diffusion
network-mux

-- Points to nfrisby-pr93-lookahead-merge-commit tag
source-repository-package
type: git
location: https://github.com/IntersectMBO/typed-protocols
tag: 9b4627221ae5d649f2303c6926a8dba3f9934658
--sha256: sha256-55skVYIR0WjXMwJEirLgF0HFHUpFLBppuV9gvTWqoOI=
subdir:
typed-protocols

-- Points to ouroboros-ledger/leios-prototype
source-repository-package
type: git
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@
{-# LANGUAGE GADTs #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneKindSignatures #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE ViewPatterns #-}

{-# OPTIONS_GHC -Wno-orphans #-}

module Ouroboros.Consensus.Cardano.Block
Expand Down Expand Up @@ -214,12 +217,17 @@ module Ouroboros.Consensus.Cardano.Block
, EraMismatch (..)
) where

import Control.Monad.Except (throwError, withExcept)
import Data.Kind
import Data.Proxy (Proxy (..))
import Data.Functor.Product (Product (..))
import Data.SOP.BasicFunctors
import Data.SOP.Constraint (All, SListI)
import Data.SOP.Functors
import Data.SOP.Index (Index (..))
import Data.SOP.Index (Index (..), hcizipWith)
import qualified Data.SOP.Match as Match
import Data.SOP.Strict
import Ouroboros.Consensus.Block (BlockProtocol)
import Ouroboros.Consensus.Block (BlockProtocol, SlotNo)
import Ouroboros.Consensus.Byron.Ledger.Block (ByronBlock)
import Ouroboros.Consensus.HardFork.Combinator
import Ouroboros.Consensus.HardFork.Combinator.AcrossEras
Expand All @@ -245,6 +253,8 @@ import Ouroboros.Consensus.Shelley.Ledger.Ledger
( ShelleyPartialLedgerConfig (..)
)
import Ouroboros.Consensus.Shelley.Ledger.Leios ()
import Ouroboros.Consensus.Shelley.Protocol.TPraos ()
import Ouroboros.Consensus.Shelley.Protocol.Praos ()
import Ouroboros.Consensus.Storage.LedgerDB (ResolveLeiosBlock (..))
import Ouroboros.Consensus.TypeFamilyWrappers

Expand Down Expand Up @@ -1537,6 +1547,7 @@ instance
, ShelleyCompatible (Praos c) DijkstraEra
, HasCanonicalTxIn (CardanoEras c)
, HasHardForkTxOut (CardanoEras c)
, CanHardFork (CardanoEras c)
) =>
ResolveLeiosBlock (HardForkBlock (CardanoEras c))
where
Expand Down Expand Up @@ -1596,6 +1607,13 @@ instance
HeaderDijkstra dHdr -> headerLeiosAnnouncement dHdr
_ -> Nothing

-- Compositional dispatch over the era stack (even though in practice only
-- Dijkstra carries an announcement, so only its instance is ever exercised).
headerElId (HardForkHeader (OneEraHeader ns)) =
hcollapse $ hcmap (Proxy @ResolveLeiosBlock) (K . headerElId) ns

validateAnnouncementChainDepState = update @(CardanoEras c)

headerContainsLeiosCert hdr = case hdr of
HeaderDijkstra dHdr -> headerContainsLeiosCert dHdr
_ -> False
Expand All @@ -1611,3 +1629,64 @@ instance
(IS (IS (IS (IS (IS (IS (IS IZ)))))))
(leiosClosureTxKeySets inner)
_ -> emptyLedgerTables

-----

-- | We don't want to add the ResolveLeiosBlock sin-bin to SingleEraBlock, so we
-- use this ad-hoc class instead.
class (SingleEraBlock blk, ResolveLeiosBlock blk) => AnnouncementEraBlock blk
instance (SingleEraBlock blk, ResolveLeiosBlock blk) => AnnouncementEraBlock blk

-- | Adapted from "Ouroboros.Consensus.HardFork.Combinator.Protocol.update"
update ::
forall xs.
(CanHardFork xs, All AnnouncementEraBlock xs) =>
ConsensusConfig (HardForkProtocol xs) ->
OneEraValidateView xs ->
SlotNo ->
Ticked (HardForkChainDepState xs) ->
Except (HardForkValidationErr xs) ()
update
HardForkConsensusConfig{..}
(OneEraValidateView view)
slot
(TickedHardForkChainDepState chainDepState ei) =
case State.match view chainDepState of
Left mismatch ->
throwError $
HardForkValidationErrWrongEra . MismatchEraInfo $
Match.bihcmap
proxySingle
singleEraInfo
(LedgerEraInfo . chainDepStateInfo . State.currentState)
mismatch
Right matched ->
hcollapse
. hcizipWith (Proxy :: Proxy AnnouncementEraBlock) (updateEra ei slot) cfgs
$ matched
where
cfgs = getPerEraConsensusConfig hardForkConsensusConfigPerEra

-- | Adapted from "Ouroboros.Consensus.HardFork.Combinator.Protocol.updateEra"
updateEra ::
forall xs blk.
(SListI xs, SingleEraBlock blk, ResolveLeiosBlock blk) =>
EpochInfo (Except PastHorizonException) ->
SlotNo ->
Index xs blk ->
WrapPartialConsensusConfig blk ->
Product WrapValidateView (Ticked :.: WrapChainDepState) blk ->
K (Except (HardForkValidationErr xs) ()) blk
updateEra
ei
slot
index
cfg
(Pair view (Comp chainDepState)) =
K $
withExcept (injectValidationErr index) $
validateAnnouncementChainDepState @blk
(completeConsensusConfig' ei cfg)
(unwrapValidateView view)
slot
(unwrapTickedChainDepState chainDepState)
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ data instance Header (ShelleyBlock proto era) = ShelleyHeader
deriving Generic

deriving instance ShelleyCompatible proto era => Show (Header (ShelleyBlock proto era))
deriving instance ShelleyCompatible proto era => Eq (Header (ShelleyBlock proto era))
deriving instance ShelleyCompatible proto era => Eq (Header (ShelleyBlock proto era)) -- TODO sound to use only 'shelleyHeaderHash'?
deriving instance ShelleyCompatible proto era => NoThunks (Header (ShelleyBlock proto era))

instance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@

module Ouroboros.Consensus.Shelley.Ledger.Leios () where

import qualified Cardano.Crypto.Hash as Crypto (hashToBytesShort)
import Cardano.Ledger.Api (Tx)
import Cardano.Ledger.Binary (decCBOR, decodeFullAnnotator)
import qualified Cardano.Ledger.Block as Core
import Cardano.Ledger.Core (TopTx, injectFailure)
import qualified Cardano.Ledger.Core as Core
import Cardano.Ledger.Dijkstra.BlockBody (leiosCertBlockBodyL)
import Cardano.Ledger.Hashes (KeyHash (..))
import qualified Cardano.Ledger.Shelley.API as SL
import Cardano.Ledger.Shelley.Rules (ledgerPpL)
import qualified Cardano.Ledger.Shelley.UTxO as SL
Expand All @@ -31,13 +33,29 @@ import Data.Maybe.Strict (strictMaybeToMaybe)
import Data.Proxy (Proxy (..))
import qualified Data.Sequence.Strict as StrictSeq
import LeiosDemoDb (leiosDbLookupEbClosure)
import LeiosDemoTypes (EbAnnouncement (..), LeiosPoint (..), RbHash (..))
import LeiosDemoLogic.Announcements.ElBimap (ElId (MkElId))
import LeiosDemoTypes
( EbAnnouncement (..)
, LeiosPoint (..)
, RbHash (..)
)
import Lens.Micro ((.~), (^.))
import Ouroboros.Consensus.Block (ChainHash (..), blockPrevHash, toRawHash)
import Ouroboros.Consensus.Ledger.Abstract (getTipSlot)
import Ouroboros.Consensus.Ledger.SupportsMempool (getTransactionKeySets)
import Ouroboros.Consensus.Ledger.Tables (stowLedgerTables, unstowLedgerTables)
import Ouroboros.Consensus.Protocol.Praos (Praos, PraosCrypto, PraosState (..))
import Ouroboros.Consensus.Protocol.Praos
( ConsensusConfig (..)
, Praos
, PraosCrypto
, PraosParams (..)
, PraosState (..)
, Ticked (..)
, WhetherToUpperBoundOCERT (..)
, doValidateKESSignatureWorker
, doValidateVRFSignature
)
import Ouroboros.Consensus.Protocol.Praos.Views (plvPoolDistr)
import Ouroboros.Consensus.Protocol.Praos.Header
( Header (..)
, HeaderBody (..)
Expand Down Expand Up @@ -195,6 +213,38 @@ instance
where
Header{headerBody} = shelleyHeaderRaw hdr

headerElId hdr =
MkElId
headerBody.hbSlotNo
(Crypto.hashToBytesShort . unKeyHash . SL.hashKey $ headerBody.hbVk)
where
Header{headerBody} = shelleyHeaderRaw hdr

-- The announcement is validated out-of-context against a (possibly lagging)
-- immutable tip, so we skip the OCERT counter's upper bound
-- ('DoNotUpperBoundOCERT'): a counter ahead of our recorded view is honestly
-- explained by that lag. The election proof (VRF) and the signature (KES +
-- opcert, including the counter's revocation lower bound) are checked in full.
validateAnnouncementChainDepState cfg hv _slot tcs = do
-- validate the claimed election
doValidateVRFSignature
(praosStateEpochNonce cs)
pd
(praosLeaderF prms)
hv
-- authenticate the message
doValidateKESSignatureWorker
DoNotUpperBoundOCERT
(praosMaxKESEvo prms)
(praosSlotsPerKESPeriod prms)
pd
(praosStateOCertCounters cs)
hv
where
prms = praosParams cfg
cs = tickedPraosStateChainDepState tcs
SL.PoolDistr pd _ = plvPoolDistr (tickedPraosStateLedgerView tcs)

protocolStateLeiosAnnouncement st = do
ann <- strictMaybeToMaybe $ praosStateLeiosAnnouncement st
pure
Expand Down
Loading
Loading