|
5 | 5 | {-# LANGUAGE NamedFieldPuns #-} |
6 | 6 | {-# LANGUAGE RecordWildCards #-} |
7 | 7 | {-# LANGUAGE ScopedTypeVariables #-} |
| 8 | +{-# LANGUAGE TypeApplications #-} |
8 | 9 | {-# LANGUAGE TypeOperators #-} |
9 | 10 |
|
10 | 11 | -- | Queries |
@@ -305,14 +306,18 @@ getPerasCertSnapshot CDB{..} = PerasCertDB.getCertSnapshot cdbPerasCertDB |
305 | 306 | -- - ones the immutable tip is older than the slot of the target point: |
306 | 307 | -- * returns the block at the target slot if it is occupied;n |
307 | 308 | -- * 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)) |
309 | 311 | 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 |
316 | 321 |
|
317 | 322 | {------------------------------------------------------------------------------- |
318 | 323 | Unifying interface over the immutable DB and volatile DB, but independent |
|
0 commit comments