1
+ {-# LANGUAGE BangPatterns #-}
1
2
{-# LANGUAGE CPP #-}
2
3
{-# LANGUAGE DataKinds #-}
3
4
{-# LANGUAGE DeriveAnyClass #-}
@@ -35,6 +36,7 @@ import Data.Set (Set)
35
36
import qualified Data.Set as Set
36
37
import Data.Void
37
38
import Data.Word
39
+ import qualified Debug.Trace as DT
38
40
import GHC.Generics
39
41
import NoThunks.Class
40
42
import Ouroboros.Consensus.Block
@@ -210,8 +212,9 @@ mkInternals bss h =
210
212
eFrk <- newForkerAtTarget h reg VolatileTip
211
213
case eFrk of
212
214
Left {} -> error " Unreachable, Volatile tip MUST be in LedgerDB"
213
- Right frk ->
215
+ Right frk -> do
214
216
forkerPush frk st >> atomically (forkerCommit frk) >> forkerClose frk
217
+ getEnv h pruneLedgerSeq
215
218
, reapplyThenPushNOW = \ blk -> getEnv h $ \ env -> withRegistry $ \ reg -> do
216
219
eFrk <- newForkerAtTarget h reg VolatileTip
217
220
case eFrk of
@@ -226,6 +229,7 @@ mkInternals bss h =
226
229
blk
227
230
(st `withLedgerTables` tables)
228
231
forkerPush frk st' >> atomically (forkerCommit frk) >> forkerClose frk
232
+ pruneLedgerSeq env
229
233
, wipeLedgerDB = getEnv h $ destroySnapshots . ldbHasFS
230
234
, closeLedgerDB =
231
235
let LDBHandle tvar = h
@@ -244,6 +248,12 @@ mkInternals bss h =
244
248
InMemoryHandleArgs -> InMemory. takeSnapshot
245
249
LSMHandleArgs x -> absurd x
246
250
251
+ pruneLedgerSeq :: LedgerDBEnv m (ExtLedgerState blk ) blk -> m ()
252
+ pruneLedgerSeq env =
253
+ join $ atomically $ stateTVar (ldbSeq env) $ prune (LedgerDbPruneKeeping k)
254
+ where
255
+ k = ledgerDbCfgSecParam $ ldbCfg env
256
+
247
257
-- | Testing only! Truncate all snapshots in the DB.
248
258
implIntTruncateSnapshots :: MonadThrow m => SomeHasFS m -> m ()
249
259
implIntTruncateSnapshots sfs@ (SomeHasFS fs) = do
@@ -412,8 +422,11 @@ implTryTakeSnapshot bss env mTime nrBlocks =
412
422
-- periodically flush the accumulated differences to the disk. However, in the
413
423
-- second version there is no need to do so, and because of that, this function
414
424
-- does nothing in this case.
415
- implTryFlush :: Applicative m => LedgerDBEnv m l blk -> m ()
416
- implTryFlush _ = pure ()
425
+ implTryFlush :: (MonadSTM m , GetTip l ) => LedgerDBEnv m l blk -> m ()
426
+ implTryFlush env = do
427
+ LedgerSeq ldb <- readTVarIO $ ldbSeq env
428
+ ! _ <- DT. traceM $ " ledger seq len: " <> show (AS. length ldb)
429
+ pure ()
417
430
418
431
implCloseDB :: IOLike m => LedgerDBHandle m l blk -> m ()
419
432
implCloseDB (LDBHandle varState) = do
0 commit comments