{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS_GHC -Wno-orphans #-}
module Cardano.Ledger.Shelley.Rules.Ppup (
ShelleyPPUP,
PpupEnv (..),
ShelleyPpupPredFailure (..),
ShelleyGovState (..),
PpupEvent (..),
PredicateFailure,
VotingPeriod (..),
votedFuturePParams,
) where
import Cardano.Ledger.BaseTypes (
Globals (quorum),
Mismatch (..),
ProtVer,
Relation (..),
ShelleyBase,
StrictMaybe (..),
)
import Cardano.Ledger.Binary (
DecCBOR (..),
EncCBOR (..),
decodeWord,
)
import Cardano.Ledger.Binary.Coders
import Cardano.Ledger.Core
import Cardano.Ledger.Hashes (GenDelegs (..))
import Cardano.Ledger.Shelley.Era (ShelleyEra, ShelleyPPUP)
import Cardano.Ledger.Shelley.Governance
import Cardano.Ledger.Shelley.PParams (
ProposedPPUpdates (ProposedPPUpdates),
Update (..),
hasLegalProtVerUpdate,
)
import Cardano.Ledger.Slot (
EpochNo (..),
SlotNo,
getTheSlotOfNoReturn,
)
import Control.DeepSeq (NFData)
import Control.Monad (guard)
import Control.Monad.Trans.Reader (asks)
import Control.SetAlgebra (dom, eval, (⊆), (⨃))
import Control.State.Transition
import qualified Data.Foldable as F (find)
import qualified Data.Map as Map
import Data.Set (Set)
import Data.Word (Word64, Word8)
import GHC.Generics (Generic)
import Lens.Micro ((^.))
import NoThunks.Class (NoThunks (..))
data PpupEnv era = PPUPEnv SlotNo (PParams era) GenDelegs
data VotingPeriod = VoteForThisEpoch | VoteForNextEpoch
deriving (Int -> VotingPeriod -> ShowS
[VotingPeriod] -> ShowS
VotingPeriod -> String
(Int -> VotingPeriod -> ShowS)
-> (VotingPeriod -> String)
-> ([VotingPeriod] -> ShowS)
-> Show VotingPeriod
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> VotingPeriod -> ShowS
showsPrec :: Int -> VotingPeriod -> ShowS
$cshow :: VotingPeriod -> String
show :: VotingPeriod -> String
$cshowList :: [VotingPeriod] -> ShowS
showList :: [VotingPeriod] -> ShowS
Show, VotingPeriod -> VotingPeriod -> Bool
(VotingPeriod -> VotingPeriod -> Bool)
-> (VotingPeriod -> VotingPeriod -> Bool) -> Eq VotingPeriod
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: VotingPeriod -> VotingPeriod -> Bool
== :: VotingPeriod -> VotingPeriod -> Bool
$c/= :: VotingPeriod -> VotingPeriod -> Bool
/= :: VotingPeriod -> VotingPeriod -> Bool
Eq, (forall x. VotingPeriod -> Rep VotingPeriod x)
-> (forall x. Rep VotingPeriod x -> VotingPeriod)
-> Generic VotingPeriod
forall x. Rep VotingPeriod x -> VotingPeriod
forall x. VotingPeriod -> Rep VotingPeriod x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. VotingPeriod -> Rep VotingPeriod x
from :: forall x. VotingPeriod -> Rep VotingPeriod x
$cto :: forall x. Rep VotingPeriod x -> VotingPeriod
to :: forall x. Rep VotingPeriod x -> VotingPeriod
Generic)
instance NoThunks VotingPeriod
instance NFData VotingPeriod
instance EncCBOR VotingPeriod where
encCBOR :: VotingPeriod -> Encoding
encCBOR VotingPeriod
VoteForThisEpoch = Word8 -> Encoding
forall a. EncCBOR a => a -> Encoding
encCBOR (Word8
0 :: Word8)
encCBOR VotingPeriod
VoteForNextEpoch = Word8 -> Encoding
forall a. EncCBOR a => a -> Encoding
encCBOR (Word8
1 :: Word8)
instance DecCBOR VotingPeriod where
decCBOR :: forall s. Decoder s VotingPeriod
decCBOR =
Decoder s Word
forall s. Decoder s Word
decodeWord Decoder s Word
-> (Word -> Decoder s VotingPeriod) -> Decoder s VotingPeriod
forall a b. Decoder s a -> (a -> Decoder s b) -> Decoder s b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Word
0 -> VotingPeriod -> Decoder s VotingPeriod
forall a. a -> Decoder s a
forall (f :: * -> *) a. Applicative f => a -> f a
pure VotingPeriod
VoteForThisEpoch
Word
1 -> VotingPeriod -> Decoder s VotingPeriod
forall a. a -> Decoder s a
forall (f :: * -> *) a. Applicative f => a -> f a
pure VotingPeriod
VoteForNextEpoch
Word
k -> Word -> Decoder s VotingPeriod
forall a (m :: * -> *). (Typeable a, MonadFail m) => Word -> m a
invalidKey Word
k
data ShelleyPpupPredFailure era
=
NonGenesisUpdatePPUP
(Mismatch RelSubset (Set (KeyHash GenesisRole)))
|
PPUpdateWrongEpoch
EpochNo
EpochNo
VotingPeriod
|
PVCannotFollowPPUP
ProtVer
deriving (Int -> ShelleyPpupPredFailure era -> ShowS
[ShelleyPpupPredFailure era] -> ShowS
ShelleyPpupPredFailure era -> String
(Int -> ShelleyPpupPredFailure era -> ShowS)
-> (ShelleyPpupPredFailure era -> String)
-> ([ShelleyPpupPredFailure era] -> ShowS)
-> Show (ShelleyPpupPredFailure era)
forall era. Int -> ShelleyPpupPredFailure era -> ShowS
forall era. [ShelleyPpupPredFailure era] -> ShowS
forall era. ShelleyPpupPredFailure era -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall era. Int -> ShelleyPpupPredFailure era -> ShowS
showsPrec :: Int -> ShelleyPpupPredFailure era -> ShowS
$cshow :: forall era. ShelleyPpupPredFailure era -> String
show :: ShelleyPpupPredFailure era -> String
$cshowList :: forall era. [ShelleyPpupPredFailure era] -> ShowS
showList :: [ShelleyPpupPredFailure era] -> ShowS
Show, ShelleyPpupPredFailure era -> ShelleyPpupPredFailure era -> Bool
(ShelleyPpupPredFailure era -> ShelleyPpupPredFailure era -> Bool)
-> (ShelleyPpupPredFailure era
-> ShelleyPpupPredFailure era -> Bool)
-> Eq (ShelleyPpupPredFailure era)
forall era.
ShelleyPpupPredFailure era -> ShelleyPpupPredFailure era -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall era.
ShelleyPpupPredFailure era -> ShelleyPpupPredFailure era -> Bool
== :: ShelleyPpupPredFailure era -> ShelleyPpupPredFailure era -> Bool
$c/= :: forall era.
ShelleyPpupPredFailure era -> ShelleyPpupPredFailure era -> Bool
/= :: ShelleyPpupPredFailure era -> ShelleyPpupPredFailure era -> Bool
Eq, (forall x.
ShelleyPpupPredFailure era -> Rep (ShelleyPpupPredFailure era) x)
-> (forall x.
Rep (ShelleyPpupPredFailure era) x -> ShelleyPpupPredFailure era)
-> Generic (ShelleyPpupPredFailure era)
forall x.
Rep (ShelleyPpupPredFailure era) x -> ShelleyPpupPredFailure era
forall x.
ShelleyPpupPredFailure era -> Rep (ShelleyPpupPredFailure era) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall era x.
Rep (ShelleyPpupPredFailure era) x -> ShelleyPpupPredFailure era
forall era x.
ShelleyPpupPredFailure era -> Rep (ShelleyPpupPredFailure era) x
$cfrom :: forall era x.
ShelleyPpupPredFailure era -> Rep (ShelleyPpupPredFailure era) x
from :: forall x.
ShelleyPpupPredFailure era -> Rep (ShelleyPpupPredFailure era) x
$cto :: forall era x.
Rep (ShelleyPpupPredFailure era) x -> ShelleyPpupPredFailure era
to :: forall x.
Rep (ShelleyPpupPredFailure era) x -> ShelleyPpupPredFailure era
Generic)
type instance EraRuleFailure "PPUP" ShelleyEra = ShelleyPpupPredFailure ShelleyEra
instance InjectRuleFailure "PPUP" ShelleyPpupPredFailure ShelleyEra
instance NoThunks (ShelleyPpupPredFailure era)
instance NFData (ShelleyPpupPredFailure era)
newtype PpupEvent era = PpupNewEpoch EpochNo
deriving ((forall x. PpupEvent era -> Rep (PpupEvent era) x)
-> (forall x. Rep (PpupEvent era) x -> PpupEvent era)
-> Generic (PpupEvent era)
forall x. Rep (PpupEvent era) x -> PpupEvent era
forall x. PpupEvent era -> Rep (PpupEvent era) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall era x. Rep (PpupEvent era) x -> PpupEvent era
forall era x. PpupEvent era -> Rep (PpupEvent era) x
$cfrom :: forall era x. PpupEvent era -> Rep (PpupEvent era) x
from :: forall x. PpupEvent era -> Rep (PpupEvent era) x
$cto :: forall era x. Rep (PpupEvent era) x -> PpupEvent era
to :: forall x. Rep (PpupEvent era) x -> PpupEvent era
Generic, PpupEvent era -> PpupEvent era -> Bool
(PpupEvent era -> PpupEvent era -> Bool)
-> (PpupEvent era -> PpupEvent era -> Bool) -> Eq (PpupEvent era)
forall era. PpupEvent era -> PpupEvent era -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall era. PpupEvent era -> PpupEvent era -> Bool
== :: PpupEvent era -> PpupEvent era -> Bool
$c/= :: forall era. PpupEvent era -> PpupEvent era -> Bool
/= :: PpupEvent era -> PpupEvent era -> Bool
Eq)
instance NFData (PpupEvent era)
instance (EraPParams era, AtMostEra "Babbage" era) => STS (ShelleyPPUP era) where
type State (ShelleyPPUP era) = ShelleyGovState era
type Signal (ShelleyPPUP era) = StrictMaybe (Update era)
type Environment (ShelleyPPUP era) = PpupEnv era
type BaseM (ShelleyPPUP era) = ShelleyBase
type PredicateFailure (ShelleyPPUP era) = ShelleyPpupPredFailure era
type Event (ShelleyPPUP era) = PpupEvent era
initialRules :: [InitialRule (ShelleyPPUP era)]
initialRules = []
transitionRules :: [TransitionRule (ShelleyPPUP era)]
transitionRules = [TransitionRule (ShelleyPPUP era)
forall era.
(EraPParams era, AtMostEra "Babbage" era) =>
TransitionRule (ShelleyPPUP era)
ppupTransitionNonEmpty]
instance Era era => EncCBOR (ShelleyPpupPredFailure era) where
encCBOR :: ShelleyPpupPredFailure era -> Encoding
encCBOR =
forall (w :: Wrapped) t. Encode w t -> Encoding
encode @_ @(ShelleyPpupPredFailure era) (Encode Open (ShelleyPpupPredFailure era) -> Encoding)
-> (ShelleyPpupPredFailure era
-> Encode Open (ShelleyPpupPredFailure era))
-> ShelleyPpupPredFailure era
-> Encoding
forall b c a. (b -> c) -> (a -> b) -> a -> c
. \case
NonGenesisUpdatePPUP Mismatch RelSubset (Set (KeyHash GenesisRole))
mm -> (Mismatch RelSubset (Set (KeyHash GenesisRole))
-> ShelleyPpupPredFailure era)
-> Word
-> Encode
Open
(Mismatch RelSubset (Set (KeyHash GenesisRole))
-> ShelleyPpupPredFailure era)
forall t. t -> Word -> Encode Open t
Sum Mismatch RelSubset (Set (KeyHash GenesisRole))
-> ShelleyPpupPredFailure era
forall era.
Mismatch RelSubset (Set (KeyHash GenesisRole))
-> ShelleyPpupPredFailure era
NonGenesisUpdatePPUP Word
0 Encode
Open
(Mismatch RelSubset (Set (KeyHash GenesisRole))
-> ShelleyPpupPredFailure era)
-> Encode
(Closed Dense) (Mismatch RelSubset (Set (KeyHash GenesisRole)))
-> Encode Open (ShelleyPpupPredFailure era)
forall (w :: Wrapped) a t (r :: Density).
Encode w (a -> t) -> Encode (Closed r) a -> Encode w t
!> Mismatch RelSubset (Set (KeyHash GenesisRole))
-> Encode
(Closed Dense) (Mismatch RelSubset (Set (KeyHash GenesisRole)))
forall t. EncCBOR t => t -> Encode (Closed Dense) t
To Mismatch RelSubset (Set (KeyHash GenesisRole))
mm
PPUpdateWrongEpoch EpochNo
ce EpochNo
e VotingPeriod
vp -> (EpochNo -> EpochNo -> VotingPeriod -> ShelleyPpupPredFailure era)
-> Word
-> Encode
Open
(EpochNo -> EpochNo -> VotingPeriod -> ShelleyPpupPredFailure era)
forall t. t -> Word -> Encode Open t
Sum EpochNo -> EpochNo -> VotingPeriod -> ShelleyPpupPredFailure era
forall era.
EpochNo -> EpochNo -> VotingPeriod -> ShelleyPpupPredFailure era
PPUpdateWrongEpoch Word
1 Encode
Open
(EpochNo -> EpochNo -> VotingPeriod -> ShelleyPpupPredFailure era)
-> Encode (Closed Dense) EpochNo
-> Encode
Open (EpochNo -> VotingPeriod -> ShelleyPpupPredFailure era)
forall (w :: Wrapped) a t (r :: Density).
Encode w (a -> t) -> Encode (Closed r) a -> Encode w t
!> EpochNo -> Encode (Closed Dense) EpochNo
forall t. EncCBOR t => t -> Encode (Closed Dense) t
To EpochNo
ce Encode Open (EpochNo -> VotingPeriod -> ShelleyPpupPredFailure era)
-> Encode (Closed Dense) EpochNo
-> Encode Open (VotingPeriod -> ShelleyPpupPredFailure era)
forall (w :: Wrapped) a t (r :: Density).
Encode w (a -> t) -> Encode (Closed r) a -> Encode w t
!> EpochNo -> Encode (Closed Dense) EpochNo
forall t. EncCBOR t => t -> Encode (Closed Dense) t
To EpochNo
e Encode Open (VotingPeriod -> ShelleyPpupPredFailure era)
-> Encode (Closed Dense) VotingPeriod
-> Encode Open (ShelleyPpupPredFailure era)
forall (w :: Wrapped) a t (r :: Density).
Encode w (a -> t) -> Encode (Closed r) a -> Encode w t
!> VotingPeriod -> Encode (Closed Dense) VotingPeriod
forall t. EncCBOR t => t -> Encode (Closed Dense) t
To VotingPeriod
vp
PVCannotFollowPPUP ProtVer
p -> (ProtVer -> ShelleyPpupPredFailure era)
-> Word -> Encode Open (ProtVer -> ShelleyPpupPredFailure era)
forall t. t -> Word -> Encode Open t
Sum ProtVer -> ShelleyPpupPredFailure era
forall era. ProtVer -> ShelleyPpupPredFailure era
PVCannotFollowPPUP Word
2 Encode Open (ProtVer -> ShelleyPpupPredFailure era)
-> Encode (Closed Dense) ProtVer
-> Encode Open (ShelleyPpupPredFailure era)
forall (w :: Wrapped) a t (r :: Density).
Encode w (a -> t) -> Encode (Closed r) a -> Encode w t
!> ProtVer -> Encode (Closed Dense) ProtVer
forall t. EncCBOR t => t -> Encode (Closed Dense) t
To ProtVer
p
instance Era era => DecCBOR (ShelleyPpupPredFailure era) where
decCBOR :: forall s. Decoder s (ShelleyPpupPredFailure era)
decCBOR = Decode (Closed Dense) (ShelleyPpupPredFailure era)
-> Decoder s (ShelleyPpupPredFailure era)
forall t (w :: Wrapped) s. Typeable t => Decode w t -> Decoder s t
decode (Decode (Closed Dense) (ShelleyPpupPredFailure era)
-> Decoder s (ShelleyPpupPredFailure era))
-> ((Word -> Decode Open (ShelleyPpupPredFailure era))
-> Decode (Closed Dense) (ShelleyPpupPredFailure era))
-> (Word -> Decode Open (ShelleyPpupPredFailure era))
-> Decoder s (ShelleyPpupPredFailure era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text
-> (Word -> Decode Open (ShelleyPpupPredFailure era))
-> Decode (Closed Dense) (ShelleyPpupPredFailure era)
forall t.
Text -> (Word -> Decode Open t) -> Decode (Closed Dense) t
Summands Text
"ShelleyPpupPredFailure" ((Word -> Decode Open (ShelleyPpupPredFailure era))
-> Decoder s (ShelleyPpupPredFailure era))
-> (Word -> Decode Open (ShelleyPpupPredFailure era))
-> Decoder s (ShelleyPpupPredFailure era)
forall a b. (a -> b) -> a -> b
$ \case
Word
0 -> (Mismatch RelSubset (Set (KeyHash GenesisRole))
-> ShelleyPpupPredFailure era)
-> Decode
Open
(Mismatch RelSubset (Set (KeyHash GenesisRole))
-> ShelleyPpupPredFailure era)
forall t. t -> Decode Open t
SumD Mismatch RelSubset (Set (KeyHash GenesisRole))
-> ShelleyPpupPredFailure era
forall era.
Mismatch RelSubset (Set (KeyHash GenesisRole))
-> ShelleyPpupPredFailure era
NonGenesisUpdatePPUP Decode
Open
(Mismatch RelSubset (Set (KeyHash GenesisRole))
-> ShelleyPpupPredFailure era)
-> Decode
(Closed (ZonkAny 0))
(Mismatch RelSubset (Set (KeyHash GenesisRole)))
-> Decode Open (ShelleyPpupPredFailure era)
forall a (w1 :: Wrapped) t (w :: Density).
Typeable a =>
Decode w1 (a -> t) -> Decode (Closed w) a -> Decode w1 t
<! Decode
(Closed (ZonkAny 0))
(Mismatch RelSubset (Set (KeyHash GenesisRole)))
forall t (w :: Wrapped). DecCBOR t => Decode w t
From
Word
1 -> (EpochNo -> EpochNo -> VotingPeriod -> ShelleyPpupPredFailure era)
-> Decode
Open
(EpochNo -> EpochNo -> VotingPeriod -> ShelleyPpupPredFailure era)
forall t. t -> Decode Open t
SumD EpochNo -> EpochNo -> VotingPeriod -> ShelleyPpupPredFailure era
forall era.
EpochNo -> EpochNo -> VotingPeriod -> ShelleyPpupPredFailure era
PPUpdateWrongEpoch Decode
Open
(EpochNo -> EpochNo -> VotingPeriod -> ShelleyPpupPredFailure era)
-> Decode (Closed (ZonkAny 3)) EpochNo
-> Decode
Open (EpochNo -> VotingPeriod -> ShelleyPpupPredFailure era)
forall a (w1 :: Wrapped) t (w :: Density).
Typeable a =>
Decode w1 (a -> t) -> Decode (Closed w) a -> Decode w1 t
<! Decode (Closed (ZonkAny 3)) EpochNo
forall t (w :: Wrapped). DecCBOR t => Decode w t
From Decode Open (EpochNo -> VotingPeriod -> ShelleyPpupPredFailure era)
-> Decode (Closed (ZonkAny 2)) EpochNo
-> Decode Open (VotingPeriod -> ShelleyPpupPredFailure era)
forall a (w1 :: Wrapped) t (w :: Density).
Typeable a =>
Decode w1 (a -> t) -> Decode (Closed w) a -> Decode w1 t
<! Decode (Closed (ZonkAny 2)) EpochNo
forall t (w :: Wrapped). DecCBOR t => Decode w t
From Decode Open (VotingPeriod -> ShelleyPpupPredFailure era)
-> Decode (Closed (ZonkAny 1)) VotingPeriod
-> Decode Open (ShelleyPpupPredFailure era)
forall a (w1 :: Wrapped) t (w :: Density).
Typeable a =>
Decode w1 (a -> t) -> Decode (Closed w) a -> Decode w1 t
<! Decode (Closed (ZonkAny 1)) VotingPeriod
forall t (w :: Wrapped). DecCBOR t => Decode w t
From
Word
2 -> (ProtVer -> ShelleyPpupPredFailure era)
-> Decode Open (ProtVer -> ShelleyPpupPredFailure era)
forall t. t -> Decode Open t
SumD ProtVer -> ShelleyPpupPredFailure era
forall era. ProtVer -> ShelleyPpupPredFailure era
PVCannotFollowPPUP Decode Open (ProtVer -> ShelleyPpupPredFailure era)
-> Decode (Closed (ZonkAny 4)) ProtVer
-> Decode Open (ShelleyPpupPredFailure era)
forall a (w1 :: Wrapped) t (w :: Density).
Typeable a =>
Decode w1 (a -> t) -> Decode (Closed w) a -> Decode w1 t
<! Decode (Closed (ZonkAny 4)) ProtVer
forall t (w :: Wrapped). DecCBOR t => Decode w t
From
Word
k -> Word -> Decode Open (ShelleyPpupPredFailure era)
forall (w :: Wrapped) t. Word -> Decode w t
Invalid Word
k
ppupTransitionNonEmpty ::
(EraPParams era, AtMostEra "Babbage" era) => TransitionRule (ShelleyPPUP era)
ppupTransitionNonEmpty :: forall era.
(EraPParams era, AtMostEra "Babbage" era) =>
TransitionRule (ShelleyPPUP era)
ppupTransitionNonEmpty = do
TRC
( PPUPEnv slot pp (GenDelegs genDelegs)
, pps@( ShelleyGovState
{ sgsCurProposals = ProposedPPUpdates pupS
, sgsFutureProposals = ProposedPPUpdates fpupS
}
)
, update
) <-
Rule
(ShelleyPPUP era)
'Transition
(RuleContext 'Transition (ShelleyPPUP era))
F (Clause (ShelleyPPUP era) 'Transition) (TRC (ShelleyPPUP era))
forall sts (rtype :: RuleType).
Rule sts rtype (RuleContext rtype sts)
judgmentContext
case update of
StrictMaybe (Update era)
Signal (ShelleyPPUP era)
SNothing -> ShelleyGovState era
-> F (Clause (ShelleyPPUP era) 'Transition) (ShelleyGovState era)
forall a. a -> F (Clause (ShelleyPPUP era) 'Transition) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure State (ShelleyPPUP era)
ShelleyGovState era
pps
SJust (Update (ProposedPPUpdates Map (KeyHash GenesisRole) (PParamsUpdate era)
pup) EpochNo
targetEpochNo) -> do
Exp Bool -> Bool
forall s t. Embed s t => Exp t -> s
eval (Map (KeyHash GenesisRole) (PParamsUpdate era)
-> Exp (Sett (KeyHash GenesisRole) ())
forall k s (f :: * -> * -> *) v.
(Ord k, HasExp s (f k v)) =>
s -> Exp (Sett k ())
dom Map (KeyHash GenesisRole) (PParamsUpdate era)
pup Exp (Sett (KeyHash GenesisRole) ())
-> Exp (Sett (KeyHash GenesisRole) ()) -> Exp Bool
forall k (f :: * -> * -> *) (g :: * -> * -> *) s1 v s2 u.
(Ord k, Iter f, Iter g, HasExp s1 (f k v), HasExp s2 (g k u)) =>
s1 -> s2 -> Exp Bool
⊆ Map (KeyHash GenesisRole) GenDelegPair
-> Exp (Sett (KeyHash GenesisRole) ())
forall k s (f :: * -> * -> *) v.
(Ord k, HasExp s (f k v)) =>
s -> Exp (Sett k ())
dom Map (KeyHash GenesisRole) GenDelegPair
genDelegs)
Bool
-> PredicateFailure (ShelleyPPUP era)
-> Rule (ShelleyPPUP era) 'Transition ()
forall sts (ctx :: RuleType).
Bool -> PredicateFailure sts -> Rule sts ctx ()
?! Mismatch RelSubset (Set (KeyHash GenesisRole))
-> ShelleyPpupPredFailure era
forall era.
Mismatch RelSubset (Set (KeyHash GenesisRole))
-> ShelleyPpupPredFailure era
NonGenesisUpdatePPUP
Mismatch
{ mismatchSupplied :: Set (KeyHash GenesisRole)
mismatchSupplied = Exp (Sett (KeyHash GenesisRole) ()) -> Set (KeyHash GenesisRole)
forall s t. Embed s t => Exp t -> s
eval (Exp (Sett (KeyHash GenesisRole) ()) -> Set (KeyHash GenesisRole))
-> Exp (Sett (KeyHash GenesisRole) ()) -> Set (KeyHash GenesisRole)
forall a b. (a -> b) -> a -> b
$ Map (KeyHash GenesisRole) (PParamsUpdate era)
-> Exp (Sett (KeyHash GenesisRole) ())
forall k s (f :: * -> * -> *) v.
(Ord k, HasExp s (f k v)) =>
s -> Exp (Sett k ())
dom Map (KeyHash GenesisRole) (PParamsUpdate era)
pup
, mismatchExpected :: Set (KeyHash GenesisRole)
mismatchExpected = Exp (Sett (KeyHash GenesisRole) ()) -> Set (KeyHash GenesisRole)
forall s t. Embed s t => Exp t -> s
eval (Exp (Sett (KeyHash GenesisRole) ()) -> Set (KeyHash GenesisRole))
-> Exp (Sett (KeyHash GenesisRole) ()) -> Set (KeyHash GenesisRole)
forall a b. (a -> b) -> a -> b
$ Map (KeyHash GenesisRole) GenDelegPair
-> Exp (Sett (KeyHash GenesisRole) ())
forall k s (f :: * -> * -> *) v.
(Ord k, HasExp s (f k v)) =>
s -> Exp (Sett k ())
dom Map (KeyHash GenesisRole) GenDelegPair
genDelegs
}
let firstIllegalProtVerUpdate :: Maybe ProtVer
firstIllegalProtVerUpdate = do
ppu <- (PParamsUpdate era -> Bool)
-> Map (KeyHash GenesisRole) (PParamsUpdate era)
-> Maybe (PParamsUpdate era)
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Maybe a
F.find (Bool -> Bool
not (Bool -> Bool)
-> (PParamsUpdate era -> Bool) -> PParamsUpdate era -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PParams era -> PParamsUpdate era -> Bool
forall era.
(AtMostEra "Babbage" era, EraPParams era) =>
PParams era -> PParamsUpdate era -> Bool
hasLegalProtVerUpdate PParams era
pp) Map (KeyHash GenesisRole) (PParamsUpdate era)
pup
SJust newBadProtVer <- Just (ppu ^. ppuProtocolVersionL)
Just newBadProtVer
Maybe ProtVer
-> (ProtVer -> PredicateFailure (ShelleyPPUP era))
-> Rule (ShelleyPPUP era) 'Transition ()
forall a sts (ctx :: RuleType).
Maybe a -> (a -> PredicateFailure sts) -> Rule sts ctx ()
failOnJust Maybe ProtVer
firstIllegalProtVerUpdate ProtVer -> PredicateFailure (ShelleyPPUP era)
ProtVer -> ShelleyPpupPredFailure era
forall era. ProtVer -> ShelleyPpupPredFailure era
PVCannotFollowPPUP
(curEpochNo, tooLate, nextEpochNo) <- BaseM (ShelleyPPUP era) (EpochNo, SlotNo, EpochNo)
-> Rule (ShelleyPPUP era) 'Transition (EpochNo, SlotNo, EpochNo)
forall sts a (ctx :: RuleType).
STS sts =>
BaseM sts a -> Rule sts ctx a
liftSTS (BaseM (ShelleyPPUP era) (EpochNo, SlotNo, EpochNo)
-> Rule (ShelleyPPUP era) 'Transition (EpochNo, SlotNo, EpochNo))
-> BaseM (ShelleyPPUP era) (EpochNo, SlotNo, EpochNo)
-> Rule (ShelleyPPUP era) 'Transition (EpochNo, SlotNo, EpochNo)
forall a b. (a -> b) -> a -> b
$ HasCallStack => SlotNo -> ShelleyBase (EpochNo, SlotNo, EpochNo)
SlotNo -> ShelleyBase (EpochNo, SlotNo, EpochNo)
getTheSlotOfNoReturn SlotNo
slot
tellEvent $ PpupNewEpoch nextEpochNo
if slot < tooLate
then do
(curEpochNo == targetEpochNo)
?! PPUpdateWrongEpoch curEpochNo targetEpochNo VoteForThisEpoch
let curProposals = Map (KeyHash GenesisRole) (PParamsUpdate era)
-> ProposedPPUpdates era
forall era.
Map (KeyHash GenesisRole) (PParamsUpdate era)
-> ProposedPPUpdates era
ProposedPPUpdates (Exp (Map (KeyHash GenesisRole) (PParamsUpdate era))
-> Map (KeyHash GenesisRole) (PParamsUpdate era)
forall s t. Embed s t => Exp t -> s
eval (Map (KeyHash GenesisRole) (PParamsUpdate era)
pupS Map (KeyHash GenesisRole) (PParamsUpdate era)
-> Map (KeyHash GenesisRole) (PParamsUpdate era)
-> Exp (Map (KeyHash GenesisRole) (PParamsUpdate era))
forall k s1 (f :: * -> * -> *) v s2 (g :: * -> * -> *).
(Ord k, HasExp s1 (f k v), HasExp s2 (g k v)) =>
s1 -> s2 -> Exp (f k v)
⨃ Map (KeyHash GenesisRole) (PParamsUpdate era)
pup))
!coreNodeQuorum <- liftSTS $ asks quorum
pure $
pps
{ sgsCurProposals = curProposals
, sgsFutureProposals = ProposedPPUpdates fpupS
, sgsFuturePParams =
PotentialPParamsUpdate $ votedFuturePParams curProposals pp coreNodeQuorum
}
else do
(succ curEpochNo == targetEpochNo)
?! PPUpdateWrongEpoch curEpochNo targetEpochNo VoteForNextEpoch
pure $
pps
{ sgsCurProposals = ProposedPPUpdates pupS
, sgsFutureProposals = ProposedPPUpdates (eval (fpupS ⨃ pup))
}
votedFuturePParams ::
forall era.
EraPParams era =>
ProposedPPUpdates era ->
PParams era ->
Word64 ->
Maybe (PParams era)
votedFuturePParams :: forall era.
EraPParams era =>
ProposedPPUpdates era
-> PParams era -> Word64 -> Maybe (PParams era)
votedFuturePParams (ProposedPPUpdates Map (KeyHash GenesisRole) (PParamsUpdate era)
pppu) PParams era
pp Word64
quorumN = do
let votes :: Map (PParamsUpdate era) Word64
votes =
(PParamsUpdate era
-> Map (PParamsUpdate era) Word64
-> Map (PParamsUpdate era) Word64)
-> Map (PParamsUpdate era) Word64
-> Map (KeyHash GenesisRole) (PParamsUpdate era)
-> Map (PParamsUpdate era) Word64
forall a b k. (a -> b -> b) -> b -> Map k a -> b
Map.foldr
(\PParamsUpdate era
vote -> (Word64 -> Word64 -> Word64)
-> PParamsUpdate era
-> Word64
-> Map (PParamsUpdate era) Word64
-> Map (PParamsUpdate era) Word64
forall k a. Ord k => (a -> a -> a) -> k -> a -> Map k a -> Map k a
Map.insertWith Word64 -> Word64 -> Word64
forall a. Num a => a -> a -> a
(+) PParamsUpdate era
vote Word64
1)
(Map (PParamsUpdate era) Word64
forall k a. Map k a
Map.empty :: Map.Map (PParamsUpdate era) Word64)
Map (KeyHash GenesisRole) (PParamsUpdate era)
pppu
consensus :: Map (PParamsUpdate era) Word64
consensus = (Word64 -> Bool)
-> Map (PParamsUpdate era) Word64 -> Map (PParamsUpdate era) Word64
forall a k. (a -> Bool) -> Map k a -> Map k a
Map.filter (Word64 -> Word64 -> Bool
forall a. Ord a => a -> a -> Bool
>= Word64
quorumN) Map (PParamsUpdate era) Word64
votes
[ppu] <- [PParamsUpdate era] -> Maybe [PParamsUpdate era]
forall a. a -> Maybe a
Just ([PParamsUpdate era] -> Maybe [PParamsUpdate era])
-> [PParamsUpdate era] -> Maybe [PParamsUpdate era]
forall a b. (a -> b) -> a -> b
$ Map (PParamsUpdate era) Word64 -> [PParamsUpdate era]
forall k a. Map k a -> [k]
Map.keys Map (PParamsUpdate era) Word64
consensus
let ppNew = PParams era -> PParamsUpdate era -> PParams era
forall era.
EraPParams era =>
PParams era -> PParamsUpdate era -> PParams era
applyPPUpdates PParams era
pp PParamsUpdate era
ppu
guard $
toInteger (ppNew ^. ppMaxTxSizeL) + toInteger (ppNew ^. ppMaxBHSizeL)
< toInteger (ppNew ^. ppMaxBBSizeL)
pure ppNew