Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ repository cardano-haskell-packages
-- update either of these.
index-state:
-- Bump this if you need newer packages from Hackage
, hackage.haskell.org 2025-09-26T20:57:57Z
, hackage.haskell.org 2025-10-23T13:39:53Z
-- Bump this if you need newer packages from CHaP
, cardano-haskell-packages 2025-10-01T14:54:25Z

Expand Down
12 changes: 6 additions & 6 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!--
A new scriv changelog fragment.
Uncomment the section that is right (remove the HTML comment wrapper).
For top level release notes, leave all the headers commented out.
-->

### Patch

- Bump to `resource-registry ^>= 0.2`.

<!--
### Non-Breaking
- A bullet item for the Non-Breaking category.
-->
<!--
### Breaking
- A bullet item for the Breaking category.
-->
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ library
ouroboros-network-framework ^>=0.19,
ouroboros-network-protocols ^>=0.15,
random,
resource-registry ^>=0.1,
resource-registry ^>=0.2,
safe-wild-cards ^>=1.0,
serialise ^>=0.2,
text,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1158,7 +1158,7 @@ runThreadNetwork
mempool
txs0

void $ allocate registry (\_ -> pure threadCrucialTxs) cancelThread
void $ allocateThread registry (\_ -> pure threadCrucialTxs)

forkTxProducer
coreNodeId
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!--
A new scriv changelog fragment.
Uncomment the section that is right (remove the HTML comment wrapper).
For top level release notes, leave all the headers commented out.
-->

### Patch

- Bump to `resource-registry ^>= 0.2`.

### Non-Breaking

- Do not open forkers unnecessarily in the Mempool when re-syncing it.

- Committing a forker will move the handles to the registry of the LedgerDB. The
discarded fork will be queued to be released by the `garbageCollect` logic.

<!--
### Breaking
- A bullet item for the Breaking category.
-->
4 changes: 2 additions & 2 deletions ouroboros-consensus/ouroboros-consensus.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ library
psqueues ^>=0.2.3,
quiet ^>=0.2,
rawlock ^>=0.1.1,
resource-registry ^>=0.1,
resource-registry ^>=0.2,
semialign >=1.1,
serialise ^>=0.2,
singletons,
Expand Down Expand Up @@ -393,7 +393,7 @@ library ouroboros-consensus-lsm
ouroboros-consensus,
primitive,
random,
resource-registry ^>=0.1,
resource-registry ^>=0.2,
serialise ^>=0.2,
streaming,
text,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ import Data.Void
import Database.LSMTree (Salt, Session, Table)
import qualified Database.LSMTree as LSM
import GHC.Generics
import GHC.Stack (HasCallStack)
import NoThunks.Class
import Ouroboros.Consensus.Block
import Ouroboros.Consensus.Ledger.Abstract
Expand Down Expand Up @@ -167,21 +168,22 @@ newLSMLedgerTablesHandle ::
, IndexedMemPack (l EmptyMK) (TxOut l)
) =>
Tracer m LedgerDBV2Trace ->
ResourceRegistry m ->
(ResourceKey m, UTxOTable m) ->
m (LedgerTablesHandle m l)
newLSMLedgerTablesHandle tracer rr (resKey, t) = do
newLSMLedgerTablesHandle tracer (origResKey, t) = do
traceWith tracer TraceLedgerTablesHandleCreate
tv <- newTVarIO origResKey
pure
LedgerTablesHandle
{ close = implClose resKey
, duplicate = implDuplicate rr t tracer
{ close = implClose tv
, duplicate = \rr -> implDuplicate rr t tracer
, read = implRead t
, readRange = implReadRange t
, readAll = implReadAll t
, pushDiffs = implPushDiffs t
, takeHandleSnapshot = implTakeHandleSnapshot t
, tablesSize = pure Nothing
, transfer = atomically . writeTVar tv
}

{-# INLINE implClose #-}
Expand All @@ -192,8 +194,9 @@ newLSMLedgerTablesHandle tracer rr (resKey, t) = do
{-# INLINE implPushDiffs #-}
{-# INLINE implTakeHandleSnapshot #-}

implClose :: IOLike m => ResourceKey m -> m ()
implClose = Monad.void . release
implClose :: (HasCallStack, IOLike m) => StrictTVar m (ResourceKey m) -> m ()
implClose tv =
Monad.void $ release =<< readTVarIO tv

implDuplicate ::
( IOLike m
Expand All @@ -203,17 +206,17 @@ implDuplicate ::
ResourceRegistry m ->
UTxOTable m ->
Tracer m LedgerDBV2Trace ->
m (LedgerTablesHandle m l)
m (ResourceKey m, LedgerTablesHandle m l)
implDuplicate rr t tracer = do
table <-
(rk, table) <-
allocate
rr
(\_ -> LSM.duplicate t)
( \t' -> do
traceWith tracer TraceLedgerTablesHandleClose
LSM.closeTable t'
)
newLSMLedgerTablesHandle tracer rr table
(rk,) <$> newLSMLedgerTablesHandle tracer (rk, table)

implRead ::
forall m l.
Expand Down Expand Up @@ -461,7 +464,7 @@ loadSnapshot tracer rr ccfg fs session ds =
case pointToWithOriginRealPoint (castPoint (getTip extLedgerSt)) of
Origin -> throwE InitFailureGenesis
NotOrigin pt -> do
values <-
(rk, values) <-
lift $
allocate
rr
Expand All @@ -481,7 +484,7 @@ loadSnapshot tracer rr ccfg fs session ds =
$ InitFailureRead
ReadSnapshotDataCorruption
(,pt)
<$> lift (empty extLedgerSt values (newLSMLedgerTablesHandle tracer rr))
<$> lift (empty extLedgerSt (rk, values) (newLSMLedgerTablesHandle tracer))

-- | Create the initial LSM table from values, which should happen only at
-- Genesis.
Expand All @@ -495,18 +498,16 @@ tableFromValuesMK ::
LedgerTables l ValuesMK ->
m (ResourceKey m, UTxOTable m)
tableFromValuesMK tracer rr session st (LedgerTables (ValuesMK values)) = do
res@(_, table) <-
(rk, table) <-
allocate
rr
( \_ ->
LSM.newTableWith (LSM.defaultTableConfig{LSM.confFencePointerIndex = LSM.OrdinaryIndex}) session
)
(\_ -> LSM.newTable session)
( \tb -> do
traceWith tracer TraceLedgerTablesHandleClose
LSM.closeTable tb
)
mapM_ (go table) $ chunks 1000 $ Map.toList values
pure res
pure (rk, table)
where
go table items =
LSM.inserts table $
Expand Down Expand Up @@ -600,7 +601,7 @@ instance
newHandleFromValues trcr reg res st = do
table <-
tableFromValuesMK trcr reg (sessionResource res) (forgetLedgerTables st) (ltprj st)
newLSMLedgerTablesHandle trcr reg table
newLSMLedgerTablesHandle trcr table

snapshotManager _ res = Ouroboros.Consensus.Storage.LedgerDB.V2.LSM.snapshotManager (sessionResource res)

Expand Down Expand Up @@ -731,7 +732,7 @@ mkLSMYieldArgs fp snapName mkFS mkGen _ reg = do
(LSM.SnapshotLabel $ T.pack "UTxO table")
)
LSM.closeTable
YieldLSM 1000 <$> newLSMLedgerTablesHandle nullTracer reg tb
YieldLSM 1000 <$> newLSMLedgerTablesHandle nullTracer tb

-- | Create Sink arguments for LSM
mkLSMSinkArgs ::
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,23 +413,23 @@ implSyncWithLedger mpEnv =
-- state didn't change.
withTMVarAnd istate (const $ getCurrentLedgerState ldgrInterface registry) $
\is (MempoolLedgerDBView ls meFrk) -> do
eFrk <- meFrk
case eFrk of
-- This case should happen only if the tip has moved again, this time
-- to a separate fork, since the background thread saw a change in the
-- tip, which should happen very rarely
Left{} -> do
traceWith trcr TraceMempoolTipMovedBetweenSTMBlocks
pure (Nothing, is)
Right frk -> do
let (slot, ls') = tickLedgerState cfg $ ForgeInUnknownSlot ls
if pointHash (isTip is) == castHash (getTipHash ls) && isSlotNo is == slot
then do
-- The tip didn't change, put the same state.
traceWith trcr $ TraceMempoolSyncNotNeeded (isTip is)
pure (Just (snapshotFromIS is), is)
else do
-- The tip changed, we have to revalidate
let (slot, ls') = tickLedgerState cfg $ ForgeInUnknownSlot ls
if pointHash (isTip is) == castHash (getTipHash ls) && isSlotNo is == slot
then do
-- The tip didn't change, put the same state.
traceWith trcr $ TraceMempoolSyncNotNeeded (isTip is)
pure (Just (snapshotFromIS is), is)
else do
-- The tip changed, we have to revalidate
eFrk <- meFrk
case eFrk of
-- This case should happen only if the tip has moved again, this time
-- to a separate fork, since the background thread saw a change in the
-- tip, which should happen very rarely
Left{} -> do
traceWith trcr TraceMempoolTipMovedBetweenSTMBlocks
pure (Nothing, is)
Right frk -> do
modifyMVar_
forkerMVar
( \oldFrk -> do
Expand Down
Loading
Loading