Skip to content

Leios EB inclusion#1921

Merged
bladyjoker merged 36 commits intoleios-prototypefrom
bladyjoker/leios-eb-apply
Apr 1, 2026
Merged

Leios EB inclusion#1921
bladyjoker merged 36 commits intoleios-prototypefrom
bladyjoker/leios-eb-apply

Conversation

@bladyjoker
Copy link
Copy Markdown
Contributor

@bladyjoker bladyjoker commented Mar 11, 2026

input-output-hk/ouroboros-leios#774

DONE

  • Ledger: [DO-NOT-MERGE] Leios prototype cardano-ledger#5626

    • New Block fields blockMayAnnouncedEb :: Maybe EbHash and blockCertifiesEb :: Bool(NOTE: Currently we keep this in the body and not the header)
    • ShelleyLedgerState in OuroborosConsensus is tracking the last announced EB
    • applyBlock for ConwayEra handles a Certificate Body.
  • Forge: Issues a Block with EB announcement and Certificates

    • When the EB was produced it's marked in the forged LedgerBlock (blockMayAnnouncedEb)
    • When the previously announced EB is fully downloaded (entire tx closure is available) and (mock) certified, the use of that EB is marked in the new LedgerBlock (blockCertifiesEb)
    • !!! Mempool Partitioning !!! - We currently split the transactions in the Mempool in 2 parts, first part is for a Block with inlined transactions and second for an EB. However, that's a problem!
      When a Leader tries to forge a Block with a Certificate AND additionally wants to announce a new EB, the transaction in that EB are likely to be invalid wrt to the Ledger state induced by the application of the Certificate.
      Instead, when a Certified EB is available during Forge, Mempool needs to be "rebased" to a Ledger state after the Certified EB application (and the surviving transactions can go to an EB and be announced)
      • Skip announcement when certifying as an interim solution (see 02ef504)
  • ChainDB: When the blk contains a Leios Certificate we must resolve its transaction closure in order to applyBlock

    • resolveLeiosBlock call (ResolveLeiosBlock blk class method) was introduced in a call chain to applyBlock to resolve the transactions if the blk contains a Leios Certificate
    • Shelley resolveLeiosBlock resolves the transaction closure and provides it to the Ledger
  • Test

    • Test new LeiosDB queries
    • Test that a EB has been announced
    • Test that a Certificate has been included
    • Old ouroboros-consensus tests are passing?
  • Sqlite implementation

    • Get tx closure by EB Point
    • Get certificate by EB Point

@bladyjoker bladyjoker self-assigned this Mar 11, 2026
@bladyjoker bladyjoker changed the base branch from main to leios-prototype March 11, 2026 12:36
$ cabal run ouroboros-consensus-cardano:run-threadnet -- run --threadnet-config run-threadnet-example-config/example-threadnet-config.json --slots 100 --txs-per-slot 10
("Node",CoreNodeId 0,"current slot",SlotNo 7,ShelleyLedgerLeiosState {sllsMaybeAnnouncedEb = Nothing, sllsTooSoonToCertify = False, sllsTouched = 0})
("Node",CoreNodeId 1,"current slot",SlotNo 7,ShelleyLedgerLeiosState {sllsMaybeAnnouncedEb = Nothing, sllsTooSoonToCertify = False, sllsTouched = 0})
("Node",CoreNodeId 2,"current slot",SlotNo 7,ShelleyLedgerLeiosState {sllsMaybeAnnouncedEb = Nothing, sllsTooSoonToCertify = False, sllsTouched = 0})
run-threadnet: FailureEvaluation FIXME(bladyjoker)
CallStack (from HasCallStack):
  error, called at src/shelley/Ouroboros/Consensus/Shelley/Ledger/Ledger.hs:312:37 in ouroboros-consensus-cardano-0.25.1.0-inplace:Ouroboros.Consensus.Shelley.Ledger.Ledger
I had an assumption that turned out wrong. `applyTick` is called just before
`applyBlock`, and I thought it's applied on each "tick" (ie. new slot).

13:59 $ cabal run ouroboros-consensus-cardano:run-threadnet -- run --threadnet-config run-threadnet-example-config/example-threadnet-config.json --slots 15 --txs-per-slot 10
...
("Node",CoreNodeId 0,"current slot",SlotNo 14,ShelleyLedgerLeiosState {sllsMaybeAnnouncedEb = Nothing, sllsTooSoonToCertify = False, sllsApplyTickCount = 2, sllsApplyBlockCount = 2})
("Node",CoreNodeId 1,"current slot",SlotNo 14,ShelleyLedgerLeiosState {sllsMaybeAnnouncedEb = Nothing, sllsTooSoonToCertify = False, sllsApplyTickCount = 2, sllsApplyBlockCount = 2})
("Node",CoreNodeId 2,"current slot",SlotNo 14,ShelleyLedgerLeiosState {sllsMaybeAnnouncedEb = Nothing, sllsTooSoonToCertify = False, sllsApplyTickCount = 2, sllsApplyBlockCount = 2})
*** Exceptions?
Nothing
*** Tips
Just (SlotNo 14,fromList [(CoreId (CoreNodeId 0),At (BlockNo 1)),(CoreId (CoreNodeId 1),At (BlockNo 1)),(CoreId (CoreNodeId 2),At (BlockNo 1))])
*** Leios
("eb-slotno",fromList [(CoreId (CoreNodeId 0),fromList []),(CoreId (CoreNodeId 1),fromList []),(CoreId (CoreNodeId 2),fromList [])])
("eb-points",fromList [(CoreId (CoreNodeId 0),fromList []),(CoreId (CoreNodeId 1),fromList []),(CoreId (CoreNodeId 2),fromList [])])
("eb-txs",fromList [(CoreId (CoreNodeId 0),0),(CoreId (CoreNodeId 1),0),(CoreId (CoreNodeId 2),0)])
*** Outputting log files
Currently, the Shelley Block is used to convey the information rather than
the header, namely `blockMayAnnouncedEb` and `blockCertifiesEb`. The addition
to the `ShelleyLedgerState` called `ShelleyLedgerLeiosState` maintains two
state variables, namely `sllsMaybeAnnouncedEb` which denotes the EB announcement
of the last `Block`, and `sllsTooSoonToCertify` which denotes whether previous
EB announcement is old enough to be used.

Try with:

15:30 $ cabal run ouroboros-consensus-cardano:run-threadnet -- run
--threadnet-config run-threadnet-example-config/example-threadnet-config.json
--slots 30 --txs-per-slot 500
… it.

WARN: This compiles and runs but is fundamentally broken
10:17 $ cabal run ouroboros-consensus-cardano:run-threadnet -- run
--threadnet-config run-threadnet-example-config/example-threadnet-config.json
--slots 100 --txs-per-slot 500

...
run-threadnet: FailureEvaluation In Shelley baby yea
CallStack (from HasCallStack):
  error, called at src/shelley/Ouroboros/Consensus/Shelley/Ledger/Block.hs:161:47 in ouroboros-consensus-cardano-0.25.1.0-inplace:Ouroboros.Consensus.Shelley.Ledger.Block

Still lots is broken, but we can run-threadnet and reach the Shelley
`resolveLeiosBlock` call.
@bladyjoker bladyjoker force-pushed the bladyjoker/leios-eb-apply branch from 5c70494 to 3951cd0 Compare March 19, 2026 09:21
@bladyjoker
Copy link
Copy Markdown
Contributor Author

bladyjoker commented Mar 19, 2026

Mempool partitioning with Certificates

forge leiosDb mempool = do
  mayCertifiedEb <- getCertifiedEb leiosDb
  case mayCertifiedEb of
    -- As is now
    Nothing -> do
      mempoolTxs <- snapshotMempool mempool    
      (inlinedTxs, restTxs) <- splitTxs praosCapacity mempoolTxs 
      ebTxs <- splitTxs ebCapacity restTxs
      forgeBlock (InlinedTxs inlinedTxs) ebTxs
    -- With the Certificates
    Just (cert, certifiedEbTxs) -> do
      rebaseAndApplyMempool mempool certifiedEbTxs -- magic
      mempoolTxs <- snapshotMempool mempool         
      (eb, restTxs) <- splitTxs ebCapacity mempoolTxs 
      forgeBlock cert ebTxs

@ch1bo ch1bo linked an issue Mar 19, 2026 that may be closed by this pull request
$ cabal run ouroboros-consensus-cardano:run-threadnet -- run --threadnet-config run-threadnet-example-config/example-threadnet-config.json --slots 100 --txs-per-slot 500

("certifying",LeiosCertificate {unLeiosCertificate = "trust me bruv"},MkLeiosPoint {pointSlotNo = SlotNo 10, pointEbHash = "\SUB\194\252%5\230\GS\139S\139\191\219\173\&5\211\189\207G>4\232\&4\136`<c\DLE\185bw}\DEL"})
run-threadnet: FailureEvaluation Certificate body must include EB transaction closure (I was expecting this to be resolved) Certificate {unCertificate = "trust me bruv"}
CallStack (from HasCallStack):
  error, called at src/Cardano/Ledger/Block.hs:111:5 in cardano-ledger-core-1.17.0.0-inplace:Cardano.Ledger.Block
@bladyjoker bladyjoker changed the title (Shelley)LedgerState meets Leios Leios EB inclusion Mar 21, 2026
@ch1bo ch1bo force-pushed the bladyjoker/leios-eb-apply branch from 97aa3d0 to 5ef1406 Compare March 23, 2026 19:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Prototype Chain Inclusion

2 participants