Skip to content

Commit 2b4b350

Browse files
committed
LedgerDB.V2: take snapshot at immutable tip
This ensures that the underlying handle isn't garbage-collected, as we only schedule a garbage collection for all states with a slot number strictly smaller than the immutable tip. Also, a very small benefit is that we get (slightly) faster replay on node startup.
1 parent f2563ab commit 2b4b350

File tree

1 file changed

+8
-4
lines changed
  • ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Storage/LedgerDB

1 file changed

+8
-4
lines changed

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
{-# LANGUAGE TypeFamilies #-}
1515
{-# LANGUAGE TypeOperators #-}
1616
{-# LANGUAGE UndecidableInstances #-}
17+
{-# LANGUAGE ViewPatterns #-}
1718

1819
module Ouroboros.Consensus.Storage.LedgerDB.V2 (mkInitDb) where
1920

@@ -197,9 +198,11 @@ mkInternals ::
197198
mkInternals bss h =
198199
TestInternals
199200
{ takeSnapshotNOW = \whereTo suff -> getEnv h $ \env -> do
200-
let selectWhereTo = case whereTo of
201-
TakeAtImmutableTip -> anchorHandle
202-
TakeAtVolatileTip -> currentHandle
201+
let selectWhereTo =
202+
case whereTo of
203+
TakeAtImmutableTip -> anchorHandle
204+
TakeAtVolatileTip -> currentHandle
205+
. volatileSuffix (ledgerDbCfgSecParam (ldbCfg env))
203206
withStateRef env (MkSolo . selectWhereTo) $ \(MkSolo st) ->
204207
Monad.void $
205208
takeSnapshot
@@ -381,7 +384,8 @@ implTryTakeSnapshot ::
381384
implTryTakeSnapshot bss env mTime nrBlocks =
382385
if onDiskShouldTakeSnapshot (ldbSnapshotPolicy env) (uncurry (flip diffTime) <$> mTime) nrBlocks
383386
then do
384-
withStateRef env (MkSolo . anchorHandle) $ \(MkSolo st) ->
387+
let volSuff = volatileSuffix (ledgerDbCfgSecParam (ldbCfg env))
388+
withStateRef env (MkSolo . anchorHandle . volSuff) $ \(MkSolo st) ->
385389
Monad.void $
386390
takeSnapshot
387391
(configCodec . getExtLedgerCfg . ledgerDbCfg $ ldbCfg env)

0 commit comments

Comments
 (0)