Skip to content

Commit 97792c2

Browse files
committed
LedgerDB.V2.TestInternals: make takeSnapshotNOW safe
Not necessary given how it is currently being used, but it is also easy enough to make it resilient against the race condition, so why not?
1 parent b89a04b commit 97792c2

File tree

1 file changed

+9
-11
lines changed
  • ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Storage/LedgerDB

1 file changed

+9
-11
lines changed

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

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -196,19 +196,17 @@ mkInternals ::
196196
mkInternals bss h =
197197
TestInternals
198198
{ takeSnapshotNOW = \whereTo suff -> getEnv h $ \env -> do
199-
st <-
200-
( case whereTo of
199+
let selectWhereTo = case whereTo of
201200
TakeAtImmutableTip -> anchorHandle
202201
TakeAtVolatileTip -> currentHandle
203-
)
204-
<$> readTVarIO (ldbSeq env)
205-
Monad.void $
206-
takeSnapshot
207-
(configCodec . getExtLedgerCfg . ledgerDbCfg $ ldbCfg env)
208-
(LedgerDBSnapshotEvent >$< ldbTracer env)
209-
(ldbHasFS env)
210-
suff
211-
st
202+
withStateRef env (MkSolo . selectWhereTo) $ \(MkSolo st) ->
203+
Monad.void $
204+
takeSnapshot
205+
(configCodec . getExtLedgerCfg . ledgerDbCfg $ ldbCfg env)
206+
(LedgerDBSnapshotEvent >$< ldbTracer env)
207+
(ldbHasFS env)
208+
suff
209+
st
212210
, push = \st -> withRegistry $ \reg -> do
213211
eFrk <- newForkerAtTarget h reg VolatileTip
214212
case eFrk of

0 commit comments

Comments
 (0)