Skip to content
Permalink
Browse files

Actually check the hash in ImmDB.getBlockWithPoint

  • Loading branch information...
mrBliss committed May 15, 2019
1 parent 77b11d9 commit e0faafb78b1dd62dd22d002ec3e290b8d890b70a
Showing with 12 additions and 4 deletions.
  1. +12 −4 ouroboros-consensus/src/Ouroboros/Storage/ChainDB/ImmDB.hs
@@ -1,4 +1,5 @@
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ScopedTypeVariables #-}
@@ -128,6 +129,8 @@ openDB args@ImmDbArgs{..} = do
Getting and parsing blocks
-------------------------------------------------------------------------------}

-- | Return the block corresponding to the given point, if it is part of the
-- ImmutableDB.
getBlockWithPoint :: (MonadCatch m, HasHeader blk)
=> ImmDB m blk -> Point blk -> m (Maybe blk)
getBlockWithPoint db Point{..} = do
@@ -142,15 +145,20 @@ getBlockWithPoint db Point{..} = do
-- non-existent after)
-- * If the block does not exist in the database at all, we'd have done two
-- reads before returning 'Nothing', but both of those reads are cheap
mbImmBlock <- getBlock db (Right pointSlot)
case mbImmBlock of
Just block -> return $ Just block
mbBlock <- getBlockWithHash (Right pointSlot) pointHash
case mbBlock of
Just block -> return (Just block)
Nothing -> do
epochNo <- epochInfoEpoch pointSlot
getBlock db (Left epochNo)
getBlockWithHash (Left epochNo) pointHash
where
EpochInfo{..} = immEpochInfo db

-- Important: we check whether the block's hash matches the point's hash
getBlockWithHash epochOrSlot hash = getBlock db epochOrSlot >>= \case
Just block | BlockHash (blockHash block) == hash -> return $ Just block
_ -> return $ Nothing

getBlockAtTip :: (MonadCatch m, HasHeader blk)
=> ImmDB m blk -> m (Maybe blk)
getBlockAtTip db = do

0 comments on commit e0faafb

Please sign in to comment.
You can’t perform that action at this time.