Skip to content

Commit 6a9ec88

Browse files
committed
TOSQUASH forgot to add new file
1 parent 96fce00 commit 6a9ec88

File tree

1 file changed

+22
-0
lines changed
  • ouroboros-consensus/src/unstable-mempool-test-utils/Test/Consensus/Mempool

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{-# LANGUAGE BangPatterns #-}
2+
{-# LANGUAGE LambdaCase #-}
3+
4+
module Test.Consensus.Mempool.Multiplicity (leastMultiplicity) where
5+
6+
import Ouroboros.Consensus.Mock.Ledger.Block (simpleBlockTxCapacity)
7+
import Ouroboros.Network.SizeInBytes (SizeInBytes)
8+
9+
-- | This function accurately mimics how
10+
-- 'Ouroboros.Consensus.Mempool.Update.shouldTryToAddTx' would behave when
11+
-- adding valid transactions of the following sizes, in order, to an initially
12+
-- empty mempool.
13+
leastMultiplicity :: [SizeInBytes] -> Int
14+
leastMultiplicity =
15+
go 1 0
16+
where
17+
go !n !acc = \case
18+
[] -> n
19+
x:xs ->
20+
if acc + x <= simpleBlockTxCapacity
21+
then go n (acc + x) xs
22+
else go (n + 1) x xs

0 commit comments

Comments
 (0)