Skip to content

Commit

Permalink
Change type of nOpt pparam to Word16
Browse files Browse the repository at this point in the history
  • Loading branch information
teodanciu committed Dec 3, 2024
1 parent 730c811 commit 3e9e752
Show file tree
Hide file tree
Showing 19 changed files with 30 additions and 31 deletions.
2 changes: 1 addition & 1 deletion eras/alonzo/impl/cddl-files/alonzo.cddl
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ protocol_param_update =
, ? 5: coin ; key deposit
, ? 6: coin ; pool deposit
, ? 7: epoch ; maximum epoch
, ? 8: uint ; n_opt: desired number of stake pools
, ? 8: uint .size 2 ; n_opt: desired number of stake pools
, ? 9: nonnegative_interval ; pool pledge influence
, ? 10: unit_interval ; expansion rate
, ? 11: unit_interval ; treasury growth rate
Expand Down
2 changes: 1 addition & 1 deletion eras/alonzo/impl/src/Cardano/Ledger/Alonzo/PParams.hs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ data AlonzoPParams f era = AlonzoPParams
, appEMax :: !(HKD f EpochInterval)
-- ^ Maximum number of epochs in the future a pool retirement is allowed to
-- be scheduled for.
, appNOpt :: !(HKD f Natural)
, appNOpt :: !(HKD f Word16)
-- ^ Desired number of pools
, appA0 :: !(HKD f NonNegativeInterval)
-- ^ Pool influence
Expand Down
2 changes: 1 addition & 1 deletion eras/babbage/impl/cddl-files/babbage.cddl
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ protocol_param_update =
, ? 5: coin ; key deposit
, ? 6: coin ; pool deposit
, ? 7: epoch ; maximum epoch
, ? 8: uint ; n_opt: desired number of stake pools
, ? 8: uint .size 2 ; n_opt: desired number of stake pools
, ? 9: nonnegative_interval ; pool pledge influence
, ? 10: unit_interval ; expansion rate
, ? 11: unit_interval ; treasury growth rate
Expand Down
2 changes: 1 addition & 1 deletion eras/babbage/impl/src/Cardano/Ledger/Babbage/PParams.hs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ data BabbagePParams f era = BabbagePParams
, bppEMax :: !(HKD f EpochInterval)
-- ^ Maximum number of epochs in the future a pool retirement is allowed to
-- be scheduled for.
, bppNOpt :: !(HKD f Natural)
, bppNOpt :: !(HKD f Word16)
-- ^ Desired number of pools
, bppA0 :: !(HKD f NonNegativeInterval)
-- ^ Pool influence
Expand Down
9 changes: 3 additions & 6 deletions eras/conway/impl/src/Cardano/Ledger/Conway/PParams.hs
Original file line number Diff line number Diff line change
Expand Up @@ -700,10 +700,7 @@ instance Crypto c => EraPParams (ConwayEra c) where
hkdKeyDepositL = lens (unTHKD . cppKeyDeposit) $ \pp x -> pp {cppKeyDeposit = THKD x}
hkdPoolDepositL = lens (unTHKD . cppPoolDeposit) $ \pp x -> pp {cppPoolDeposit = THKD x}
hkdEMaxL = lens (unTHKD . cppEMax) $ \pp x -> pp {cppEMax = THKD x}
hkdNOptL :: forall f. HKDFunctor f => Lens' (PParamsHKD f (ConwayEra c)) (HKD f Natural)
hkdNOptL =
lens (asNaturalHKD @f @Word16 . (unTHKD . cppNOpt)) $
\pp x -> pp {cppNOpt = THKD (asBoundedIntegralHKD @f @Natural @Word16 x)}
hkdNOptL = lens (unTHKD . cppNOpt) $ \pp x -> pp {cppNOpt = THKD x}
hkdA0L = lens (unTHKD . cppA0) $ \pp x -> pp {cppA0 = THKD x}
hkdRhoL = lens (unTHKD . cppRho) $ \pp x -> pp {cppRho = THKD x}
hkdTauL = lens (unTHKD . cppTau) $ \pp x -> pp {cppTau = THKD x}
Expand Down Expand Up @@ -1213,7 +1210,7 @@ upgradeConwayPParams UpgradeConwayPParams {..} BabbagePParams {..} =
, cppKeyDeposit = THKD bppKeyDeposit
, cppPoolDeposit = THKD bppPoolDeposit
, cppEMax = THKD bppEMax
, cppNOpt = THKD (asBoundedIntegralHKD @f @Natural @Word16 bppNOpt)
, cppNOpt = THKD bppNOpt
, cppA0 = THKD bppA0
, cppRho = THKD bppRho
, cppTau = THKD bppTau
Expand Down Expand Up @@ -1267,7 +1264,7 @@ downgradeConwayPParams ConwayPParams {..} =
, bppKeyDeposit = unTHKD cppKeyDeposit
, bppPoolDeposit = unTHKD cppPoolDeposit
, bppEMax = unTHKD cppEMax
, bppNOpt = asNaturalHKD @f @Word16 (unTHKD cppNOpt)
, bppNOpt = unTHKD cppNOpt
, bppA0 = unTHKD cppA0
, bppRho = unTHKD cppRho
, bppTau = unTHKD cppTau
Expand Down
2 changes: 2 additions & 0 deletions eras/shelley/impl/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## 1.15.0.0

* Change param of `PoolRank.desirability` to `Word16`
* Change type of `nOpt` in `RewardParams` to `Word16`
* Add lenses for `LedgerEnv`. #4748
* `ledgerSlotNoL`
* `ledgerEpochNoL`
Expand Down
2 changes: 1 addition & 1 deletion eras/shelley/impl/cddl-files/shelley.cddl
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ protocol_param_update = {? 0 : uint
, ? 5 : coin
, ? 6 : coin
, ? 7 : epoch
, ? 8 : uint
, ? 8 : uint .size 2
, ? 9 : nonnegative_interval
, ? 10 : unit_interval
, ? 11 : unit_interval
Expand Down
4 changes: 2 additions & 2 deletions eras/shelley/impl/src/Cardano/Ledger/Shelley/API/Wallet.hs
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@ import Data.Ratio ((%))
import Data.Set (Set)
import qualified Data.Set as Set
import qualified Data.VMap as VMap
import Data.Word (Word16)
import GHC.Generics (Generic)
import Lens.Micro
import NoThunks.Class (NoThunks (..))
import Numeric.Natural (Natural)

--------------------------------------------------------------------------------
-- UTxOs
Expand Down Expand Up @@ -320,7 +320,7 @@ deriving instance ToJSON RewardInfoPool

-- | Global information that influences stake pool rewards
data RewardParams = RewardParams
{ nOpt :: Natural
{ nOpt :: Word16
-- ^ Desired number of stake pools
, a0 :: NonNegativeInterval
-- ^ Influence of the pool owner's pledge on rewards
Expand Down
5 changes: 2 additions & 3 deletions eras/shelley/impl/src/Cardano/Ledger/Shelley/PParams.hs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ import Data.Word (Word16, Word32)
import GHC.Generics (Generic)
import Lens.Micro (lens, (^.))
import NoThunks.Class (NoThunks (..))
import Numeric.Natural (Natural)

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

Expand All @@ -120,7 +119,7 @@ data ShelleyPParams f era = ShelleyPParams
-- ^ The amount of a pool registration deposit
, sppEMax :: !(HKD f EpochInterval)
-- ^ epoch bound on pool retirement
, sppNOpt :: !(HKD f Natural)
, sppNOpt :: !(HKD f Word16)
-- ^ Desired number of pools
, sppA0 :: !(HKD f NonNegativeInterval)
-- ^ Pool influence
Expand Down Expand Up @@ -496,7 +495,7 @@ shelleyCommonPParamsHKDPairs px pp =
, ("stakeAddressDeposit", hkdMap px (toJSON @Coin) (pp ^. hkdKeyDepositL @era @f))
, ("stakePoolDeposit", hkdMap px (toJSON @Coin) (pp ^. hkdPoolDepositL @era @f))
, ("poolRetireMaxEpoch", hkdMap px (toJSON @EpochInterval) (pp ^. hkdEMaxL @era @f))
, ("stakePoolTargetNum", hkdMap px (toJSON @Natural) (pp ^. hkdNOptL @era @f))
, ("stakePoolTargetNum", hkdMap px (toJSON @Word16) (pp ^. hkdNOptL @era @f))
, ("poolPledgeInfluence", hkdMap px (toJSON @NonNegativeInterval) (pp ^. hkdA0L @era @f))
, ("monetaryExpansion", hkdMap px (toJSON @UnitInterval) (pp ^. hkdRhoL @era @f))
, ("treasuryCut", hkdMap px (toJSON @UnitInterval) (pp ^. hkdTauL @era @f))
Expand Down
3 changes: 2 additions & 1 deletion eras/shelley/impl/src/Cardano/Ledger/Shelley/PoolRank.hs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ import qualified Data.Sequence.Strict as StrictSeq
import Data.Set (Set)
import qualified Data.Set as Set
import qualified Data.VMap as VMap
import Data.Word (Word16)
import GHC.Generics (Generic)
import Lens.Micro ((^.), _1)
import NoThunks.Class (NoThunks (..))
Expand Down Expand Up @@ -266,7 +267,7 @@ toNonMyopicPair nm@(NonMyopic _ _) =
-- corresponding to f^~ in section 5.6.1 of
-- "Design Specification for Delegation and Incentives in Cardano"
desirability ::
(NonNegativeInterval, Natural) ->
(NonNegativeInterval, Word16) ->
Coin ->
PoolParams c ->
PerformanceEstimate ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ protocol_param_update =
, opt (idx 5 ==> coin) -- key deposit
, opt (idx 6 ==> coin) -- pool deposit
, opt (idx 7 ==> epoch) -- maximum epoch
, opt (idx 8 ==> VUInt) -- n_opt: desired number of stake pools
, opt (idx 8 ==> VUInt `sized` (2 :: Word64)) -- n_opt: desired number of stake pools
, opt (idx 9 ==> nonnegative_interval) -- pool pledge influence
, opt (idx 10 ==> unit_interval) -- expansion rate
, opt (idx 11 ==> unit_interval) -- treasury growth rate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ genEMax Constants {frequencyLowMaxEpoch} =
EpochInterval . fromIntegral <$> genWord64 frequencyLowMaxEpoch 500

-- | nOpt
genNOpt :: HasCallStack => Gen Natural
genNOpt = genNatural 1 100
genNOpt :: HasCallStack => Gen Word16
genNOpt = fromIntegral <$> genNatural 1 100

-- | genKeyDeposit
-- NOTE: we need to keep these deposits small, otherwise
Expand Down
1 change: 1 addition & 0 deletions libs/cardano-ledger-core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## 1.16.0.0

* Change lens type of `hkdNOptL`, `ppNOptL`, and `ppuNOptL` to `Word16`
* Add `epochFromSlot`
* Remove usage of a `Reader` monad in `epochInfoEpoch`, `epochInfoFirst` and `epochInfoSize`.
* Add `eraProtVersions`
Expand Down
7 changes: 3 additions & 4 deletions libs/cardano-ledger-core/src/Cardano/Ledger/Core/PParams.hs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ import Data.Map.Strict (Map)
import qualified Data.Map.Strict as Map
import Data.Word (Word16, Word32)
import GHC.Generics (Generic (..), K1 (..), M1 (..), U1, V1, type (:*:) (..))
import GHC.Natural (Natural)
import Lens.Micro (Lens', SimpleGetter, lens)
import NoThunks.Class (NoThunks)

Expand Down Expand Up @@ -322,7 +321,7 @@ class
hkdEMaxL :: HKDFunctor f => Lens' (PParamsHKD f era) (HKD f EpochInterval)

-- | Desired number of pools
hkdNOptL :: HKDFunctor f => Lens' (PParamsHKD f era) (HKD f Natural)
hkdNOptL :: HKDFunctor f => Lens' (PParamsHKD f era) (HKD f Word16)

-- | Pool influence
hkdA0L :: HKDFunctor f => Lens' (PParamsHKD f era) (HKD f NonNegativeInterval)
Expand Down Expand Up @@ -409,7 +408,7 @@ ppEMaxL :: forall era. EraPParams era => Lens' (PParams era) EpochInterval
ppEMaxL = ppLens . hkdEMaxL @era @Identity

-- | Desired number of pools
ppNOptL :: forall era. EraPParams era => Lens' (PParams era) Natural
ppNOptL :: forall era. EraPParams era => Lens' (PParams era) Word16
ppNOptL = ppLens . hkdNOptL @era @Identity

-- | Pool influence
Expand Down Expand Up @@ -475,7 +474,7 @@ ppuEMaxL :: forall era. EraPParams era => Lens' (PParamsUpdate era) (StrictMaybe
ppuEMaxL = ppuLens . hkdEMaxL @era @StrictMaybe

-- | Desired number of pools
ppuNOptL :: forall era. EraPParams era => Lens' (PParamsUpdate era) (StrictMaybe Natural)
ppuNOptL :: forall era. EraPParams era => Lens' (PParamsUpdate era) (StrictMaybe Word16)
ppuNOptL = ppuLens . hkdNOptL @era @StrictMaybe

-- | Pool influence
Expand Down
4 changes: 2 additions & 2 deletions libs/cardano-ledger-core/src/Cardano/Ledger/EpochBoundary.hs
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ import qualified Data.Map.Strict as Map
import Data.Ratio ((%))
import Data.Typeable
import Data.VMap as VMap
import Data.Word (Word16)
import GHC.Generics (Generic)
import GHC.Word (Word64)
import Lens.Micro (Lens', lens, (^.), _1, _2)
import NoThunks.Class (AllowThunksIn (..), NoThunks (..))
import Numeric.Natural (Natural)

-- | Type of stake as map from hash key to coins associated.
newtype Stake c = Stake
Expand Down Expand Up @@ -135,7 +135,7 @@ sumStakePerPool delegs (Stake stake) = VMap.foldlWithKey accum Map.empty stake
-- | Calculate maximal pool reward
maxPool' ::
NonNegativeInterval ->
Natural ->
Word16 ->
Coin ->
Rational ->
Rational ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ data SimplePParams era = SimplePParams
, keyDeposit :: Coin
, poolDeposit :: Coin
, eMax :: EpochInterval
, nOpt :: Natural
, nOpt :: Word16
, a0 :: NonNegativeInterval
, rho :: UnitInterval
, tau :: UnitInterval
Expand Down Expand Up @@ -289,7 +289,7 @@ data SimplePPUpdate = SimplePPUpdate
, ukeyDeposit :: StrictMaybe Coin
, upoolDeposit :: StrictMaybe Coin
, ueMax :: StrictMaybe EpochInterval
, unOpt :: StrictMaybe Natural
, unOpt :: StrictMaybe Word16
, ua0 :: StrictMaybe NonNegativeInterval
, urho :: StrictMaybe UnitInterval
, utau :: StrictMaybe UnitInterval
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ eMax_ ::
(EraSpecPParams era, BaseUniverse fn) => Term fn (SimplePParams era) -> Term fn EpochInterval
eMax_ simplepp = sel @7 simplepp

nOpt_ :: (EraSpecPParams era, BaseUniverse fn) => Term fn (SimplePParams era) -> Term fn Natural
nOpt_ :: (EraSpecPParams era, BaseUniverse fn) => Term fn (SimplePParams era) -> Term fn Word16
nOpt_ simplepp = sel @8 simplepp

a0_ ::
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ data PParamsField era
| -- | epoch bound on pool retirement
EMax EpochInterval
| -- | Desired number of pools
NOpt Natural
NOpt Word16
| -- | Pool influence
A0 NonNegativeInterval
| -- | Monetary expansion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1130,7 +1130,7 @@ pcPParamsField x = case x of
KeyDeposit coin -> [("keydeposit", pcCoin coin)]
PoolDeposit coin -> [("pooldeposit", pcCoin coin)]
EMax n -> [("emax", ppEpochInterval n)]
NOpt natural -> [("NOpt", ppNatural natural)]
NOpt n -> [("NOpt", ppWord16 n)]
A0 i -> [("A0", viaShow i)]
Rho u -> [("Rho", ppUnitInterval u)]
Tau u -> [("Tau", ppUnitInterval u)]
Expand Down

0 comments on commit 3e9e752

Please sign in to comment.