Skip to content

Commit 756a79a

Browse files
authored
Conway: also enable mempool ref script size limit (#1168)
Also implementing #1166 (comment), but in a more fine-grained fashion The insight here is that `txRefScriptSize` is implemented using `getBabbageTxDict` for Shelley-based blocks, see the usage sites of that function in `Ouroboros.Consensus.Mempool.Impl.Common` and `Ouroboros.Consensus.Mempool.Update`.
2 parents a718db0 + c6ba2a0 commit 756a79a

File tree

4 files changed

+24
-5
lines changed

4 files changed

+24
-5
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
### Non-Breaking
2+
3+
- Also enabled total ref script size limit in the mempool in Conway (it
4+
continues to be enabled in Babbage).

ouroboros-consensus-cardano/src/shelley/Ouroboros/Consensus/Shelley/Eras.hs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,11 @@ defaultApplyShelleyBasedTx globals ledgerEnv mempoolState _wti tx = do
211211
refScriptPredicate = case getBabbageTxDict (Proxy @era) of
212212
Nothing -> pure ()
213213
Just (BabbageTxDict mkError)
214+
-- The ledger rules of Conway (and later eras) already handle ref
215+
-- scripts appropriately, so we only need to perform the checks below
216+
-- for Babbage.
217+
| not $ isBeforeConway (Proxy @era)
218+
-> pure ()
214219
-- Reject it if it has more than 100 kibibytes of ref script.
215220
| refScriptsSize > totalRefScriptsSizeLimit
216221
-> throwError $ mkError
@@ -299,7 +304,12 @@ instance (Praos.PraosCrypto c) => ShelleyBasedEra (ConwayEra c) where
299304

300305
getConwayEraGovDict _ = Just ConwayEraGovDict
301306

302-
getBabbageTxDict _ = Nothing
307+
getBabbageTxDict _ = Just $ BabbageTxDict $ \a b ->
308+
SL.ApplyTxError
309+
$ pure
310+
$ Conway.ConwayUtxowFailure
311+
$ Conway.UtxoFailure
312+
$ Conway.MaxTxSizeUTxO a b
303313

304314
applyAlonzoBasedTx :: forall era.
305315
( ShelleyBasedEra era,
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
### Non-Breaking
2+
3+
- Mempool: also changed to use the more conservative value of Ledger's
4+
`maxRefScriptSizePerBlock`, ie 1MiB, that was decided on for Conway.

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,11 @@ pureTryAddTx cfg txSize wti tx is
185185
-- mempool, and...
186186
| let curSize = msNumBytes $ isMempoolSize is
187187
, curSize < getMempoolCapacityBytes (isCapacity is)
188-
-- ... if the mempool has less than 2.5 mebibytes of ref scripts.
189-
, let maxTotalRefScriptSize = 5 * 512 * 1024 -- 2.5 Mebibytes
190-
curTotalRefScriptSize = isTotalRefScriptSize is
191-
, curTotalRefScriptSize Prelude.< maxTotalRefScriptSize
188+
-- ... if the mempool will have at most 1 mebibyte of ref scripts.
189+
, let curTotalRefScriptSize = isTotalRefScriptSize is
190+
newTxRefScriptSize = txRefScriptSize cfg (isLedgerState is) tx
191+
maxTotalRefScriptSize = 1024 * 1024 -- 1MiB
192+
, curTotalRefScriptSize + newTxRefScriptSize Prelude.<= maxTotalRefScriptSize
192193
=
193194
case eVtx of
194195
-- We only extended the ValidationResult with a single transaction

0 commit comments

Comments
 (0)