@@ -27,6 +27,7 @@ module Cardano.Ledger.Babbage.Rules.Utxo (
2727 validateCollateralEqBalance ,
2828 validateOutputTooSmallUTxO ,
2929 disjointRefInputs ,
30+ updateUTxOStateByTxValidity ,
3031) where
3132
3233import Cardano.Ledger.Allegra.Rules (AllegraUtxoPredFailure , shelleyToAllegraUtxoPredFailure )
@@ -461,36 +462,52 @@ utxoTransition ::
461462utxoTransition = do
462463 TRC (UtxoEnv slot pp certState, utxos, tx) <- judgmentContext
463464 babbageUtxoValidation
464- let utxo = utxosUtxo utxos
465465 updatedGovState <-
466466 trans @ (EraRule " UTXOS" era ) $
467- TRC (UtxosEnv slot pp certState utxo, utxosGovState utxos, tx)
467+ TRC (UtxosEnv slot pp certState (utxosUtxo utxos), utxosGovState utxos, tx)
468+ updateUTxOStateByTxValidity pp certState updatedGovState tx utxos
468469
470+ updateUTxOStateByTxValidity ::
471+ forall era .
472+ ( AlonzoEraTx era
473+ , BabbageEraTxBody era
474+ , EraStake era
475+ , EraCertState era
476+ , Event (EraRule " UTXO" era ) ~ AlonzoUtxoEvent era
477+ ) =>
478+ PParams era ->
479+ CertState era ->
480+ GovState era ->
481+ Tx TopTx era ->
482+ UTxOState era ->
483+ Rule (EraRule " UTXO" era ) 'Transition (UTxOState era )
484+ updateUTxOStateByTxValidity pp certState govState tx utxoState =
469485 let txBody = tx ^. bodyTxL
470- case tx ^. isValidTxL of
471- IsValid True ->
472- updateUTxOState
473- pp
474- utxos
475- txBody
476- certState
477- updatedGovState
478- (tellEvent . TotalDeposits (hashAnnotated txBody))
479- (\ a b -> tellEvent $ TxUTxODiff a b)
480- IsValid False ->
481- {- utxoKeep = txBody ^. collateralInputsTxBodyL ⋪ utxo -}
482- {- utxoDel = txBody ^. collateralInputsTxBodyL ◁ utxo -}
483- let ! (utxoKeep, utxoDel) = extractKeys (unUTxO utxo) (txBody ^. collateralInputsTxBodyL)
484- UTxO collouts = collOuts txBody
485- DeltaCoin collateralFees = collAdaBalance txBody utxoDel -- NEW to Babbage
486- in pure $!
487- utxos {- (collInputs txb ⋪ utxo) ∪ collouts tx -}
488- { utxosUtxo = UTxO (Map. union utxoKeep collouts) -- NEW to Babbage
489- {- fees + collateralFees -}
490- , utxosFees = utxosFees utxos <> Coin collateralFees -- NEW to Babbage
491- , utxosInstantStake =
492- deleteInstantStake (UTxO utxoDel) (addInstantStake (UTxO collouts) (utxos ^. instantStakeL))
493- }
486+ utxo = utxosUtxo utxoState
487+ in case tx ^. isValidTxL of
488+ IsValid True ->
489+ updateUTxOState
490+ pp
491+ utxoState
492+ txBody
493+ certState
494+ govState
495+ (tellEvent . TotalDeposits (hashAnnotated txBody))
496+ (\ a b -> tellEvent $ TxUTxODiff a b)
497+ IsValid False ->
498+ {- utxoKeep = txBody ^. collateralInputsTxBodyL ⋪ utxo -}
499+ {- utxoDel = txBody ^. collateralInputsTxBodyL ◁ utxo -}
500+ let ! (utxoKeep, utxoDel) = extractKeys (unUTxO utxo) (txBody ^. collateralInputsTxBodyL)
501+ UTxO collouts = collOuts txBody
502+ DeltaCoin collateralFees = collAdaBalance txBody utxoDel -- NEW to Babbage
503+ in pure $!
504+ utxoState {- (collInputs txb ⋪ utxo) ∪ collouts tx -}
505+ { utxosUtxo = UTxO (Map. union utxoKeep collouts) -- NEW to Babbage
506+ {- fees + collateralFees -}
507+ , utxosFees = utxosFees utxoState <> Coin collateralFees -- NEW to Babbage
508+ , utxosInstantStake =
509+ deleteInstantStake (UTxO utxoDel) (addInstantStake (UTxO collouts) (utxoState ^. instantStakeL))
510+ }
494511
495512--------------------------------------------------------------------------------
496513-- BabbageUTXO STS
0 commit comments