Skip to content

Commit d351b26

Browse files
authored
Merge pull request #5007 from IntersectMBO/aniketd/remove-conwaynewepochpredfailure
Remove ConwayNewEpochPredFailure
2 parents 5d3061d + 5a93279 commit d351b26

File tree

9 files changed

+15
-111
lines changed

9 files changed

+15
-111
lines changed

eras/conway/impl/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## 1.20.0.0
44

5+
- Remove `ConwayNewEpochPredFailure` and replace it with `Void`. #5007
56
* Added to `PParams`: `ppCommitteeMaxTermLength`,`ppCommitteeMinSize`,`ppDRepActivity`,`ppDRepDeposit`,`ppDRepVotingThresholds`,`ppGovActionDeposit`,`ppGovActionLifetime`,`ppGovProtocolVersion`,`ppMinFeeRefScriptCostPerByte`,`ppPoolVotingThresholds`
67
* Moved `ConwayEraPlutusTxInfo` class from `Context` module to `TxInfo`
78
* Removed `Cardano.Ledger.Conway.Plutus.Context` module

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

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
module Cardano.Ledger.Conway.Rules.NewEpoch (
1919
ConwayNEWEPOCH,
20-
ConwayNewEpochPredFailure (..),
2120
ConwayNewEpochEvent (..),
2221
) where
2322

@@ -54,28 +53,15 @@ import Cardano.Ledger.Slot (EpochNo (EpochNo))
5453
import Cardano.Ledger.State
5554
import qualified Cardano.Ledger.Val as Val
5655
import Control.DeepSeq (NFData)
56+
import Control.Exception (assert)
5757
import Control.State.Transition
5858
import Data.Default (Default (..))
5959
import qualified Data.Map.Strict as Map
6060
import Data.Set (Set)
61+
import Data.Void (Void)
6162
import GHC.Generics (Generic)
6263
import Lens.Micro ((%~), (&), (^.))
6364

64-
newtype ConwayNewEpochPredFailure era
65-
= CorruptRewardUpdate
66-
RewardUpdate -- The reward update which violates an invariant
67-
deriving (Generic)
68-
69-
deriving instance Eq (ConwayNewEpochPredFailure era)
70-
71-
deriving instance
72-
( Show (PredicateFailure (EraRule "EPOCH" era))
73-
, Show (PredicateFailure (EraRule "RATIFY" era))
74-
) =>
75-
Show (ConwayNewEpochPredFailure era)
76-
77-
instance NFData (ConwayNewEpochPredFailure era)
78-
7965
data ConwayNewEpochEvent era
8066
= DeltaRewardEvent !(Event (EraRule "RUPD" era))
8167
| RestrainedRewards
@@ -121,14 +107,16 @@ instance
121107
, GovState era ~ ConwayGovState era
122108
, Eq (PredicateFailure (EraRule "RATIFY" era))
123109
, Show (PredicateFailure (EraRule "RATIFY" era))
110+
, Eq (PredicateFailure (ConwayNEWEPOCH era))
111+
, Show (PredicateFailure (ConwayNEWEPOCH era))
124112
) =>
125113
STS (ConwayNEWEPOCH era)
126114
where
127115
type State (ConwayNEWEPOCH era) = NewEpochState era
128116
type Signal (ConwayNEWEPOCH era) = EpochNo
129117
type Environment (ConwayNEWEPOCH era) = ()
130118
type BaseM (ConwayNEWEPOCH era) = ShelleyBase
131-
type PredicateFailure (ConwayNEWEPOCH era) = ConwayNewEpochPredFailure era
119+
type PredicateFailure (ConwayNEWEPOCH era) = Void
132120
type Event (ConwayNEWEPOCH era) = ConwayNewEpochEvent era
133121

134122
initialRules =
@@ -162,6 +150,8 @@ newEpochTransition ::
162150
, GovState era ~ ConwayGovState era
163151
, Eq (PredicateFailure (EraRule "RATIFY" era))
164152
, Show (PredicateFailure (EraRule "RATIFY" era))
153+
, Eq (PredicateFailure (ConwayNEWEPOCH era))
154+
, Show (PredicateFailure (ConwayNEWEPOCH era))
165155
) =>
166156
TransitionRule (ConwayNEWEPOCH era)
167157
newEpochTransition = do
@@ -216,7 +206,7 @@ updateRewards ::
216206
Rule (ConwayNEWEPOCH era) 'Transition (EpochState era)
217207
updateRewards es e ru'@(RewardUpdate dt dr rs_ df _) = do
218208
let totRs = sumRewards (es ^. prevPParamsEpochStateL . ppProtocolVersionL) rs_
219-
Val.isZero (dt <> dr <> toDeltaCoin totRs <> df) ?! CorruptRewardUpdate ru'
209+
in assert (Val.isZero (dt <> dr <> toDeltaCoin totRs <> df)) (pure ())
220210
let !(!es', filtered) = applyRUpdFiltered ru' es
221211
tellEvent $ RestrainedRewards e (frShelleyIgnored filtered) (frUnregistered filtered)
222212
-- This event (which is only generated once per epoch) must be generated even if the
@@ -226,8 +216,8 @@ updateRewards es e ru'@(RewardUpdate dt dr rs_ df _) = do
226216

227217
instance
228218
( STS (ConwayNEWEPOCH era)
229-
, PredicateFailure (EraRule "NEWEPOCH" era) ~ ConwayNewEpochPredFailure era
230219
, Event (EraRule "NEWEPOCH" era) ~ ConwayNewEpochEvent era
220+
, PredicateFailure (EraRule "NEWEPOCH" era) ~ PredicateFailure (ConwayNEWEPOCH era)
231221
) =>
232222
Embed (ConwayNEWEPOCH era) (ShelleyTICK era)
233223
where

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,6 @@ instance ToExpr (PParamsHKD StrictMaybe era) => ToExpr (RatifySignal era)
281281

282282
instance ToExpr (PParamsHKD StrictMaybe era) => ToExpr (EnactSignal era)
283283

284-
instance ToExpr (ConwayNewEpochPredFailure era)
285-
286284
instance
287285
( ToExpr (PParamsHKD Identity era)
288286
, ToExpr (PParamsHKD StrictMaybe era)

eras/shelley/impl/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## 1.17.0.0
44

5+
- Remove `CorruptRewardUpdate` predicate failure and replace that check with an assertion. #5007
56
* Added to `PParams`: `shelleyPParams`, `ppA0`,`ppD`,`ppEMax`,`ppExtraEntropy`,`ppMaxBBSize`,`ppKeyDeposit`,`ppMinFeeA`,`ppMinFeeB`,`ppMinPoolCost` `ppMaxBHSize`,`ppMaxTxSize`,`ppNOpt`,`ppProtocolVersion`,`ppPoolDeposit`,`ppRho`,`ppTau`
67
* Removed from `PParams`: `shelleyCommonPParamsHKDPairs`,`shelleyCommonPParamsHKDPairsV6`,`shelleyCommonPParamsHKDPairsV8`
78
* Replace export from `Cardano.Ledger.Shelley.UTxO` of deprecated `balance` and `coinBalance` with `sumUTxO` and `sumCoinUTxO` respectively

eras/shelley/impl/src/Cardano/Ledger/Shelley/Rules/NewEpoch.hs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import Cardano.Ledger.Slot (EpochNo (..))
4242
import Cardano.Ledger.State
4343
import qualified Cardano.Ledger.Val as Val
4444
import Control.DeepSeq (NFData)
45+
import Control.Exception (assert)
4546
import Control.State.Transition
4647
import Data.Default (Default, def)
4748
import qualified Data.Map.Strict as Map
@@ -52,8 +53,6 @@ import NoThunks.Class (NoThunks (..))
5253

5354
data ShelleyNewEpochPredFailure era
5455
= EpochFailure (PredicateFailure (EraRule "EPOCH" era)) -- Subtransition Failures
55-
| CorruptRewardUpdate
56-
RewardUpdate -- The reward update which violates an invariant
5756
| MirFailure (PredicateFailure (EraRule "MIR" era)) -- Subtransition Failures
5857
deriving (Generic)
5958

@@ -265,7 +264,7 @@ updateRewards ::
265264
Rule (ShelleyNEWEPOCH era) 'Transition (EpochState era)
266265
updateRewards es e ru'@(RewardUpdate dt dr rs_ df _) = do
267266
let totRs = sumRewards (es ^. prevPParamsEpochStateL . ppProtocolVersionL) rs_
268-
Val.isZero (dt <> (dr <> toDeltaCoin totRs <> df)) ?! CorruptRewardUpdate ru'
267+
in assert (Val.isZero (dt <> (dr <> toDeltaCoin totRs <> df))) (pure ())
269268
let !(!es', filtered) = applyRUpdFiltered ru' es
270269
tellEvent $ RestrainedRewards e (frShelleyIgnored filtered) (frUnregistered filtered)
271270
-- This event (which is only generated once per epoch) must be generated even if the

eras/shelley/test-suite/test/Test/Cardano/Ledger/Shelley/RulesTests.hs

Lines changed: 1 addition & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -9,35 +9,19 @@
99
module Test.Cardano.Ledger.Shelley.RulesTests (
1010
chainExamples,
1111
multisigExamples,
12-
testTickF,
1312
) where
1413

15-
import Cardano.Ledger.BaseTypes (Network (..), StrictMaybe (..))
14+
import Cardano.Ledger.BaseTypes (Network (..))
1615
import Cardano.Ledger.Coin (Coin (..))
1716
import Cardano.Ledger.Core (hashScript)
1817
import Cardano.Ledger.Credential (pattern ScriptHashObj)
1918
import Cardano.Ledger.Keys (asWitness, hashKey)
2019
import Cardano.Ledger.Shelley (ShelleyEra)
21-
import Cardano.Ledger.Shelley.API (ShelleyTICK, ShelleyTICKF)
22-
import Cardano.Ledger.Shelley.LedgerState (
23-
EpochState (..),
24-
LedgerState (..),
25-
NewEpochState (..),
26-
UTxOState (..),
27-
totalObligation,
28-
utxosGovStateL,
29-
)
30-
import Cardano.Ledger.Shelley.RewardUpdate (PulsingRewUpdate (..), RewardUpdate (..))
3120
import Cardano.Ledger.Shelley.Rules (ShelleyUtxowPredFailure (..))
3221
import Cardano.Ledger.Shelley.TxBody (RewardAccount (..), Withdrawals (..))
33-
import Cardano.Ledger.Slot (EpochNo (..))
34-
import Cardano.Protocol.TPraos.API (GetLedgerView (..))
35-
import Control.State.Transition.Extended (TRC (..))
3622
import Data.Either (isRight)
3723
import qualified Data.Map.Strict as Map
38-
import Data.Maybe (fromMaybe)
3924
import qualified Data.Set as Set
40-
import Lens.Micro ((^.))
4125
import Test.Cardano.Ledger.Core.KeyPair (vKey)
4226
import Test.Cardano.Ledger.Shelley.Examples (testCHAINExample)
4327
import qualified Test.Cardano.Ledger.Shelley.Examples.Cast as Cast
@@ -62,10 +46,8 @@ import Test.Cardano.Ledger.Shelley.MultiSigExamples (
6246
)
6347
import Test.Cardano.Ledger.Shelley.Serialisation.EraIndepGenerators ()
6448
import Test.Cardano.Ledger.Shelley.Serialisation.Generators ()
65-
import Test.Cardano.Ledger.Shelley.Utils
6649
import Test.Tasty (TestTree, testGroup)
6750
import Test.Tasty.HUnit (Assertion, assertBool, testCase, (@?=))
68-
import Test.Tasty.QuickCheck (Property, discard, testProperty, (===))
6951

7052
chainExamples :: TestTree
7153
chainExamples =
@@ -488,54 +470,3 @@ testRwdAliceSignsAlone''' =
488470
(Coin 0)
489471
[asWitness Cast.alicePay, asWitness Cast.bobPay]
490472
wits = Set.singleton $ hashScript @ShelleyEra bobOnly
491-
492-
-- | The reward aggregation bug described in the Shelley ledger spec in
493-
-- section 17.4 (in the Errata) resulted in needing to use 'aggregatedRewards' to change
494-
-- the behavior of how rewards are collected starting at protocol version 3.
495-
-- Instead of collecting a `Coin` for each stake credential, we collect 'Set Reward'.
496-
-- In major protocol version 2, it is impossible for this set to be empty, but sadly this
497-
-- property is not enforced in the types. For this reason, the property test
498-
-- 'propTickfPerservesLedgerView' removes these empty sets from an otherwise arbitrary
499-
-- 'NewEpochState'.
500-
filterEmptyRewards :: NewEpochState ShelleyEra -> NewEpochState ShelleyEra
501-
filterEmptyRewards (NewEpochState el bprev bcur es ru pd stash) =
502-
NewEpochState el bprev bcur es ru' pd stash
503-
where
504-
removeEmptyRewards = Map.filter $ not . Set.null
505-
ru' = case ru of
506-
SNothing -> SNothing
507-
SJust (Pulsing _ _) -> SNothing
508-
SJust (Complete rewardUpdate) ->
509-
SJust . Complete $ rewardUpdate {rs = removeEmptyRewards (rs rewardUpdate)}
510-
511-
setDepositsToObligation :: NewEpochState ShelleyEra -> NewEpochState ShelleyEra
512-
setDepositsToObligation nes = nes {nesEs = es {esLState = ls {lsUTxOState = utxoState}}}
513-
where
514-
es = nesEs nes
515-
ls = esLState es
516-
utxoState =
517-
(lsUTxOState ls)
518-
{ utxosDeposited =
519-
totalObligation
520-
(lsCertState ls)
521-
(utxoState ^. utxosGovStateL)
522-
}
523-
524-
-- | This property test checks the correctness of the TICKF transation.
525-
-- TICKF is used by the consensus layer to get a ledger view in a computationally
526-
-- cheaper way than using the TICK rule.
527-
-- Therefore TICKF and TICK need to compute the same ledger view.
528-
propTickfPerservesLedgerView :: NewEpochState ShelleyEra -> Property
529-
propTickfPerservesLedgerView nes =
530-
let (EpochNo e) = nesEL nes
531-
slot = slotFromEpoch (EpochNo $ e + 1)
532-
nes' = setDepositsToObligation (filterEmptyRewards nes)
533-
tickNes = runShelleyBase $ applySTSTest @(ShelleyTICK ShelleyEra) (TRC ((), nes', slot))
534-
tickFNes = runShelleyBase $ applySTSTest @(ShelleyTICKF ShelleyEra) (TRC ((), nes', slot))
535-
in fromMaybe discard $ do
536-
Right tickNes' <- pure tickNes
537-
Right tickFNes' <- pure tickFNes
538-
pure $ currentLedgerView tickNes' === currentLedgerView tickFNes'
539-
540-
testTickF :: TestTree
541-
testTickF = testProperty "TICKF properties" propTickfPerservesLedgerView

eras/shelley/test-suite/test/Tests.hs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import qualified Test.Cardano.Ledger.Shelley.Rules.Deposits as Deposits (tests)
1616
import qualified Test.Cardano.Ledger.Shelley.RulesTests as RulesTests (
1717
chainExamples,
1818
multisigExamples,
19-
testTickF,
2019
)
2120
import qualified Test.Cardano.Ledger.Shelley.SafeHash as SafeHash (safeHashTest)
2221
import qualified Test.Cardano.Ledger.Shelley.Serialisation as Serialisation
@@ -52,7 +51,6 @@ defaultTests =
5251
, Serialisation.tests
5352
, RulesTests.chainExamples
5453
, RulesTests.multisigExamples
55-
, RulesTests.testTickF
5654
, UnitTests.unitTests
5755
, SafeHash.safeHashTest
5856
]

libs/cardano-ledger-conformance/src/Test/Cardano/Ledger/Conformance/SpecTranslate/Conway/Cert.hs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,3 @@ instance
223223
<$> toSpecRep nesEL
224224
<*> toSpecRep nesEs
225225
<*> toSpecRep nesRu
226-
227-
instance SpecTranslate ctx (ConwayNewEpochPredFailure era) where
228-
type SpecRep (ConwayNewEpochPredFailure era) = OpaqueErrorString
229-
toSpecRep = pure . showOpaqueErrorString

libs/cardano-ledger-test/src/Test/Cardano/Ledger/Generic/PrettyCore.hs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ import Cardano.Ledger.Conway.Rules (
134134
ConwayGovCertPredFailure (..),
135135
ConwayGovPredFailure (..),
136136
ConwayLedgerPredFailure (..),
137-
ConwayNewEpochPredFailure,
138137
ConwayUtxosPredFailure,
139138
EnactSignal (..),
140139
GovEnv (..),
@@ -1265,7 +1264,7 @@ ppNEWEPOCH Allegra x = ppShelleyNewEpochPredicateFailure x
12651264
ppNEWEPOCH Mary x = ppShelleyNewEpochPredicateFailure x
12661265
ppNEWEPOCH Alonzo x = ppShelleyNewEpochPredicateFailure x
12671266
ppNEWEPOCH Babbage x = ppShelleyNewEpochPredicateFailure x
1268-
ppNEWEPOCH Conway x = ppConwayNewEpochPredFailure x
1267+
ppNEWEPOCH Conway x = absurd x
12691268

12701269
ppEPOCH :: Proof era -> PredicateFailure (EraRule "EPOCH" era) -> PDoc
12711270
ppEPOCH Shelley x = ppShelleyEpochPredFailure x
@@ -1702,21 +1701,12 @@ instance Reflect era => PrettyA (ShelleyTickPredFailure era) where
17021701
ppShelleyNewEpochPredicateFailure ::
17031702
forall era. Reflect era => ShelleyNewEpochPredFailure era -> PDoc
17041703
ppShelleyNewEpochPredicateFailure (EpochFailure x) = ppEPOCH @era reify x
1705-
ppShelleyNewEpochPredicateFailure (CorruptRewardUpdate x) =
1706-
ppSexp "CorruptRewardUpdate" [ppRewardUpdate x]
17071704
ppShelleyNewEpochPredicateFailure (MirFailure _) =
17081705
error "In the Conway era, there is no (EraRule MIR) type instance."
17091706

17101707
instance Reflect era => PrettyA (ShelleyNewEpochPredFailure era) where
17111708
prettyA = ppShelleyNewEpochPredicateFailure
17121709

1713-
ppConwayNewEpochPredFailure :: ConwayNewEpochPredFailure era -> PDoc
1714-
ppConwayNewEpochPredFailure (ConwayRules.CorruptRewardUpdate x) =
1715-
ppSexp "CorruptRewardUpdate" [ppRewardUpdate x]
1716-
1717-
instance PrettyA (ConwayNewEpochPredFailure era) where
1718-
prettyA = ppConwayNewEpochPredFailure
1719-
17201710
-- ===============
17211711

17221712
ppShelleyEpochPredFailure :: forall era. ShelleyEpochPredFailure era -> PDoc

0 commit comments

Comments
 (0)