Skip to content

Commit 605c734

Browse files
committed
[wip] wait for block with stm
1 parent c974498 commit 605c734

File tree

1 file changed

+12
-7
lines changed
  • ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Storage/ChainDB/Impl

1 file changed

+12
-7
lines changed

ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Storage/ChainDB/Impl/Query.hs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
{-# LANGUAGE NamedFieldPuns #-}
66
{-# LANGUAGE RecordWildCards #-}
77
{-# LANGUAGE ScopedTypeVariables #-}
8+
{-# LANGUAGE TypeApplications #-}
89
{-# LANGUAGE TypeOperators #-}
910

1011
-- | Queries
@@ -305,14 +306,18 @@ getPerasCertSnapshot CDB{..} = PerasCertDB.getCertSnapshot cdbPerasCertDB
305306
-- - ones the immutable tip is older than the slot of the target point:
306307
-- * returns the block at the target slot if it is occupied;n
307308
-- * otherwise, returns the block from the next occupied slot.
308-
waitForImmutableBlock :: IOLike m => ChainDbEnv m blk -> RealPoint blk -> m (Maybe (RealPoint blk))
309+
waitForImmutableBlock ::
310+
forall blk m. IOLike m => ChainDbEnv m blk -> RealPoint blk -> m (Maybe (RealPoint blk))
309311
waitForImmutableBlock CDB{cdbImmutableDB} targetRealPoint = do
310-
atomically (ImmutableDB.getTip cdbImmutableDB) >>= \case
311-
Origin -> pure Nothing
312-
At tip ->
313-
if ImmutableDB.tipSlotNo tip >= realPointSlot targetRealPoint
314-
then ImmutableDB.getBlockAtOrAfterPoint cdbImmutableDB targetRealPoint
315-
else pure Nothing
312+
-- first, wait until the target slot is older than the immutable tip
313+
_ <- atomically $ do
314+
ImmutableDB.getTip cdbImmutableDB >>= \case
315+
Origin -> retry
316+
At tip -> do
317+
check (ImmutableDB.tipSlotNo tip >= realPointSlot targetRealPoint)
318+
pure (ImmutableDB.tipToRealPoint tip)
319+
-- then, query the DB for a point at or directly following the target slot
320+
ImmutableDB.getBlockAtOrAfterPoint cdbImmutableDB targetRealPoint
316321

317322
{-------------------------------------------------------------------------------
318323
Unifying interface over the immutable DB and volatile DB, but independent

0 commit comments

Comments
 (0)