Skip to content

Commit

Permalink
TOSQUASH forgot to add new file
Browse files Browse the repository at this point in the history
  • Loading branch information
nfrisby committed Jul 10, 2024
1 parent 03b4a1e commit fb968f8
Showing 1 changed file with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE LambdaCase #-}

module Test.Consensus.Mempool.Multiplicity (leastMultiplicity) where

import Ouroboros.Consensus.Mock.Ledger.Block (simpleBlockTxCapacity)
import Ouroboros.Network.SizeInBytes (SizeInBytes)

-- | This function accurately mimics how
-- 'Ouroboros.Consensus.Mempool.Update.shouldTryToAddTx' would behave when
-- adding valid transactions of the following sizes, in order, to an initially
-- empty mempool.
leastMultiplicity :: [SizeInBytes] -> Int
leastMultiplicity =
go 1 0
where
go !n !acc = \case
[] -> n
x:xs ->
if acc + x <= simpleBlockTxCapacity
then go n (acc + x) xs
else go (n + 1) x xs

0 comments on commit fb968f8

Please sign in to comment.