Skip to content

Commit a8f0463

Browse files
committed
o-c-cardano: add DijkstraMeasure
1 parent 5a750fe commit a8f0463

File tree

2 files changed

+44
-7
lines changed
  • ouroboros-consensus-cardano/src
    • ouroboros-consensus-cardano/Ouroboros/Consensus/Cardano
    • shelley/Ouroboros/Consensus/Shelley/Ledger

2 files changed

+44
-7
lines changed

ouroboros-consensus-cardano/src/ouroboros-consensus-cardano/Ouroboros/Consensus/Cardano/CanHardFork.hs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ type CardanoHardForkConstraints c =
128128
-- the calculation of later rewards. In this transition, we consume the
129129
-- 'shelleyToAllegraAVVMsToDelete' as deletions in the ledger tables.
130130
instance CardanoHardForkConstraints c => CanHardFork (CardanoEras c) where
131-
type HardForkTxMeasure (CardanoEras c) = ConwayMeasure
131+
type HardForkTxMeasure (CardanoEras c) = DijkstraMeasure
132132

133133
hardForkEraTranslation =
134134
EraTranslation
@@ -227,7 +227,7 @@ instance CardanoHardForkConstraints c => CanHardFork (CardanoEras c) where
227227
`o` fromAlonzo
228228
`o` fromConway
229229
`o` fromConway
230-
`o` fromConway
230+
`o` fromDijkstra
231231
`o` nil
232232
where
233233
nil :: SOP.NS f '[] -> a
@@ -243,10 +243,11 @@ instance CardanoHardForkConstraints c => CanHardFork (CardanoEras c) where
243243
SOP.Z (WrapTxMeasure x) -> f x
244244
SOP.S y -> g y
245245

246-
fromByteSize :: IgnoringOverflow ByteSize32 -> ConwayMeasure
246+
fromByteSize :: IgnoringOverflow ByteSize32 -> DijkstraMeasure
247247
fromByteSize x = fromAlonzo $ AlonzoMeasure x mempty
248248
fromAlonzo x = fromConway $ ConwayMeasure x mempty
249-
fromConway x = x
249+
fromConway x = fromDijkstra $ DijkstraMeasure x
250+
fromDijkstra x = x
250251

251252
class SelectView (BlockProtocol blk) ~ PraosChainSelectView c => HasPraosSelectView c blk
252253
instance SelectView (BlockProtocol blk) ~ PraosChainSelectView c => HasPraosSelectView c blk

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

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ module Ouroboros.Consensus.Shelley.Ledger.Mempool
3333
-- * Exported for tests
3434
, AlonzoMeasure (..)
3535
, ConwayMeasure (..)
36+
, DijkstraMeasure (..)
3637
, fromExUnits
3738
) where
3839

@@ -628,6 +629,41 @@ instance
628629

629630
-----
630631

632+
newtype DijkstraMeasure = DijkstraMeasure
633+
{ conwayMeasure :: ConwayMeasure
634+
}
635+
deriving stock (Eq, Generic, Show)
636+
deriving anyclass NoThunks
637+
deriving newtype (Semigroup, Monoid, HasByteSize, TxMeasureMetrics)
638+
deriving
639+
Measure
640+
via (InstantiatedAt Generic DijkstraMeasure)
641+
642+
blockCapacityDijkstraMeasure ::
643+
forall proto era mk.
644+
( ShelleyCompatible proto era
645+
, L.AlonzoEraPParams era
646+
) =>
647+
TickedLedgerState (ShelleyBlock proto era) mk ->
648+
DijkstraMeasure
649+
blockCapacityDijkstraMeasure = DijkstraMeasure . blockCapacityConwayMeasure
650+
651+
txMeasureDijkstra ::
652+
forall proto era.
653+
( ShelleyCompatible proto era
654+
, L.AlonzoEraTxWits era
655+
, L.BabbageEraTxBody era
656+
, ExUnitsTooBigUTxO era
657+
, MaxTxSizeUTxO era
658+
, TxRefScriptsSizeTooBig era
659+
) =>
660+
TickedLedgerState (ShelleyBlock proto era) ValuesMK ->
661+
GenTx (ShelleyBlock proto era) ->
662+
V.Validation (TxErrorSG era) DijkstraMeasure
663+
txMeasureDijkstra st tx = DijkstraMeasure <$> txMeasureConway st tx -- TODO(geo2a): eta-reduce
664+
665+
-----
666+
631667
data ConwayMeasure = ConwayMeasure
632668
{ alonzoMeasure :: !AlonzoMeasure
633669
, refScriptsSize :: !(IgnoringOverflow ByteSize32)
@@ -769,6 +805,6 @@ instance
769805
ShelleyCompatible p DijkstraEra =>
770806
TxLimits (ShelleyBlock p DijkstraEra)
771807
where
772-
type TxMeasure (ShelleyBlock p DijkstraEra) = ConwayMeasure
773-
txMeasure _cfg st tx = runValidation $ txMeasureConway st tx
774-
blockCapacityTxMeasure _cfg = blockCapacityConwayMeasure
808+
type TxMeasure (ShelleyBlock p DijkstraEra) = DijkstraMeasure
809+
txMeasure _cfg st tx = runValidation $ txMeasureDijkstra st tx
810+
blockCapacityTxMeasure _cfg = blockCapacityDijkstraMeasure

0 commit comments

Comments
 (0)