Skip to content
Permalink
Browse files

Don't generate 'Pending' txs for 'putTxHistory' + add invariant at ca…

…llee site

There's no reason we would call 'putTxHistory' with pending
transactions. Pending transactions insertation should always be
a collateral result of inserting a checkpoint that contains some
pending txs.
  • Loading branch information...
KtorZ committed Jun 12, 2019
1 parent ba673d4 commit 14fcfeb4a2c45a59519892cdd898a580d4d3c3ab
@@ -274,7 +274,11 @@ newDBLayer fp = do
ExceptT $ runQuery' $
selectWallet wid >>= \case
Just _ -> do
let (metas, txins, txouts) = mkTxHistory wid txs
let (metas, txins, txouts) = mkTxHistory wid $ W.invariant
("putTxHistory has been called with pending txs: "
<> show txs)
txs
(not . foldl (\b a -> (b || W.isPending a)) False)
putTxMetas metas
putTxs txins txouts
pure $ Right ()
@@ -625,7 +629,6 @@ deleteLooseTransactions = do
"LEFT OUTER JOIN tx_meta ON tx_meta.tx_id = "<> t <>".tx_id " <>
"WHERE (tx_meta.tx_id IS NULL))"


selectLatestCheckpoint
:: W.WalletId
-> SqlPersistM (Maybe Checkpoint)
@@ -41,6 +41,7 @@ module Cardano.Wallet.Primitive.Types
, TxStatus(..)
, TxWitness (..)
, txIns
, isPending

-- * Address
, Address (..)
@@ -474,6 +475,10 @@ data TxWitness
-- ^ Used to redeem ADA from the pre-sale
deriving (Eq, Show)

-- | True if the given tuple refers to a pending transaction
isPending :: (Tx, TxMeta) -> Bool
isPending = (== Pending) . (status :: TxMeta -> TxStatus) . snd

{-------------------------------------------------------------------------------
Address
-------------------------------------------------------------------------------}
@@ -85,6 +85,7 @@ import Cardano.Wallet.Primitive.Types
, WalletName (..)
, WalletPassphraseInfo (..)
, WalletState (..)
, isPending
)
import Control.Concurrent.Async
( forConcurrently_ )
@@ -354,7 +355,12 @@ instance Arbitrary GenTxHistory where
-- Ensure unique transaction IDs within a given batch of transactions to add
-- to the history.
arbitrary = GenTxHistory . Map.fromList <$> do
txs <- arbitrary
-- NOTE
-- For the tx history, we discard pending transaction since pending txs
-- should only be inserted as a collateral of inserting a checkpoint!
-- There's no way we would call 'putTxHistory' with pending transaction.
-- (cf invariant in code).
txs <- filter (not . isPending) <$> arbitrary
return $ (\(tx, meta) -> (mockTxId tx, (tx, meta))) <$> txs
where
mockTxId :: Tx -> Hash "Tx"

0 comments on commit 14fcfeb

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