Skip to content

Commit

Permalink
Merge #1780
Browse files Browse the repository at this point in the history
1780: Use MD5 instead of ShortHash in Mempool tests r=nfrisby a=nfrisby

Closes #1779.

I also included some of the additions that we needed in order to debug the original hash collision.

Co-authored-by: Nicolas Frisby <[email protected]>
  • Loading branch information
iohk-bors[bot] and nfrisby authored Mar 10, 2020
2 parents 049cc6a + 8eecd3c commit cca25ad
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ instance Condense Tx where

type Ix = Word
type Amount = Word
type TxId = Hash ShortHash Tx
type TxId = Hash MD5 Tx
type TxIn = (TxId, Ix)
type TxOut = (Addr, Amount)
type Utxo = Map TxIn TxOut
Expand Down
3 changes: 3 additions & 0 deletions ouroboros-consensus/src/Ouroboros/Consensus/Mempool/API.hs
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,9 @@ data MempoolAddTxResult blk
-- ^ The transaction was rejected and could not be added to the mempool
-- for the specified reason.

deriving instance Eq (ApplyTxErr blk) => Eq (MempoolAddTxResult blk)
deriving instance Show (ApplyTxErr blk) => Show (MempoolAddTxResult blk)

isTxAddedOrAlreadyInMempool :: MempoolAddTxResult blk -> Bool
isTxAddedOrAlreadyInMempool MempoolTxAdded = True
isTxAddedOrAlreadyInMempool MempoolTxAlreadyInMempool = True
Expand Down
11 changes: 8 additions & 3 deletions ouroboros-consensus/test-consensus/Test/Consensus/Mempool.hs
Original file line number Diff line number Diff line change
Expand Up @@ -318,11 +318,14 @@ ppTestSetup :: TestSetup -> String
ppTestSetup TestSetup { testInitialTxs
, testMempoolCap = MempoolCapacityBytes mpCap
} = unlines $
["Initial contents of the Mempool:"] <>
(map condense testInitialTxs) <>
["Mempool capacity:"] <>
["Initial contents of the Mempool:"] <>
(map ppTestTxWithHash testInitialTxs) <>
["Mempool capacity:"] <>
[condense mpCap]

ppTestTxWithHash :: TestTx -> String
ppTestTxWithHash x = condense (hash (simpleGenTx x) :: Hash MD5 Tx, x)

-- | Given some transactions, calculate the sum of their sizes in bytes.
txSizesInBytes :: [TestTx] -> TxSizeInBytes
txSizesInBytes = foldl' (\acc tx -> acc + txSize tx) 0
Expand Down Expand Up @@ -660,6 +663,8 @@ withTestMempool setup@TestSetup { testLedgerState, testInitialTxs, testMempoolCa
testMempoolCap
tracer
result <- addTxs mempool testInitialTxs
-- the invalid transactions are reported in the same order they were
-- added, so the first error is not the result of a cascade
whenJust (find (isTxRejected . snd) result) $ \(invalidTx, _) -> error $
"Invalid initial transaction: " <> condense invalidTx

Expand Down

0 comments on commit cca25ad

Please sign in to comment.