Skip to content

Commit 2e01b1c

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 e2ae71a commit 2e01b1c

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
@@ -213,8 +213,9 @@ mkInternals bss h =
213213
eFrk <- newForkerAtTarget h reg VolatileTip
214214
case eFrk of
215215
Left{} -> error "Unreachable, Volatile tip MUST be in LedgerDB"
216-
Right frk ->
216+
Right frk -> do
217217
forkerPush frk st >> atomically (forkerCommit frk) >> forkerClose frk
218+
getEnv h pruneLedgerSeq
218219
, reapplyThenPushNOW = \blk -> getEnv h $ \env -> withRegistry $ \reg -> do
219220
eFrk <- newForkerAtTarget h reg VolatileTip
220221
case eFrk of
@@ -229,6 +230,7 @@ mkInternals bss h =
229230
blk
230231
(st `withLedgerTables` tables)
231232
forkerPush frk st' >> atomically (forkerCommit frk) >> forkerClose frk
233+
pruneLedgerSeq env
232234
, wipeLedgerDB = getEnv h $ destroySnapshots . ldbHasFS
233235
, closeLedgerDB =
234236
let LDBHandle tvar = h
@@ -251,6 +253,12 @@ mkInternals bss h =
251253
InMemoryHandleArgs -> InMemory.takeSnapshot
252254
LSMHandleArgs x -> absurd x
253255

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

0 commit comments

Comments
 (0)