{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS_GHC -Wno-orphans #-}
module Cardano.Ledger.Conway.Rules.Ratify (
RatifyState (..),
committeeAccepted,
committeeAcceptedRatio,
spoAccepted,
spoAcceptedRatio,
dRepAccepted,
dRepAcceptedRatio,
acceptedByEveryone,
prevActionAsExpected,
validCommitteeTerm,
withdrawalCanWithdraw,
) where
import Cardano.Ledger.BaseTypes (
BoundedRational (..),
ProtVer,
ShelleyBase,
StrictMaybe (..),
addEpochInterval,
)
import Cardano.Ledger.CertState (CommitteeAuthorization (..), CommitteeState (csCommitteeCreds))
import Cardano.Ledger.Coin (Coin (..), CompactForm (..))
import Cardano.Ledger.Conway.Core
import Cardano.Ledger.Conway.Era (ConwayENACT, ConwayRATIFY)
import Cardano.Ledger.Conway.Governance (
Committee (..),
DefaultVote (..),
GovAction (..),
GovActionState (..),
GovRelation,
ProposalProcedure (..),
RatifyEnv (..),
RatifySignal (..),
RatifyState (..),
Vote (..),
defaultStakePoolVote,
ensCommitteeL,
ensProtVerL,
ensTreasuryL,
gasAction,
rsDelayedL,
rsEnactStateL,
rsEnactedL,
rsExpiredL,
votingCommitteeThreshold,
votingDRepThreshold,
votingStakePoolThreshold,
withGovActionParent,
)
import Cardano.Ledger.Conway.Rules.Enact (EnactSignal (..), EnactState (..))
import Cardano.Ledger.Credential (Credential (..))
import Cardano.Ledger.DRep (DRep (..), DRepState (..))
import Cardano.Ledger.PoolDistr (PoolDistr (..), individualTotalPoolStake)
import Cardano.Ledger.Shelley.HardForks (bootstrapPhase)
import Cardano.Ledger.Slot (EpochNo (..))
import Cardano.Ledger.Val (Val (..), (<+>))
import Control.State.Transition.Extended (
Embed (..),
STS (..),
TRC (..),
TransitionRule,
judgmentContext,
trans,
)
import Data.Foldable (Foldable (..))
import Data.Map.Strict (Map)
import qualified Data.Map.Strict as Map
import Data.Ratio ((%))
import qualified Data.Sequence as Seq
import qualified Data.Sequence.Strict as SSeq
import qualified Data.Set as Set
import Data.Void (Void, absurd)
import Lens.Micro
instance
( ConwayEraPParams era
, Embed (EraRule "ENACT" era) (ConwayRATIFY era)
, State (EraRule "ENACT" era) ~ EnactState era
, Environment (EraRule "ENACT" era) ~ ()
, Signal (EraRule "ENACT" era) ~ EnactSignal era
) =>
STS (ConwayRATIFY era)
where
type Environment (ConwayRATIFY era) = RatifyEnv era
type PredicateFailure (ConwayRATIFY era) = Void
type Signal (ConwayRATIFY era) = RatifySignal era
type State (ConwayRATIFY era) = RatifyState era
type BaseM (ConwayRATIFY era) = ShelleyBase
initialRules :: [InitialRule (ConwayRATIFY era)]
initialRules = []
transitionRules :: [TransitionRule (ConwayRATIFY era)]
transitionRules = [forall era.
(Embed (EraRule "ENACT" era) (ConwayRATIFY era),
State (EraRule "ENACT" era) ~ EnactState era,
Environment (EraRule "ENACT" era) ~ (),
Signal (EraRule "ENACT" era) ~ EnactSignal era,
ConwayEraPParams era) =>
TransitionRule (ConwayRATIFY era)
ratifyTransition]
committeeAccepted ::
ConwayEraPParams era =>
RatifyEnv era ->
RatifyState era ->
GovActionState era ->
Bool
committeeAccepted :: forall era.
ConwayEraPParams era =>
RatifyEnv era -> RatifyState era -> GovActionState era -> Bool
committeeAccepted RatifyEnv {CommitteeState era
reCommitteeState :: forall era. RatifyEnv era -> CommitteeState era
reCommitteeState :: CommitteeState era
reCommitteeState, EpochNo
reCurrentEpoch :: forall era. RatifyEnv era -> EpochNo
reCurrentEpoch :: EpochNo
reCurrentEpoch} RatifyState era
rs GovActionState era
gas =
case forall era.
ConwayEraPParams era =>
EpochNo
-> RatifyState era
-> CommitteeState era
-> GovAction era
-> StrictMaybe UnitInterval
votingCommitteeThreshold EpochNo
reCurrentEpoch RatifyState era
rs CommitteeState era
reCommitteeState (forall era. GovActionState era -> GovAction era
gasAction GovActionState era
gas) of
StrictMaybe UnitInterval
SNothing -> Bool
False
SJust UnitInterval
r ->
UnitInterval
r forall a. Eq a => a -> a -> Bool
== forall a. Bounded a => a
minBound Bool -> Bool -> Bool
|| Rational
acceptedRatio forall a. Ord a => a -> a -> Bool
>= forall r. BoundedRational r => r -> Rational
unboundRational UnitInterval
r
where
acceptedRatio :: Rational
acceptedRatio =
forall era.
Map (Credential 'ColdCommitteeRole) EpochNo
-> Map (Credential 'HotCommitteeRole) Vote
-> CommitteeState era
-> EpochNo
-> Rational
committeeAcceptedRatio Map (Credential 'ColdCommitteeRole) EpochNo
members (forall era.
GovActionState era -> Map (Credential 'HotCommitteeRole) Vote
gasCommitteeVotes GovActionState era
gas) CommitteeState era
reCommitteeState EpochNo
reCurrentEpoch
members :: Map (Credential 'ColdCommitteeRole) EpochNo
members = forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap' forall era.
Committee era -> Map (Credential 'ColdCommitteeRole) EpochNo
committeeMembers (RatifyState era
rs forall s a. s -> Getting a s a -> a
^. forall era. Lens' (RatifyState era) (EnactState era)
rsEnactStateL forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall era. Lens' (EnactState era) (StrictMaybe (Committee era))
ensCommitteeL)
committeeAcceptedRatio ::
forall era.
Map (Credential 'ColdCommitteeRole) EpochNo ->
Map (Credential 'HotCommitteeRole) Vote ->
CommitteeState era ->
EpochNo ->
Rational
committeeAcceptedRatio :: forall era.
Map (Credential 'ColdCommitteeRole) EpochNo
-> Map (Credential 'HotCommitteeRole) Vote
-> CommitteeState era
-> EpochNo
-> Rational
committeeAcceptedRatio Map (Credential 'ColdCommitteeRole) EpochNo
members Map (Credential 'HotCommitteeRole) Vote
votes CommitteeState era
committeeState EpochNo
currentEpoch
| Integer
totalExcludingAbstain forall a. Eq a => a -> a -> Bool
== Integer
0 = Rational
0
| Bool
otherwise = Integer
yesVotes forall a. Integral a => a -> a -> Ratio a
% Integer
totalExcludingAbstain
where
accumVotes ::
(Integer, Integer) ->
Credential 'ColdCommitteeRole ->
EpochNo ->
(Integer, Integer)
accumVotes :: (Integer, Integer)
-> Credential 'ColdCommitteeRole -> EpochNo -> (Integer, Integer)
accumVotes (!Integer
yes, !Integer
tot) Credential 'ColdCommitteeRole
member EpochNo
expiry
| EpochNo
currentEpoch forall a. Ord a => a -> a -> Bool
> EpochNo
expiry = (Integer
yes, Integer
tot)
| Bool
otherwise =
case forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup Credential 'ColdCommitteeRole
member (forall era.
CommitteeState era
-> Map (Credential 'ColdCommitteeRole) CommitteeAuthorization
csCommitteeCreds CommitteeState era
committeeState) of
Maybe CommitteeAuthorization
Nothing -> (Integer
yes, Integer
tot)
Just (CommitteeMemberResigned StrictMaybe Anchor
_) -> (Integer
yes, Integer
tot)
Just (CommitteeHotCredential Credential 'HotCommitteeRole
hotKey) ->
case forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup Credential 'HotCommitteeRole
hotKey Map (Credential 'HotCommitteeRole) Vote
votes of
Maybe Vote
Nothing -> (Integer
yes, Integer
tot forall a. Num a => a -> a -> a
+ Integer
1)
Just Vote
Abstain -> (Integer
yes, Integer
tot)
Just Vote
VoteNo -> (Integer
yes, Integer
tot forall a. Num a => a -> a -> a
+ Integer
1)
Just Vote
VoteYes -> (Integer
yes forall a. Num a => a -> a -> a
+ Integer
1, Integer
tot forall a. Num a => a -> a -> a
+ Integer
1)
(Integer
yesVotes, Integer
totalExcludingAbstain) = forall a k b. (a -> k -> b -> a) -> a -> Map k b -> a
Map.foldlWithKey' (Integer, Integer)
-> Credential 'ColdCommitteeRole -> EpochNo -> (Integer, Integer)
accumVotes (Integer
0, Integer
0) Map (Credential 'ColdCommitteeRole) EpochNo
members
spoAccepted ::
ConwayEraPParams era => RatifyEnv era -> RatifyState era -> GovActionState era -> Bool
spoAccepted :: forall era.
ConwayEraPParams era =>
RatifyEnv era -> RatifyState era -> GovActionState era -> Bool
spoAccepted RatifyEnv era
re RatifyState era
rs GovActionState era
gas =
case forall era.
ConwayEraPParams era =>
RatifyState era -> GovAction era -> StrictMaybe UnitInterval
votingStakePoolThreshold RatifyState era
rs (forall era. GovActionState era -> GovAction era
gasAction GovActionState era
gas) of
SJust UnitInterval
r ->
UnitInterval
r forall a. Eq a => a -> a -> Bool
== forall a. Bounded a => a
minBound Bool -> Bool -> Bool
|| forall era.
RatifyEnv era -> GovActionState era -> ProtVer -> Rational
spoAcceptedRatio RatifyEnv era
re GovActionState era
gas (RatifyState era
rs forall s a. s -> Getting a s a -> a
^. forall era. Lens' (RatifyState era) (EnactState era)
rsEnactStateL forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall era. EraPParams era => Lens' (EnactState era) ProtVer
ensProtVerL) forall a. Ord a => a -> a -> Bool
>= forall r. BoundedRational r => r -> Rational
unboundRational UnitInterval
r
StrictMaybe UnitInterval
SNothing -> Bool
False
spoAcceptedRatio :: forall era. RatifyEnv era -> GovActionState era -> ProtVer -> Rational
spoAcceptedRatio :: forall era.
RatifyEnv era -> GovActionState era -> ProtVer -> Rational
spoAcceptedRatio
RatifyEnv
{ reStakePoolDistr :: forall era. RatifyEnv era -> PoolDistr
reStakePoolDistr = PoolDistr Map (KeyHash 'StakePool) IndividualPoolStake
individualPoolStake (CompactCoin Word64
totalActiveStake)
, Map (Credential 'Staking) DRep
reDelegatees :: forall era. RatifyEnv era -> Map (Credential 'Staking) DRep
reDelegatees :: Map (Credential 'Staking) DRep
reDelegatees
, Map (KeyHash 'StakePool) PoolParams
rePoolParams :: forall era. RatifyEnv era -> Map (KeyHash 'StakePool) PoolParams
rePoolParams :: Map (KeyHash 'StakePool) PoolParams
rePoolParams
}
GovActionState
{ Map (KeyHash 'StakePool) Vote
gasStakePoolVotes :: forall era. GovActionState era -> Map (KeyHash 'StakePool) Vote
gasStakePoolVotes :: Map (KeyHash 'StakePool) Vote
gasStakePoolVotes
, gasProposalProcedure :: forall era. GovActionState era -> ProposalProcedure era
gasProposalProcedure = ProposalProcedure {GovAction era
pProcGovAction :: forall era. ProposalProcedure era -> GovAction era
pProcGovAction :: GovAction era
pProcGovAction}
}
ProtVer
pv
| Word64
totalActiveStake forall a. Eq a => a -> a -> Bool
== Word64
0 = Rational
0
| Word64
totalActiveStake forall a. Eq a => a -> a -> Bool
== Word64
abstainStake = Rational
0
| Bool
otherwise = forall a. Integral a => a -> Integer
toInteger Word64
yesStake forall a. Integral a => a -> a -> Ratio a
% forall a. Integral a => a -> Integer
toInteger (Word64
totalActiveStake forall a. Num a => a -> a -> a
- Word64
abstainStake)
where
accumStake :: (Word64, Word64)
-> KeyHash 'StakePool -> IndividualPoolStake -> (Word64, Word64)
accumStake (!Word64
yes, !Word64
abstain) KeyHash 'StakePool
poolId IndividualPoolStake
distr =
let CompactCoin Word64
stake = IndividualPoolStake -> CompactForm Coin
individualTotalPoolStake IndividualPoolStake
distr
vote :: Maybe Vote
vote = forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup KeyHash 'StakePool
poolId Map (KeyHash 'StakePool) Vote
gasStakePoolVotes
in case Maybe Vote
vote of
Maybe Vote
Nothing
| HardForkInitiation {} <- GovAction era
pProcGovAction -> (Word64
yes, Word64
abstain)
| ProtVer -> Bool
bootstrapPhase ProtVer
pv -> (Word64
yes, Word64
abstain forall a. Num a => a -> a -> a
+ Word64
stake)
| Bool
otherwise -> case KeyHash 'StakePool
-> Map (KeyHash 'StakePool) PoolParams
-> Map (Credential 'Staking) DRep
-> DefaultVote
defaultStakePoolVote KeyHash 'StakePool
poolId Map (KeyHash 'StakePool) PoolParams
rePoolParams Map (Credential 'Staking) DRep
reDelegatees of
DefaultVote
DefaultNoConfidence
| NoConfidence {} <- GovAction era
pProcGovAction -> (Word64
yes forall a. Num a => a -> a -> a
+ Word64
stake, Word64
abstain)
DefaultVote
DefaultAbstain -> (Word64
yes, Word64
abstain forall a. Num a => a -> a -> a
+ Word64
stake)
DefaultVote
_ -> (Word64
yes, Word64
abstain)
Just Vote
Abstain -> (Word64
yes, Word64
abstain forall a. Num a => a -> a -> a
+ Word64
stake)
Just Vote
VoteNo -> (Word64
yes, Word64
abstain)
Just Vote
VoteYes -> (Word64
yes forall a. Num a => a -> a -> a
+ Word64
stake, Word64
abstain)
(Word64
yesStake, Word64
abstainStake) =
forall a k b. (a -> k -> b -> a) -> a -> Map k b -> a
Map.foldlWithKey' (Word64, Word64)
-> KeyHash 'StakePool -> IndividualPoolStake -> (Word64, Word64)
accumStake (Word64
0, Word64
0) Map (KeyHash 'StakePool) IndividualPoolStake
individualPoolStake
dRepAccepted ::
ConwayEraPParams era => RatifyEnv era -> RatifyState era -> GovActionState era -> Bool
dRepAccepted :: forall era.
ConwayEraPParams era =>
RatifyEnv era -> RatifyState era -> GovActionState era -> Bool
dRepAccepted RatifyEnv era
re RatifyState era
rs GovActionState {Map (Credential 'DRepRole) Vote
gasDRepVotes :: forall era. GovActionState era -> Map (Credential 'DRepRole) Vote
gasDRepVotes :: Map (Credential 'DRepRole) Vote
gasDRepVotes, ProposalProcedure era
gasProposalProcedure :: ProposalProcedure era
gasProposalProcedure :: forall era. GovActionState era -> ProposalProcedure era
gasProposalProcedure} =
case forall era.
ConwayEraPParams era =>
RatifyState era -> GovAction era -> StrictMaybe UnitInterval
votingDRepThreshold RatifyState era
rs GovAction era
govAction of
SJust UnitInterval
r ->
UnitInterval
r forall a. Eq a => a -> a -> Bool
== forall a. Bounded a => a
minBound
Bool -> Bool -> Bool
|| forall era.
RatifyEnv era
-> Map (Credential 'DRepRole) Vote -> GovAction era -> Rational
dRepAcceptedRatio RatifyEnv era
re Map (Credential 'DRepRole) Vote
gasDRepVotes GovAction era
govAction forall a. Ord a => a -> a -> Bool
>= forall r. BoundedRational r => r -> Rational
unboundRational UnitInterval
r
StrictMaybe UnitInterval
SNothing -> Bool
False
where
govAction :: GovAction era
govAction = forall era. ProposalProcedure era -> GovAction era
pProcGovAction ProposalProcedure era
gasProposalProcedure
dRepAcceptedRatio ::
forall era.
RatifyEnv era ->
Map (Credential 'DRepRole) Vote ->
GovAction era ->
Rational
dRepAcceptedRatio :: forall era.
RatifyEnv era
-> Map (Credential 'DRepRole) Vote -> GovAction era -> Rational
dRepAcceptedRatio RatifyEnv {Map DRep (CompactForm Coin)
reDRepDistr :: forall era. RatifyEnv era -> Map DRep (CompactForm Coin)
reDRepDistr :: Map DRep (CompactForm Coin)
reDRepDistr, Map (Credential 'DRepRole) DRepState
reDRepState :: forall era. RatifyEnv era -> Map (Credential 'DRepRole) DRepState
reDRepState :: Map (Credential 'DRepRole) DRepState
reDRepState, EpochNo
reCurrentEpoch :: EpochNo
reCurrentEpoch :: forall era. RatifyEnv era -> EpochNo
reCurrentEpoch} Map (Credential 'DRepRole) Vote
gasDRepVotes GovAction era
govAction
| Word64
totalExcludingAbstainStake forall a. Eq a => a -> a -> Bool
== Word64
0 = Rational
0
| Bool
otherwise = forall a. Integral a => a -> Integer
toInteger Word64
yesStake forall a. Integral a => a -> a -> Ratio a
% forall a. Integral a => a -> Integer
toInteger Word64
totalExcludingAbstainStake
where
accumStake :: (Word64, Word64) -> DRep -> CompactForm Coin -> (Word64, Word64)
accumStake (!Word64
yes, !Word64
tot) DRep
drep (CompactCoin Word64
stake) =
case DRep
drep of
DRepCredential Credential 'DRepRole
cred ->
case forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup Credential 'DRepRole
cred Map (Credential 'DRepRole) DRepState
reDRepState of
Maybe DRepState
Nothing -> (Word64
yes, Word64
tot)
Just DRepState
drepState
| EpochNo
reCurrentEpoch forall a. Ord a => a -> a -> Bool
> DRepState -> EpochNo
drepExpiry DRepState
drepState -> (Word64
yes, Word64
tot)
| Bool
otherwise ->
case forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup Credential 'DRepRole
cred Map (Credential 'DRepRole) Vote
gasDRepVotes of
Maybe Vote
Nothing -> (Word64
yes, Word64
tot forall a. Num a => a -> a -> a
+ Word64
stake)
Just Vote
VoteYes -> (Word64
yes forall a. Num a => a -> a -> a
+ Word64
stake, Word64
tot forall a. Num a => a -> a -> a
+ Word64
stake)
Just Vote
Abstain -> (Word64
yes, Word64
tot)
Just Vote
VoteNo -> (Word64
yes, Word64
tot forall a. Num a => a -> a -> a
+ Word64
stake)
DRep
DRepAlwaysNoConfidence ->
case GovAction era
govAction of
NoConfidence StrictMaybe (GovPurposeId 'CommitteePurpose era)
_ -> (Word64
yes forall a. Num a => a -> a -> a
+ Word64
stake, Word64
tot forall a. Num a => a -> a -> a
+ Word64
stake)
GovAction era
_ -> (Word64
yes, Word64
tot forall a. Num a => a -> a -> a
+ Word64
stake)
DRep
DRepAlwaysAbstain -> (Word64
yes, Word64
tot)
(Word64
yesStake, Word64
totalExcludingAbstainStake) = forall a k b. (a -> k -> b -> a) -> a -> Map k b -> a
Map.foldlWithKey' (Word64, Word64) -> DRep -> CompactForm Coin -> (Word64, Word64)
accumStake (Word64
0, Word64
0) Map DRep (CompactForm Coin)
reDRepDistr
delayingAction :: GovAction era -> Bool
delayingAction :: forall era. GovAction era -> Bool
delayingAction NoConfidence {} = Bool
True
delayingAction HardForkInitiation {} = Bool
True
delayingAction UpdateCommittee {} = Bool
True
delayingAction NewConstitution {} = Bool
True
delayingAction TreasuryWithdrawals {} = Bool
False
delayingAction ParameterChange {} = Bool
False
delayingAction InfoAction {} = Bool
False
withdrawalCanWithdraw :: GovAction era -> Coin -> Bool
withdrawalCanWithdraw :: forall era. GovAction era -> Coin -> Bool
withdrawalCanWithdraw (TreasuryWithdrawals Map RewardAccount Coin
m StrictMaybe ScriptHash
_) Coin
treasury =
forall a b k. (a -> b -> b) -> b -> Map k a -> b
Map.foldr' forall t. Val t => t -> t -> t
(<+>) forall t. Val t => t
zero Map RewardAccount Coin
m forall a. Ord a => a -> a -> Bool
<= Coin
treasury
withdrawalCanWithdraw GovAction era
_ Coin
_ = Bool
True
acceptedByEveryone ::
ConwayEraPParams era =>
RatifyEnv era ->
RatifyState era ->
GovActionState era ->
Bool
acceptedByEveryone :: forall era.
ConwayEraPParams era =>
RatifyEnv era -> RatifyState era -> GovActionState era -> Bool
acceptedByEveryone RatifyEnv era
env RatifyState era
st GovActionState era
gas =
forall era.
ConwayEraPParams era =>
RatifyEnv era -> RatifyState era -> GovActionState era -> Bool
committeeAccepted RatifyEnv era
env RatifyState era
st GovActionState era
gas
Bool -> Bool -> Bool
&& forall era.
ConwayEraPParams era =>
RatifyEnv era -> RatifyState era -> GovActionState era -> Bool
spoAccepted RatifyEnv era
env RatifyState era
st GovActionState era
gas
Bool -> Bool -> Bool
&& forall era.
ConwayEraPParams era =>
RatifyEnv era -> RatifyState era -> GovActionState era -> Bool
dRepAccepted RatifyEnv era
env RatifyState era
st GovActionState era
gas
ratifyTransition ::
forall era.
( Embed (EraRule "ENACT" era) (ConwayRATIFY era)
, State (EraRule "ENACT" era) ~ EnactState era
, Environment (EraRule "ENACT" era) ~ ()
, Signal (EraRule "ENACT" era) ~ EnactSignal era
, ConwayEraPParams era
) =>
TransitionRule (ConwayRATIFY era)
ratifyTransition :: forall era.
(Embed (EraRule "ENACT" era) (ConwayRATIFY era),
State (EraRule "ENACT" era) ~ EnactState era,
Environment (EraRule "ENACT" era) ~ (),
Signal (EraRule "ENACT" era) ~ EnactSignal era,
ConwayEraPParams era) =>
TransitionRule (ConwayRATIFY era)
ratifyTransition = do
TRC
( env :: Environment (ConwayRATIFY era)
env@RatifyEnv {EpochNo
reCurrentEpoch :: EpochNo
reCurrentEpoch :: forall era. RatifyEnv era -> EpochNo
reCurrentEpoch}
, st :: State (ConwayRATIFY era)
st@( RatifyState
rsEnactState :: EnactState era
rsEnactState@EnactState
{ PParams era
ensCurPParams :: forall era. EnactState era -> PParams era
ensCurPParams :: PParams era
ensCurPParams
, Coin
ensTreasury :: forall era. EnactState era -> Coin
ensTreasury :: Coin
ensTreasury
, GovRelation StrictMaybe era
ensPrevGovActionIds :: forall era. EnactState era -> GovRelation StrictMaybe era
ensPrevGovActionIds :: GovRelation StrictMaybe era
ensPrevGovActionIds
}
Seq (GovActionState era)
_rsEnacted
Set GovActionId
_rsExpired
Bool
rsDelayed
)
, RatifySignal StrictSeq (GovActionState era)
rsig
) <-
forall sts (rtype :: RuleType).
Rule sts rtype (RuleContext rtype sts)
judgmentContext
case StrictSeq (GovActionState era)
rsig of
gas :: GovActionState era
gas@GovActionState {GovActionId
gasId :: forall era. GovActionState era -> GovActionId
gasId :: GovActionId
gasId, EpochNo
gasExpiresAfter :: forall era. GovActionState era -> EpochNo
gasExpiresAfter :: EpochNo
gasExpiresAfter} SSeq.:<| StrictSeq (GovActionState era)
sigs -> do
let govAction :: GovAction era
govAction = forall era. GovActionState era -> GovAction era
gasAction GovActionState era
gas
if forall era.
GovActionState era -> GovRelation StrictMaybe era -> Bool
prevActionAsExpected GovActionState era
gas GovRelation StrictMaybe era
ensPrevGovActionIds
Bool -> Bool -> Bool
&& forall era.
ConwayEraPParams era =>
GovAction era -> PParams era -> EpochNo -> Bool
validCommitteeTerm GovAction era
govAction PParams era
ensCurPParams EpochNo
reCurrentEpoch
Bool -> Bool -> Bool
&& Bool -> Bool
not Bool
rsDelayed
Bool -> Bool -> Bool
&& forall era. GovAction era -> Coin -> Bool
withdrawalCanWithdraw GovAction era
govAction Coin
ensTreasury
Bool -> Bool -> Bool
&& forall era.
ConwayEraPParams era =>
RatifyEnv era -> RatifyState era -> GovActionState era -> Bool
acceptedByEveryone Environment (ConwayRATIFY era)
env State (ConwayRATIFY era)
st GovActionState era
gas
then do
EnactState era
newEnactState <-
forall sub super (rtype :: RuleType).
Embed sub super =>
RuleContext rtype sub -> Rule super rtype (State sub)
trans @(EraRule "ENACT" era) forall a b. (a -> b) -> a -> b
$
forall sts. (Environment sts, State sts, Signal sts) -> TRC sts
TRC ((), EnactState era
rsEnactState, forall era. GovActionId -> GovAction era -> EnactSignal era
EnactSignal GovActionId
gasId GovAction era
govAction)
let
st' :: RatifyState era
st' =
State (ConwayRATIFY era)
st
forall a b. a -> (a -> b) -> b
& forall era. Lens' (RatifyState era) (EnactState era)
rsEnactStateL forall s t a b. ASetter s t a b -> b -> s -> t
.~ EnactState era
newEnactState
forall a b. a -> (a -> b) -> b
& forall era. Lens' (RatifyState era) Bool
rsDelayedL forall s t a b. ASetter s t a b -> b -> s -> t
.~ forall era. GovAction era -> Bool
delayingAction GovAction era
govAction
forall a b. a -> (a -> b) -> b
& forall era. Lens' (RatifyState era) (Seq (GovActionState era))
rsEnactedL forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ (forall a. Seq a -> a -> Seq a
Seq.:|> GovActionState era
gas)
forall sub super (rtype :: RuleType).
Embed sub super =>
RuleContext rtype sub -> Rule super rtype (State sub)
trans @(ConwayRATIFY era) forall a b. (a -> b) -> a -> b
$ forall sts. (Environment sts, State sts, Signal sts) -> TRC sts
TRC (Environment (ConwayRATIFY era)
env, RatifyState era
st', forall era. StrictSeq (GovActionState era) -> RatifySignal era
RatifySignal StrictSeq (GovActionState era)
sigs)
else do
RatifyState era
st' <- forall sub super (rtype :: RuleType).
Embed sub super =>
RuleContext rtype sub -> Rule super rtype (State sub)
trans @(ConwayRATIFY era) forall a b. (a -> b) -> a -> b
$ forall sts. (Environment sts, State sts, Signal sts) -> TRC sts
TRC (Environment (ConwayRATIFY era)
env, State (ConwayRATIFY era)
st, forall era. StrictSeq (GovActionState era) -> RatifySignal era
RatifySignal StrictSeq (GovActionState era)
sigs)
if EpochNo
gasExpiresAfter forall a. Ord a => a -> a -> Bool
< EpochNo
reCurrentEpoch
then forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ RatifyState era
st' forall a b. a -> (a -> b) -> b
& forall era. Lens' (RatifyState era) (Set GovActionId)
rsExpiredL forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ forall a. Ord a => a -> Set a -> Set a
Set.insert GovActionId
gasId
else forall (f :: * -> *) a. Applicative f => a -> f a
pure RatifyState era
st'
StrictSeq (GovActionState era)
SSeq.Empty -> forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ State (ConwayRATIFY era)
st forall a b. a -> (a -> b) -> b
& forall era. Lens' (RatifyState era) (EnactState era)
rsEnactStateL forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall era. Lens' (EnactState era) Coin
ensTreasuryL forall s t a b. ASetter s t a b -> b -> s -> t
.~ Integer -> Coin
Coin Integer
0
prevActionAsExpected :: GovActionState era -> GovRelation StrictMaybe era -> Bool
prevActionAsExpected :: forall era.
GovActionState era -> GovRelation StrictMaybe era -> Bool
prevActionAsExpected GovActionState era
gas GovRelation StrictMaybe era
prevGovActionIds =
forall era a.
GovActionState era
-> a
-> (forall (p :: GovActionPurpose).
(forall (f :: * -> *).
Lens' (GovRelation f era) (f (GovPurposeId p era)))
-> StrictMaybe (GovPurposeId p era) -> GovPurposeId p era -> a)
-> a
withGovActionParent GovActionState era
gas Bool
True forall a b. (a -> b) -> a -> b
$ \forall (f :: * -> *).
Lens' (GovRelation f era) (f (GovPurposeId p era))
govRelationL StrictMaybe (GovPurposeId p era)
parent GovPurposeId p era
_ ->
StrictMaybe (GovPurposeId p era)
parent forall a. Eq a => a -> a -> Bool
== GovRelation StrictMaybe era
prevGovActionIds forall s a. s -> Getting a s a -> a
^. forall (f :: * -> *).
Lens' (GovRelation f era) (f (GovPurposeId p era))
govRelationL
validCommitteeTerm ::
ConwayEraPParams era =>
GovAction era ->
PParams era ->
EpochNo ->
Bool
validCommitteeTerm :: forall era.
ConwayEraPParams era =>
GovAction era -> PParams era -> EpochNo -> Bool
validCommitteeTerm GovAction era
govAction PParams era
pp EpochNo
currentEpoch =
case GovAction era
govAction of
UpdateCommittee StrictMaybe (GovPurposeId 'CommitteePurpose era)
_ Set (Credential 'ColdCommitteeRole)
_ Map (Credential 'ColdCommitteeRole) EpochNo
newMembers UnitInterval
_ -> Map (Credential 'ColdCommitteeRole) EpochNo -> Bool
withinMaxTermLength Map (Credential 'ColdCommitteeRole) EpochNo
newMembers
GovAction era
_ -> Bool
True
where
committeeMaxTermLength :: EpochInterval
committeeMaxTermLength = PParams era
pp forall s a. s -> Getting a s a -> a
^. forall era.
ConwayEraPParams era =>
Lens' (PParams era) EpochInterval
ppCommitteeMaxTermLengthL
withinMaxTermLength :: Map (Credential 'ColdCommitteeRole) EpochNo -> Bool
withinMaxTermLength = forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all (forall a. Ord a => a -> a -> Bool
<= EpochNo -> EpochInterval -> EpochNo
addEpochInterval EpochNo
currentEpoch EpochInterval
committeeMaxTermLength)
instance EraGov era => Embed (ConwayENACT era) (ConwayRATIFY era) where
wrapFailed :: PredicateFailure (ConwayENACT era)
-> PredicateFailure (ConwayRATIFY era)
wrapFailed = forall a. Void -> a
absurd
wrapEvent :: Event (ConwayENACT era) -> Event (ConwayRATIFY era)
wrapEvent = forall a. Void -> a
absurd