Skip to content

Commit a50f2d7

Browse files
committed
Factor out AlonzoMeasure functionality
1 parent 8623d6a commit a50f2d7

File tree

1 file changed

+31
-36
lines changed
  • ouroboros-consensus-cardano/src/shelley/Ouroboros/Consensus/Shelley/Ledger

1 file changed

+31
-36
lines changed

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

Lines changed: 31 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import Cardano.Ledger.Alonzo.Core (Tx, TxSeq, bodyTxL, eraProtVerLow,
3939
import Cardano.Ledger.Alonzo.Scripts (ExUnits, ExUnits',
4040
unWrapExUnits)
4141
import Cardano.Ledger.Alonzo.Tx (totExUnits)
42+
import qualified Cardano.Ledger.Api as L
4243
import Cardano.Ledger.Binary (Annotator (..), DecCBOR (..),
4344
EncCBOR (..), FromCBOR (..), FullByteString (..),
4445
ToCBOR (..), toPlainDecoder)
@@ -313,19 +314,9 @@ instance ( ShelleyCompatible p (AlonzoEra c)
313314

314315
type TxMeasure (ShelleyBlock p (AlonzoEra c)) = AlonzoMeasure
315316

316-
txMeasure _st (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-
}
317+
txMeasure _st = txMeasureAlonzo
321318

322-
txsBlockCapacity ledgerState =
323-
AlonzoMeasure {
324-
byteSize = Mempool.ByteSize $ txsMaxBytes ledgerState
325-
, exUnits = fromExUnits $ pparams ^. ppMaxBlockExUnitsL
326-
}
327-
where
328-
pparams = getPParams $ tickedShelleyLedgerState ledgerState
319+
txsBlockCapacity = txsBlockCapacityAlonzo
329320

330321
data AlonzoMeasure = AlonzoMeasure {
331322
byteSize :: !Mempool.ByteSize
@@ -337,43 +328,47 @@ data AlonzoMeasure = AlonzoMeasure {
337328
fromExUnits :: ExUnits -> ExUnits' (WithTop Natural)
338329
fromExUnits = fmap NotTop . unWrapExUnits
339330

331+
txMeasureAlonzo ::
332+
forall proto era.
333+
(ShelleyCompatible proto era, L.AlonzoEraTxWits era)
334+
=> Validated (GenTx (ShelleyBlock proto era)) -> AlonzoMeasure
335+
txMeasureAlonzo (ShelleyValidatedTx _txid vtx) =
336+
AlonzoMeasure {
337+
byteSize = Mempool.ByteSize $ txInBlockSize (mkShelleyTx @era @proto tx)
338+
, exUnits = fromExUnits $ totExUnits tx
339+
}
340+
where
341+
tx = SL.extractTx vtx
342+
343+
txsBlockCapacityAlonzo ::
344+
forall proto era.
345+
(ShelleyCompatible proto era, L.AlonzoEraPParams era)
346+
=> TickedLedgerState (ShelleyBlock proto era) -> AlonzoMeasure
347+
txsBlockCapacityAlonzo ledgerState =
348+
AlonzoMeasure {
349+
byteSize = Mempool.ByteSize $ txsMaxBytes ledgerState
350+
, exUnits = fromExUnits $ pparams ^. ppMaxBlockExUnitsL
351+
}
352+
where
353+
pparams = getPParams $ tickedShelleyLedgerState ledgerState
354+
340355
instance ( ShelleyCompatible p (BabbageEra c)
341356
) => Mempool.TxLimits (ShelleyBlock p (BabbageEra c)) where
342357

343358
type TxMeasure (ShelleyBlock p (BabbageEra c)) = AlonzoMeasure
344359

345-
txMeasure _st (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-
}
360+
txMeasure _st = txMeasureAlonzo
350361

351-
txsBlockCapacity ledgerState =
352-
AlonzoMeasure {
353-
byteSize = Mempool.ByteSize $ txsMaxBytes ledgerState
354-
, exUnits = fromExUnits $ pparams ^. ppMaxBlockExUnitsL
355-
}
356-
where
357-
pparams = getPParams $ tickedShelleyLedgerState ledgerState
362+
txsBlockCapacity = txsBlockCapacityAlonzo
358363

359364
instance ( ShelleyCompatible p (ConwayEra c)
360365
) => Mempool.TxLimits (ShelleyBlock p (ConwayEra c)) where
361366

362367
type TxMeasure (ShelleyBlock p (ConwayEra c)) = AlonzoMeasure
363368

364-
txMeasure _st (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+
txMeasure _st = txMeasureAlonzo
369370

370-
txsBlockCapacity ledgerState =
371-
AlonzoMeasure {
372-
byteSize = Mempool.ByteSize $ txsMaxBytes ledgerState
373-
, exUnits = fromExUnits $ pparams ^. ppMaxBlockExUnitsL
374-
}
375-
where
376-
pparams = getPParams $ tickedShelleyLedgerState ledgerState
371+
txsBlockCapacity = txsBlockCapacityAlonzo
377372

378373
{-------------------------------------------------------------------------------
379374
WithTop

0 commit comments

Comments
 (0)