Skip to content

Commit 93829e2

Browse files
committed
TOSQUASH fixup overflow workarounds and their explanations
1 parent b90124a commit 93829e2

File tree

4 files changed

+11
-4
lines changed
  • ouroboros-consensus-diffusion/test/consensus-test/Test/Consensus/HardFork/Combinator
  • ouroboros-consensus
    • src/ouroboros-consensus/Ouroboros/Consensus/Mempool
    • test/consensus-test/Test/Consensus

4 files changed

+11
-4
lines changed

ouroboros-consensus-diffusion/test/consensus-test/Test/Consensus/HardFork/Combinator/A.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,8 @@ instance LedgerSupportsMempool BlockA where
330330

331331
instance 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

336337
newtype instance TxId (GenTx BlockA) = TxIdA Int

ouroboros-consensus-diffusion/test/consensus-test/Test/Consensus/HardFork/Combinator/B.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,8 @@ instance LedgerSupportsMempool BlockB where
266266

267267
instance 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

272273
data instance TxId (GenTx BlockB)

ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Mempool/Capacity.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff 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 =

ouroboros-consensus/test/consensus-test/Test/Consensus/Mempool.hs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)