Skip to content

Commit

Permalink
DB.MVar: Make it slightly less eager in evaluation
Browse files Browse the repository at this point in the history
Our MockSealedTx can't be fully evaluated because it contains bottom
values.

It should be sufficient to evaluate the MVar database to WHNF.
  • Loading branch information
rvl committed Sep 14, 2021
1 parent 5855e84 commit ea729af
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
17 changes: 7 additions & 10 deletions lib/core/src/Cardano/Wallet/DB/MVar.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE RankNTypes #-}
Expand Down Expand Up @@ -67,8 +68,6 @@ import Cardano.Wallet.Primitive.Types.Hash
( Hash )
import Cardano.Wallet.Primitive.Types.Tx
( TransactionInfo (..) )
import Control.DeepSeq
( NFData, force )
import Control.Monad.IO.Unlift
( MonadUnliftIO (..) )
import Control.Monad.Trans.Except
Expand All @@ -85,9 +84,7 @@ import UnliftIO.MVar
newDBLayer
:: forall m s k.
( MonadUnliftIO m
, MonadFail m
, NFData (k 'RootK XPrv)
, NFData s)
, MonadFail m )
=> TimeInterpreter Identity
-> m (DBLayer m s k)
newDBLayer timeInterpreter = do
Expand Down Expand Up @@ -232,7 +229,7 @@ newDBLayer timeInterpreter = do

-- | Apply an operation to the model database, then update the mutable variable.
alterDB
:: (MonadUnliftIO m, NFData s, NFData xprv)
:: MonadUnliftIO m
=> (Err WalletId -> Maybe err)
-- ^ Error type converter
-> MVar (Database WalletId s xprv)
Expand All @@ -242,15 +239,15 @@ alterDB
-> m (Either err a)
alterDB convertErr db op = modifyMVar db (bubble . op)
where
bubble (Left e, db') = case convertErr e of
Just e' -> pure (force db', Left e')
bubble (Left e, !db') = case convertErr e of
Just e' -> pure (db', Left e')
Nothing -> throwIO $ MVarDBError e
bubble (Right a, db') = pure (force db', Right a)
bubble (Right a, !db') = pure (db', Right a)

-- | Run a query operation on the model database. Any error results are turned
-- into a runtime exception.
readDB
:: (MonadUnliftIO m, NFData s, NFData xprv)
:: MonadUnliftIO m
=> MVar (Database WalletId s xprv)
-- ^ The database variable
-> ModelOp WalletId s xprv a
Expand Down
2 changes: 1 addition & 1 deletion lib/core/src/Cardano/Wallet/DB/Model.hs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ import qualified Data.Map.Strict as Map
data Database wid s xprv = Database
{ wallets :: !(Map wid (WalletDatabase s xprv))
-- ^ Wallet-related information.
, txs :: Map (Hash "Tx") Tx
, txs :: !(Map (Hash "Tx") Tx)
-- ^ In the database, transactions are global and not associated with any
-- particular wallet.
} deriving (Generic, NFData)
Expand Down

0 comments on commit ea729af

Please sign in to comment.