From 062ccaa7fe40fd7f2f27fa5f63601c8b6069bc9e Mon Sep 17 00:00:00 2001 From: Jared Corduan Date: Fri, 8 Oct 2021 14:25:43 -0400 Subject: [PATCH] move BlocksMade to core (BaseTypes) --- eras/alonzo/impl/src/Cardano/Ledger/Alonzo.hs | 4 +-- .../impl/src/Cardano/Ledger/Allegra.hs | 3 ++- .../impl/src/Cardano/Ledger/Mary.hs | 3 ++- .../shelley/impl/src/Cardano/Ledger/Pretty.hs | 4 +-- .../Ledger/Shelley/API/ByronTranslation.hs | 1 + .../src/Cardano/Ledger/Shelley/API/Genesis.hs | 3 ++- .../src/Cardano/Ledger/Shelley/API/Wallet.hs | 11 ++++++-- .../src/Cardano/Ledger/Shelley/BlockChain.hs | 2 +- .../Cardano/Ledger/Shelley/EpochBoundary.hs | 25 ++++++------------- .../src/Cardano/Ledger/Shelley/LedgerState.hs | 4 +-- .../Ledger/Shelley/RewardProvenance.hs | 2 +- .../src/Cardano/Ledger/Shelley/Rules/Bbody.hs | 3 +-- .../src/Cardano/Ledger/Shelley/Rules/Rupd.hs | 4 +-- .../test-suite/bench/BenchValidation.hs | 6 ++--- .../Cardano/Ledger/Shelley/Rules/Chain.hs | 5 ++-- .../Serialisation/EraIndepGenerators.hs | 2 +- .../Ledger/Shelley/Examples/Combinators.hs | 11 ++++++-- .../Ledger/Shelley/Examples/PoolLifetime.hs | 19 +++++++------- .../Ledger/Shelley/Examples/TwoPools.hs | 7 +++--- .../Test/Cardano/Ledger/Shelley/Rewards.hs | 15 ++++++----- .../Shelley/Serialisation/Golden/Encoding.hs | 6 ++--- .../src/Cardano/Ledger/BaseTypes.hs | 11 ++++++++ .../src/Cardano/Ledger/Example.hs | 3 ++- .../Ledger/Examples/TwoPhaseValidation.hs | 3 +-- 24 files changed, 88 insertions(+), 69 deletions(-) diff --git a/eras/alonzo/impl/src/Cardano/Ledger/Alonzo.hs b/eras/alonzo/impl/src/Cardano/Ledger/Alonzo.hs index 7360f9a8ac0..9982789d67f 100644 --- a/eras/alonzo/impl/src/Cardano/Ledger/Alonzo.hs +++ b/eras/alonzo/impl/src/Cardano/Ledger/Alonzo.hs @@ -43,7 +43,7 @@ import Cardano.Ledger.Alonzo.TxInfo (validScript) import qualified Cardano.Ledger.Alonzo.TxSeq as Alonzo (TxSeq (..), hashTxSeq) import Cardano.Ledger.Alonzo.TxWitness (TxWitness (..)) import Cardano.Ledger.AuxiliaryData (AuxiliaryDataHash (..), ValidateAuxiliaryData (..)) -import qualified Cardano.Ledger.BaseTypes as Shelley +import Cardano.Ledger.BaseTypes (BlocksMade (..)) import Cardano.Ledger.Coin import qualified Cardano.Ledger.Core as Core import qualified Cardano.Ledger.Crypto as CC @@ -178,7 +178,7 @@ instance pp = sgProtocolParams sg instance (CC.Crypto c) => UsesTxOut (AlonzoEra c) where - makeTxOut _proxy addr val = TxOut addr val Shelley.SNothing + makeTxOut _proxy addr val = TxOut addr val SNothing instance CC.Crypto c => API.CLI (AlonzoEra c) where evaluateMinFee = minfee diff --git a/eras/shelley-ma/impl/src/Cardano/Ledger/Allegra.hs b/eras/shelley-ma/impl/src/Cardano/Ledger/Allegra.hs index 8ba3d4c77be..c662666f499 100644 --- a/eras/shelley-ma/impl/src/Cardano/Ledger/Allegra.hs +++ b/eras/shelley-ma/impl/src/Cardano/Ledger/Allegra.hs @@ -19,11 +19,12 @@ module Cardano.Ledger.Allegra ) where +import Cardano.Ledger.BaseTypes (BlocksMade (..)) import Cardano.Ledger.Crypto (Crypto) import qualified Cardano.Ledger.Crypto as CC import qualified Cardano.Ledger.Era as E (Era (Crypto)) import Cardano.Ledger.Shelley.API hiding (PParams, Tx, TxBody, TxOut, WitnessSet) -import Cardano.Ledger.Shelley.EpochBoundary (BlocksMade (..), emptySnapShots) +import Cardano.Ledger.Shelley.EpochBoundary (emptySnapShots) import Cardano.Ledger.Shelley.LedgerState (minfee) import qualified Cardano.Ledger.Shelley.PParams as Shelley (PParamsUpdate) import Cardano.Ledger.Shelley.Tx (WitnessSet) diff --git a/eras/shelley-ma/impl/src/Cardano/Ledger/Mary.hs b/eras/shelley-ma/impl/src/Cardano/Ledger/Mary.hs index 977c363330e..f94f022f9e3 100644 --- a/eras/shelley-ma/impl/src/Cardano/Ledger/Mary.hs +++ b/eras/shelley-ma/impl/src/Cardano/Ledger/Mary.hs @@ -18,12 +18,13 @@ module Cardano.Ledger.Mary ) where +import Cardano.Ledger.BaseTypes (BlocksMade (..)) import Cardano.Ledger.Crypto (Crypto) import qualified Cardano.Ledger.Crypto as CC import qualified Cardano.Ledger.Era as E (Era (Crypto)) import qualified Cardano.Ledger.Mary.Value as V (Value) import Cardano.Ledger.Shelley.API hiding (TxBody) -import Cardano.Ledger.Shelley.EpochBoundary (BlocksMade (..), emptySnapShots) +import Cardano.Ledger.Shelley.EpochBoundary (emptySnapShots) import Cardano.Ledger.Shelley.LedgerState (minfee) import qualified Cardano.Ledger.Shelley.PParams as Shelley (PParamsUpdate) import Cardano.Ledger.ShelleyMA diff --git a/eras/shelley/impl/src/Cardano/Ledger/Pretty.hs b/eras/shelley/impl/src/Cardano/Ledger/Pretty.hs index 5fe762a057e..b3e7194d4c7 100644 --- a/eras/shelley/impl/src/Cardano/Ledger/Pretty.hs +++ b/eras/shelley/impl/src/Cardano/Ledger/Pretty.hs @@ -28,6 +28,7 @@ import Cardano.Ledger.Address import Cardano.Ledger.AuxiliaryData (AuxiliaryDataHash (..)) import Cardano.Ledger.BaseTypes ( ActiveSlotCoeff, + BlocksMade (..), BoundedRational (..), DnsName, FixedPoint, @@ -71,8 +72,7 @@ import Cardano.Ledger.Shelley.Address.Bootstrap (BootstrapWitness (..), ChainCod import Cardano.Ledger.Shelley.BlockChain (Block (..)) import Cardano.Ledger.Shelley.CompactAddr (CompactAddr (..), decompactAddr) import Cardano.Ledger.Shelley.EpochBoundary - ( BlocksMade (..), - SnapShot (..), + ( SnapShot (..), SnapShots (..), Stake (..), ) diff --git a/eras/shelley/impl/src/Cardano/Ledger/Shelley/API/ByronTranslation.hs b/eras/shelley/impl/src/Cardano/Ledger/Shelley/API/ByronTranslation.hs index b2f1663411f..9f4c3a65ba7 100644 --- a/eras/shelley/impl/src/Cardano/Ledger/Shelley/API/ByronTranslation.hs +++ b/eras/shelley/impl/src/Cardano/Ledger/Shelley/API/ByronTranslation.hs @@ -18,6 +18,7 @@ import qualified Cardano.Chain.Common as Byron import qualified Cardano.Chain.UTxO as Byron import qualified Cardano.Crypto.Hash as Crypto import qualified Cardano.Crypto.Hashing as Hashing +import Cardano.Ledger.BaseTypes (BlocksMade (..)) import Cardano.Ledger.Chain (pparamsToChainChecksPParams) import Cardano.Ledger.Coin (CompactForm (CompactCoin)) import qualified Cardano.Ledger.Crypto as CC diff --git a/eras/shelley/impl/src/Cardano/Ledger/Shelley/API/Genesis.hs b/eras/shelley/impl/src/Cardano/Ledger/Shelley/API/Genesis.hs index 8cf132a8b3c..3b5a6202010 100644 --- a/eras/shelley/impl/src/Cardano/Ledger/Shelley/API/Genesis.hs +++ b/eras/shelley/impl/src/Cardano/Ledger/Shelley/API/Genesis.hs @@ -5,6 +5,7 @@ module Cardano.Ledger.Shelley.API.Genesis where +import Cardano.Ledger.BaseTypes (BlocksMade (..)) import Cardano.Ledger.Core (EraRule) import Cardano.Ledger.Crypto (Crypto) import Cardano.Ledger.Shelley (ShelleyEra) @@ -25,7 +26,7 @@ import Cardano.Ledger.Shelley.API.Types genesisUTxO, word64ToCoin, ) -import Cardano.Ledger.Shelley.EpochBoundary (BlocksMade (..), emptySnapShots) +import Cardano.Ledger.Shelley.EpochBoundary (emptySnapShots) import Cardano.Ledger.Val (Val ((<->))) import Control.State.Transition (STS (State)) import Data.Default.Class (Default, def) diff --git a/eras/shelley/impl/src/Cardano/Ledger/Shelley/API/Wallet.hs b/eras/shelley/impl/src/Cardano/Ledger/Shelley/API/Wallet.hs index c8f054c40de..569e4dd0580 100644 --- a/eras/shelley/impl/src/Cardano/Ledger/Shelley/API/Wallet.hs +++ b/eras/shelley/impl/src/Cardano/Ledger/Shelley/API/Wallet.hs @@ -55,7 +55,14 @@ import Cardano.Crypto.DSIGN.Class (decodeSignedDSIGN, sizeSigDSIGN, sizeVerKeyDS import qualified Cardano.Crypto.VRF as VRF import Cardano.Ledger.Address (Addr (..)) import Cardano.Ledger.BHeaderView (isOverlaySlot) -import Cardano.Ledger.BaseTypes (Globals (..), NonNegativeInterval, Seed, UnitInterval, epochInfo) +import Cardano.Ledger.BaseTypes + ( BlocksMade, + Globals (..), + NonNegativeInterval, + Seed, + UnitInterval, + epochInfo, + ) import Cardano.Ledger.Coin (Coin (..)) import qualified Cardano.Ledger.Core as Core import Cardano.Ledger.Credential (Credential (..)) @@ -489,7 +496,7 @@ getRewardProvenance globals newepochstate = epochstate = nesEs newepochstate maxsupply :: Coin maxsupply = Coin (fromIntegral (maxLovelaceSupply globals)) - blocksmade :: EB.BlocksMade (Crypto era) + blocksmade :: BlocksMade (Crypto era) blocksmade = nesBprev newepochstate epochnumber = nesEL newepochstate slotsPerEpoch :: EpochSize diff --git a/eras/shelley/impl/src/Cardano/Ledger/Shelley/BlockChain.hs b/eras/shelley/impl/src/Cardano/Ledger/Shelley/BlockChain.hs index c9fd20259ea..b709970b180 100644 --- a/eras/shelley/impl/src/Cardano/Ledger/Shelley/BlockChain.hs +++ b/eras/shelley/impl/src/Cardano/Ledger/Shelley/BlockChain.hs @@ -72,6 +72,7 @@ import qualified Cardano.Crypto.Hash.Class as Hash import qualified Cardano.Crypto.VRF as VRF import Cardano.Ledger.BaseTypes ( ActiveSlotCoeff, + BlocksMade (..), Nonce (..), Seed (..), StrictMaybe (..), @@ -93,7 +94,6 @@ import Cardano.Ledger.Serialization encodeFoldableEncoder, encodeFoldableMapEncoder, ) -import Cardano.Ledger.Shelley.EpochBoundary (BlocksMade (..)) import Cardano.Ledger.Shelley.Tx (Tx, segwitTx) import Cardano.Ledger.Slot (SlotNo (..)) import Cardano.Ledger.TxIn (TxIn (..), txid) diff --git a/eras/shelley/impl/src/Cardano/Ledger/Shelley/EpochBoundary.hs b/eras/shelley/impl/src/Cardano/Ledger/Shelley/EpochBoundary.hs index 574e2aaf899..a1c55d41feb 100644 --- a/eras/shelley/impl/src/Cardano/Ledger/Shelley/EpochBoundary.hs +++ b/eras/shelley/impl/src/Cardano/Ledger/Shelley/EpochBoundary.hs @@ -19,7 +19,6 @@ -- This modules implements the necessary functions for the changes that can happen at epoch boundaries. module Cardano.Ledger.Shelley.EpochBoundary ( Stake (..), - BlocksMade (..), SnapShot (..), SnapShots (..), emptySnapShot, @@ -29,12 +28,16 @@ module Cardano.Ledger.Shelley.EpochBoundary obligation, maxPool, maxPool', + + -- * Deprecated + BlocksMade, ) where import Cardano.Binary (FromCBOR (..), ToCBOR (..), encodeListLen) import Cardano.Ledger.Address (Addr (..)) import Cardano.Ledger.BaseTypes (BoundedRational (..), NonNegativeInterval) +import qualified Cardano.Ledger.BaseTypes as Core (BlocksMade) import Cardano.Ledger.Coin ( Coin (..), coinToRational, @@ -52,7 +55,6 @@ import Cardano.Ledger.Val ((<+>), (<×>)) import qualified Cardano.Ledger.Val as Val import Control.DeepSeq (NFData) import Control.SetAlgebra (dom, eval, setSingleton, (▷), (◁)) -import Data.Aeson import Data.Default.Class (Default, def) import Data.Map.Strict (Map) import qualified Data.Map.Strict as Map @@ -61,22 +63,6 @@ import GHC.Generics (Generic) import GHC.Records (HasField, getField) import NoThunks.Class (NoThunks (..)) import Numeric.Natural (Natural) -import Quiet - --- | Blocks made -newtype BlocksMade crypto = BlocksMade - { unBlocksMade :: Map (KeyHash 'StakePool crypto) Natural - } - deriving (Eq, NoThunks, Generic, NFData) - deriving (Show) via Quiet (BlocksMade crypto) - -deriving instance (CC.Crypto crypto) => ToJSON (BlocksMade crypto) - -deriving instance (CC.Crypto crypto) => FromJSON (BlocksMade crypto) - -deriving instance CC.Crypto crypto => ToCBOR (BlocksMade crypto) - -deriving instance CC.Crypto crypto => FromCBOR (BlocksMade crypto) -- | Type of stake as map from hash key to coins associated. newtype Stake crypto = Stake @@ -252,3 +238,6 @@ emptySnapShot = SnapShot (Stake Map.empty) Map.empty Map.empty emptySnapShots :: SnapShots crypto emptySnapShots = SnapShots emptySnapShot emptySnapShot emptySnapShot (Coin 0) + +{-# DEPRECATED BlocksMade "Import from Cardano.Ledger.BaseTypes instead" #-} +type BlocksMade = Core.BlocksMade diff --git a/eras/shelley/impl/src/Cardano/Ledger/Shelley/LedgerState.hs b/eras/shelley/impl/src/Cardano/Ledger/Shelley/LedgerState.hs index 51e2505785c..f061b672bd2 100644 --- a/eras/shelley/impl/src/Cardano/Ledger/Shelley/LedgerState.hs +++ b/eras/shelley/impl/src/Cardano/Ledger/Shelley/LedgerState.hs @@ -103,6 +103,7 @@ import Cardano.Binary import Cardano.Ledger.Address (Addr (..), bootstrapKeyHash, isBootstrapRedeemer) import Cardano.Ledger.BaseTypes ( ActiveSlotCoeff, + BlocksMade (..), BoundedRational (..), NonNegativeInterval, ShelleyBase, @@ -152,8 +153,7 @@ import Cardano.Ledger.Shelley.Delegation.Certificates requiresVKeyWitness, ) import Cardano.Ledger.Shelley.EpochBoundary - ( BlocksMade (..), - SnapShot (..), + ( SnapShot (..), SnapShots (..), Stake (..), aggregateUtxoCoinByCredential, diff --git a/eras/shelley/impl/src/Cardano/Ledger/Shelley/RewardProvenance.hs b/eras/shelley/impl/src/Cardano/Ledger/Shelley/RewardProvenance.hs index 8af90da8609..63a21e4a5d8 100644 --- a/eras/shelley/impl/src/Cardano/Ledger/Shelley/RewardProvenance.hs +++ b/eras/shelley/impl/src/Cardano/Ledger/Shelley/RewardProvenance.hs @@ -19,12 +19,12 @@ import Cardano.Binary decodeDouble, encodeDouble, ) +import Cardano.Ledger.BaseTypes (BlocksMade (..)) import Cardano.Ledger.Coin (Coin (..)) import Cardano.Ledger.Credential (Credential (..)) import qualified Cardano.Ledger.Crypto as CC import Cardano.Ledger.Keys (KeyHash (..), KeyRole (..)) import Cardano.Ledger.SafeHash (SafeHash, unsafeMakeSafeHash) -import Cardano.Ledger.Shelley.EpochBoundary (BlocksMade (..)) import Cardano.Ledger.Shelley.Orphans () import Cardano.Ledger.Shelley.TxBody (PoolParams (..), RewardAcnt (..)) import Control.DeepSeq (NFData) diff --git a/eras/shelley/impl/src/Cardano/Ledger/Shelley/Rules/Bbody.hs b/eras/shelley/impl/src/Cardano/Ledger/Shelley/Rules/Bbody.hs index 8d77716845a..c704349b537 100644 --- a/eras/shelley/impl/src/Cardano/Ledger/Shelley/Rules/Bbody.hs +++ b/eras/shelley/impl/src/Cardano/Ledger/Shelley/Rules/Bbody.hs @@ -22,7 +22,7 @@ module Cardano.Ledger.Shelley.Rules.Bbody where import Cardano.Ledger.BHeaderView (BHeaderView (..), isOverlaySlot) -import Cardano.Ledger.BaseTypes (ShelleyBase, UnitInterval, epochInfo) +import Cardano.Ledger.BaseTypes (BlocksMade, ShelleyBase, UnitInterval, epochInfo) import qualified Cardano.Ledger.Core as Core import Cardano.Ledger.Era (Era (Crypto), SupportsSegWit (fromTxSeq, hashTxSeq)) import qualified Cardano.Ledger.Era as Era @@ -31,7 +31,6 @@ import Cardano.Ledger.Keys (DSignable, Hash, coerceKeyRole) import Cardano.Ledger.Serialization (ToCBORGroup) import Cardano.Ledger.Shelley.BlockChain (Block (..), bBodySize, incrBlocks) import Cardano.Ledger.Shelley.Constraints (UsesAuxiliary, UsesTxBody) -import Cardano.Ledger.Shelley.EpochBoundary (BlocksMade) import Cardano.Ledger.Shelley.LedgerState ( AccountState, LedgerState, diff --git a/eras/shelley/impl/src/Cardano/Ledger/Shelley/Rules/Rupd.hs b/eras/shelley/impl/src/Cardano/Ledger/Shelley/Rules/Rupd.hs index be6e2659fef..7fbeff70cd5 100644 --- a/eras/shelley/impl/src/Cardano/Ledger/Shelley/Rules/Rupd.hs +++ b/eras/shelley/impl/src/Cardano/Ledger/Shelley/Rules/Rupd.hs @@ -23,7 +23,8 @@ module Cardano.Ledger.Shelley.Rules.Rupd where import Cardano.Ledger.BaseTypes - ( NonNegativeInterval, + ( BlocksMade, + NonNegativeInterval, ShelleyBase, StrictMaybe (..), UnitInterval, @@ -36,7 +37,6 @@ import Cardano.Ledger.BaseTypes import Cardano.Ledger.Coin (Coin (..)) import qualified Cardano.Ledger.Core as Core import Cardano.Ledger.Era (Crypto, Era) -import Cardano.Ledger.Shelley.EpochBoundary (BlocksMade) import Cardano.Ledger.Shelley.LedgerState ( EpochState, PulsingRewUpdate (..), diff --git a/eras/shelley/test-suite/bench/BenchValidation.hs b/eras/shelley/test-suite/bench/BenchValidation.hs index cca6bf3b33d..7c1e0688b59 100644 --- a/eras/shelley/test-suite/bench/BenchValidation.hs +++ b/eras/shelley/test-suite/bench/BenchValidation.hs @@ -27,7 +27,8 @@ module BenchValidation ) where -import Cardano.Ledger.BaseTypes (Globals (..)) +import Cardano.Ledger.BaseTypes (Globals (..), unBlocksMade) +import Cardano.Ledger.Block (Block (..)) import qualified Cardano.Ledger.Core as Core import qualified Cardano.Ledger.Crypto as CryptoClass import Cardano.Ledger.Era (Era (..)) @@ -41,9 +42,8 @@ import Cardano.Ledger.Shelley.API.Protocol updateChainDepState, ) import Cardano.Ledger.Shelley.Bench.Gen (genBlock, genChainState) -import Cardano.Ledger.Shelley.BlockChain (Block (..), slotToNonce) +import Cardano.Ledger.Shelley.BlockChain (slotToNonce) import Cardano.Ledger.Shelley.Constraints (TransValue) -import Cardano.Ledger.Shelley.EpochBoundary (unBlocksMade) import Cardano.Ledger.Shelley.LedgerState ( NewEpochState, nesBcur, diff --git a/eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/Rules/Chain.hs b/eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/Rules/Chain.hs index f7858de77fa..492db068556 100644 --- a/eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/Rules/Chain.hs +++ b/eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/Rules/Chain.hs @@ -28,7 +28,8 @@ where import Cardano.Ledger.BHeaderView (BHeaderView) import Cardano.Ledger.BaseTypes - ( Globals (..), + ( BlocksMade (..), + Globals (..), Nonce (..), ShelleyBase, StrictMaybe (..), @@ -59,7 +60,7 @@ import Cardano.Ledger.Shelley.API.Wallet ) import Cardano.Ledger.Shelley.BlockChain (Block (..)) import Cardano.Ledger.Shelley.Constraints (UsesValue) -import Cardano.Ledger.Shelley.EpochBoundary (BlocksMade (..), emptySnapShots) +import Cardano.Ledger.Shelley.EpochBoundary (emptySnapShots) import Cardano.Ledger.Shelley.LedgerState ( AccountState (..), DPState (..), diff --git a/eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/Serialisation/EraIndepGenerators.hs b/eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/Serialisation/EraIndepGenerators.hs index 82433c43555..4d434b3ea43 100644 --- a/eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/Serialisation/EraIndepGenerators.hs +++ b/eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/Serialisation/EraIndepGenerators.hs @@ -42,6 +42,7 @@ import qualified Cardano.Crypto.Hash as Hash import Cardano.Ledger.AuxiliaryData (AuxiliaryDataHash (..)) import Cardano.Ledger.BaseTypes ( ActiveSlotCoeff, + BlocksMade (..), DnsName, NonNegativeInterval, PositiveInterval, @@ -69,7 +70,6 @@ import Cardano.Ledger.Shelley.Constraints UsesTxOut, UsesValue, ) -import Cardano.Ledger.Shelley.EpochBoundary (BlocksMade (..)) import Cardano.Ledger.Shelley.LedgerState (FutureGenDeleg) import qualified Cardano.Ledger.Shelley.Metadata as MD import Cardano.Ledger.Shelley.RewardProvenance diff --git a/eras/shelley/test-suite/test/Test/Cardano/Ledger/Shelley/Examples/Combinators.hs b/eras/shelley/test-suite/test/Test/Cardano/Ledger/Shelley/Examples/Combinators.hs index 4c066b429fd..ef193317f62 100644 --- a/eras/shelley/test-suite/test/Test/Cardano/Ledger/Shelley/Examples/Combinators.hs +++ b/eras/shelley/test-suite/test/Test/Cardano/Ledger/Shelley/Examples/Combinators.hs @@ -46,7 +46,14 @@ module Test.Cardano.Ledger.Shelley.Examples.Combinators ) where -import Cardano.Ledger.BaseTypes (NonNegativeInterval, Nonce (..), StrictMaybe (..), UnitInterval, (⭒)) +import Cardano.Ledger.BaseTypes + ( BlocksMade (..), + NonNegativeInterval, + Nonce (..), + StrictMaybe (..), + UnitInterval, + (⭒), + ) import Cardano.Ledger.Coin (Coin (..)) import qualified Cardano.Ledger.Core as Core import Cardano.Ledger.Credential @@ -65,7 +72,7 @@ import Cardano.Ledger.Shelley.BlockChain bheader, ) import Cardano.Ledger.Shelley.Constraints (UsesTxBody, UsesTxOut) -import Cardano.Ledger.Shelley.EpochBoundary (BlocksMade (..), SnapShot, SnapShots (..)) +import Cardano.Ledger.Shelley.EpochBoundary (SnapShot, SnapShots (..)) import Cardano.Ledger.Shelley.LedgerState ( AccountState (..), DPState (..), diff --git a/eras/shelley/test-suite/test/Test/Cardano/Ledger/Shelley/Examples/PoolLifetime.hs b/eras/shelley/test-suite/test/Test/Cardano/Ledger/Shelley/Examples/PoolLifetime.hs index 1ea9338945a..54f2575e500 100644 --- a/eras/shelley/test-suite/test/Test/Cardano/Ledger/Shelley/Examples/PoolLifetime.hs +++ b/eras/shelley/test-suite/test/Test/Cardano/Ledger/Shelley/Examples/PoolLifetime.hs @@ -18,7 +18,8 @@ module Test.Cardano.Ledger.Shelley.Examples.PoolLifetime where import Cardano.Ledger.BaseTypes - ( BoundedRational (..), + ( BlocksMade (..), + BoundedRational (..), Globals (..), Network (..), Nonce, @@ -331,7 +332,7 @@ blockEx2 = makePulser :: forall era. (C.UsesPP era) => - EB.BlocksMade (Crypto era) -> + BlocksMade (Crypto era) -> ChainState era -> PulsingRewUpdate (Crypto era) makePulser bs cs = p @@ -350,10 +351,10 @@ makePulser' :: (C.UsesPP era) => ChainState era -> PulsingRewUpdate (Crypto era) -makePulser' = makePulser (EB.BlocksMade mempty) +makePulser' = makePulser (BlocksMade mempty) pulserEx2 :: forall c. (ExMock (Crypto (ShelleyEra c))) => PulsingRewUpdate c -pulserEx2 = makePulser (EB.BlocksMade mempty) expectedStEx1 +pulserEx2 = makePulser (BlocksMade mempty) expectedStEx1 expectedStEx2 :: forall c. @@ -485,7 +486,7 @@ blockEx4 = (mkOCert (coreNodeKeysBySchedule @(ShelleyEra c) ppEx 190) 0 (KESPeriod 0)) pulserEx4 :: forall c. (ExMock c) => PulsingRewUpdate c -pulserEx4 = makePulser (EB.BlocksMade mempty) expectedStEx3 +pulserEx4 = makePulser (BlocksMade mempty) expectedStEx3 rewardUpdateEx4 :: forall c. RewardUpdate c rewardUpdateEx4 = @@ -619,7 +620,7 @@ rewardUpdateEx6 = } pulserEx6 :: forall c. (ExMock c) => PulsingRewUpdate c -pulserEx6 = makePulser (EB.BlocksMade mempty) expectedStEx5 +pulserEx6 = makePulser (BlocksMade mempty) expectedStEx5 expectedStEx6 :: forall c. (ExMock (Crypto (ShelleyEra c))) => ChainState (ShelleyEra c) expectedStEx6 = @@ -734,7 +735,7 @@ nonMyopicEx8 = rewardPot8 pulserEx8 :: forall c. (ExMock c) => PulsingRewUpdate c -pulserEx8 = makePulser (EB.BlocksMade $ Map.singleton (hk Cast.alicePoolKeys) 1) expectedStEx7 +pulserEx8 = makePulser (BlocksMade $ Map.singleton (hk Cast.alicePoolKeys) 1) expectedStEx7 rewardUpdateEx8 :: forall c. Cr.Crypto c => RewardUpdate c rewardUpdateEx8 = @@ -780,7 +781,7 @@ rewardInfoTest = rewardInfoEx8 @?= expected RP.RewardProvenance { RP.spe = unEpochSize . runShelleyBase $ epochInfoSize (epochInfo testGlobals) (EpochNo 0), RP.blocks = - EB.BlocksMade $ + BlocksMade $ Map.singleton (_poolId $ Cast.alicePoolParams) 1, RP.maxLL = supply, RP.deltaR1 = rpot, @@ -1026,7 +1027,7 @@ nonMyopicEx11 = (Coin 0) pulserEx11 :: forall c. (ExMock c) => PulsingRewUpdate c -pulserEx11 = makePulser (EB.BlocksMade mempty) expectedStEx10 +pulserEx11 = makePulser (BlocksMade mempty) expectedStEx10 rewardUpdateEx11 :: forall c. Cr.Crypto c => RewardUpdate c rewardUpdateEx11 = diff --git a/eras/shelley/test-suite/test/Test/Cardano/Ledger/Shelley/Examples/TwoPools.hs b/eras/shelley/test-suite/test/Test/Cardano/Ledger/Shelley/Examples/TwoPools.hs index 0cba3ca5db2..b2db6e21d0c 100644 --- a/eras/shelley/test-suite/test/Test/Cardano/Ledger/Shelley/Examples/TwoPools.hs +++ b/eras/shelley/test-suite/test/Test/Cardano/Ledger/Shelley/Examples/TwoPools.hs @@ -20,7 +20,8 @@ module Test.Cardano.Ledger.Shelley.Examples.TwoPools where import Cardano.Ledger.BaseTypes - ( BoundedRational (..), + ( BlocksMade (..), + BoundedRational (..), Globals (..), Network (..), Nonce, @@ -40,7 +41,7 @@ import qualified Cardano.Ledger.Crypto as CryptoClass import Cardano.Ledger.Era (Crypto (..)) import Cardano.Ledger.Keys (KeyRole (..), asWitness, coerceKeyRole) import Cardano.Ledger.SafeHash (hashAnnotated) -import Cardano.Ledger.Shelley.BlockChain (Block, bheader) +import Cardano.Ledger.Block (Block, bheader) import qualified Cardano.Ledger.Shelley.EpochBoundary as EB import Cardano.Ledger.Shelley.LedgerState ( PulsingRewUpdate (..), @@ -773,7 +774,7 @@ pulserEx9 :: PulsingRewUpdate (Crypto era) pulserEx9 pp = makePulser - ( EB.BlocksMade $ + ( BlocksMade $ Map.fromList [(hk Cast.alicePoolKeys, 2), (hk Cast.bobPoolKeys, 1)] ) diff --git a/eras/shelley/test-suite/test/Test/Cardano/Ledger/Shelley/Rewards.hs b/eras/shelley/test-suite/test/Test/Cardano/Ledger/Shelley/Rewards.hs index 901d6d4568a..d8113c105d5 100644 --- a/eras/shelley/test-suite/test/Test/Cardano/Ledger/Shelley/Rewards.hs +++ b/eras/shelley/test-suite/test/Test/Cardano/Ledger/Shelley/Rewards.hs @@ -21,6 +21,7 @@ import Cardano.Crypto.Seed (mkSeedFromBytes) import qualified Cardano.Crypto.VRF as Crypto import Cardano.Ledger.BaseTypes ( ActiveSlotCoeff, + BlocksMade (..), BoundedRational (..), Globals (..), Network (..), @@ -50,14 +51,12 @@ import Cardano.Ledger.Keys import Cardano.Ledger.Pretty (PrettyA (..)) import Cardano.Ledger.Shelley.API.Wallet (getRewardProvenance) import Cardano.Ledger.Shelley.EpochBoundary - ( BlocksMade (..), - SnapShot (..), + ( SnapShot (..), SnapShots (..), Stake (..), maxPool, poolStake, ) -import qualified Cardano.Ledger.Shelley.EpochBoundary as EB import qualified Cardano.Ledger.Shelley.HardForks as HardForks import Cardano.Ledger.Shelley.LedgerState ( AccountState (..), @@ -412,7 +411,7 @@ justRewardInfo globals newepochstate = epochstate = nesEs newepochstate maxsupply :: Coin maxsupply = Coin (fromIntegral (maxLovelaceSupply globals)) - blocksmade :: EB.BlocksMade (Crypto era) + blocksmade :: BlocksMade (Crypto era) blocksmade = nesBprev newepochstate epochnumber = nesEL newepochstate slotsPerEpoch :: EpochSize @@ -446,7 +445,7 @@ nothingInNothingOut newepochstate = epochstate = nesEs newepochstate maxsupply :: Coin maxsupply = Coin (fromIntegral (maxLovelaceSupply globals)) - blocksmade :: EB.BlocksMade (Crypto era) + blocksmade :: BlocksMade (Crypto era) blocksmade = nesBprev newepochstate epochnumber = nesEL newepochstate slotsPerEpoch :: EpochSize @@ -469,7 +468,7 @@ justInJustOut newepochstate = epochstate = nesEs newepochstate maxsupply :: Coin maxsupply = Coin (fromIntegral (maxLovelaceSupply globals)) - blocksmade :: EB.BlocksMade (Crypto era) + blocksmade :: BlocksMade (Crypto era) blocksmade = nesBprev newepochstate epochnumber = nesEL newepochstate slotsPerEpoch :: EpochSize @@ -695,7 +694,7 @@ oldEqualsNew newepochstate = epochstate = nesEs newepochstate maxsupply :: Coin maxsupply = Coin (fromIntegral (maxLovelaceSupply globals)) - blocksmade :: EB.BlocksMade (Crypto era) + blocksmade :: BlocksMade (Crypto era) blocksmade = nesBprev newepochstate epochnumber = nesEL newepochstate slotsPerEpoch :: EpochSize @@ -716,7 +715,7 @@ oldEqualsNewOn newepochstate = old === new epochstate = nesEs newepochstate maxsupply :: Coin maxsupply = Coin (fromIntegral (maxLovelaceSupply globals)) - blocksmade :: EB.BlocksMade (Crypto era) + blocksmade :: BlocksMade (Crypto era) blocksmade = nesBprev newepochstate epochnumber = nesEL newepochstate slotsPerEpoch :: EpochSize diff --git a/eras/shelley/test-suite/test/Test/Cardano/Ledger/Shelley/Serialisation/Golden/Encoding.hs b/eras/shelley/test-suite/test/Test/Cardano/Ledger/Shelley/Serialisation/Golden/Encoding.hs index 9e242e4faa7..d398812292d 100644 --- a/eras/shelley/test-suite/test/Test/Cardano/Ledger/Shelley/Serialisation/Golden/Encoding.hs +++ b/eras/shelley/test-suite/test/Test/Cardano/Ledger/Shelley/Serialisation/Golden/Encoding.hs @@ -29,7 +29,8 @@ import Cardano.Ledger.Address ) import Cardano.Ledger.AuxiliaryData (hashAuxiliaryData) import Cardano.Ledger.BaseTypes - ( BoundedRational (..), + ( BlocksMade (..), + BoundedRational (..), Network (..), Nonce (..), StrictMaybe (..), @@ -92,8 +93,7 @@ import Cardano.Ledger.Shelley.Delegation.Certificates pattern RetirePool, ) import Cardano.Ledger.Shelley.EpochBoundary - ( BlocksMade (..), - SnapShot (..), + ( SnapShot (..), SnapShots (..), Stake (..), ) diff --git a/libs/cardano-ledger-core/src/Cardano/Ledger/BaseTypes.hs b/libs/cardano-ledger-core/src/Cardano/Ledger/BaseTypes.hs index 006a9ac94fb..2a97462682a 100644 --- a/libs/cardano-ledger-core/src/Cardano/Ledger/BaseTypes.hs +++ b/libs/cardano-ledger-core/src/Cardano/Ledger/BaseTypes.hs @@ -2,6 +2,7 @@ {-# LANGUAGE DeriveAnyClass #-} {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE DerivingVia #-} +{-# LANGUAGE DerivingStrategies #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-} @@ -45,6 +46,7 @@ module Cardano.Ledger.BaseTypes activeSlotVal, activeSlotLog, module Data.Maybe.Strict, + BlocksMade (..), -- * STS Base Globals (..), @@ -64,6 +66,7 @@ import Cardano.Binary import Cardano.Crypto.Hash import Cardano.Crypto.Util (SignableRepresentation (..)) import qualified Cardano.Crypto.VRF as VRF +import Cardano.Ledger.Keys (KeyHash, KeyRole (..)) import Cardano.Ledger.NonIntegral (ln') import Cardano.Ledger.Serialization (decodeRecordSum, ratioFromCBOR, ratioToCBOR) import Cardano.Prelude (NFData, cborError) @@ -589,3 +592,11 @@ instance FromCBOR Network where word8ToNetwork <$> fromCBOR >>= \case Nothing -> cborError $ DecoderErrorCustom "Network" "Unknown network id" Just n -> pure n + +-- | Blocks made +newtype BlocksMade crypto = BlocksMade + { unBlocksMade :: Map (KeyHash 'StakePool crypto) Natural + } + deriving (Eq, Generic) + deriving (Show) via Quiet (BlocksMade crypto) + deriving newtype (NoThunks, NFData, ToJSON, FromJSON, ToCBOR, FromCBOR) diff --git a/libs/cardano-ledger-example-shelley/src/Cardano/Ledger/Example.hs b/libs/cardano-ledger-example-shelley/src/Cardano/Ledger/Example.hs index 981d4cfdad0..308d1d77a3f 100644 --- a/libs/cardano-ledger-example-shelley/src/Cardano/Ledger/Example.hs +++ b/libs/cardano-ledger-example-shelley/src/Cardano/Ledger/Example.hs @@ -16,6 +16,7 @@ import Cardano.Ledger.AuxiliaryData ( AuxiliaryDataHash (..), ValidateAuxiliaryData (..), ) +import Cardano.Ledger.BaseTypes (BlocksMade (..)) import Cardano.Ledger.Coin (Coin) import qualified Cardano.Ledger.Core as Core import qualified Cardano.Ledger.Crypto as CryptoClass @@ -52,7 +53,7 @@ import qualified Cardano.Ledger.Shelley.BlockChain as Shelley txSeqTxns, ) import Cardano.Ledger.Shelley.Constraints (UsesPParams (..), UsesTxBody, UsesTxOut (..), UsesValue) -import Cardano.Ledger.Shelley.EpochBoundary (BlocksMade (..), emptySnapShots) +import Cardano.Ledger.Shelley.EpochBoundary (emptySnapShots) import Cardano.Ledger.Shelley.Metadata (Metadata (Metadata), validMetadatum) import Cardano.Ledger.Shelley.PParams () import Cardano.Ledger.Shelley.PParams as Shelley diff --git a/libs/cardano-ledger-test/src/Test/Cardano/Ledger/Examples/TwoPhaseValidation.hs b/libs/cardano-ledger-test/src/Test/Cardano/Ledger/Examples/TwoPhaseValidation.hs index 6b7bf6223f5..3c22fd935f5 100644 --- a/libs/cardano-ledger-test/src/Test/Cardano/Ledger/Examples/TwoPhaseValidation.hs +++ b/libs/cardano-ledger-test/src/Test/Cardano/Ledger/Examples/TwoPhaseValidation.hs @@ -47,7 +47,7 @@ import Cardano.Ledger.Alonzo.Tx import Cardano.Ledger.Alonzo.TxInfo (FailureDescription (..), txInfo, valContext) import Cardano.Ledger.Alonzo.TxWitness (RdmrPtr (..), Redeemers (..), TxDats (..), unRedeemers) import Cardano.Ledger.BHeaderView (BHeaderView (..)) -import Cardano.Ledger.BaseTypes (Network (..), StrictMaybe (..), textToUrl) +import Cardano.Ledger.BaseTypes (BlocksMade (..), Network (..), StrictMaybe (..), textToUrl) import Cardano.Ledger.Coin (Coin (..)) import Cardano.Ledger.Core (EraRule) import qualified Cardano.Ledger.Core as Core @@ -81,7 +81,6 @@ import Cardano.Ledger.Shelley.API UTxO (..), ) import Cardano.Ledger.Shelley.BlockChain (Block (..), bBodySize) -import Cardano.Ledger.Shelley.EpochBoundary (BlocksMade (..)) import Cardano.Ledger.Shelley.LedgerState (UTxOState (..), WitHashes (..)) import Cardano.Ledger.Shelley.Rules.Bbody (BbodyEnv (..), BbodyPredicateFailure (..), BbodyState (..)) import Cardano.Ledger.Shelley.Rules.Delegs (DelegsPredicateFailure (..))