Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
8f3092d
LeiosCacheIndex: define the pure type and methods
nfrisby Aug 4, 2026
504bf9a
LeiosCacheIndex: maintain it but don't rely on it
nfrisby Aug 4, 2026
5a9c9b2
LeiosCacheIndex: test suite for the pure impl
nfrisby Aug 4, 2026
03af612
LeiosTxCache: add monadic wrapper around pure impl
nfrisby Aug 4, 2026
e3ecce5
LeiosTxCache: add benchmark
nfrisby Aug 4, 2026
9313e42
LeiosTxCache: add hash table
nfrisby Aug 4, 2026
2daf76d
LeiosTxCache: add mutable hash table-based impl
nfrisby Aug 4, 2026
f875486
LeiosTxCache: add test for mutable hash table-based impl
nfrisby Aug 4, 2026
8322d31
LeiosTxCache: also benchmark mutable hash table-based impl
nfrisby Aug 4, 2026
01a74bf
LeiosTxCache: improve optimization of Mutable.hs
nfrisby Aug 4, 2026
6667a22
LeiosTxCache: add Haddock about current and future design
nfrisby Aug 5, 2026
5591095
LeiosTxCache: reorganize modules
nfrisby Aug 5, 2026
6bfea70
LeiosTxCache: test across different load factors
nfrisby Aug 5, 2026
810ede4
LeiosTxCache: add TraceLeiosTxCacheEbBody
nfrisby Aug 5, 2026
cdacfbe
LeiosTxCache: use the Optimized LeiosTxCache (the hash table)
nfrisby Aug 5, 2026
52060f5
LeiosTxCache: test our SipHash-2-4
nfrisby Aug 5, 2026
2129b3c
LeiosTxCache: white-box test of hash table invariants
nfrisby Aug 5, 2026
b6b0fab
LeiosTxCache: duplicate hash table test-suite with -fcheck-prim-bounds
nfrisby Aug 5, 2026
fb2fad4
LeiosTxCache: test linear probing even with low hash table load
nfrisby Aug 5, 2026
7887b2a
LeiosTxCache: use all 64 SipHash-2-4 test vectors, not only two
nfrisby Aug 5, 2026
db00d58
Leios Forge: rearrange storing/announcing/caching
nfrisby Aug 6, 2026
acc90d5
Leios ChainSync: also process MsgRollForwards as EB announcements
nfrisby Aug 6, 2026
1462122
LeiosTxCache: update Haddock about the backing store
nfrisby Aug 6, 2026
9e6b934
LeiosTxCache: add NodeKernel.leiosEvictStaleTxCacheEbs Watcher
nfrisby Aug 6, 2026
092e5b0
LeiosTxCache: also benchmark a SQLite impl
nfrisby Aug 7, 2026
b4a6082
LeiosTxCache: now ChainDB evicts TxCache just before pruning LeiosDb
nfrisby Aug 10, 2026
9f3cd8c
LeiosTxCache: add lookupBody
nfrisby Aug 10, 2026
337e0c7
LeiosTxCache: update comment about core LeiosTxCache invariant
nfrisby Aug 10, 2026
f4438c8
Apply fourmolu and cabal-gild
ch1bo Aug 28, 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
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,14 @@ byronBlockForging creds =
tickedPBftState
, forgeBlock = \ForgeBlockArgs{..} ->
return $
forgeByronBlock
fbConfig
fbCurrentBlockNo
fbCurrentSlotNo
fbCurrentTickedLedgerState
fbRbTxs
fbIsLeader
flip (,) Nothing $
forgeByronBlock
fbConfig
fbCurrentBlockNo
fbCurrentSlotNo
fbCurrentTickedLedgerState
fbRbTxs
fbIsLeader
, finalize = pure ()
}
where
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,16 @@ import qualified Cardano.Ledger.Shelley.API as SL (Block (..), extractTx)
import Cardano.Prelude (nonEmpty)
import qualified Cardano.Protocol.TPraos.BHeader as SL
import Control.Exception
import Control.Monad (void, when)
import Control.Monad (when)
import Control.Tracer (traceWith)
import Data.ByteString.Short (fromShort)
import Data.Maybe (isJust)
import Data.Maybe.Strict (StrictMaybe (..), maybeToStrictMaybe)
import qualified Data.Sequence.Strict as Seq
import qualified Data.Typeable as Typeable
import LeiosDemoDb (LeiosDbConnection (..))
import LeiosDemoTypes
( EbAnnouncement (..)
, ForgedLeiosEb (..)
, LeiosPoint (..)
, RbHash (..)
, TraceLeiosKernel (..)
, forgeLeiosEb
Expand Down Expand Up @@ -73,7 +71,7 @@ forgeShelleyBlock ::
HotKey (ProtoCrypto proto) m ->
CanBeLeader proto ->
ForgeBlockArgs m (ShelleyBlock proto era) ->
m (ShelleyBlock proto era)
m (ShelleyBlock proto era, Maybe ForgedLeiosEb)
forgeShelleyBlock hotKey cbl ForgeBlockArgs{..} = do
-- Forge an RB and attempt to announce an EB and/or certify a previously announced one:
--
Expand All @@ -85,7 +83,7 @@ forgeShelleyBlock hotKey cbl ForgeBlockArgs{..} = do
-- been rebased onto the post-certificate ledger state.
mayEbAnn <-
case Typeable.eqT @era @DijkstraEra of
Just Refl -> mkAndStoreEb
Just Refl -> mkEb
Nothing -> pure Nothing
let rbBody = mkBody fbMayLeiosCert
actualRbBodySize = SL.blockBodySize protocolVersion rbBody
Expand Down Expand Up @@ -122,9 +120,10 @@ forgeShelleyBlock hotKey cbl ForgeBlockArgs{..} = do
traceWith fbLeiosTracer $
TraceLeiosCertifiedAndAnnounced{atSlot = fbCurrentSlotNo, rbHash = MkRbHash announcingRbHashBytes}
Nothing -> pure ()
return $
assert (verifyBlockIntegrity (configSlotsPerKESPeriod $ configConsensus fbConfig) blk) $
blk
return
( assert (verifyBlockIntegrity (configSlotsPerKESPeriod $ configConsensus fbConfig) blk) blk
, fst <$> mayEbAnn
)
where
protocolVersion = shelleyProtocolVersion $ configBlock fbConfig

Expand Down Expand Up @@ -154,16 +153,12 @@ forgeShelleyBlock hotKey cbl ForgeBlockArgs{..} = do
. getTipHash
$ fbCurrentTickedLedgerState

-- Produce an EB from fbEbTxs, store it into fbLeiosDb, and return the
-- announcement to embed in the header. An honest forger only emits an
-- EB when it has txs to put in it; empty mempool ⇒ no EB ⇒ no
-- announcement (matches the original prototype). Persists the EB into
-- 'LeiosDb' before returning, so the closure is available locally
-- before the header carrying the announcement is finalised and
-- diffused — a peer that fetches our header will be able to pull the
-- closure from us in the same round-trip.
mkAndStoreEb :: m (Maybe (ForgedLeiosEb, EbAnnouncement))
mkAndStoreEb = case nonEmpty (fmap extractTx fbEbTxs) of
-- Produce an EB from 'fbEbTxs' and return it together with the announcement
-- to embed in the header. An honest forger only emits an EB when it has txs
-- to put in it; empty mempool ⇒ no EB ⇒ no announcement (matches the original
-- prototype).
mkEb :: m (Maybe (ForgedLeiosEb, EbAnnouncement))
mkEb = case nonEmpty (fmap extractTx fbEbTxs) of
Nothing -> pure Nothing
Just ebTxs -> do
let forgedEb = forgeLeiosEb fbCurrentSlotNo ebTxs
Expand All @@ -174,24 +169,11 @@ forgeShelleyBlock hotKey cbl ForgeBlockArgs{..} = do
{ ebAnnouncementHash = ebHash
, ebAnnouncementSize = ebSize
}
ebPoint =
MkLeiosPoint
{ pointSlotNo = fbCurrentSlotNo
, pointEbHash = ebHash
}
traceWith fbLeiosTracer $
TraceLeiosBlockForged
{ slot = fbCurrentSlotNo
, eb = forgedEb.body
, ebMeasure = ByteSize32 ebSize
, mempoolRestMeasure = ByteSize32 0
}
leiosDbInsertEbPoint fbLeiosDb ebPoint ebSize
void $ leiosDbInsertEbBody fbLeiosDb ebPoint forgedEb.body
void $ leiosDbInsertTxs fbLeiosDb forgedEb.txClosure
traceWith fbLeiosTracer $
TraceLeiosBlockStored
{ slot = fbCurrentSlotNo
, eb = forgedEb.body
}
pure (Just (forgedEb, ebAnn))
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,14 @@ dualByronBlockForging creds =
, checkCanForge = checkCanForge . dualTopLevelConfigMain
, forgeBlock = \ForgeBlockArgs{..} ->
return $
forgeDualByronBlock
fbConfig
fbCurrentBlockNo
fbCurrentSlotNo
fbCurrentTickedLedgerState
fbRbTxs
fbIsLeader
flip (,) Nothing $
forgeDualByronBlock
fbConfig
fbCurrentBlockNo
fbCurrentSlotNo
fbCurrentTickedLedgerState
fbRbTxs
fbIsLeader
, finalize = return ()
}
where
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ analyse dbaConfig args =
shfs
flavargs
leiosDbHandle
(\_ -> pure ()) -- no LeiosTxCache in this tool
$ ChainDB.defaultArgs
-- Set @k=1@ to reduce the memory usage of the LedgerDB. We only ever
-- go forward so we don't need to account for rollbacks.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ runForge ::
GenTxs blk ->
LeiosDbConnection IO ->
IO ForgeResult
runForge epochSize_ nextSlot opts chainDB blockForging cfg genTxs leiosDb = do
runForge epochSize_ nextSlot opts chainDB blockForging cfg genTxs _leiosDb = do
putStrLn $ "--> epoch size: " ++ show epochSize_
putStrLn $ "--> will process until: " ++ show opts
-- Synthetic forging doesn't gather votes; supply a vote state with
Expand Down Expand Up @@ -233,7 +233,9 @@ runForge epochSize_ nextSlot opts chainDB blockForging cfg genTxs leiosDb = do
tickedLedgerState

-- Actually produce the block
newBlock <-
--
-- TODO the block may be accompanied by an EB, which is entirely ignored
(newBlock, _mForgedEb) <-
lift $
Block.forgeBlock
blockForging'
Expand All @@ -246,7 +248,6 @@ runForge epochSize_ nextSlot opts chainDB blockForging cfg genTxs leiosDb = do
, fbEbTxs = []
, fbIsLeader = proof
, fbChainDepState = Nothing
, fbLeiosDb = leiosDb
, fbLeiosTracer = Trace.nullTracer
, fbLeiosVoteState = leiosVoteState
, fbMayLeiosCert = Nothing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ synthesize genTxs DBSynthesizerConfig{confOptions, confShelleyGenesis, confDbDir
(Node.stdMkChainDbHasFS confDbDir)
flavargs
leiosDbHandle
(\_ -> pure ()) -- no LeiosTxCache in this tool
$ ChainDB.defaultArgs

mbfs <- mkForgers nullTracer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ import qualified Network.Mux as Mux
import Network.TypedProtocol.Codec
import Network.TypedProtocol.Peer (Peer (Effect))
import Ouroboros.Consensus.Block
import Ouroboros.Consensus.BlockchainTime.WallClock.Types
( diffRelTime
, systemTimeCurrent
)
import Ouroboros.Consensus.Config (DiffusionPipeliningSupport (..))
import Ouroboros.Consensus.HeaderValidation (HeaderWithTime)
import Ouroboros.Consensus.Ledger.SupportsMempool
Expand All @@ -157,7 +161,7 @@ import Ouroboros.Consensus.Storage.LedgerDB.Forker
( ResolveLeiosBlock
)
import Ouroboros.Consensus.Storage.Serialisation (SerialisedHeader)
import Ouroboros.Consensus.Util (ShowProxy)
import Ouroboros.Consensus.Util (ShowProxy, whenJust)
import Ouroboros.Consensus.Util.IOLike
import Ouroboros.Consensus.Util.Orphans ()
import Ouroboros.Network.Block
Expand Down Expand Up @@ -351,6 +355,7 @@ mkHandlers ::
( IOLike m
, MonadTime m
, MonadTimer m
, ConvertRawHash blk
, LedgerSupportsMempool blk
, HasTxId (GenTx blk)
, LedgerSupportsProtocol blk
Expand Down Expand Up @@ -397,8 +402,29 @@ mkHandlers
, CsClient.tracer =
contramap (TraceLabelPeer peer) (Node.chainSyncClientTracer tracers)
, CsClient.getDiffusionPipeliningSupport = getDiffusionPipeliningSupport
, CsClient.leiosCertRbCallback =
Leios.leiosCertRbCallback (getLeiosOutstanding, getLeiosReady) peerVars
, CsClient.leiosMsgRollForwardCallback = \hdr hdrSlotTime cds -> do
Leios.checkMsgRollForwardForLeiosOffers
(getLeiosOutstanding, getLeiosReady)
peerVars
hdr
cds
-- Feed any EB this header announces into the central
-- announcement state (relay + dedup + txCache), central-only:
-- a roll-forward is not this peer announcing over LeiosNotify,
-- so no PeerState is touched. Date it from the header slot's
-- onset (its ChainSync arrival latency).
whenJust (Leios.mkAnnouncingHeader hdr) $ \ancHdr -> do
now <- systemTimeCurrent systemTime
Leios.processAnnouncementCentrally
(Node.leiosKernelTracer tracers)
getLeiosCentralState
(getLeiosOutstanding, getLeiosReady)
getLeiosTxCache
(Just peer)
Leios.ReceivedViaChainSync
Announcements.DoRelay
(Just (diffRelTime now hdrSlotTime))
ancHdr
}
dynEnv
, hChainSyncServer = \peer _version ->
Expand Down Expand Up @@ -493,23 +519,20 @@ mkHandlers
(Leios.ancHeader ancH)
)
-- central part of the processing
( \ancHdr (shouldRelay, age, anc'@(p, _sz)) -> do
( \ancHdr (shouldRelay, age, (p, _sz)) -> do
traceWith tracer $
MkTraceLeiosPeer $
"MsgLeiosBlockAnnouncement new: " <> Leios.prettyLeiosPoint p
MVar.modifyMVar_ getLeiosCentralState $ \cst ->
-- TODO OK to hold this the whole time we're writing to the LeiosNotify queues (NB those enqeues never block)?
Announcements.onAnnouncementCentral
(contramap Leios.traceNewAnnouncement kernelTracer)
Leios.ancElId
( \_elSt ->
Leios.recordAnnouncedEb (getLeiosOutstanding, getLeiosReady) anc'
)
cst
(Just peer)
shouldRelay
(Just age)
ancHdr
Leios.processAnnouncementCentrally
kernelTracer
getLeiosCentralState
(getLeiosOutstanding, getLeiosReady)
getLeiosTxCache
(Just peer)
Leios.ReceivedViaLeiosNotify
shouldRelay
(Just age)
ancHdr
)
peerSt0
anc
Expand Down Expand Up @@ -666,6 +689,7 @@ mkHandlers
(leiosPeerTracer peer)
((== Terminate) <$> controlMessageSTM)
(getLeiosOutstanding, getLeiosReady)
getLeiosTxCache
leiosConn
(Leios.MkPeerId peer)
reqVar
Expand All @@ -684,6 +708,7 @@ mkHandlers
, getLeiosOutstanding
, getLeiosReady
, getLeiosCentralState
, getLeiosTxCache
} = nodeKernel

leiosPeerTracer peer = TraceLabelPeer peer `contramap` Node.leiosPeerTracer tracers
Expand Down
Loading
Loading