Skip to content

Commit a7fb33a

Browse files
committed
Changed dRepDeposits to CompactCoin
1 parent 0550aa8 commit a7fb33a

File tree

13 files changed

+64
-40
lines changed

13 files changed

+64
-40
lines changed

eras/conway/impl/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
## 1.20.0.0
44

5+
* Change the type of `cppDRepDeposit` to `CompactForm Coin`
6+
* Add `ppDRepDepositCompactL` and `ppuDRepDepositCompactL`
7+
* Replace `hkdDRepDepositL` with `hkdDRepDepositCompactL`
58
* Delete `Tx` newtype wrapper
69
* Hide `Cardano.Ledger.Conway.Translation` module and remove its re-exports: `addrPtrNormalize` and `translateDatum`
710
* Removed:

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

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ module Cardano.Ledger.Conway.PParams (
3030
ppCommitteeMinSize,
3131
ppDRepActivity,
3232
ppDRepDeposit,
33+
ppDRepDepositCompactL,
3334
ppDRepVotingThresholds,
3435
ppGovActionDeposit,
3536
ppGovActionLifetime,
@@ -87,6 +88,7 @@ module Cardano.Ledger.Conway.PParams (
8788
asNaturalHKD,
8889
asBoundedIntegralHKD,
8990
ppGroup,
91+
asCompactCoinHKD,
9092
) where
9193

9294
import Cardano.Ledger.Alonzo.PParams
@@ -119,7 +121,8 @@ import Cardano.Ledger.Binary (
119121
encodeListLen,
120122
)
121123
import Cardano.Ledger.Binary.Coders
122-
import Cardano.Ledger.Coin (Coin (Coin), CompactForm (..))
124+
import Cardano.Ledger.Coin (Coin (Coin), CompactForm (..), compactCoinOrError, partialCompactCoinL)
125+
import Cardano.Ledger.Compactible (partialCompactFL)
123126
import Cardano.Ledger.Conway.Era (ConwayEra, hardforkConwayBootstrapPhase)
124127
import Cardano.Ledger.Core (EraPParams (..))
125128
import Cardano.Ledger.HKD (
@@ -180,7 +183,7 @@ class BabbageEraPParams era => ConwayEraPParams era where
180183
hkdCommitteeMaxTermLengthL :: HKDFunctor f => Lens' (PParamsHKD f era) (HKD f EpochInterval)
181184
hkdGovActionLifetimeL :: HKDFunctor f => Lens' (PParamsHKD f era) (HKD f EpochInterval)
182185
hkdGovActionDepositL :: HKDFunctor f => Lens' (PParamsHKD f era) (HKD f Coin)
183-
hkdDRepDepositL :: HKDFunctor f => Lens' (PParamsHKD f era) (HKD f Coin)
186+
hkdDRepDepositCompactL :: HKDFunctor f => Lens' (PParamsHKD f era) (HKD f (CompactForm Coin))
184187
hkdDRepActivityL :: HKDFunctor f => Lens' (PParamsHKD f era) (HKD f EpochInterval)
185188
hkdMinFeeRefScriptCostPerByteL ::
186189
HKDFunctor f => Lens' (PParamsHKD f era) (HKD f NonNegativeInterval)
@@ -233,8 +236,11 @@ ppGovActionLifetimeL = ppLensHKD . hkdGovActionLifetimeL @era @Identity
233236
ppGovActionDepositL :: forall era. ConwayEraPParams era => Lens' (PParams era) Coin
234237
ppGovActionDepositL = ppLensHKD . hkdGovActionDepositL @era @Identity
235238

236-
ppDRepDepositL :: forall era. ConwayEraPParams era => Lens' (PParams era) Coin
237-
ppDRepDepositL = ppLensHKD . hkdDRepDepositL @era @Identity
239+
ppDRepDepositCompactL :: forall era. ConwayEraPParams era => Lens' (PParams era) (CompactForm Coin)
240+
ppDRepDepositCompactL = ppLensHKD . hkdDRepDepositCompactL @era @Identity
241+
242+
ppDRepDepositL :: ConwayEraPParams era => Lens' (PParams era) Coin
243+
ppDRepDepositL = ppDRepDepositCompactL . partialCompactCoinL
238244

239245
ppDRepActivityL :: forall era. ConwayEraPParams era => Lens' (PParams era) EpochInterval
240246
ppDRepActivityL = ppLensHKD . hkdDRepActivityL @era @Identity
@@ -267,9 +273,13 @@ ppuGovActionDepositL ::
267273
forall era. ConwayEraPParams era => Lens' (PParamsUpdate era) (StrictMaybe Coin)
268274
ppuGovActionDepositL = ppuLensHKD . hkdGovActionDepositL @era @StrictMaybe
269275

276+
ppuDRepDepositCompactL ::
277+
forall era. ConwayEraPParams era => Lens' (PParamsUpdate era) (StrictMaybe (CompactForm Coin))
278+
ppuDRepDepositCompactL = ppuLensHKD . hkdDRepDepositCompactL @era @StrictMaybe
279+
270280
ppuDRepDepositL ::
271281
forall era. ConwayEraPParams era => Lens' (PParamsUpdate era) (StrictMaybe Coin)
272-
ppuDRepDepositL = ppuLensHKD . hkdDRepDepositL @era @StrictMaybe
282+
ppuDRepDepositL = ppuDRepDepositCompactL . partialCompactFL
273283

274284
ppuDRepActivityL ::
275285
forall era. ConwayEraPParams era => Lens' (PParamsUpdate era) (StrictMaybe EpochInterval)
@@ -678,7 +688,7 @@ data ConwayPParams f era = ConwayPParams
678688
-- ^ Gov action lifetime in number of Epochs
679689
, cppGovActionDeposit :: !(THKD ('PPGroups 'GovGroup 'SecurityGroup) f Coin)
680690
-- ^ The amount of the Gov Action deposit
681-
, cppDRepDeposit :: !(THKD ('PPGroups 'GovGroup 'NoStakePoolGroup) f Coin)
691+
, cppDRepDeposit :: !(THKD ('PPGroups 'GovGroup 'NoStakePoolGroup) f (CompactForm Coin))
682692
-- ^ The amount of a DRep registration deposit
683693
, cppDRepActivity :: !(THKD ('PPGroups 'GovGroup 'NoStakePoolGroup) f EpochInterval)
684694
-- ^ The number of Epochs that a DRep can perform no activity without losing their @Active@ status.
@@ -945,7 +955,7 @@ instance ConwayEraPParams ConwayEra where
945955
lens (unTHKD . cppGovActionLifetime) $ \pp x -> pp {cppGovActionLifetime = THKD x}
946956
hkdGovActionDepositL =
947957
lens (unTHKD . cppGovActionDeposit) $ \pp x -> pp {cppGovActionDeposit = THKD x}
948-
hkdDRepDepositL =
958+
hkdDRepDepositCompactL =
949959
lens (unTHKD . cppDRepDeposit) $ \pp x -> pp {cppDRepDeposit = THKD x}
950960
hkdDRepActivityL =
951961
lens (unTHKD . cppDRepActivity) $ \pp x -> pp {cppDRepActivity = THKD x}
@@ -989,7 +999,7 @@ emptyConwayPParams =
989999
, cppCommitteeMaxTermLength = THKD (EpochInterval 0)
9901000
, cppGovActionLifetime = THKD (EpochInterval 0)
9911001
, cppGovActionDeposit = THKD (Coin 0)
992-
, cppDRepDeposit = THKD (Coin 0)
1002+
, cppDRepDeposit = THKD (CompactCoin 0)
9931003
, cppDRepActivity = THKD (EpochInterval 0)
9941004
, cppMinFeeRefScriptCostPerByte = THKD minBound
9951005
}
@@ -1121,7 +1131,7 @@ upgradeConwayPParams UpgradeConwayPParams {..} BabbagePParams {..} =
11211131
, cppCommitteeMaxTermLength = THKD ucppCommitteeMaxTermLength
11221132
, cppGovActionLifetime = THKD ucppGovActionLifetime
11231133
, cppGovActionDeposit = THKD ucppGovActionDeposit
1124-
, cppDRepDeposit = THKD ucppDRepDeposit
1134+
, cppDRepDeposit = THKD $ asCompactCoinHKD @f ucppDRepDeposit
11251135
, cppDRepActivity = THKD ucppDRepActivity
11261136
, cppMinFeeRefScriptCostPerByte = THKD ucppMinFeeRefScriptCostPerByte
11271137
}
@@ -1235,6 +1245,9 @@ instance CollectModifiedPPGroups (K1 i (NoUpdate a) p) where
12351245
instance CollectModifiedPPGroups (a u) => CollectModifiedPPGroups (M1 i c a u) where
12361246
collectModifiedPPGroups (M1 x) = collectModifiedPPGroups x
12371247

1248+
asCompactCoinHKD :: forall f. HKDFunctor f => HKD f Coin -> HKD f (CompactForm Coin)
1249+
asCompactCoinHKD = hkdMap (Proxy @f) compactCoinOrError
1250+
12381251
-- | Care should be taken to not apply this function to signed values, otherwise it will result in
12391252
-- an `ArithmeticUnderflow` exception for negative numbers.
12401253
asNaturalHKD :: forall f i. (HKDFunctor f, Integral i) => HKD f i -> HKD f Natural

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

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import Cardano.Ledger.Binary (
3737
)
3838
import Cardano.Ledger.Binary.Coders
3939
import Cardano.Ledger.Coin (Coin)
40+
import Cardano.Ledger.Compactible (Compactible (..))
4041
import Cardano.Ledger.Conway.Core
4142
import Cardano.Ledger.Conway.Era (ConwayEra, ConwayGOVCERT, hardforkConwayBootstrapPhase)
4243
import Cardano.Ledger.Conway.Governance (
@@ -47,6 +48,7 @@ import Cardano.Ledger.Conway.Governance (
4748
GovPurposeId,
4849
ProposalProcedure (..),
4950
)
51+
import Cardano.Ledger.Conway.PParams (ppDRepDepositCompactL)
5052
import Cardano.Ledger.Conway.State
5153
import Cardano.Ledger.Conway.TxCert (ConwayGovCert (..))
5254
import Cardano.Ledger.Credential (Credential)
@@ -178,7 +180,8 @@ conwayGovCertTransition = do
178180
, cert
179181
) <-
180182
judgmentContext
181-
let ppDRepDeposit = cgcePParams ^. ppDRepDepositL
183+
let ppDRepDepositCompact = cgcePParams ^. ppDRepDepositCompactL
184+
ppDRepDeposit = fromCompact ppDRepDepositCompact
182185
ppDRepActivity = cgcePParams ^. ppDRepActivityL
183186
checkAndOverwriteCommitteeMemberState coldCred newMemberState = do
184187
let VState {vsCommitteeState = CommitteeState csCommitteeCreds} = certState ^. certVStateL
@@ -217,7 +220,7 @@ conwayGovCertTransition = do
217220
cgceCurrentEpoch
218221
(certState ^. certVStateL . vsNumDormantEpochsL)
219222
, drepAnchor = mAnchor
220-
, drepDeposit = ppDRepDeposit
223+
, drepDeposit = ppDRepDepositCompact
221224
, drepDelegs = mempty
222225
}
223226
pure $
@@ -250,18 +253,17 @@ conwayGovCertTransition = do
250253
pure $
251254
certState
252255
& certVStateL . vsDRepsL
253-
%~ ( Map.adjust
254-
( \drepState ->
255-
drepState
256-
& drepExpiryL
257-
.~ computeDRepExpiry
258-
ppDRepActivity
259-
cgceCurrentEpoch
260-
(certState ^. certVStateL . vsNumDormantEpochsL)
261-
& drepAnchorL .~ mAnchor
262-
)
263-
cred
264-
)
256+
%~ Map.adjust
257+
( \drepState ->
258+
drepState
259+
& drepExpiryL
260+
.~ computeDRepExpiry
261+
ppDRepActivity
262+
cgceCurrentEpoch
263+
(certState ^. certVStateL . vsNumDormantEpochsL)
264+
& drepAnchorL .~ mAnchor
265+
)
266+
cred
265267
ConwayAuthCommitteeHotKey coldCred hotCred ->
266268
checkAndOverwriteCommitteeMemberState coldCred $ CommitteeHotCredential hotCred
267269
ConwayResignCommitteeColdKey coldCred anchor ->

eras/conway/impl/src/Cardano/Ledger/Conway/State/CertState.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import Cardano.Ledger.Binary (
3636
encodeListLen,
3737
)
3838
import Cardano.Ledger.Coin (Coin (..))
39+
import Cardano.Ledger.Compactible (Compactible (..))
3940
import Cardano.Ledger.Conway.Era (ConwayEra)
4041
import Cardano.Ledger.Conway.State.Account (ConwayEraAccounts)
4142
import Cardano.Ledger.Conway.State.VState
@@ -112,7 +113,7 @@ conwayObligationCertState :: ConwayEraCertState era => CertState era -> Obligati
112113
conwayObligationCertState certState =
113114
let accum ans drepState = ans <> drepDeposit drepState
114115
in (shelleyObligationCertState certState)
115-
{ oblDRep = F.foldl' accum (Coin 0) (certState ^. certVStateL . vsDRepsL)
116+
{ oblDRep = fromCompact $ F.foldl' accum mempty (certState ^. certVStateL . vsDRepsL)
116117
}
117118

118119
conwayCertsTotalDepositsTxBody ::

eras/conway/impl/src/Cardano/Ledger/Conway/State/VState.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import Cardano.Ledger.Binary (
3232
)
3333
import Cardano.Ledger.Binary.Coders (Decode (..), Encode (..), decode, encode, (!>), (<!))
3434
import Cardano.Ledger.Coin (Coin (..))
35+
import Cardano.Ledger.Compactible (Compactible (..))
3536
import Cardano.Ledger.Core
3637
import Cardano.Ledger.Credential (Credential (..))
3738
import Cardano.Ledger.Shelley.State
@@ -64,7 +65,7 @@ data VState era = VState
6465

6566
-- | Function that looks up the deposit for currently registered DRep
6667
lookupDepositVState :: VState era -> Credential 'DRepRole -> Maybe Coin
67-
lookupDepositVState vstate = fmap drepDeposit . flip Map.lookup (vstate ^. vsDRepsL)
68+
lookupDepositVState vstate = fmap (fromCompact . drepDeposit) . flip Map.lookup (vstate ^. vsDRepsL)
6869

6970
instance Default (VState era) where
7071
def = VState def def (EpochNo 0)

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
module Test.Cardano.Ledger.Conway.Genesis (expectedConwayGenesis) where
99

1010
import Cardano.Ledger.BaseTypes (EpochInterval (..), textToUrl)
11-
import Cardano.Ledger.Coin (Coin (..))
11+
import Cardano.Ledger.Coin (Coin (..), CompactForm (..))
1212
import Cardano.Ledger.Conway
1313
import Cardano.Ledger.Conway.Genesis (ConwayGenesis (..))
1414
import Cardano.Ledger.Conway.Governance (Anchor (..), Committee (..))
@@ -62,7 +62,7 @@ expectedConwayGenesis =
6262
, DRepState
6363
{ drepExpiry = EpochNo 1000
6464
, drepAnchor = SNothing
65-
, drepDeposit = Coin 5000
65+
, drepDeposit = CompactCoin 5000
6666
, drepDelegs = mempty
6767
}
6868
)
@@ -77,7 +77,7 @@ expectedConwayGenesis =
7777
{ anchorUrl = fromJust $ textToUrl 99 "example.com"
7878
, anchorDataHash = def
7979
}
80-
, drepDeposit = Coin 6000
80+
, drepDeposit = CompactCoin 6000
8181
, drepDelegs = mempty
8282
}
8383
)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ unRegisterDRep ::
363363
ImpTestM era ()
364364
unRegisterDRep drep = do
365365
drepState <- getDRepState drep
366-
let refund = drepDeposit drepState
366+
let refund = fromCompact $ drepDeposit drepState
367367
submitTxAnn_ "UnRegister DRep" $
368368
mkBasicTx mkBasicTxBody
369369
& bodyTxL . certsTxBodyL

eras/dijkstra/src/Cardano/Ledger/Dijkstra/PParams.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ data DijkstraPParams f era = DijkstraPParams
135135
-- ^ Gov action lifetime in number of Epochs
136136
, dppGovActionDeposit :: !(THKD ('PPGroups 'GovGroup 'SecurityGroup) f Coin)
137137
-- ^ The amount of the Gov Action deposit
138-
, dppDRepDeposit :: !(THKD ('PPGroups 'GovGroup 'NoStakePoolGroup) f Coin)
138+
, dppDRepDeposit :: !(THKD ('PPGroups 'GovGroup 'NoStakePoolGroup) f (CompactForm Coin))
139139
-- ^ The amount of a DRep registration deposit
140140
, dppDRepActivity :: !(THKD ('PPGroups 'GovGroup 'NoStakePoolGroup) f EpochInterval)
141141
-- ^ The number of Epochs that a DRep can perform no activity without losing their @Active@ status.
@@ -558,7 +558,7 @@ instance ConwayEraPParams DijkstraEra where
558558
lens (unTHKD . dppGovActionLifetime) $ \pp x -> pp {dppGovActionLifetime = THKD x}
559559
hkdGovActionDepositL =
560560
lens (unTHKD . dppGovActionDeposit) $ \pp x -> pp {dppGovActionDeposit = THKD x}
561-
hkdDRepDepositL =
561+
hkdDRepDepositCompactL =
562562
lens (unTHKD . dppDRepDeposit) $ \pp x -> pp {dppDRepDeposit = THKD x}
563563
hkdDRepActivityL =
564564
lens (unTHKD . dppDRepActivity) $ \pp x -> pp {dppDRepActivity = THKD x}
@@ -601,7 +601,7 @@ emptyDijkstraPParams =
601601
, dppCommitteeMaxTermLength = THKD (EpochInterval 0)
602602
, dppGovActionLifetime = THKD (EpochInterval 0)
603603
, dppGovActionDeposit = THKD (Coin 0)
604-
, dppDRepDeposit = THKD (Coin 0)
604+
, dppDRepDeposit = THKD (CompactCoin 0)
605605
, dppDRepActivity = THKD (EpochInterval 0)
606606
, dppMinFeeRefScriptCostPerByte = THKD minBound
607607
, dppMaxRefScriptSizePerBlock = THKD 0

libs/cardano-ledger-core/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## 1.18.0.0
44

5+
* Add `drepDepositCompactL`
6+
* Change the type of `drepDeposit` to `CompactForm Coin`
57
* Remove `AccountState` type synonym for `ChainAccountState`
68
* Remove `rewards`, `delegations`, `ptrsMap` and `dsUnifiedL`
79
* Replace `dsUnified` with `dsAccounts` in `DState`

libs/cardano-ledger-core/src/Cardano/Ledger/DRep.hs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import Cardano.Ledger.Binary (
2828
internsFromSet,
2929
)
3030
import Cardano.Ledger.Binary.Coders (Decode (..), Encode (..), decode, encode, (!>), (<!))
31-
import Cardano.Ledger.Coin (Coin)
31+
import Cardano.Ledger.Coin (Coin, CompactForm, partialCompactCoinL)
3232
import Cardano.Ledger.Credential (Credential (..), credToText, parseCredential)
3333
import Cardano.Ledger.Hashes (ScriptHash)
3434
import Cardano.Ledger.Keys (KeyHash (..), KeyRole (..))
@@ -147,7 +147,7 @@ pattern DRepCredential c <- (dRepToCred -> Just c)
147147
data DRepState = DRepState
148148
{ drepExpiry :: !EpochNo
149149
, drepAnchor :: !(StrictMaybe Anchor)
150-
, drepDeposit :: !Coin
150+
, drepDeposit :: !(CompactForm Coin)
151151
, drepDelegs :: !(Set (Credential 'Staking))
152152
}
153153
deriving (Show, Eq, Ord, Generic)
@@ -208,7 +208,10 @@ drepAnchorL :: Lens' DRepState (StrictMaybe Anchor)
208208
drepAnchorL = lens drepAnchor (\x y -> x {drepAnchor = y})
209209

210210
drepDepositL :: Lens' DRepState Coin
211-
drepDepositL = lens drepDeposit (\x y -> x {drepDeposit = y})
211+
drepDepositL = drepDepositCompactL . partialCompactCoinL
212+
213+
drepDepositCompactL :: Lens' DRepState (CompactForm Coin)
214+
drepDepositCompactL = lens drepDeposit (\x y -> x {drepDeposit = y})
212215

213216
drepDelegsL :: Lens' DRepState (Set (Credential 'Staking))
214217
drepDelegsL = lens drepDelegs (\x y -> x {drepDelegs = y})

0 commit comments

Comments
 (0)