Skip to content

Change the type of psDeposits to CompactForm Coin #5031

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions eras/alonzo/impl/src/Cardano/Ledger/Alonzo/PParams.hs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ import Cardano.Ledger.Binary.Coders (
invalidField,
(!>),
)
import Cardano.Ledger.Coin (Coin (..))
import Cardano.Ledger.Coin (Coin (..), CompactForm (..))
import Cardano.Ledger.Core (EraPParams (..))
import Cardano.Ledger.HKD (HKD, HKDFunctor (..))
import Cardano.Ledger.Mary.Core
Expand Down Expand Up @@ -260,7 +260,7 @@ data AlonzoPParams f era = AlonzoPParams
-- ^ Maximal block header size
, appKeyDeposit :: !(HKD f Coin)
-- ^ The amount of a key registration deposit
, appPoolDeposit :: !(HKD f Coin)
, appPoolDeposit :: !(HKD f (CompactForm Coin))
-- ^ The amount of a pool registration deposit
, appEMax :: !(HKD f EpochInterval)
-- ^ Maximum number of epochs in the future a pool retirement is allowed to
Expand Down Expand Up @@ -563,7 +563,7 @@ emptyAlonzoPParams =
, appMaxTxSize = 2048
, appMaxBHSize = 0
, appKeyDeposit = Coin 0
, appPoolDeposit = Coin 0
, appPoolDeposit = CompactCoin 0
, appEMax = EpochInterval 0
, appNOpt = 100
, appA0 = minBound
Expand Down
6 changes: 3 additions & 3 deletions eras/babbage/impl/src/Cardano/Ledger/Babbage/PParams.hs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ import Cardano.Ledger.Binary.Coders (
invalidField,
(!>),
)
import Cardano.Ledger.Coin (Coin (..))
import Cardano.Ledger.Coin (Coin (..), CompactForm (..))
import Cardano.Ledger.Core (EraPParams (..))
import Cardano.Ledger.HKD (HKD, HKDFunctor (..))
import Cardano.Ledger.Orphans ()
Expand Down Expand Up @@ -148,7 +148,7 @@ data BabbagePParams f era = BabbagePParams
-- ^ Maximal block header size
, bppKeyDeposit :: !(HKD f Coin)
-- ^ The amount of a key registration deposit
, bppPoolDeposit :: !(HKD f Coin)
, bppPoolDeposit :: !(HKD f (CompactForm Coin))
-- ^ The amount of a pool registration deposit
, bppEMax :: !(HKD f EpochInterval)
-- ^ Maximum number of epochs in the future a pool retirement is allowed to
Expand Down Expand Up @@ -385,7 +385,7 @@ emptyBabbagePParams =
, bppMaxTxSize = 2048
, bppMaxBHSize = 0
, bppKeyDeposit = Coin 0
, bppPoolDeposit = Coin 0
, bppPoolDeposit = CompactCoin 0
, bppEMax = EpochInterval 0
, bppNOpt = 100
, bppA0 = minBound
Expand Down
8 changes: 4 additions & 4 deletions eras/conway/impl/src/Cardano/Ledger/Conway/PParams.hs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ import Cardano.Ledger.Binary (
encodeListLen,
)
import Cardano.Ledger.Binary.Coders
import Cardano.Ledger.Coin (Coin (Coin))
import Cardano.Ledger.Coin (Coin (Coin), CompactForm (..))
import Cardano.Ledger.Conway.Era (ConwayEra)
import Cardano.Ledger.Core (EraPParams (..))
import Cardano.Ledger.HKD (
Expand Down Expand Up @@ -569,7 +569,7 @@ data ConwayPParams f era = ConwayPParams
-- ^ Maximal block header size
, cppKeyDeposit :: !(THKD ('PPGroups 'EconomicGroup 'NoStakePoolGroup) f Coin)
-- ^ The amount of a key registration deposit
, cppPoolDeposit :: !(THKD ('PPGroups 'EconomicGroup 'NoStakePoolGroup) f Coin)
, cppPoolDeposit :: !(THKD ('PPGroups 'EconomicGroup 'NoStakePoolGroup) f (CompactForm Coin))
-- ^ The amount of a pool registration deposit
, cppEMax :: !(THKD ('PPGroups 'TechnicalGroup 'NoStakePoolGroup) f EpochInterval)
-- ^ Maximum number of epochs in the future a pool retirement is allowed to
Expand Down Expand Up @@ -806,7 +806,7 @@ instance ConwayEraPParams ConwayEra where
, isValid (/= EpochInterval 0) ppuCommitteeMaxTermLengthL
, isValid (/= EpochInterval 0) ppuGovActionLifetimeL
, -- Coins
isValid (/= zero) ppuPoolDepositL
isValid (/= CompactCoin 0) ppuPoolDepositL
, isValid (/= zero) ppuGovActionDepositL
, isValid (/= zero) ppuDRepDepositL
, bootstrapPhase pv
Expand Down Expand Up @@ -982,7 +982,7 @@ emptyConwayPParams =
, cppMaxTxSize = THKD 2048
, cppMaxBHSize = THKD 0
, cppKeyDeposit = THKD (Coin 0)
, cppPoolDeposit = THKD (Coin 0)
, cppPoolDeposit = THKD (CompactCoin 0)
, cppEMax = THKD (EpochInterval 0)
, cppNOpt = THKD 100
, cppA0 = THKD minBound
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module Test.Cardano.Ledger.Conway.Imp.GovSpec (spec) where

import Cardano.Ledger.Address (RewardAccount (..))
import Cardano.Ledger.BaseTypes
import Cardano.Ledger.Coin (Coin (Coin))
import Cardano.Ledger.Coin (Coin (Coin), CompactForm (..))
import Cardano.Ledger.Conway.Core
import Cardano.Ledger.Conway.Governance
import Cardano.Ledger.Conway.Rules (ConwayGovPredFailure (..))
Expand Down Expand Up @@ -223,7 +223,7 @@ pparamUpdateSpec =
testMalformedProposal
"ppuPoolDepositL cannot be 0"
ppuPoolDepositL
zero
$ CompactCoin 0
testMalformedProposal
"ppuGovActionDepositL cannot be 0"
ppuGovActionDepositL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import Test.Cardano.Ledger.Conway.ImpTest
import Test.Cardano.Ledger.Core.KeyPair
import Test.Cardano.Ledger.Core.Rational ((%!))
import Test.Cardano.Ledger.Imp.Common
import Cardano.Ledger.Compactible (Compactible(..))

spec ::
forall era.
Expand Down Expand Up @@ -661,7 +662,7 @@ votingSpec =
it "Rewards contribute to active voting stake even in the absence of StakeDistr" $ whenPostBootstrap $ do
let govActionLifetime = 5
govActionDeposit = Coin 1_000_000
poolDeposit = Coin 858_000
poolDeposit = CompactCoin 858_000
-- Only modify the applicable thresholds
modifyPParams $ \pp ->
pp
Expand Down Expand Up @@ -695,7 +696,7 @@ votingSpec =
-- Increase the rewards of the delegator to this DRep
-- to barely make the threshold (65 %! 100)
registerAndRetirePoolToMakeReward $ KeyHashObj stakingKH1
getReward (KeyHashObj stakingKH1) `shouldReturn` poolDeposit <> govActionDeposit
getReward (KeyHashObj stakingKH1) `shouldReturn` fromCompact poolDeposit <> govActionDeposit
isDRepAccepted addCCGaid `shouldReturn` True
-- The same vote should now successfully ratify the proposal
passEpoch
Expand Down Expand Up @@ -972,7 +973,7 @@ votingSpec =
whenPostBootstrap $ do
let govActionLifetime = 5
govActionDeposit = Coin 1_000_000
poolDeposit = Coin 200_000
poolDeposit = CompactCoin 200_000
-- Only modify the applicable thresholds
modifyPParams $ \pp ->
pp
Expand Down Expand Up @@ -1017,7 +1018,7 @@ votingSpec =
-- Add to the rewards of the delegator to this SPO
-- to barely make the threshold (51 %! 100)
registerAndRetirePoolToMakeReward delegatorCStaking1
getReward delegatorCStaking1 `shouldReturn` poolDeposit <> govActionDeposit
getReward delegatorCStaking1 `shouldReturn` fromCompact poolDeposit <> govActionDeposit
-- The same vote should now successfully ratify the proposal
-- NOTE: It takes 2 epochs for SPO votes as opposed to 1 epoch
-- for DRep votes to ratify a proposal.
Expand Down
9 changes: 5 additions & 4 deletions eras/shelley/impl/src/Cardano/Ledger/Shelley/PParams.hs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ import Cardano.Ledger.Binary (
encodeWord,
)
import Cardano.Ledger.Binary.Coders (Decode (From, RecD), decode, (<!))
import Cardano.Ledger.Coin (Coin (..))
import Cardano.Ledger.Coin (Coin (..), CompactForm (..))
import Cardano.Ledger.Core
import Cardano.Ledger.HKD (HKD, HKDFunctor (..))
import Cardano.Ledger.Hashes (GenDelegs)
Expand Down Expand Up @@ -93,6 +93,7 @@ import Data.Word (Word16, Word32)
import GHC.Generics (Generic)
import Lens.Micro (lens, (^.))
import NoThunks.Class (NoThunks (..))
import Cardano.Ledger.Compactible (Compactible(..))

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

Expand All @@ -110,7 +111,7 @@ data ShelleyPParams f era = ShelleyPParams
-- ^ Maximal block header size
, sppKeyDeposit :: !(HKD f Coin)
-- ^ The amount of a key registration deposit
, sppPoolDeposit :: !(HKD f Coin)
, sppPoolDeposit :: !(HKD f (CompactForm Coin))
-- ^ The amount of a pool registration deposit
, sppEMax :: !(HKD f EpochInterval)
-- ^ epoch bound on pool retirement
Expand Down Expand Up @@ -292,7 +293,7 @@ emptyShelleyPParams =
, sppMaxTxSize = 2048
, sppMaxBHSize = 0
, sppKeyDeposit = Coin 0
, sppPoolDeposit = Coin 0
, sppPoolDeposit = CompactCoin 0
, sppEMax = EpochInterval 0
, sppNOpt = 100
, sppA0 = minBound
Expand Down Expand Up @@ -490,7 +491,7 @@ shelleyCommonPParamsHKDPairs px pp =
, ("maxTxSize", hkdMap px (toJSON @Word32) (pp ^. hkdMaxTxSizeL @era @f))
, ("maxBlockHeaderSize", hkdMap px (toJSON @Word16) (pp ^. hkdMaxBHSizeL @era @f))
, ("stakeAddressDeposit", hkdMap px (toJSON @Coin) (pp ^. hkdKeyDepositL @era @f))
, ("stakePoolDeposit", hkdMap px (toJSON @Coin) (pp ^. hkdPoolDepositL @era @f))
, ("stakePoolDeposit", hkdMap px (toJSON @(CompactForm Coin)) (pp ^. hkdPoolDepositL @era @f))
, ("poolRetireMaxEpoch", hkdMap px (toJSON @EpochInterval) (pp ^. hkdEMaxL @era @f))
, ("stakePoolTargetNum", hkdMap px (toJSON @Word16) (pp ^. hkdNOptL @era @f))
, ("poolPledgeInfluence", hkdMap px (toJSON @NonNegativeInterval) (pp ^. hkdA0L @era @f))
Expand Down
14 changes: 8 additions & 6 deletions eras/shelley/impl/src/Cardano/Ledger/Shelley/Rules/PoolReap.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ where

import Cardano.Ledger.Address (RewardAccount, raCredential)
import Cardano.Ledger.BaseTypes (ShelleyBase)
import Cardano.Ledger.Coin (Coin)
import Cardano.Ledger.Coin (Coin, CompactForm)
import Cardano.Ledger.Core
import Cardano.Ledger.Credential (Credential)
import Cardano.Ledger.PoolParams (ppRewardAccount)
Expand All @@ -36,7 +36,7 @@ import Cardano.Ledger.Shelley.LedgerState (
import Cardano.Ledger.Shelley.LedgerState.Types (potEqualsObligation)
import Cardano.Ledger.Slot (EpochNo (..))
import Cardano.Ledger.State
import Cardano.Ledger.UMap (UView (RewDepUView, SPoolUView), compactCoinOrError)
import Cardano.Ledger.UMap (UView (RewDepUView, SPoolUView), compactCoinOrError, fromCompact)
import qualified Cardano.Ledger.UMap as UM
import Cardano.Ledger.Val ((<+>), (<->))
import Control.DeepSeq (NFData)
Expand All @@ -58,6 +58,7 @@ import qualified Data.Set as Set (member)
import GHC.Generics (Generic)
import Lens.Micro
import NoThunks.Class (NoThunks (..))
import Data.Bifunctor (Bifunctor(..))

data ShelleyPoolreapState era = PoolreapState
{ prUTxOSt :: UTxOState era
Expand All @@ -75,9 +76,9 @@ instance NFData (ShelleyPoolreapPredFailure era)

data ShelleyPoolreapEvent era = RetiredPools
{ refundPools ::
Map.Map (Credential 'Staking) (Map.Map (KeyHash 'StakePool) Coin)
Map.Map (Credential 'Staking) (Map.Map (KeyHash 'StakePool) (CompactForm Coin))
, unclaimedPools ::
Map.Map (Credential 'Staking) (Map.Map (KeyHash 'StakePool) Coin)
Map.Map (Credential 'Staking) (Map.Map (KeyHash 'StakePool) (CompactForm Coin))
, epochNo :: EpochNo
}
deriving (Generic)
Expand Down Expand Up @@ -137,18 +138,19 @@ poolReapTransition = do
retired :: Set (KeyHash 'StakePool)
retired = eval (dom (psRetiring ps ▷ setSingleton e))
-- The Map of pools (retiring this epoch) to their deposits
retiringDeposits, remainingDeposits :: Map.Map (KeyHash 'StakePool) Coin
retiringDeposits, remainingDeposits :: Map.Map (KeyHash 'StakePool) (CompactForm Coin)
(retiringDeposits, remainingDeposits) =
Map.partitionWithKey (\k _ -> Set.member k retired) (psDeposits ps)
rewardAccounts :: Map.Map (KeyHash 'StakePool) RewardAccount
rewardAccounts = Map.map ppRewardAccount $ eval (retired ◁ psStakePoolParams ps)
rewardAccounts_ ::
Map.Map (KeyHash 'StakePool) (RewardAccount, Coin)
Map.Map (KeyHash 'StakePool) (RewardAccount, CompactForm Coin)
rewardAccounts_ = Map.intersectionWith (,) rewardAccounts retiringDeposits
rewardAccounts' :: Map.Map RewardAccount Coin
rewardAccounts' =
Map.fromListWith (<+>)
. Map.elems
. fmap (second fromCompact)
$ rewardAccounts_
refunds :: Map.Map (Credential 'Staking) Coin
mRefunds :: Map.Map (Credential 'Staking) Coin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import Cardano.Ledger.Binary (
encodeListLen,
)
import Cardano.Ledger.Coin (Coin (..))
import Cardano.Ledger.Compactible (Compactible (..))
import Cardano.Ledger.Core
import Cardano.Ledger.Credential (Credential (..))
import Cardano.Ledger.Shelley.Era (ShelleyEra)
Expand Down Expand Up @@ -71,7 +72,7 @@ shelleyObligationCertState certState =
Obligations
{ oblStake =
UM.fromCompact (UM.sumDepositUView (UM.RewDepUView (certState ^. certDStateL . dsUnifiedL)))
, oblPool = F.foldl' (<>) (Coin 0) (certState ^. certPStateL . psDepositsL)
, oblPool = F.foldl' (<>) (Coin 0) (fmap fromCompact $ certState ^. certPStateL . psDepositsL)
, oblDRep = Coin 0
, oblProposal = Coin 0
}
Expand Down
3 changes: 2 additions & 1 deletion eras/shelley/impl/src/Cardano/Ledger/Shelley/TxCert.hs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ import qualified Data.Set as Set
import GHC.Generics (Generic)
import Lens.Micro
import NoThunks.Class (NoThunks (..))
import Cardano.Ledger.Compactible (Compactible(..))

instance EraTxCert ShelleyEra where
type TxCert ShelleyEra = ShelleyTxCert ShelleyEra
Expand Down Expand Up @@ -565,7 +566,7 @@ shelleyTotalDepositsTxCerts pp isRegPoolRegistered certs =
numKeys
<×> (pp ^. ppKeyDepositL)
<+> numNewRegPoolCerts
<×> (pp ^. ppPoolDepositL)
<×> fromCompact (pp ^. ppPoolDepositL)
where
numKeys = getSum @Int $ foldMap' (\x -> if isRegStakeTxCert x then 1 else 0) certs
numNewRegPoolCerts = Set.size (F.foldl' addNewPoolIds Set.empty certs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
{-# LANGUAGE OverloadedLists #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilyDependencies #-}
Expand Down Expand Up @@ -675,7 +674,7 @@ instance
& ppMaxBBSizeL .~ 65536
& ppMaxTxSizeL .~ 16384
& ppKeyDepositL .~ Coin 2_000_000
& ppPoolDepositL .~ Coin 500_000_000
& ppPoolDepositL .~ CompactCoin 500_000_000
& ppEMaxL .~ EpochInterval 18
& ppNOptL .~ 150
& ppA0L .~ (3 %! 10)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import Cardano.Ledger.BaseTypes (
inject,
mkTxIxPartial,
)
import Cardano.Ledger.Coin (Coin (..))
import Cardano.Ledger.Coin (Coin (..), CompactForm (..))
import Cardano.Ledger.Credential (Credential (..))
import Cardano.Ledger.Keys (asWitness)
import Cardano.Ledger.PoolParams (
Expand Down Expand Up @@ -135,7 +135,7 @@ ppsBench =
& ppMinFeeAL .~ Coin 0
& ppMinFeeBL .~ Coin 0
& ppMinUTxOValueL .~ Coin 10
& ppPoolDepositL .~ Coin 0
& ppPoolDepositL .~ CompactCoin 0
& ppRhoL .~ unsafeBoundRational 0.0021
& ppTauL .~ unsafeBoundRational 0.2

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import Cardano.Ledger.BaseTypes (
succVersion,
unsafeNonZero,
)
import Cardano.Ledger.Coin (Coin (..))
import Cardano.Ledger.Coin (Coin (..), CompactForm (..))
import Cardano.Ledger.Core
import Cardano.Ledger.Keys (
GenDelegPair (..),
Expand Down Expand Up @@ -162,11 +162,11 @@ hi = 200000
-- NOTE: we need to keep these deposits small, otherwise
-- when we generate sequences of transactions we will bleed too
-- much funds into the deposit pool (i.e. funds not available as utxo)
genPoolDeposit :: HasCallStack => Gen Coin
genPoolDeposit :: HasCallStack => Gen (CompactForm Coin)
genPoolDeposit =
increasingProbabilityAt
(Coin <$> genInteger 0 100)
(Coin 0, Coin 100)
(CompactCoin <$> genWord64 0 100)
(CompactCoin 0, CompactCoin 100)

-- Generates a Neutral or actual Nonces with equal frequency
genExtraEntropy :: HasCallStack => Gen Nonce
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ adaPreservationProps =
, map feesNonDecreasing noEpochBoundarySsts
]

infoRetire :: Map (KeyHash 'StakePool) Coin -> KeyHash 'StakePool -> String
infoRetire :: Show a => Map (KeyHash 'StakePool) a -> KeyHash 'StakePool -> String
infoRetire deposits keyhash = showKeyHash keyhash ++ extra
where
extra = case Map.lookup keyhash deposits of
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import Cardano.Ledger.Shelley.LedgerState (
)
import Cardano.Ledger.Shelley.Rules.Reports (synopsisCoinMap)
import Cardano.Ledger.Shelley.State
import Cardano.Ledger.UMap (depositMap)
import Cardano.Ledger.UMap (depositMap, fromCompact)
import qualified Cardano.Ledger.UMap as UM
import Cardano.Ledger.Val ((<+>))
import qualified Data.Map.Strict as Map
Expand Down Expand Up @@ -89,14 +89,14 @@ depositInvariant SourceSignalTarget {source = chainSt} =
allDeposits = utxosDeposited utxost
sumCoin = Map.foldl' (<+>) (Coin 0)
keyDeposits = (UM.fromCompact . UM.sumDepositUView . UM.RewDepUView . dsUnified) dstate
poolDeposits = sumCoin (psDeposits pstate)
poolDeposits = sumCoin (fromCompact <$> psDeposits pstate)
in counterexample
( ansiDocToString . Pretty.vsep $
[ "Deposit invariant fails:"
, Pretty.indent 2 . Pretty.vsep . map Pretty.pretty $
[ "All deposits = " ++ show allDeposits
, "Key deposits = " ++ synopsisCoinMap (Just (depositMap (dsUnified dstate)))
, "Pool deposits = " ++ synopsisCoinMap (Just (psDeposits pstate))
, "Pool deposits = " ++ synopsisCoinMap (Just (fromCompact <$> psDeposits pstate))
]
]
)
Expand Down
Loading
Loading