Skip to content

Commit f169fbf

Browse files
committed
Add deprecations and replacement lenses
* Add `casTreasuryL` and `casReservesL` * Deprecate `asTreasuryL` and `asReservesL` * Add pattern synonym for `AccountState` with deprecation pragma
1 parent f944226 commit f169fbf

File tree

34 files changed

+97
-105
lines changed

34 files changed

+97
-105
lines changed

eras/conway/impl/src/Cardano/Ledger/Conway/Rules/Epoch.hs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ import Cardano.Ledger.Shelley.LedgerState (
6767
EpochState (..),
6868
LedgerState (..),
6969
UTxOState (..),
70-
asTreasuryL,
7170
curPParamsEpochStateL,
7271
esChainAccountState,
7372
esChainAccountStateL,
@@ -244,7 +243,7 @@ applyEnactedWithdrawals chainAccountState dState enactedState =
244243
-- + unclaimed - totWithdrawals
245244
-- we just subtract the `refunds`
246245
-- - refunds
247-
& asTreasuryL %~ (<-> fold successfulWithdrawls)
246+
& casTreasuryL %~ (<-> fold successfulWithdrawls)
248247
-- The use of the partial function `compactCoinOrError` is justified here because
249248
-- 1. the decoder for coin at the proposal-submission boundary has already
250249
-- confirmed we have a compactible value
@@ -378,7 +377,7 @@ epochTransition = do
378377
chainAccountState3 =
379378
chainAccountState2
380379
-- Move donations and unclaimed rewards from proposals to treasury:
381-
& asTreasuryL <>~ (utxoState0 ^. utxosDonationL <> fold unclaimed)
380+
& casTreasuryL <>~ (utxoState0 ^. utxosDonationL <> fold unclaimed)
382381
utxoState2 =
383382
utxoState1
384383
& utxosDepositedL .~ totalObligation certState2 govState1

eras/conway/impl/src/Cardano/Ledger/Conway/Rules/Ledger.hs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,13 @@ import Cardano.Ledger.Conway.Rules.GovCert (ConwayGovCertPredFailure)
8383
import Cardano.Ledger.Conway.Rules.Utxo (ConwayUtxoPredFailure)
8484
import Cardano.Ledger.Conway.Rules.Utxos (ConwayUtxosPredFailure)
8585
import Cardano.Ledger.Conway.Rules.Utxow (ConwayUtxowPredFailure)
86-
import Cardano.Ledger.Conway.State (ConwayEraCertState)
86+
import Cardano.Ledger.Conway.State
8787
import Cardano.Ledger.Conway.UTxO (txNonDistinctRefScriptsSize)
8888
import Cardano.Ledger.Credential (Credential (..), credKeyHash)
8989
import qualified Cardano.Ledger.Shelley.HardForks as HF (bootstrapPhase)
9090
import Cardano.Ledger.Shelley.LedgerState (
9191
LedgerState (..),
9292
UTxOState (..),
93-
asTreasuryL,
94-
dsUnifiedL,
95-
utxoL,
9693
utxosGovStateL,
9794
)
9895
import Cardano.Ledger.Shelley.Rules (
@@ -108,7 +105,6 @@ import Cardano.Ledger.Shelley.Rules (
108105
shelleyLedgerAssertions,
109106
)
110107
import Cardano.Ledger.Slot (epochFromSlot)
111-
import Cardano.Ledger.State (EraCertState (..), EraUTxO (..))
112108
import Cardano.Ledger.UMap (UView (..))
113109
import qualified Cardano.Ledger.UMap as UMap
114110
import Control.DeepSeq (NFData)
@@ -363,7 +359,7 @@ ledgerTransition ::
363359
TransitionRule (someLEDGER era)
364360
ledgerTransition = do
365361
TRC
366-
( LedgerEnv slot mbCurEpochNo _txIx pp account
362+
( LedgerEnv slot mbCurEpochNo _txIx pp chainAccountState
367363
, LedgerState utxoState certState
368364
, tx
369365
) <-
@@ -375,7 +371,7 @@ ledgerTransition = do
375371
if tx ^. isValidTxL == IsValid True
376372
then do
377373
let txBody = tx ^. bodyTxL
378-
actualTreasuryValue = account ^. asTreasuryL
374+
actualTreasuryValue = chainAccountState ^. casTreasuryL
379375
case txBody ^. currentTreasuryValueTxBodyL of
380376
SNothing -> pure ()
381377
SJust submittedTreasuryValue ->

eras/conway/impl/testlib/Test/Cardano/Ledger/Conway/Imp/EnactSpec.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import Cardano.Ledger.Conway.Core
1717
import Cardano.Ledger.Conway.Governance
1818
import Cardano.Ledger.Conway.PParams
1919
import Cardano.Ledger.Conway.Rules
20+
import Cardano.Ledger.Conway.State
2021
import Cardano.Ledger.Credential
2122
import Cardano.Ledger.Shelley.LedgerState
2223
import Cardano.Ledger.Shelley.Rules (ShelleyTickEvent (..))
@@ -184,7 +185,7 @@ treasuryWithdrawalsSpec =
184185
-- check that the sum of the rewards matches what was spent from the treasury
185186
sumRewardAccounts withdrawals `shouldReturn` (initialTreasury <-> expectedTreasury)
186187
where
187-
getTreasury = getsNES (nesEsL . esChainAccountStateL . asTreasuryL)
188+
getTreasury = getsNES (nesEsL . esChainAccountStateL . casTreasuryL)
188189
sumRewardAccounts withdrawals = mconcat <$> traverse (getRewardAccountAmount . fst) withdrawals
189190
genWithdrawalsExceeding (Coin val) n = do
190191
vals <- genValuesExceeding val n

eras/conway/impl/testlib/Test/Cardano/Ledger/Conway/Imp/EpochSpec.hs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import Cardano.Ledger.Conway.Rules (
2121
ConwayEpochEvent (GovInfoEvent),
2222
ConwayNewEpochEvent (..),
2323
)
24+
import Cardano.Ledger.Conway.State
2425
import Cardano.Ledger.Shelley.LedgerState
2526
import Cardano.Ledger.Shelley.Rules (Event, ShelleyTickEvent (..))
2627
import Cardano.Ledger.Val
@@ -421,7 +422,7 @@ treasuryWithdrawalExpectation extraWithdrawals = do
421422
donateToTreasury withdrawalAmount
422423
committeeHotCreds <- registerInitialCommittee
423424
(dRepCred, _, _) <- setupSingleDRep 1_000_000
424-
treasuryStart <- getsNES $ nesEsL . esChainAccountStateL . asTreasuryL
425+
treasuryStart <- getsNES $ nesEsL . esChainAccountStateL . casTreasuryL
425426
treasuryStart `shouldBe` withdrawalAmount
426427
rewardAccount <- registerRewardAccount
427428
govPolicy <- getGovPolicy
@@ -436,7 +437,7 @@ treasuryWithdrawalExpectation extraWithdrawals = do
436437
getReward (raCredential rewardAccount) `shouldReturn` mempty
437438
passEpoch -- 2nd epoch crossing enacts all the ratified actions
438439
expectMissingGovActionId govActionId
439-
treasuryEnd <- getsNES $ nesEsL . esChainAccountStateL . asTreasuryL
440+
treasuryEnd <- getsNES $ nesEsL . esChainAccountStateL . casTreasuryL
440441
impAnn "Withdrawal deducted from treasury" $
441442
treasuryStart <-> treasuryEnd `shouldBe` withdrawalAmount
442443
impAnn "Withdrawal received by reward account" $
@@ -445,7 +446,7 @@ treasuryWithdrawalExpectation extraWithdrawals = do
445446
depositMovesToTreasuryWhenStakingAddressUnregisters :: ConwayEraImp era => ImpTestM era ()
446447
depositMovesToTreasuryWhenStakingAddressUnregisters = do
447448
disableTreasuryExpansion
448-
initialTreasury <- getsNES $ nesEsL . esChainAccountStateL . asTreasuryL
449+
initialTreasury <- getsNES $ nesEsL . esChainAccountStateL . casTreasuryL
449450
modifyPParams $ \pp ->
450451
pp
451452
& ppGovActionLifetimeL .~ EpochInterval 8

eras/conway/impl/testlib/Test/Cardano/Ledger/Conway/Imp/RatifySpec.hs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ import Cardano.Ledger.Coin
1212
import Cardano.Ledger.Conway.Core
1313
import Cardano.Ledger.Conway.Governance
1414
import Cardano.Ledger.Conway.PParams
15+
import Cardano.Ledger.Conway.State
1516
import Cardano.Ledger.Conway.TxCert
1617
import Cardano.Ledger.Credential
17-
import Cardano.Ledger.DRep
1818
import Cardano.Ledger.Shelley.HardForks (bootstrapPhase)
1919
import Cardano.Ledger.Shelley.LedgerState
2020
import qualified Cardano.Ledger.UMap as UM
@@ -476,14 +476,14 @@ committeeMinSizeAffectsInFlightProposalsSpec =
476476
& ppuCommitteeMinSizeL .~ SJust 3
477477
submitYesVoteCCs_ hotCommitteeCs gaiPC
478478
submitYesVote_ (DRepVoter drepC) gaiPC
479-
treasury <- getsNES $ nesEsL . esChainAccountStateL . asTreasuryL
479+
treasury <- getsNES $ nesEsL . esChainAccountStateL . casTreasuryL
480480
passNEpochs 2
481481
-- The ParameterChange prevents the TreasuryWithdrawal from being enacted,
482482
-- because it has higher priority.
483483
getLastEnactedParameterChange `shouldReturn` SJust (GovPurposeId gaiPC)
484484
isCommitteeAccepted gaiTW `shouldReturn` False
485485
currentProposalsShouldContain gaiTW
486-
getsNES (nesEsL . esChainAccountStateL . asTreasuryL) `shouldReturn` treasury
486+
getsNES (nesEsL . esChainAccountStateL . casTreasuryL) `shouldReturn` treasury
487487
it "TreasuryWithdrawal ratifies due to a decrease in CommitteeMinSize" $ whenPostBootstrap $ do
488488
disableTreasuryExpansion
489489
(drepC, hotCommitteeC, _) <- electBasicCommittee
@@ -492,14 +492,14 @@ committeeMinSizeAffectsInFlightProposalsSpec =
492492
-- Ensure sufficient amount in the treasury
493493
submitTx_ $ mkBasicTx (mkBasicTxBody & treasuryDonationTxBodyL .~ amount)
494494
passEpoch
495-
treasury <- getsNES $ nesEsL . esChainAccountStateL . asTreasuryL
495+
treasury <- getsNES $ nesEsL . esChainAccountStateL . casTreasuryL
496496
gaiTW <- submitTreasuryWithdrawal amount
497497
submitYesVote_ (CommitteeVoter hotCommitteeC) gaiTW
498498
submitYesVote_ (DRepVoter drepC) gaiTW
499499
setCommitteeMinSize 2
500500
isCommitteeAccepted gaiTW `shouldReturn` False
501501
passNEpochs 2
502-
getsNES (nesEsL . esChainAccountStateL . asTreasuryL) `shouldReturn` treasury
502+
getsNES (nesEsL . esChainAccountStateL . casTreasuryL) `shouldReturn` treasury
503503
-- We do not enact the ParameterChange here because that does not pass
504504
-- ratification as the CC size is smaller than MinSize.
505505
-- We instead just add another Committee member to reach the CommitteeMinSize.
@@ -511,7 +511,7 @@ committeeMinSizeAffectsInFlightProposalsSpec =
511511
_hotCommitteeC' <- registerCommitteeHotKey coldCommitteeCred
512512
isCommitteeAccepted gaiTW `shouldReturn` True
513513
passNEpochs 2
514-
getsNES (nesEsL . esChainAccountStateL . asTreasuryL) `shouldReturn` (treasury <-> amount)
514+
getsNES (nesEsL . esChainAccountStateL . casTreasuryL) `shouldReturn` (treasury <-> amount)
515515

516516
spoVotesForHardForkInitiation ::
517517
forall era.
@@ -854,7 +854,7 @@ votingSpec =
854854
passEpoch
855855
getCommitteeMembers `shouldReturn` mempty
856856
it "AlwaysAbstain" $ whenPostBootstrap $ do
857-
let getTreasury = getsNES (nesEsL . esChainAccountStateL . asTreasuryL)
857+
let getTreasury = getsNES (nesEsL . esChainAccountStateL . casTreasuryL)
858858

859859
disableTreasuryExpansion
860860
donateToTreasury $ Coin 5_000_000

eras/conway/impl/testlib/Test/Cardano/Ledger/Conway/ImpTest.hs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,6 @@ import Cardano.Ledger.Plutus.Language (Language (..), SLanguage (..), hashPlutus
184184
import Cardano.Ledger.PoolParams (PoolParams (..), ppRewardAccount)
185185
import qualified Cardano.Ledger.Shelley.HardForks as HardForks (bootstrapPhase)
186186
import Cardano.Ledger.Shelley.LedgerState (
187-
asTreasuryL,
188187
curPParamsEpochStateL,
189188
epochStateGovStateL,
190189
epochStatePoolParamsL,
@@ -1171,7 +1170,7 @@ logRatificationChecks gaId = do
11711170
committee <- getsNES $ nesEsL . epochStateGovStateL . committeeGovStateL
11721171
ratEnv@RatifyEnv {reCurrentEpoch} <- getRatifyEnv
11731172
let ratSt = RatifyState ens mempty mempty False
1174-
curTreasury <- getsNES $ nesEsL . esChainAccountStateL . asTreasuryL
1173+
curTreasury <- getsNES $ nesEsL . esChainAccountStateL . casTreasuryL
11751174
currentEpoch <- getsNES nesELL
11761175
pv <- getProtVer
11771176
let
@@ -1671,13 +1670,13 @@ expectCommitteeMemberAbsence cc = do
16711670
donateToTreasury :: ConwayEraImp era => Coin -> ImpTestM era ()
16721671
donateToTreasury amount =
16731672
impAnn ("Donation to treasury in the amount of: " ++ show amount) $ do
1674-
treasuryStart <- getsNES $ nesEsL . esChainAccountStateL . asTreasuryL
1673+
treasuryStart <- getsNES $ nesEsL . esChainAccountStateL . casTreasuryL
16751674
submitTx_ $ mkBasicTx (mkBasicTxBody & treasuryDonationTxBodyL .~ amount)
1676-
treasuryEndEpoch0 <- getsNES $ nesEsL . esChainAccountStateL . asTreasuryL
1675+
treasuryEndEpoch0 <- getsNES $ nesEsL . esChainAccountStateL . casTreasuryL
16771676
-- Actual donation happens on the epoch boundary
16781677
treasuryStart `shouldBe` treasuryEndEpoch0
16791678
passEpoch
1680-
treasuryEndEpoch1 <- getsNES $ nesEsL . esChainAccountStateL . asTreasuryL
1679+
treasuryEndEpoch1 <- getsNES $ nesEsL . esChainAccountStateL . casTreasuryL
16811680
treasuryEndEpoch1 <-> treasuryStart `shouldBe` amount
16821681

16831682
expectMembers ::

eras/shelley-ma/test-suite/test/Test/Cardano/Ledger/Allegra/ScriptTranslation.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ module Test.Cardano.Ledger.Allegra.ScriptTranslation (
77
where
88

99
import Cardano.Ledger.Allegra (AllegraEra)
10+
import Cardano.Ledger.Allegra.State
1011
import Cardano.Ledger.Genesis (NoGenesis (..))
1112
import Cardano.Ledger.Shelley (ShelleyEra)
1213
import qualified Cardano.Ledger.Shelley.API as S
@@ -63,7 +64,7 @@ testScriptPostTranslation =
6364
Nothing
6465
minBound
6566
emptyPParams
66-
(S.ChainAccountState (S.Coin 0) (S.Coin 0))
67+
(ChainAccountState (S.Coin 0) (S.Coin 0))
6768
utxoStShelley = def {S.utxosUtxo = utxo}
6869
utxoStAllegra = fromRight . runExcept $ translateEra @AllegraEra NoGenesis utxoStShelley
6970
txb =

eras/shelley-ma/test-suite/test/Test/Cardano/Ledger/Mary/Examples/MultiAssets.hs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ import Cardano.Ledger.Coin (Coin (..))
2424
import Cardano.Ledger.Keys (asWitness)
2525
import Cardano.Ledger.Mary (MaryEra)
2626
import Cardano.Ledger.Mary.Core
27+
import Cardano.Ledger.Mary.State
2728
import Cardano.Ledger.Mary.Value (
2829
AssetName (..),
2930
MaryValue (..),
3031
MultiAsset (..),
3132
PolicyID (..),
3233
)
3334
import Cardano.Ledger.Shelley.API (LedgerEnv (..), ShelleyLEDGER)
34-
import Cardano.Ledger.Shelley.LedgerState (ChainAccountState (..))
3535
import Cardano.Ledger.Shelley.Rules (ShelleyLedgerPredFailure (..), ShelleyUtxowPredFailure (..))
3636
import Cardano.Ledger.Shelley.Scripts (
3737
pattern RequireAllOf,
@@ -41,7 +41,6 @@ import Cardano.Ledger.Shelley.Tx (ShelleyTx (..))
4141
import Cardano.Ledger.Shelley.TxOut (ShelleyTxOut (..))
4242
import Cardano.Ledger.Shelley.TxWits (addrWits)
4343
import Cardano.Ledger.Slot (SlotNo (..))
44-
import Cardano.Ledger.State (UTxO (..))
4544
import Cardano.Ledger.TxIn (TxId, TxIn (..), mkTxInPartial)
4645
import Cardano.Ledger.Val ((<+>), (<->))
4746
import qualified Cardano.Ledger.Val as Val

eras/shelley/impl/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## 1.17.0.0
44

5-
* Rename `esAccountState` and `esAccountStateL` to `esChainAccountState` and `esChainAccountStateL`
5+
* Rename `esAccountState` to `esChainAccountState`
66
* Replaced `prDState` and `prPState` with `prCertState` in `ShelleyPoolreapState`
77
* Removed `ShelleyPoolreapEnv` (became obsolete)
88
* Removed `shelleyCertVState` from `ShelleyCertState`

eras/shelley/impl/src/Cardano/Ledger/Shelley/API/ByronTranslation.hs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,8 @@ import Cardano.Ledger.Shelley.API.Types
2828
import Cardano.Ledger.Shelley.Core
2929
import Cardano.Ledger.Shelley.LedgerState.Types (curPParamsEpochStateL, prevPParamsEpochStateL)
3030
import Cardano.Ledger.Shelley.Rules ()
31-
import Cardano.Ledger.Shelley.State ()
31+
import Cardano.Ledger.Shelley.State
3232
import Cardano.Ledger.Shelley.Translation (FromByronTranslationContext (..))
33-
import Cardano.Ledger.State (coinBalance, emptySnapShots)
3433
import qualified Cardano.Ledger.UMap as UM
3534
import Cardano.Ledger.Val (zero, (<->))
3635
import qualified Data.ByteString.Short as SBS

0 commit comments

Comments
 (0)