Skip to content

Commit f8271b2

Browse files
committed
LedgerDB.V1: fix race between chain switch and forker acquisition
1 parent fd31cf8 commit f8271b2

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
### Patch
2+
3+
- Fix a race condition between chain switches and LedgerDB.V1 forker acquisition.

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -759,13 +759,14 @@ acquireAtTarget ::
759759
Either Word64 (Target (Point blk)) ->
760760
ReadLocked m (Either GetForkerError (DbChangelog l))
761761
acquireAtTarget ldbEnv target = readLocked $ runExceptT $ do
762-
dblog <- lift $ readTVarIO (ldbChangelog ldbEnv)
763-
volSuffix <- lift $ atomically $ getVolatileSuffix $ ldbGetVolatileSuffix ldbEnv
764-
-- The DbChangelog might contain more than k states if they have not yet
765-
-- been garbage-collected.
766-
let volStates = volSuffix $ changelogStates dblog
762+
(dblog, volStates) <- lift $ atomically $ do
763+
dblog <- readTVar (ldbChangelog ldbEnv)
764+
-- The DbChangelog might contain more than k states if they have not yet
765+
-- been garbage-collected.
766+
volSuffix <- getVolatileSuffix $ ldbGetVolatileSuffix ldbEnv
767+
pure (dblog, volSuffix $ changelogStates dblog)
767768

768-
immTip :: Point blk
769+
let immTip :: Point blk
769770
immTip = castPoint $ getTip $ AS.anchor volStates
770771

771772
rollbackMax :: Word64

0 commit comments

Comments
 (0)