File tree Expand file tree Collapse file tree 4 files changed +11
-4
lines changed
ouroboros-consensus-diffusion/test/consensus-test/Test/Consensus/HardFork/Combinator
src/ouroboros-consensus/Ouroboros/Consensus/Mempool
test/consensus-test/Test/Consensus Expand file tree Collapse file tree 4 files changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -330,7 +330,8 @@ instance LedgerSupportsMempool BlockA where
330330
331331instance TxLimits BlockA where
332332 type TxMeasure BlockA = ByteSize
333- blockCapacityTxMeasure _cfg _st = ByteSize 1
333+ -- default mempool capacity is two blocks, so maxBound/2 avoids overflow
334+ blockCapacityTxMeasure _cfg _st = ByteSize $ maxBound `div` 2
334335 txMeasure _cfg _st _tx = ByteSize 0
335336
336337newtype instance TxId (GenTx BlockA ) = TxIdA Int
Original file line number Diff line number Diff line change @@ -266,7 +266,8 @@ instance LedgerSupportsMempool BlockB where
266266
267267instance TxLimits BlockB where
268268 type TxMeasure BlockB = ByteSize
269- blockCapacityTxMeasure _cfg _st = ByteSize 1
269+ -- default mempool capacity is two blocks, so maxBound/2 avoids overflow
270+ blockCapacityTxMeasure _cfg _st = ByteSize $ maxBound `div` 2
270271 txMeasure _cfg _st _tx = ByteSize 0
271272
272273data instance TxId (GenTx BlockB )
Original file line number Diff line number Diff line change @@ -63,6 +63,8 @@ computeMempoolCapacity cfg st override =
6363 blockCount = case override of
6464 NoMempoolCapacityBytesOverride -> 2
6565 MempoolCapacityBytesOverride (ByteSize x) ->
66+ -- This calculation is happening at Word32. Thus overflow is silently
67+ -- accepted.
6668 max 1 $ (x + oneBlockBytes - 1 ) `div` oneBlockBytes
6769
6870 SemigroupViaMeasure capacity =
Original file line number Diff line number Diff line change @@ -1029,8 +1029,11 @@ prop_Mempool_idx_consistency (Actions actions) =
10291029 { testLedgerState = testInitLedger
10301030 , testInitialTxs = []
10311031 , testMempoolCapOverride =
1032- MempoolCapacityBytesOverride $ ByteSize $ maxBound - 100 * 1024 * 1024
1033- --- can't use maxBound, because then the check in addTx overflows
1032+ MempoolCapacityBytesOverride
1033+ $ ByteSize
1034+ $ maxBound - unByteSize simpleBlockCapacity
1035+ --- can't use maxBound, because then 'computeMempoolCapacity'
1036+ --- calculation overflows, resulting in a capacity of just one block
10341037 }
10351038
10361039 lastOfMempoolRemoved txsInMempool = \ case
You can’t perform that action at this time.
0 commit comments