Skip to content

Commit 9351e28

Browse files
authored
Mempool: reject txs that don't fit in an empty mempool (#1225)
Follow-up to #1168 that makes sure that adding a tx exceeding the per-tx limit does not cause a deadlock which prevents txs from being added to the mempool until the node is restarted. We accomplish this by validating such transactions and relying on the per-tx limit to reject them.
2 parents 6a8def9 + 7a2a047 commit 9351e28

File tree

1 file changed

+15
-1
lines changed
  • ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Mempool

1 file changed

+15
-1
lines changed

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,21 @@ pureTryAddTx cfg txSize wti tx is
189189
, let curTotalRefScriptSize = isTotalRefScriptSize is
190190
newTxRefScriptSize = txRefScriptSize cfg (isLedgerState is) tx
191191
maxTotalRefScriptSize = 1024 * 1024 -- 1MiB
192-
, curTotalRefScriptSize + newTxRefScriptSize Prelude.<= maxTotalRefScriptSize
192+
-- In case the tx exceeds the per-tx limit, let it be rejected by tx
193+
-- validation (such that we are not blocked here forever/for a long
194+
-- time).
195+
--
196+
-- For Babbage, this is 100KiB (see @totalRefScriptsSizeLimit@ in
197+
-- "Ouroboros.Consensus.Shelley.Eras"), and for Conway, this is 200KiB
198+
-- (see @maxRefScriptSizePerTx@ in "Cardano.Ledger.Conway.Rules.Ledger").
199+
txRefScriptSizeTooLarge = newTxRefScriptSize Prelude.> 200 * 1024
200+
-- There is a potential overflow in this check, causing it to be 'False'
201+
-- erroneously. In practice, this can only happen if
202+
-- 'newTxRefScriptSize' is huge, in which case 'txRefScriptSizeTooLarge'
203+
-- is 'True', so the disjunction below is still 'True'.
204+
mempoolStaysBelowCapacity =
205+
curTotalRefScriptSize + newTxRefScriptSize Prelude.<= maxTotalRefScriptSize
206+
, txRefScriptSizeTooLarge || mempoolStaysBelowCapacity
193207
=
194208
case eVtx of
195209
-- We only extended the ValidationResult with a single transaction

0 commit comments

Comments
 (0)