Skip to content

Commit

Permalink
The whole thing is buildable
Browse files Browse the repository at this point in the history
  • Loading branch information
lehins committed Feb 22, 2025
1 parent 204fa7a commit 83f800e
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 115 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ instantStakeIncludesRewards = do
]
++ [ stake
| stake@(_, reward) <-
[ (tom, rdRewardCoin tomRD) -- tom uxtxoCoin cab be zero because his address has StakeRefNull
, (mary, rdRewardCoin maryRD) -- mary uxtxoCoin can be zero because she has no UtxO entry
]
[ (tom, rdRewardCoin tomRD) -- tom uxtxoCoin cab be zero because his address has StakeRefNull
, (mary, rdRewardCoin maryRD) -- mary uxtxoCoin can be zero because she has no UtxO entry
]
, reward /= Coin 0 -- We need to filter out zero rewards from instant stake
]

Expand Down
18 changes: 1 addition & 17 deletions eras/shelley/test-suite/bench/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ import Cardano.Ledger.Shelley.LedgerState (
LedgerState (..),
PState (..),
UTxOState (..),
incrementalStakeDistr,
updateStakeDistribution,
)
import Cardano.Ledger.Shelley.PoolRank (likelihood)
import Cardano.Ledger.Shelley.State
Expand Down Expand Up @@ -196,15 +194,11 @@ profileEpochBoundary =

epochAt :: Int -> Benchmark
epochAt x =
env (QC.generate (genTestCase x n)) $ \ ~arg@(dstate, pstate, utxo) ->
env (QC.generate (genTestCase x n)) $ \arg ->
bgroup
("UTxO=" ++ show x ++ ", address=" ++ show n)
[ bench "stakeDistr" (nf action2m arg)
, bench "incrementalStakeDistr" (nf action2im arg)
, bench "instantStake" (nf benchInstantStake arg)
, env (pure (updateStakeDistribution emptyPParams mempty mempty utxo)) $ \incStake ->
bench "incrementalStakeDistr (no update)" $
nf (incrementalStakeDistr (emptyPParams @ShelleyEra) incStake dstate) pstate
]
where
n = 10000 :: Int
Expand All @@ -215,16 +209,6 @@ action2m ::
SnapShot
action2m (dstate, pstate, utxo) = stakeDistr utxo dstate pstate

action2im ::
forall era.
EraTxOut era =>
(DState era, PState era, UTxO era) ->
SnapShot
action2im (dstate, pstate, utxo) =
let pp = emptyPParams @era
incStake = updateStakeDistribution pp mempty mempty utxo
in incrementalStakeDistr pp incStake dstate pstate

benchInstantStake ::
forall era.
EraStake era =>
Expand Down
6 changes: 0 additions & 6 deletions eras/shelley/test-suite/src/Test/Cardano/Ledger/TerseTools.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import Cardano.Ledger.Credential (
Ptr (..),
StakeReference (..),
)
import Cardano.Ledger.Shelley.LedgerState (IncrementalStake (..))
import Cardano.Ledger.State (UTxO (..))
import Cardano.Ledger.TxIn (TxId (..), TxIn (..))
import qualified Data.Map.Strict as Map
Expand Down Expand Up @@ -98,10 +97,5 @@ instance Terse Coin where
instance Terse (CompactForm Coin) where
terse (CompactCoin n) = show n

tersediffincremental :: String -> IncrementalStake -> IncrementalStake -> String
tersediffincremental message (IStake a b) (IStake c d) =
tersemapdiffs (message ++ " " ++ "hashes") a c
++ tersemapdiffs (message ++ " " ++ "ptrs") b d

terseutxo :: Terse (TxOut era) => String -> UTxO era -> String
terseutxo message (UTxO mp) = terselist message (Map.toList mp)
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
module Bench.Cardano.Ledger.ApplyTx.Gen (generateApplyTxEnvForEra, ApplyTxEnv (..)) where

import Cardano.Ledger.Shelley.API (
AccountState (..),
Coin (..),
Globals,
LedgerEnv (..),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ import Cardano.Ledger.Plutus.Data
import Cardano.Ledger.Plutus.Language
import Cardano.Ledger.PoolParams
import Cardano.Ledger.Shelley.CertState (ShelleyCertState)
import Cardano.Ledger.Shelley.LedgerState hiding (ptrMap)
import Cardano.Ledger.Shelley.LedgerState
import Cardano.Ledger.Shelley.PoolRank
import Cardano.Ledger.Shelley.RewardUpdate (FreeVars, Pulser, RewardAns, RewardPulser (RSLP))
import Cardano.Ledger.Shelley.Rewards (LeaderOnlyReward, PoolRewardInfo, StakeShare)
Expand Down Expand Up @@ -1328,9 +1328,6 @@ instance
) =>
HasSpec fn (UTxOState era)

instance HasSimpleRep IncrementalStake
instance IsConwayUniv fn => HasSpec fn IncrementalStake

instance HasSimpleRep (ShelleyInstantStake era)
instance (Typeable era, IsConwayUniv fn) => HasSpec fn (ShelleyInstantStake era)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,9 @@ gdKeyHash = fieldToTerm gdKeyHashField

gdkeyL :: Lens' GenDelegPair (KeyHash 'Witness)
gdkeyL =
( lens
(\(GenDelegPair x _) -> asWitness x)
(\(GenDelegPair _ y) x -> GenDelegPair (coerceKeyRole x) y)
)
lens
(\(GenDelegPair x _) -> asWitness x)
(\(GenDelegPair _ y) x -> GenDelegPair (coerceKeyRole x) y)

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

Expand All @@ -235,7 +234,7 @@ certStateGenPreds p =
GenFrom treasury (constTarget (Coin <$> choose (1000, 4000)))
, GenFrom reserves (constTarget (Coin <$> choose (4000, 5000)))
, GenFrom deltaTreasury (constTarget (DeltaCoin <$> choose (-200, 400)))
, Negate (deltaReserves) :=: deltaTreasury -- Means deltaReserves ranges from (-400,200)
, Negate deltaReserves :=: deltaTreasury -- Means deltaReserves ranges from (-400,200)
, -- 'rewards' needs to be small enough that it leaves some slack with
-- credUniv (size about 30), but it also cannot be empty
MetaSize (SzRng 8 15) rewardSize
Expand All @@ -250,7 +249,7 @@ certStateGenPreds p =
, Dom rewards :=: Dom stakeDeposits
, Sized (AtMost 8) delegations
, Dom delegations :⊆: Dom rewards
, Dom delegations :⊆: Dom incrementalStake
, Dom delegations :⊆: Dom instantStakeTerm
, Rng delegations :⊆: Dom regPools
, if protocolVersion p >= protocolVersion Conway
then Sized (ExactSize 0) ptrs
Expand All @@ -260,7 +259,7 @@ certStateGenPreds p =
, -- Preds to compute genDelegs
-- First, a set of GenDelegPairs, where no keyHash is repeated.
Sized genDelegSize gdKeyHashSet
, ProjS gdkeyL WitHashR gdKeyHashSet `Subset` (Dom keymapUniv)
, ProjS gdkeyL WitHashR gdKeyHashSet `Subset` Dom keymapUniv
, gdKeyHashList :<-: setToListTarget gdKeyHashSet
, Sized genDelegSize genDelegs
, gdKeyHashList :=: Elems genDelegs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import Test.Tasty (TestTree, defaultMain)

epochstatePreds :: EraCertState era => Proof era -> [Pred era]
epochstatePreds _proof =
[ incrementalStake :=: markStake
[ instantStakeTerm :=: markStake
, delegations :=: markDelegs
, regPools :=: markPools
, Dom setStake `Subset` credsUniv
Expand Down
Loading

0 comments on commit 83f800e

Please sign in to comment.