Skip to content

Commit

Permalink
ChainDB: minor tidying in Reader.forward
Browse files Browse the repository at this point in the history
This diff combines two cheap STM transactions instead of running one
immediately after the other. I'm not sure the difference matters, but this
seems more likely to be correct.
  • Loading branch information
nfrisby committed Jan 14, 2021
1 parent 77c4e0e commit 010eb40
Showing 1 changed file with 9 additions and 8 deletions.
Expand Up @@ -415,14 +415,15 @@ forward ::
-> [Point blk]
-> m (Maybe (Point blk))
forward registry varReader blockComponent CDB{..} = \pts -> do
-- NOTE: we don't use 'Query.getCurrentChain', which only returns the last
-- @k@ headers, because we want to see the headers that have not yet been
-- written to the ImmutableDB too.
(curChain, readerState) <- atomically $
(,) <$> readTVar cdbChain <*> readTVar varReader
slotNoAtImmutableDBTip <- atomically $
ImmutableDB.getTipSlot cdbImmutableDB
findFirstPointOnChain curChain readerState slotNoAtImmutableDBTip pts
-- NOTE: we use `cdbChain` instead of 'Query.getCurrentChain', which only
-- returns the last @k@ headers, because we need to also see the headers
-- that happen to have not yet been GC'd over to the ImmutableDB.
join $ atomically $
findFirstPointOnChain
<$> readTVar cdbChain
<*> readTVar varReader
<*> ImmutableDB.getTipSlot cdbImmutableDB
<*> pure pts
where
findFirstPointOnChain ::
HasCallStack
Expand Down

0 comments on commit 010eb40

Please sign in to comment.