Skip to content

Commit

Permalink
Make snapshots of GovActionsState
Browse files Browse the repository at this point in the history
Made ConwayFeatures failures look nicer
  • Loading branch information
Soupstraw committed Aug 25, 2023
1 parent 63d98c3 commit d6260b2
Show file tree
Hide file tree
Showing 68 changed files with 562 additions and 242 deletions.
2 changes: 1 addition & 1 deletion eras/allegra/impl/cardano-ledger-allegra.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ library
cardano-crypto-class,
cardano-ledger-binary >=1.0,
cardano-ledger-core >=1.6 && <1.7,
cardano-ledger-shelley >=1.5.1 && <1.6,
cardano-ledger-shelley >=1.6 && <1.7,
cardano-strict-containers,
cardano-slotting,
cborg,
Expand Down
3 changes: 3 additions & 0 deletions eras/allegra/impl/src/Cardano/Ledger/Allegra/PParams.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Cardano.Ledger.Core
import Cardano.Ledger.Crypto
import Cardano.Ledger.Shelley.Governance
import Cardano.Ledger.Shelley.PParams
import Cardano.Ledger.Val (Val (..))
import Data.Coerce
import Lens.Micro

Expand Down Expand Up @@ -55,3 +56,5 @@ instance Crypto c => EraGov (AllegraEra c) where
curPParamsGovStateL = curPParamsShelleyGovStateL

prevPParamsGovStateL = prevPParamsShelleyGovStateL

obligationGovState = const zero
5 changes: 3 additions & 2 deletions eras/allegra/impl/src/Cardano/Ledger/Allegra/Rules/Utxo.hs
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,13 @@ import Cardano.Ledger.Rules.ValidationMode (
)
import Cardano.Ledger.SafeHash (SafeHash, hashAnnotated)
import Cardano.Ledger.Shelley.Governance
import Cardano.Ledger.Shelley.LedgerState (PPUPPredFailure, keyTxRefunds, totalTxDeposits)
import Cardano.Ledger.Shelley.LedgerState (PPUPPredFailure, keyTxRefunds)
import qualified Cardano.Ledger.Shelley.LedgerState as Shelley
import Cardano.Ledger.Shelley.PParams (Update)
import Cardano.Ledger.Shelley.Rules (PpupEnv (..), ShelleyPPUP, ShelleyPpupPredFailure)
import qualified Cardano.Ledger.Shelley.Rules as Shelley
import Cardano.Ledger.Shelley.Tx (ShelleyTx (..), TxIn)
import Cardano.Ledger.Shelley.TxBody (ShelleyEraTxBody (..))
import Cardano.Ledger.Shelley.UTxO (txup)
import Cardano.Ledger.UTxO (EraUTxO (..), UTxO (..), txouts)
import qualified Cardano.Ledger.Val as Val
Expand Down Expand Up @@ -205,7 +206,7 @@ utxoTransition = do
runTest $ Shelley.validateMaxTxSizeUTxO pp tx

let refunded = keyTxRefunds pp dpstate txb
let depositChange = totalTxDeposits pp dpstate txb Val.<-> refunded
let depositChange = getTotalDepositsTxBody pp dpstate txb Val.<-> refunded
tellEvent $ TotalDeposits (hashAnnotated txb) depositChange
pure $! Shelley.updateUTxOState pp u txb depositChange ppup'

Expand Down
3 changes: 3 additions & 0 deletions eras/allegra/impl/src/Cardano/Ledger/Allegra/TxBody.hs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ import Cardano.Ledger.Shelley.PParams (Update)
import Cardano.Ledger.Shelley.TxBody (
ShelleyEraTxBody (..),
Withdrawals (..),
totalTxDepositsShelley,
)
import Cardano.Ledger.TxIn (TxIn (..))
import Control.DeepSeq (NFData (..))
Expand Down Expand Up @@ -348,6 +349,8 @@ instance Crypto c => ShelleyEraTxBody (AllegraEra c) where
lensMemoRawType atbrUpdate $ \txBodyRaw update -> txBodyRaw {atbrUpdate = update}
{-# INLINEABLE updateTxBodyL #-}

getTotalDepositsTxBody = totalTxDepositsShelley

instance Crypto c => AllegraEraTxBody (AllegraEra c) where
{-# SPECIALIZE instance AllegraEraTxBody (AllegraEra StandardCrypto) #-}

Expand Down
2 changes: 1 addition & 1 deletion eras/alonzo/impl/cardano-ledger-alonzo.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ library
cardano-ledger-binary >=1.0.1,
cardano-ledger-core >=1.6 && <1.7,
cardano-ledger-mary >=1.1,
cardano-ledger-shelley ^>=1.5.1,
cardano-ledger-shelley ^>=1.6,
cardano-slotting,
cardano-strict-containers,
containers,
Expand Down
3 changes: 3 additions & 0 deletions eras/alonzo/impl/src/Cardano/Ledger/Alonzo/PParams.hs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ import Cardano.Ledger.Shelley.PParams (
shelleyCommonPParamsHKDPairsV6,
)
import Cardano.Ledger.TreeDiff (ToExpr (..))
import Cardano.Ledger.Val (Val (..))
import Control.DeepSeq (NFData)
import Data.Aeson as Aeson (
FromJSON (parseJSON),
Expand Down Expand Up @@ -290,6 +291,8 @@ instance Crypto c => EraGov (AlonzoEra c) where

prevPParamsGovStateL = prevPParamsShelleyGovStateL

obligationGovState = const zero

instance Era era => EncCBOR (AlonzoPParams Identity era) where
encCBOR AlonzoPParams {..} =
encodeListLen (23 + listLen appProtocolVersion)
Expand Down
12 changes: 3 additions & 9 deletions eras/alonzo/impl/src/Cardano/Ledger/Alonzo/Rules/Ledger.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import Cardano.Ledger.Shelley.LedgerState (
DState (..),
LedgerState (..),
UTxOState (..),
obligationCertState,
)
import Cardano.Ledger.Shelley.Rules (
DelegsEnv (..),
Expand All @@ -36,6 +35,7 @@ import Cardano.Ledger.Shelley.Rules (
ShelleyDelegsPredFailure,
ShelleyLEDGERS,
UtxoEnv (..),
shelleyLedgerAssertions,
)
import Cardano.Ledger.Shelley.Rules as Shelley (
LedgerEnv (..),
Expand All @@ -46,7 +46,6 @@ import Cardano.Ledger.Shelley.Rules as Shelley (
depositEqualsObligation,
)
import Control.State.Transition (
Assertion (..),
Embed (..),
STS (..),
TRC (..),
Expand Down Expand Up @@ -109,6 +108,7 @@ ledgerTransition = do
instance
( DSignable (EraCrypto era) (Hash (EraCrypto era) EraIndependentTxBody)
, AlonzoEraTx era
, EraGov era
, Tx era ~ AlonzoTx era
, Embed (EraRule "DELEGS" era) (AlonzoLEDGER era)
, Embed (EraRule "UTXOW" era) (AlonzoLEDGER era)
Expand All @@ -134,13 +134,7 @@ instance

renderAssertionViolation = Shelley.depositEqualsObligation

assertions =
[ PostCondition
"Deposit pot must equal obligation (AlonzoLEDGER)"
( \(TRC (_, _, _))
(LedgerState utxoSt dpstate) -> obligationCertState dpstate == utxosDeposited utxoSt
)
]
assertions = shelleyLedgerAssertions

instance
( Era era
Expand Down
3 changes: 1 addition & 2 deletions eras/alonzo/impl/src/Cardano/Ledger/Alonzo/Rules/Utxos.hs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ import Cardano.Ledger.Shelley.LedgerState (
PPUPPredFailure,
UTxOState (..),
keyTxRefunds,
totalTxDeposits,
updateStakeDistribution,
)
import qualified Cardano.Ledger.Shelley.LedgerState as Shelley
Expand Down Expand Up @@ -250,7 +249,7 @@ alonzoEvalScriptsTxValid = do
let txBody = tx ^. bodyTxL
protVer = pp ^. ppProtocolVersionL
refunded = keyTxRefunds pp dpstate txBody
depositChange = totalTxDeposits pp dpstate txBody <-> refunded
depositChange = getTotalDepositsTxBody pp dpstate txBody <-> refunded
tellEvent $ TotalDeposits (hashAnnotated txBody) depositChange
() <- pure $! traceEvent validBegin ()

Expand Down
3 changes: 3 additions & 0 deletions eras/alonzo/impl/src/Cardano/Ledger/Alonzo/TxBody.hs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ import Cardano.Ledger.MemoBytes (
)
import Cardano.Ledger.SafeHash (HashAnnotated (..), SafeToHash)
import Cardano.Ledger.Shelley.PParams (Update)
import Cardano.Ledger.Shelley.TxBody (totalTxDepositsShelley)
import Cardano.Ledger.TxIn (TxIn (..))
import Control.DeepSeq (NFData (..))
import Data.Sequence.Strict (StrictSeq)
Expand Down Expand Up @@ -208,6 +209,8 @@ instance Crypto c => ShelleyEraTxBody (AlonzoEra c) where
lensMemoRawType atbrUpdate (\txBodyRaw update_ -> txBodyRaw {atbrUpdate = update_})
{-# INLINEABLE updateTxBodyL #-}

getTotalDepositsTxBody = totalTxDepositsShelley

instance Crypto c => AllegraEraTxBody (AlonzoEra c) where
{-# SPECIALIZE instance AllegraEraTxBody (AlonzoEra StandardCrypto) #-}

Expand Down
2 changes: 1 addition & 1 deletion eras/alonzo/test-suite/cardano-ledger-alonzo-test.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ library
cardano-ledger-core:{cardano-ledger-core, testlib} >=1.5 && <1.7,
cardano-ledger-pretty,
cardano-ledger-allegra ^>=1.2,
cardano-ledger-shelley:{cardano-ledger-shelley, testlib} >=1.5 && <1.6,
cardano-ledger-shelley:{cardano-ledger-shelley, testlib} >=1.6 && <1.7,
cardano-ledger-shelley-test ^>=1.2,
cardano-ledger-shelley-ma-test ^>=1.2,
cardano-ledger-mary ^>=1.3,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import Test.Cardano.Ledger.Shelley.Generator.Utxo (genTx)
-- with meaningful delegation certificates.
instance
( EraGen era
, EraGov era
, AlonzoEraTx era
, Mock (EraCrypto era)
, MinLEDGER_STS era
Expand Down
2 changes: 1 addition & 1 deletion eras/babbage/impl/cardano-ledger-babbage.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ library
cardano-ledger-binary >=1.0,
cardano-ledger-core >=1.6 && <1.7,
cardano-ledger-mary >=1.1,
cardano-ledger-shelley ^>=1.5,
cardano-ledger-shelley ^>=1.6,
cardano-slotting,
cardano-strict-containers,
containers,
Expand Down
3 changes: 3 additions & 0 deletions eras/babbage/impl/src/Cardano/Ledger/Babbage/PParams.hs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ import Cardano.Ledger.Orphans ()
import Cardano.Ledger.Shelley.PParams (emptyPPPUpdates)
import Cardano.Ledger.Slot (EpochNo (..))
import Cardano.Ledger.TreeDiff (ToExpr (..))
import Cardano.Ledger.Val (Val (..))
import Control.DeepSeq (NFData)
import Data.Aeson as Aeson (
Key,
Expand Down Expand Up @@ -246,6 +247,8 @@ instance Crypto c => EraGov (BabbageEra c) where

prevPParamsGovStateL = prevPParamsShelleyGovStateL

obligationGovState = const zero

instance Era era => EncCBOR (BabbagePParams Identity era) where
encCBOR BabbagePParams {..} =
encodeListLen (21 + listLen bppProtocolVersion)
Expand Down
16 changes: 3 additions & 13 deletions eras/babbage/impl/src/Cardano/Ledger/Babbage/Rules/Ledger.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
Expand All @@ -23,7 +22,6 @@ import Cardano.Ledger.Shelley.LedgerState (
CertState (..),
LedgerState (..),
UTxOState (..),
obligationCertState,
)
import Cardano.Ledger.Shelley.Rules (
DelegsEnv (..),
Expand All @@ -35,24 +33,24 @@ import Cardano.Ledger.Shelley.Rules (
ShelleyLedgerEvent (..),
ShelleyLedgerPredFailure (..),
UtxoEnv (..),
shelleyLedgerAssertions,
)
import Cardano.Ledger.Shelley.Rules as Shelley (
ShelleyLedgersEvent (LedgerEvent),
ShelleyLedgersPredFailure (LedgerFailure),
depositEqualsObligation,
)
import Control.State.Transition (
Assertion (..),
Embed (..),
STS (..),
TRC (..),
)
import Data.Sequence (Seq)

-- ==================================================

instance
( AlonzoEraTx era
, EraGov era
, Embed (EraRule "DELEGS" era) (BabbageLEDGER era)
, Embed (EraRule "UTXOW" era) (BabbageLEDGER era)
, Environment (EraRule "UTXOW" era) ~ UtxoEnv era
Expand All @@ -77,15 +75,7 @@ instance

renderAssertionViolation = Shelley.depositEqualsObligation

assertions =
[ PostCondition
"Deposit pot must equal obligation (BabbageLEDGER)"
( \(TRC (_, _, _))
(LedgerState utxoSt dpstate) ->
obligationCertState dpstate
== utxosDeposited utxoSt
)
]
assertions = shelleyLedgerAssertions

instance
( Era era
Expand Down
3 changes: 1 addition & 2 deletions eras/babbage/impl/src/Cardano/Ledger/Babbage/Rules/Utxos.hs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ import Cardano.Ledger.Shelley.LedgerState (
PPUPPredFailure,
UTxOState (..),
keyTxRefunds,
totalTxDeposits,
updateStakeDistribution,
)
import Cardano.Ledger.Shelley.PParams (Update)
Expand Down Expand Up @@ -161,7 +160,7 @@ tellDepositChangeEvent pp dpstate txBody = do
{- refunded := keyRefunds pp txb -}
let refunded = keyTxRefunds pp dpstate txBody
{- depositChange := (totalDeposits pp poolParams txcerts txb) − refunded -}
let depositChange = totalTxDeposits pp dpstate txBody <-> refunded
let depositChange = getTotalDepositsTxBody pp dpstate txBody <-> refunded
tellEvent $ TotalDeposits (hashAnnotated txBody) depositChange
pure depositChange

Expand Down
3 changes: 3 additions & 0 deletions eras/babbage/impl/src/Cardano/Ledger/Babbage/TxBody.hs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ import Cardano.Ledger.MemoBytes (
)
import Cardano.Ledger.SafeHash (HashAnnotated (..), SafeToHash)
import Cardano.Ledger.Shelley.PParams (Update)
import Cardano.Ledger.Shelley.TxBody (totalTxDepositsShelley)
import Cardano.Ledger.TxIn (TxIn (..))
import Control.DeepSeq (NFData)
import Data.Sequence.Strict (StrictSeq, (|>))
Expand Down Expand Up @@ -418,6 +419,8 @@ instance Crypto c => ShelleyEraTxBody (BabbageEra c) where
updateTxBodyL = updateBabbageTxBodyL
{-# INLINE updateTxBodyL #-}

getTotalDepositsTxBody = totalTxDepositsShelley

instance Crypto c => AllegraEraTxBody (BabbageEra c) where
{-# SPECIALIZE instance AllegraEraTxBody (BabbageEra StandardCrypto) #-}

Expand Down
2 changes: 1 addition & 1 deletion eras/babbage/test-suite/cardano-ledger-babbage-test.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ library
cardano-ledger-shelley-ma-test >=1.1,
cardano-ledger-mary ^>=1.3,
cardano-ledger-shelley-test >=1.1,
cardano-ledger-shelley >=1.4 && <1.6,
cardano-ledger-shelley >=1.6 && <1.7,
cardano-strict-containers,
cardano-slotting,
containers,
Expand Down
29 changes: 29 additions & 0 deletions eras/conway/impl/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,35 @@

## 1.8.0.0

* Remove `rsFuture` from `RatifyState`
* Add to `GovActionsState`:
* `curGovActionsState`
* `prevGovActionsState`
* `prevDRepState`
* `prevCommitteeState`
* Add `ToExpr` instances to:
* `PoolVotingThresholds`
* `DRepVotingThresholds`
* `GovActionState`
* `GovActionsState`
* `EnactState`
* `RatifyState`
* `ConwayGovState`
* `GovActionIx`
* `GovActionId`
* `Vote`
* `Committee`
* `PrevGovActionId`
* `GovAction`
* `ConwayPParams` with `Identity` and `StrictMaybe`
* Add lenses:
* `cgEnactStateL`
* `curGovActionsStateL`
* `prevGovActionsStateL`
* `prevDRepStateL`
* `prevCommitteeStateL`
* Replace `cgRatifyState` with `cgEnactState`
* Deprecate `cgRatifyStateL`
* Add `ProposalDepositIncorrect` predicate failure, that is produced when `ProposalProcedure` deposit does not match `"govActionDeposit"` from `PParams` #3669
* Add "minCommitteeSize" `PParam` validation for `NewCommittee` `GovAction` #3668
* Add `committeeMembersL` and `committeeQuorumL` lenses for `Committee`
Expand Down
2 changes: 1 addition & 1 deletion eras/conway/impl/cardano-ledger-conway.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ library
cardano-ledger-babbage >=1.4.1,
cardano-ledger-core ^>=1.6,
cardano-ledger-mary >=1.1,
cardano-ledger-shelley ^>=1.5.1,
cardano-ledger-shelley ^>=1.6,
cardano-slotting,
cardano-strict-containers,
containers,
Expand Down
5 changes: 5 additions & 0 deletions eras/conway/impl/src/Cardano/Ledger/Conway/Core.hs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import Cardano.Ledger.Binary.Encoding (EncCBOR (encCBOR))
import Cardano.Ledger.Coin (Coin)
import Cardano.Ledger.Conway.Governance.Procedures (ProposalProcedure, VotingProcedures)
import Cardano.Ledger.HKD (HKD, HKDFunctor)
import Cardano.Ledger.TreeDiff (ToExpr)
import Control.DeepSeq (NFData)
import Data.Aeson (ToJSON)
import Data.Default.Class (Default)
Expand Down Expand Up @@ -136,6 +137,8 @@ data PoolVotingThresholds = PoolVotingThresholds
}
deriving (Eq, Ord, Show, Generic, Default, ToJSON, NFData, NoThunks)

instance ToExpr PoolVotingThresholds

instance EncCBOR PoolVotingThresholds where
encCBOR PoolVotingThresholds {..} =
encodeListLen 4
Expand Down Expand Up @@ -167,6 +170,8 @@ data DRepVotingThresholds = DRepVotingThresholds
}
deriving (Eq, Ord, Show, Generic, Default, ToJSON, NFData, NoThunks)

instance ToExpr DRepVotingThresholds

instance EncCBOR DRepVotingThresholds where
encCBOR DRepVotingThresholds {..} =
encodeListLen 10
Expand Down
Loading

0 comments on commit d6260b2

Please sign in to comment.