1212{-# OPTIONS_GHC -Wno-orphans #-}
1313
1414module Cardano.Mock.Forging.Interpreter (
15+ InterpreterState (.. ),
1516 Interpreter ,
1617 initInterpreter ,
1718 withInterpreter ,
@@ -95,8 +96,8 @@ import qualified Ouroboros.Consensus.HardFork.Combinator.AcrossEras as Consensus
9596import Ouroboros.Consensus.HardFork.Combinator.Ledger ()
9697import qualified Ouroboros.Consensus.HardFork.Combinator.Mempool as Consensus
9798import Ouroboros.Consensus.HeaderValidation (headerStateChainDep )
98- import Ouroboros.Consensus.Ledger.Abstract (TickedLedgerState , applyChainTick )
99- import Ouroboros.Consensus.Ledger.Basics (ComputeLedgerEvents (.. ), ValuesMK )
99+ import Ouroboros.Consensus.Ledger.Abstract (TickedLedgerState , applyChainTick , projectLedgerTables , stowLedgerTables , withLedgerTables )
100+ import Ouroboros.Consensus.Ledger.Basics (ComputeLedgerEvents (.. ), EmptyMK , ValuesMK )
100101import Ouroboros.Consensus.Ledger.Extended (ExtLedgerState , headerState , ledgerState )
101102import Ouroboros.Consensus.Ledger.SupportsMempool (
102103 ApplyTxErr ,
@@ -235,12 +236,14 @@ initInterpreter ::
235236initInterpreter pinfo forging traceForge mFingerprintFile = do
236237 let topLeverCfg = pInfoConfig pinfo
237238 let initSt = pInfoInitLedger pinfo
238- let ledgerView' = mkForecast topLeverCfg initSt
239+ let st = forgetLedgerTables initSt
240+ let tables = projectLedgerTables initSt
241+ let ledgerView' = mkForecast topLeverCfg st
239242 (mode, fingerprint) <- mkFingerprint mFingerprintFile
240243 stvar <-
241244 newTVarIO $
242245 InterpreterState
243- { istChain = initChainDB topLeverCfg initSt
246+ { istChain = initChainDB topLeverCfg (st, tables)
244247 , istForecast = ledgerView'
245248 , istSlot = SlotNo 0
246249 , -- The first real Byron block (ie block that can contain txs) is number 1.
@@ -323,7 +326,7 @@ forgeNextLeaders interpreter txes possibleLeaders = do
323326 interState <- getCurrentInterpreterState interpreter
324327 (blk, fingerprint) <- tryOrValidateSlot interState possibleLeaders
325328 let ! chain' = extendChainDB (istChain interState) blk
326- let ! newSt = currentState chain'
329+ let ( newSt, _) = currentState chain'
327330 let newInterState =
328331 InterpreterState
329332 { istChain = chain'
@@ -363,7 +366,7 @@ forgeNextLeaders interpreter txes possibleLeaders = do
363366 else throwIO $ FailedToValidateSlot currentSlot (lengthSlots <$> istFingerprint interState) (interpFingerFile interpreter)
364367 Just (proof, blockForging) -> do
365368 -- Tick the ledger state for the 'SlotNo' we're producing a block for
366- let ledgerState' = ledgerState $ currentState (istChain interState)
369+ let ledgerState' = ledgerState $ fst $ currentState (istChain interState)
367370
368371 tickedLedgerSt =
369372 applyChainTick
@@ -424,7 +427,7 @@ tryAllForging interpreter interState currentSlot xs = do
424427 (configConsensus cfg)
425428 ledgerView'
426429 currentSlot
427- (headerStateChainDep (headerState $ currentState $ istChain interState))
430+ (headerStateChainDep (headerState $ fst $ currentState $ istChain interState))
428431
429432 ! shouldForge <-
430433 checkShouldForge
@@ -455,15 +458,15 @@ rollbackInterpreter interpreter pnt = do
455458 ! chain' <- case rollbackChainDB (istChain interState) pnt of
456459 Just c -> pure c
457460 Nothing -> throwIO RollbackFailed
458- let newSt = currentState chain'
461+ let ( newSt, _) = currentState chain'
459462 let tip = headTip chain'
460463 let (nextSlot, nextBlock) = case tip of
461464 TipGenesis -> (SlotNo 0 , BlockNo 1 )
462465 Tip slt _ blkNo -> (slt + 1 , blkNo + 1 )
463466 let ! newInterState =
464467 InterpreterState
465468 { istChain = chain'
466- , istForecast = mkForecast cfg newSt
469+ , istForecast = mkForecast cfg $ forgetLedgerTables newSt
467470 , istSlot = nextSlot
468471 , istNextBlockNo = nextBlock
469472 , istFingerprint = istFingerprint interState
@@ -476,8 +479,10 @@ rollbackInterpreter interpreter pnt = do
476479getCurrentInterpreterState :: Interpreter -> IO InterpreterState
477480getCurrentInterpreterState = readTVarIO . interpState
478481
479- getCurrentLedgerState :: Interpreter -> IO (ExtLedgerState CardanoBlock ValuesMK )
480- getCurrentLedgerState = fmap (currentState . istChain) . getCurrentInterpreterState
482+ getCurrentLedgerState :: Interpreter -> IO (ExtLedgerState CardanoBlock EmptyMK )
483+ getCurrentLedgerState = fmap (stow . currentState . istChain) . getCurrentInterpreterState
484+ where
485+ stow (st, tables) = stowLedgerTables $ st `withLedgerTables` tables
481486
482487getNextBlockNo :: Interpreter -> IO BlockNo
483488getNextBlockNo inter =
@@ -500,7 +505,7 @@ getCurrentSlot interp = istSlot <$> readTVarIO (interpState interp)
500505
501506withBabbageLedgerState ::
502507 Interpreter ->
503- (LedgerState (ShelleyBlock PraosStandard BabbageEra ) ValuesMK -> Either ForgingError a ) ->
508+ (LedgerState (ShelleyBlock PraosStandard BabbageEra ) EmptyMK -> Either ForgingError a ) ->
504509 IO a
505510withBabbageLedgerState inter mk = do
506511 st <- getCurrentLedgerState inter
@@ -512,7 +517,7 @@ withBabbageLedgerState inter mk = do
512517
513518withConwayLedgerState ::
514519 Interpreter ->
515- (LedgerState (ShelleyBlock PraosStandard ConwayEra ) ValuesMK -> Either ForgingError a ) ->
520+ (LedgerState (ShelleyBlock PraosStandard ConwayEra ) EmptyMK -> Either ForgingError a ) ->
516521 IO a
517522withConwayLedgerState inter mk = do
518523 st <- getCurrentLedgerState inter
@@ -524,7 +529,7 @@ withConwayLedgerState inter mk = do
524529
525530withAlonzoLedgerState ::
526531 Interpreter ->
527- (LedgerState (ShelleyBlock TPraosStandard AlonzoEra ) ValuesMK -> Either ForgingError a ) ->
532+ (LedgerState (ShelleyBlock TPraosStandard AlonzoEra ) EmptyMK -> Either ForgingError a ) ->
528533 IO a
529534withAlonzoLedgerState inter mk = do
530535 st <- getCurrentLedgerState inter
@@ -536,7 +541,7 @@ withAlonzoLedgerState inter mk = do
536541
537542withShelleyLedgerState ::
538543 Interpreter ->
539- (LedgerState (ShelleyBlock TPraosStandard ShelleyEra ) ValuesMK -> Either ForgingError a ) ->
544+ (LedgerState (ShelleyBlock TPraosStandard ShelleyEra ) EmptyMK -> Either ForgingError a ) ->
540545 IO a
541546withShelleyLedgerState inter mk = do
542547 st <- getCurrentLedgerState inter
@@ -628,12 +633,9 @@ mkValidated txe =
628633
629634mkForecast ::
630635 TopLevelConfig CardanoBlock ->
631- ExtLedgerState CardanoBlock ValuesMK ->
636+ ExtLedgerState CardanoBlock mk ->
632637 Forecast (LedgerView (BlockProtocol CardanoBlock ))
633- mkForecast cfg st = ledgerViewForecastAt (configLedger cfg) (ledgerState st')
634- where
635- st' :: ExtLedgerState CardanoBlock ValuesMK
636- st' = st
638+ mkForecast cfg st = ledgerViewForecastAt (configLedger cfg) (ledgerState st)
637639
638640throwLeftIO :: Exception e => Either e a -> IO a
639641throwLeftIO = either throwIO pure
0 commit comments