Skip to content

Commit

Permalink
TOSQUASH updates to comments, indentation, and a single local variabl…
Browse files Browse the repository at this point in the history
…e name
  • Loading branch information
nfrisby committed Aug 26, 2024
1 parent b67443d commit fe778a3
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ pureTryAddTx cfg wti tx is =
-- greater than what this ledger state allows for a single transaction).
--
-- It might seem simpler to remove the failure case from 'txMeasure' and
-- simply fully validate the tx before determing whether it'd fit in the
-- mempool; that way we could reject invalid txs ASAP. However, for a
-- simply fully validate the tx before determining whether it'd fit in
-- the mempool; that way we could reject invalid txs ASAP. However, for a
-- valid tx, we'd pay that validation cost every time the node's
-- selection changed, even if the tx wouldn't fit. So it'd very much be
-- as if the mempool were effectively over capacity! What's worse, each
Expand All @@ -194,7 +194,9 @@ pureTryAddTx cfg wti tx is =
--
-- No measure of a transaction can ever be negative, so the only way
-- adding two measures could result in a smaller measure is if some
-- modular arithmetic overflowed.
-- modular arithmetic overflowed. Also, overflow necessarily yields a
-- lesser result, since adding 'maxBound' is modularly equivalent to
-- subtracting one. Recall that we're checking each individual addition.
--
-- We assume that the 'txMeasure' limit and the mempool capacity
-- 'isCapacity' are much smaller than the modulus, and so this should
Expand Down Expand Up @@ -234,8 +236,8 @@ pureTryAddTx cfg wti tx is =
-- Even with the overflow handler, it's important that 'txMeasure'
-- returns a well-bounded result. Otherwise, if an adversarial tx arrived
-- that could't even fit in an empty mempool, then that thread would
-- never release the 'MVar'. In particular, we tacitally assume here that
-- a tx that wouldn't even fit in an empty mempool would be rejected by
-- never release the 'MVar'. In particular, we tacitly assume here that a
-- tx that wouldn't even fit in an empty mempool would be rejected by
-- 'txMeasure'.
| not $ currentSize `Measure.plus` txsz Measure.<= isCapacity is
->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ localTxMonitorServer mempool =
{ capacityInBytes = unByteSize32 capacity
, sizeInBytes = unByteSize32 msNumBytes
, numberOfTxs = msNumTxs
} -- TODO what to do about overflow?
}
pure $ SendMsgReplyGetSizes sizes (serverStAcquired s txs)
, recvMsgAwaitAcquire = do
s' <- atomically $ do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,13 @@ prop_Mempool_getCapacity mcts =
MempoolCapacityBytesOverride testCapacity = testMempoolCapOverride testSetup
MempoolCapTestSetup (TestSetupWithTxs testSetup _txsToAdd) = mcts

ByteSize32 dom = simpleBlockCapacity
ByteSize32 dnom = simpleBlockCapacity

expectedCapacity =
(\n -> stimes n simpleBlockCapacity)
$ max 1
$ (unByteSize32 testCapacity + dom - 1) `div` dom -- div rounding up
-- adding one less than the denom to the numer achieves rounding up
$ (unByteSize32 testCapacity + dnom - 1) `div` dnom

-- | Test that all valid transactions added to a 'Mempool' via 'addTxs' are
-- appropriately represented in the trace of events.
Expand Down Expand Up @@ -299,7 +300,9 @@ prop_Mempool_TraceRemovedTxs setup =
| (tx, Left err) <- fst $ validateTxs ledgerState txsInMempool
]

prjTx :: (Validated (GenTx TestBlock), TicketNo, ByteSize32) -> Validated (GenTx TestBlock)
prjTx ::
(Validated (GenTx TestBlock), TicketNo, ByteSize32)
-> Validated (GenTx TestBlock)
prjTx (a, _b, _c) = a

{-------------------------------------------------------------------------------
Expand Down Expand Up @@ -833,9 +836,9 @@ instance Arbitrary MempoolCapTestSetup where
testSetupWithTxs@TestSetupWithTxs { testSetup, txs } <- arbitrary
-- The Mempool should at least be capable of containing the transactions
-- it already contains.
let currentSize = foldMap txSize (testInitialTxs testSetup)
let currentSize = foldMap txSize (testInitialTxs testSetup)
capacityMinBound = currentSize
validTxsToAdd = [tx | (tx, True) <- txs]
validTxsToAdd = [tx | (tx, True) <- txs]
-- Use the current size + the sum of all the valid transactions to add
-- as the upper bound.
capacityMaxBound = currentSize <> foldMap txSize validTxsToAdd
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ instance Ledger.HasTxId (Ledger.GenTx TestBlock) where
txId (TestBlockGenTx tx) = TestBlockTxId tx

mkGenTx :: Int -> Ledger.ByteSize32 -> Ledger.GenTx TestBlock
mkGenTx anId aSize =
TestBlockGenTx $ Tx { txNumber = anId, txSize = aSize }
mkGenTx anId aSize = TestBlockGenTx $ Tx { txNumber = anId, txSize = aSize }

instance Ledger.LedgerSupportsMempool TestBlock where
applyTx _cfg _shouldIntervene _slot gtx st = pure (st, ValidatedGenTx gtx)
Expand Down

0 comments on commit fe778a3

Please sign in to comment.