Skip to content

Commit 894940c

Browse files
committed
LedgerDB.V2.TestInternals: prune LedgerSeq
This is used in db-analyser only, where everything happens synchronously in a single thread, so it is fine to immediately prune. V1 already does this.
1 parent eaec788 commit 894940c

File tree

2 files changed

+16
-1
lines changed
  • ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Storage/LedgerDB

2 files changed

+16
-1
lines changed

ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Storage/LedgerDB/API.hs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,14 @@ data TestInternals m l blk = TestInternals
305305
{ wipeLedgerDB :: m ()
306306
, takeSnapshotNOW :: WhereToTakeSnapshot -> Maybe String -> m ()
307307
, push :: ExtLedgerState blk DiffMK -> m ()
308+
-- ^ Push a ledger state, and prune the 'LedgerDB' w.r.t. the security parameter.
309+
--
310+
-- This does not modify the set of previously applied points.
308311
, reapplyThenPushNOW :: blk -> m ()
312+
-- ^ Apply block to the tip ledger state (using reapplication), and prune the
313+
-- 'LedgerDB' w.r.t. the security parameter.
314+
--
315+
-- This does not modify the set of previously applied points.
309316
, truncateSnapshots :: m ()
310317
, closeLedgerDB :: m ()
311318
, getNumLedgerTablesHandles :: m Word64

ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Storage/LedgerDB/V2.hs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,9 @@ mkInternals bss h =
215215
eFrk <- newForkerAtTarget h reg VolatileTip
216216
case eFrk of
217217
Left{} -> error "Unreachable, Volatile tip MUST be in LedgerDB"
218-
Right frk ->
218+
Right frk -> do
219219
forkerPush frk st >> atomically (forkerCommit frk) >> forkerClose frk
220+
getEnv h pruneLedgerSeq
220221
, reapplyThenPushNOW = \blk -> getEnv h $ \env -> withRegistry $ \reg -> do
221222
eFrk <- newForkerAtTarget h reg VolatileTip
222223
case eFrk of
@@ -231,6 +232,7 @@ mkInternals bss h =
231232
blk
232233
(st `withLedgerTables` tables)
233234
forkerPush frk st' >> atomically (forkerCommit frk) >> forkerClose frk
235+
pruneLedgerSeq env
234236
, wipeLedgerDB = getEnv h $ destroySnapshots . ldbHasFS
235237
, closeLedgerDB =
236238
let LDBHandle tvar = h
@@ -253,6 +255,12 @@ mkInternals bss h =
253255
InMemoryHandleArgs -> InMemory.takeSnapshot
254256
LSMHandleArgs x -> absurd x
255257

258+
pruneLedgerSeq :: LedgerDBEnv m (ExtLedgerState blk) blk -> m ()
259+
pruneLedgerSeq env =
260+
join $ atomically $ stateTVar (ldbSeq env) $ prune (LedgerDbPruneKeeping k)
261+
where
262+
k = ledgerDbCfgSecParam $ ldbCfg env
263+
256264
-- | Testing only! Truncate all snapshots in the DB.
257265
implIntTruncateSnapshots :: MonadThrow m => SomeHasFS m -> m ()
258266
implIntTruncateSnapshots sfs@(SomeHasFS fs) = do

0 commit comments

Comments
 (0)