@@ -30,6 +30,7 @@ module Ouroboros.Consensus.Shelley.Ledger.Mempool (
3030 , perTxOverhead
3131 -- * Exported for tests
3232 , AlonzoMeasure (.. )
33+ , ConwayMeasure (.. )
3334 , fromExUnits
3435 ) where
3536
@@ -39,6 +40,7 @@ import Cardano.Ledger.Alonzo.Core (Tx, TxSeq, bodyTxL, eraProtVerLow,
3940import Cardano.Ledger.Alonzo.Scripts (ExUnits , ExUnits' ,
4041 unWrapExUnits )
4142import Cardano.Ledger.Alonzo.Tx (totExUnits )
43+ import qualified Cardano.Ledger.Api as L
4244import Cardano.Ledger.Binary (Annotator (.. ), DecCBOR (.. ),
4345 EncCBOR (.. ), FromCBOR (.. ), FullByteString (.. ),
4446 ToCBOR (.. ), toPlainDecoder )
@@ -295,37 +297,27 @@ theLedgerLens f x =
295297
296298instance ShelleyCompatible p (ShelleyEra c ) => Mempool. TxLimits (ShelleyBlock p (ShelleyEra c )) where
297299 type TxMeasure (ShelleyBlock p (ShelleyEra c )) = Mempool. ByteSize
298- txMeasure = Mempool. ByteSize . txInBlockSize . txForgetValidated
300+ txMeasure _st = Mempool. ByteSize . txInBlockSize . txForgetValidated
299301 txsBlockCapacity = Mempool. ByteSize . txsMaxBytes
300302
301303instance ShelleyCompatible p (AllegraEra c ) => Mempool. TxLimits (ShelleyBlock p (AllegraEra c )) where
302304 type TxMeasure (ShelleyBlock p (AllegraEra c )) = Mempool. ByteSize
303- txMeasure = Mempool. ByteSize . txInBlockSize . txForgetValidated
305+ txMeasure _st = Mempool. ByteSize . txInBlockSize . txForgetValidated
304306 txsBlockCapacity = Mempool. ByteSize . txsMaxBytes
305307
306308instance ShelleyCompatible p (MaryEra c ) => Mempool. TxLimits (ShelleyBlock p (MaryEra c )) where
307309 type TxMeasure (ShelleyBlock p (MaryEra c )) = Mempool. ByteSize
308- txMeasure = Mempool. ByteSize . txInBlockSize . txForgetValidated
310+ txMeasure _st = Mempool. ByteSize . txInBlockSize . txForgetValidated
309311 txsBlockCapacity = Mempool. ByteSize . txsMaxBytes
310312
311313instance ( ShelleyCompatible p (AlonzoEra c )
312314 ) => Mempool. TxLimits (ShelleyBlock p (AlonzoEra c )) where
313315
314316 type TxMeasure (ShelleyBlock p (AlonzoEra c )) = AlonzoMeasure
315317
316- txMeasure (ShelleyValidatedTx _txid vtx) =
317- AlonzoMeasure {
318- byteSize = Mempool. ByteSize $ txInBlockSize (mkShelleyTx @ (AlonzoEra c ) @ p (SL. extractTx vtx))
319- , exUnits = fromExUnits $ totExUnits (SL. extractTx vtx)
320- }
318+ txMeasure _st = txMeasureAlonzo
321319
322- txsBlockCapacity ledgerState =
323- AlonzoMeasure {
324- byteSize = Mempool. ByteSize $ txsMaxBytes ledgerState
325- , exUnits = fromExUnits $ pparams ^. ppMaxBlockExUnitsL
326- }
327- where
328- pparams = getPParams $ tickedShelleyLedgerState ledgerState
320+ txsBlockCapacity = txsBlockCapacityAlonzo
329321
330322data AlonzoMeasure = AlonzoMeasure {
331323 byteSize :: ! Mempool. ByteSize
@@ -337,43 +329,69 @@ data AlonzoMeasure = AlonzoMeasure {
337329fromExUnits :: ExUnits -> ExUnits' (WithTop Natural )
338330fromExUnits = fmap NotTop . unWrapExUnits
339331
332+ txMeasureAlonzo ::
333+ forall proto era .
334+ (ShelleyCompatible proto era , L. AlonzoEraTxWits era )
335+ => Validated (GenTx (ShelleyBlock proto era )) -> AlonzoMeasure
336+ txMeasureAlonzo (ShelleyValidatedTx _txid vtx) =
337+ AlonzoMeasure {
338+ byteSize = Mempool. ByteSize $ txInBlockSize (mkShelleyTx @ era @ proto tx)
339+ , exUnits = fromExUnits $ totExUnits tx
340+ }
341+ where
342+ tx = SL. extractTx vtx
343+
344+ txsBlockCapacityAlonzo ::
345+ forall proto era .
346+ (ShelleyCompatible proto era , L. AlonzoEraPParams era )
347+ => TickedLedgerState (ShelleyBlock proto era ) -> AlonzoMeasure
348+ txsBlockCapacityAlonzo ledgerState =
349+ AlonzoMeasure {
350+ byteSize = Mempool. ByteSize $ txsMaxBytes ledgerState
351+ , exUnits = fromExUnits $ pparams ^. ppMaxBlockExUnitsL
352+ }
353+ where
354+ pparams = getPParams $ tickedShelleyLedgerState ledgerState
355+
340356instance ( ShelleyCompatible p (BabbageEra c )
341357 ) => Mempool. TxLimits (ShelleyBlock p (BabbageEra c )) where
342358
343359 type TxMeasure (ShelleyBlock p (BabbageEra c )) = AlonzoMeasure
344360
345- txMeasure (ShelleyValidatedTx _txid vtx) =
346- AlonzoMeasure {
347- byteSize = Mempool. ByteSize $ txInBlockSize (mkShelleyTx @ (BabbageEra c ) @ p (SL. extractTx vtx))
348- , exUnits = fromExUnits $ totExUnits (SL. extractTx vtx)
349- }
361+ txMeasure _st = txMeasureAlonzo
350362
351- txsBlockCapacity ledgerState =
352- AlonzoMeasure {
353- byteSize = Mempool. ByteSize $ txsMaxBytes ledgerState
354- , exUnits = fromExUnits $ pparams ^. ppMaxBlockExUnitsL
355- }
356- where
357- pparams = getPParams $ tickedShelleyLedgerState ledgerState
363+ txsBlockCapacity = txsBlockCapacityAlonzo
364+
365+ data ConwayMeasure = ConwayMeasure {
366+ alonzoMeasure :: ! AlonzoMeasure
367+ , refScriptsSize :: ! Mempool. ByteSize
368+ } deriving stock (Eq , Generic , Show )
369+ deriving (BoundedMeasure , Measure )
370+ via (InstantiatedAt Generic ConwayMeasure )
358371
359372instance ( ShelleyCompatible p (ConwayEra c )
360373 ) => Mempool. TxLimits (ShelleyBlock p (ConwayEra c )) where
361374
362- type TxMeasure (ShelleyBlock p (ConwayEra c )) = AlonzoMeasure
375+ type TxMeasure (ShelleyBlock p (ConwayEra c )) = ConwayMeasure
363376
364- txMeasure (ShelleyValidatedTx _txid vtx) =
365- AlonzoMeasure {
366- byteSize = Mempool. ByteSize $ txInBlockSize (mkShelleyTx @ (ConwayEra c ) @ p (SL. extractTx vtx))
367- , exUnits = fromExUnits $ totExUnits (SL. extractTx vtx)
368- }
369-
370- txsBlockCapacity ledgerState =
371- AlonzoMeasure {
372- byteSize = Mempool. ByteSize $ txsMaxBytes ledgerState
373- , exUnits = fromExUnits $ pparams ^. ppMaxBlockExUnitsL
377+ txMeasure st genTx@ (ShelleyValidatedTx _txid vtx) =
378+ ConwayMeasure {
379+ alonzoMeasure = txMeasureAlonzo genTx
380+ , refScriptsSize = Mempool. ByteSize $ fromIntegral $
381+ SL. txNonDistinctRefScriptsSize utxo (SL. extractTx vtx)
374382 }
375383 where
376- pparams = getPParams $ tickedShelleyLedgerState ledgerState
384+ utxo = SL. getUTxO . tickedShelleyLedgerState $ st
385+
386+
387+ txsBlockCapacity st =
388+ ConwayMeasure {
389+ alonzoMeasure = txsBlockCapacityAlonzo st
390+ , refScriptsSize =
391+ -- TODO use maxRefScriptSizePerBlock from
392+ -- https://github.com/IntersectMBO/cardano-ledger/pull/4450
393+ Mempool. ByteSize $ 2560 * 1024 -- 2.5 MB
394+ }
377395
378396{- ------------------------------------------------------------------------------
379397 WithTop
0 commit comments