Skip to content

Commit

Permalink
addBlock, addBlock_ shouldn't be partial functions
Browse files Browse the repository at this point in the history
`addBlock_` is used by `initNodeKernel` when calling the `initChainDB`
callback from `NodeKernelArgs`.
  • Loading branch information
coot committed Nov 9, 2022
1 parent 8a9d69d commit ac457b5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import Data.Functor.Identity (Identity)
import Data.List (sortOn)
import qualified Data.List.NonEmpty as NE
import qualified Data.Map as Map
import Data.Maybe (fromJust, fromMaybe)
import Data.Maybe (fromMaybe)
import Data.Ord (Down (..))
import Data.Proxy
import Data.Sequence.Strict (StrictSeq)
Expand Down Expand Up @@ -380,7 +380,10 @@ run env@ChainDBEnv { varDB, .. } cmd =
advanceAndAdd ChainDBState { chainDB } newCurSlot blk = do
atomically $ modifyTVar varCurSlot (max newCurSlot)
-- `blockProcessed` always returns 'Just'
fromJust <$> addBlock chainDB InvalidBlockPunishment.noPunishment blk
res <- addBlock chainDB InvalidBlockPunishment.noPunishment blk
return $ case res of
Nothing -> error "advanceAndAdd: block not added"
Just pt -> pt

wipeVolatileDB :: ChainDBState m blk -> m (Point blk)
wipeVolatileDB st = do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -439,13 +439,17 @@ addBlockWaitWrittenToDisk chainDB punish blk = do

-- | Add a block synchronously: wait until the block has been processed (see
-- 'blockProcessed'). The new tip of the ChainDB is returned.
--
-- Note: this is a partial function, only to support tests.
addBlock :: IOLike m => ChainDB m blk -> InvalidBlockPunishment m -> blk -> m (Maybe (Point blk))
addBlock chainDB punish blk = do
promise <- addBlockAsync chainDB punish blk
atomically $ blockProcessed promise

-- | Add a block synchronously. Variant of 'addBlock' that doesn't return the
-- new tip of the ChainDB.
--
-- Note: this is a partial function, only to support tests.
addBlock_ :: IOLike m => ChainDB m blk -> InvalidBlockPunishment m -> blk -> m ()
addBlock_ = void ..: addBlock

Expand Down

0 comments on commit ac457b5

Please sign in to comment.