Skip to content

Remove ConwayNewEpochPredFailure #5007

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions eras/conway/impl/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## 1.20.0.0

- Remove `ConwayNewEpochPredFailure` and replace it with `Void`. #5007
* Bump `ProtVerHigh ConwayEra` to `11`
* Remove `ConwayTxBody`
* Removed `era` parameter from `ConwayTxBodyRaw`
Expand Down
28 changes: 9 additions & 19 deletions eras/conway/impl/src/Cardano/Ledger/Conway/Rules/NewEpoch.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

module Cardano.Ledger.Conway.Rules.NewEpoch (
ConwayNEWEPOCH,
ConwayNewEpochPredFailure (..),
ConwayNewEpochEvent (..),
) where

Expand Down Expand Up @@ -54,28 +53,15 @@ import Cardano.Ledger.Slot (EpochNo (EpochNo))
import Cardano.Ledger.State
import qualified Cardano.Ledger.Val as Val
import Control.DeepSeq (NFData)
import Control.Exception (assert)
import Control.State.Transition
import Data.Default (Default (..))
import qualified Data.Map.Strict as Map
import Data.Set (Set)
import Data.Void (Void)
import GHC.Generics (Generic)
import Lens.Micro ((%~), (&), (^.))

newtype ConwayNewEpochPredFailure era
= CorruptRewardUpdate
RewardUpdate -- The reward update which violates an invariant
deriving (Generic)

deriving instance Eq (ConwayNewEpochPredFailure era)

deriving instance
( Show (PredicateFailure (EraRule "EPOCH" era))
, Show (PredicateFailure (EraRule "RATIFY" era))
) =>
Show (ConwayNewEpochPredFailure era)

instance NFData (ConwayNewEpochPredFailure era)

data ConwayNewEpochEvent era
= DeltaRewardEvent !(Event (EraRule "RUPD" era))
| RestrainedRewards
Expand Down Expand Up @@ -121,14 +107,16 @@ instance
, GovState era ~ ConwayGovState era
, Eq (PredicateFailure (EraRule "RATIFY" era))
, Show (PredicateFailure (EraRule "RATIFY" era))
, Eq (PredicateFailure (ConwayNEWEPOCH era))
, Show (PredicateFailure (ConwayNEWEPOCH era))
) =>
STS (ConwayNEWEPOCH era)
where
type State (ConwayNEWEPOCH era) = NewEpochState era
type Signal (ConwayNEWEPOCH era) = EpochNo
type Environment (ConwayNEWEPOCH era) = ()
type BaseM (ConwayNEWEPOCH era) = ShelleyBase
type PredicateFailure (ConwayNEWEPOCH era) = ConwayNewEpochPredFailure era
type PredicateFailure (ConwayNEWEPOCH era) = Void
type Event (ConwayNEWEPOCH era) = ConwayNewEpochEvent era

initialRules =
Expand Down Expand Up @@ -162,6 +150,8 @@ newEpochTransition ::
, GovState era ~ ConwayGovState era
, Eq (PredicateFailure (EraRule "RATIFY" era))
, Show (PredicateFailure (EraRule "RATIFY" era))
, Eq (PredicateFailure (ConwayNEWEPOCH era))
, Show (PredicateFailure (ConwayNEWEPOCH era))
) =>
TransitionRule (ConwayNEWEPOCH era)
newEpochTransition = do
Expand Down Expand Up @@ -216,7 +206,7 @@ updateRewards ::
Rule (ConwayNEWEPOCH era) 'Transition (EpochState era)
updateRewards es e ru'@(RewardUpdate dt dr rs_ df _) = do
let totRs = sumRewards (es ^. prevPParamsEpochStateL . ppProtocolVersionL) rs_
Val.isZero (dt <> dr <> toDeltaCoin totRs <> df) ?! CorruptRewardUpdate ru'
in assert (Val.isZero (dt <> dr <> toDeltaCoin totRs <> df)) (pure ())
let !(!es', filtered) = applyRUpdFiltered ru' es
tellEvent $ RestrainedRewards e (frShelleyIgnored filtered) (frUnregistered filtered)
-- This event (which is only generated once per epoch) must be generated even if the
Expand All @@ -226,8 +216,8 @@ updateRewards es e ru'@(RewardUpdate dt dr rs_ df _) = do

instance
( STS (ConwayNEWEPOCH era)
, PredicateFailure (EraRule "NEWEPOCH" era) ~ ConwayNewEpochPredFailure era
, Event (EraRule "NEWEPOCH" era) ~ ConwayNewEpochEvent era
, PredicateFailure (EraRule "NEWEPOCH" era) ~ PredicateFailure (ConwayNEWEPOCH era)
) =>
Embed (ConwayNEWEPOCH era) (ShelleyTICK era)
where
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,6 @@ instance ToExpr (PParamsHKD StrictMaybe era) => ToExpr (RatifySignal era)

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

instance ToExpr (ConwayNewEpochPredFailure era)

instance
( ToExpr (PParamsHKD Identity era)
, ToExpr (PParamsHKD StrictMaybe era)
Expand Down
1 change: 1 addition & 0 deletions eras/shelley/impl/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## 1.17.0.0

- Remove `CorruptRewardUpdate` predicate failure and replace that check with an assertion. #5007
* Replace export from `Cardano.Ledger.Shelley.UTxO` of deprecated `balance` and `coinBalance` with `sumUTxO` and `sumCoinUTxO` respectively
* Remove `ShelleyTxBody`
* Removed `era` parameter from `ShelleyTxBodyRaw`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import Cardano.Ledger.Slot (EpochNo (..))
import Cardano.Ledger.State
import qualified Cardano.Ledger.Val as Val
import Control.DeepSeq (NFData)
import Control.Exception (assert)
import Control.State.Transition
import Data.Default (Default, def)
import qualified Data.Map.Strict as Map
Expand All @@ -52,8 +53,6 @@ import NoThunks.Class (NoThunks (..))

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

Expand Down Expand Up @@ -265,7 +264,7 @@ updateRewards ::
Rule (ShelleyNEWEPOCH era) 'Transition (EpochState era)
updateRewards es e ru'@(RewardUpdate dt dr rs_ df _) = do
let totRs = sumRewards (es ^. prevPParamsEpochStateL . ppProtocolVersionL) rs_
Val.isZero (dt <> (dr <> toDeltaCoin totRs <> df)) ?! CorruptRewardUpdate ru'
in assert (Val.isZero (dt <> (dr <> toDeltaCoin totRs <> df))) (pure ())
let !(!es', filtered) = applyRUpdFiltered ru' es
tellEvent $ RestrainedRewards e (frShelleyIgnored filtered) (frUnregistered filtered)
-- This event (which is only generated once per epoch) must be generated even if the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,3 @@ instance
<$> toSpecRep nesEL
<*> toSpecRep nesEs
<*> toSpecRep nesRu

instance SpecTranslate ctx (ConwayNewEpochPredFailure era) where
type SpecRep (ConwayNewEpochPredFailure era) = OpaqueErrorString
toSpecRep = pure . showOpaqueErrorString
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ import Cardano.Ledger.Conway.Rules (
ConwayGovCertPredFailure (..),
ConwayGovPredFailure (..),
ConwayLedgerPredFailure (..),
ConwayNewEpochPredFailure,
ConwayUtxosPredFailure,
EnactSignal (..),
GovEnv (..),
Expand Down Expand Up @@ -1265,7 +1264,7 @@ ppNEWEPOCH Allegra x = ppShelleyNewEpochPredicateFailure x
ppNEWEPOCH Mary x = ppShelleyNewEpochPredicateFailure x
ppNEWEPOCH Alonzo x = ppShelleyNewEpochPredicateFailure x
ppNEWEPOCH Babbage x = ppShelleyNewEpochPredicateFailure x
ppNEWEPOCH Conway x = ppConwayNewEpochPredFailure x
ppNEWEPOCH Conway x = absurd x

ppEPOCH :: Proof era -> PredicateFailure (EraRule "EPOCH" era) -> PDoc
ppEPOCH Shelley x = ppShelleyEpochPredFailure x
Expand Down Expand Up @@ -1702,21 +1701,12 @@ instance Reflect era => PrettyA (ShelleyTickPredFailure era) where
ppShelleyNewEpochPredicateFailure ::
forall era. Reflect era => ShelleyNewEpochPredFailure era -> PDoc
ppShelleyNewEpochPredicateFailure (EpochFailure x) = ppEPOCH @era reify x
ppShelleyNewEpochPredicateFailure (CorruptRewardUpdate x) =
ppSexp "CorruptRewardUpdate" [ppRewardUpdate x]
ppShelleyNewEpochPredicateFailure (MirFailure _) =
error "In the Conway era, there is no (EraRule MIR) type instance."

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

ppConwayNewEpochPredFailure :: ConwayNewEpochPredFailure era -> PDoc
ppConwayNewEpochPredFailure (ConwayRules.CorruptRewardUpdate x) =
ppSexp "CorruptRewardUpdate" [ppRewardUpdate x]

instance PrettyA (ConwayNewEpochPredFailure era) where
prettyA = ppConwayNewEpochPredFailure

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

ppShelleyEpochPredFailure :: forall era. ShelleyEpochPredFailure era -> PDoc
Expand Down
Loading