Skip to content

Commit 53665cc

Browse files
authored
Merge pull request #5098 from IntersectMBO/aniketd/hardfork-triggers
Hardfork triggers
2 parents c476cf2 + 91ecd56 commit 53665cc

File tree

33 files changed

+178
-177
lines changed

33 files changed

+178
-177
lines changed

eras/alonzo/impl/src/Cardano/Ledger/Alonzo/Era.hs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{-# LANGUAGE CPP #-}
22
{-# LANGUAGE DataKinds #-}
3+
{-# LANGUAGE TypeApplications #-}
34
{-# LANGUAGE TypeFamilies #-}
45
{-# OPTIONS_GHC -Wno-orphans #-}
56
#if __GLASGOW_HASKELL__ >= 908
@@ -13,8 +14,10 @@ module Cardano.Ledger.Alonzo.Era (
1314
AlonzoUTXOW,
1415
AlonzoBBODY,
1516
AlonzoLEDGER,
17+
hardforkConwayTranslateUpperBoundForPlutusScripts,
1618
) where
1719

20+
import Cardano.Ledger.BaseTypes (ProtVer (pvMajor), natVersion)
1821
import Cardano.Ledger.Internal.Era (AlonzoEra)
1922
import Cardano.Ledger.Mary (MaryEra, MaryValue)
2023
import Cardano.Ledger.Shelley.Core
@@ -90,3 +93,8 @@ type instance EraRule "TICK" AlonzoEra = ShelleyTICK AlonzoEra
9093
type instance EraRule "TICKF" AlonzoEra = ShelleyTICKF AlonzoEra
9194

9295
type instance EraRule "UPEC" AlonzoEra = ShelleyUPEC AlonzoEra
96+
97+
-- | Starting with protocol version 9, we translate the upper bound of validity
98+
-- interval correctly for Plutus scripts.
99+
hardforkConwayTranslateUpperBoundForPlutusScripts :: ProtVer -> Bool
100+
hardforkConwayTranslateUpperBoundForPlutusScripts pv = pvMajor pv > natVersion @8

eras/alonzo/impl/src/Cardano/Ledger/Alonzo/Plutus/TxInfo.hs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ module Cardano.Ledger.Alonzo.Plutus.TxInfo (
4646

4747
import Cardano.Crypto.Hash.Class (hashToBytes)
4848
import Cardano.Ledger.Alonzo.Core
49-
import Cardano.Ledger.Alonzo.Era (AlonzoEra)
49+
import Cardano.Ledger.Alonzo.Era (AlonzoEra, hardforkConwayTranslateUpperBoundForPlutusScripts)
5050
import Cardano.Ledger.Alonzo.Plutus.Context
5151
import Cardano.Ledger.Alonzo.Scripts (AlonzoPlutusPurpose (..), PlutusScript (..), toAsItem)
5252
import Cardano.Ledger.Alonzo.TxWits (unTxDatsL)
@@ -77,7 +77,6 @@ import Cardano.Ledger.Plutus.Language (
7777
import Cardano.Ledger.Plutus.TxInfo
7878
import Cardano.Ledger.PoolParams (PoolParams (..))
7979
import Cardano.Ledger.Rules.ValidationMode (Inject (..))
80-
import qualified Cardano.Ledger.Shelley.HardForks as HardForks
8180
import Cardano.Ledger.State (UTxO (..))
8281
import Cardano.Ledger.TxIn (TxIn (..), txInToText)
8382
import Cardano.Ledger.Val (zero)
@@ -231,7 +230,7 @@ transValidityInterval _ protVer epochInfo systemStart = \case
231230
ValidityInterval SNothing (SJust i) -> do
232231
t <- transSlotToPOSIXTime i
233232
pure $
234-
if HardForks.translateUpperBoundForPlutusScripts protVer
233+
if hardforkConwayTranslateUpperBoundForPlutusScripts protVer
235234
then
236235
PV1.Interval
237236
(PV1.LowerBound PV1.NegInf True)

eras/conway/impl/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
## 1.20.0.0
44

5+
- Move some hard-fork triggers and export them from `Cardano.Ledger.Conway` module.
6+
- `bootstrapPhase` to `hardforkConwayBootstrapPhase`.
7+
- `disallowUnelectedCommitteeFromVoting` to `hardforkConwayDisallowUnelectedCommitteeFromVoting`.
58
- Add `UnelectedCommitteeVoters` to `ConwayGovPredFailure` #5091
69
- Change the type of `authorizedELectedCommitteeCredentials` to
710
`StrictMaybe (Committee era) -> CommitteeState era -> Set.Set (Credential 'HotCommitteeRole)` #5091

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,16 @@
88
module Cardano.Ledger.Conway (
99
Conway,
1010
ConwayEra,
11+
hardforkConwayBootstrapPhase,
12+
hardforkConwayDisallowUnelectedCommitteeFromVoting,
1113
) where
1214

1315
import Cardano.Ledger.Babbage.TxBody ()
14-
import Cardano.Ledger.Conway.Era (ConwayEra)
16+
import Cardano.Ledger.Conway.Era (
17+
ConwayEra,
18+
hardforkConwayBootstrapPhase,
19+
hardforkConwayDisallowUnelectedCommitteeFromVoting,
20+
)
1521
import Cardano.Ledger.Conway.Governance (RunConwayRatify (..))
1622
import Cardano.Ledger.Conway.Rules ()
1723
import Cardano.Ledger.Conway.State ()

eras/conway/impl/src/Cardano/Ledger/Conway/Era.hs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{-# LANGUAGE CPP #-}
22
{-# LANGUAGE DataKinds #-}
3+
{-# LANGUAGE TypeApplications #-}
34
{-# LANGUAGE TypeFamilies #-}
45
{-# OPTIONS_GHC -Wno-orphans #-}
56
#if __GLASGOW_HASKELL__ >= 908
@@ -25,9 +26,12 @@ module Cardano.Ledger.Conway.Era (
2526
ConwayTICKF,
2627
ConwayLEDGER,
2728
ConwayRATIFY,
29+
hardforkConwayBootstrapPhase,
30+
hardforkConwayDisallowUnelectedCommitteeFromVoting,
2831
) where
2932

3033
import Cardano.Ledger.Babbage (BabbageEra)
34+
import Cardano.Ledger.BaseTypes (ProtVer (pvMajor), natVersion)
3135
import Cardano.Ledger.Core
3236
import Cardano.Ledger.Internal.Era (ConwayEra)
3337
import Cardano.Ledger.Mary.Value (MaryValue)
@@ -170,4 +174,11 @@ type instance EraRule "TICK" ConwayEra = ShelleyTICK ConwayEra
170174

171175
type instance EraRule "POOL" ConwayEra = ShelleyPOOL ConwayEra
172176

173-
-- =================================================
177+
-- | Bootstrap phase
178+
hardforkConwayBootstrapPhase :: ProtVer -> Bool
179+
hardforkConwayBootstrapPhase pv = pvMajor pv == natVersion @9
180+
181+
-- | Starting with protocol version 11, we do not allow unelected committee
182+
-- members to submit votes.
183+
hardforkConwayDisallowUnelectedCommitteeFromVoting :: ProtVer -> Bool
184+
hardforkConwayDisallowUnelectedCommitteeFromVoting pv = pvMajor pv > natVersion @10

eras/conway/impl/src/Cardano/Ledger/Conway/Governance/Internal.hs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
{-# LANGUAGE DataKinds #-}
22
{-# LANGUAGE DeriveGeneric #-}
3-
{-# LANGUAGE DerivingStrategies #-}
43
{-# LANGUAGE DerivingVia #-}
54
{-# LANGUAGE FlexibleContexts #-}
65
{-# LANGUAGE FlexibleInstances #-}
76
{-# LANGUAGE LambdaCase #-}
8-
{-# LANGUAGE MonoLocalBinds #-}
97
{-# LANGUAGE MultiParamTypeClasses #-}
108
{-# LANGUAGE NamedFieldPuns #-}
119
{-# LANGUAGE OverloadedStrings #-}
@@ -92,6 +90,7 @@ import Cardano.Ledger.Binary.Coders (
9290
(<!),
9391
)
9492
import Cardano.Ledger.Coin (Coin (..))
93+
import Cardano.Ledger.Conway.Era (hardforkConwayBootstrapPhase)
9594
import Cardano.Ledger.Conway.Governance.Procedures
9695
import Cardano.Ledger.Conway.PParams (
9796
ConwayEraPParams (..),
@@ -112,7 +111,6 @@ import Cardano.Ledger.Conway.State
112111
import Cardano.Ledger.Core
113112
import Cardano.Ledger.Credential (Credential (..))
114113
import Cardano.Ledger.PoolParams (PoolParams)
115-
import qualified Cardano.Ledger.Shelley.HardForks as HF (bootstrapPhase)
116114
import Cardano.Ledger.Shelley.LedgerState (
117115
epochStateStakeDistrL,
118116
epochStateUMapL,
@@ -479,7 +477,7 @@ votingCommitteeThresholdInternal currentEpoch pp committee (CommitteeState hotKe
479477
-- if the committee size is smaller than the minimum given in PParams,
480478
-- we treat it as if we had no committee
481479
SJust t
482-
| HF.bootstrapPhase (pp ^. ppProtocolVersionL)
480+
| hardforkConwayBootstrapPhase (pp ^. ppProtocolVersionL)
483481
|| activeCommitteeSize >= minSize ->
484482
VotingThreshold t
485483
_ -> NoVotingThreshold
@@ -531,7 +529,7 @@ votingDRepThresholdInternal pp isElectedCommittee action =
531529
, dvtHardForkInitiation
532530
, dvtTreasuryWithdrawal
533531
} -- We reset all (except InfoAction) DRep thresholds to 0 during bootstrap phase
534-
| HF.bootstrapPhase (pp ^. ppProtocolVersionL) = def
532+
| hardforkConwayBootstrapPhase (pp ^. ppProtocolVersionL) = def
535533
| otherwise = pp ^. ppDRepVotingThresholdsL
536534
in case action of
537535
NoConfidence {} -> VotingThreshold dvtMotionNoConfidence

eras/conway/impl/src/Cardano/Ledger/Conway/PParams.hs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
{-# LANGUAGE StandaloneDeriving #-}
1717
{-# LANGUAGE TypeApplications #-}
1818
{-# LANGUAGE TypeFamilies #-}
19-
{-# LANGUAGE TypeOperators #-}
2019
{-# LANGUAGE UndecidableInstances #-}
2120
{-# LANGUAGE UndecidableSuperClasses #-}
2221
{-# OPTIONS_GHC -Wno-orphans #-}
@@ -115,7 +114,7 @@ import Cardano.Ledger.Binary (
115114
)
116115
import Cardano.Ledger.Binary.Coders
117116
import Cardano.Ledger.Coin (Coin (Coin))
118-
import Cardano.Ledger.Conway.Era (ConwayEra)
117+
import Cardano.Ledger.Conway.Era (ConwayEra, hardforkConwayBootstrapPhase)
119118
import Cardano.Ledger.Core (EraPParams (..))
120119
import Cardano.Ledger.HKD (
121120
HKDApplicative (hkdLiftA2),
@@ -132,7 +131,6 @@ import Cardano.Ledger.Plutus.CostModels (
132131
)
133132
import Cardano.Ledger.Plutus.Language (Language (PlutusV3))
134133
import Cardano.Ledger.Plutus.ToPlutusData (ToPlutusData (..))
135-
import Cardano.Ledger.Shelley.HardForks (bootstrapPhase)
136134
import Cardano.Ledger.Shelley.PParams
137135
import Cardano.Ledger.Val (Val (..))
138136
import Control.DeepSeq (NFData (..), rwhnf)
@@ -888,7 +886,7 @@ instance ConwayEraPParams ConwayEra where
888886
isValid (/= zero) ppuPoolDepositL
889887
, isValid (/= zero) ppuGovActionDepositL
890888
, isValid (/= zero) ppuDRepDepositL
891-
, bootstrapPhase pv
889+
, hardforkConwayBootstrapPhase pv
892890
|| isValid ((/= zero) . unCoinPerByte) ppuCoinsPerUTxOByteL
893891
, ppu /= emptyPParamsUpdate
894892
]

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
{-# LANGUAGE FlexibleContexts #-}
66
{-# LANGUAGE LambdaCase #-}
77
{-# LANGUAGE MultiParamTypeClasses #-}
8-
{-# LANGUAGE NamedFieldPuns #-}
98
{-# LANGUAGE OverloadedStrings #-}
109
{-# LANGUAGE RecordWildCards #-}
1110
{-# LANGUAGE ScopedTypeVariables #-}
@@ -35,7 +34,7 @@ import Cardano.Ledger.Binary.Coders (
3534
)
3635
import Cardano.Ledger.Coin (Coin)
3736
import Cardano.Ledger.Conway.Core
38-
import Cardano.Ledger.Conway.Era (ConwayDELEG, ConwayEra)
37+
import Cardano.Ledger.Conway.Era (ConwayDELEG, ConwayEra, hardforkConwayBootstrapPhase)
3938
import Cardano.Ledger.Conway.State (
4039
ConwayEraCertState (..),
4140
vsDRepsL,
@@ -47,7 +46,6 @@ import Cardano.Ledger.Conway.TxCert (
4746
import Cardano.Ledger.Credential (Credential)
4847
import Cardano.Ledger.DRep (DRep (..), DRepState (..))
4948
import Cardano.Ledger.PoolParams (PoolParams)
50-
import qualified Cardano.Ledger.Shelley.HardForks as HF
5149
import Cardano.Ledger.State (
5250
EraCertState (..),
5351
dsUnifiedL,
@@ -196,7 +194,7 @@ conwayDelegTransition = do
196194
DRepAlwaysNoConfidence -> pure ()
197195
DRepCredential targetDRep -> do
198196
let dReps = certState ^. certVStateL . vsDRepsL
199-
unless (HF.bootstrapPhase (pp ^. ppProtocolVersionL)) $
197+
unless (hardforkConwayBootstrapPhase (pp ^. ppProtocolVersionL)) $
200198
targetDRep `Map.member` dReps ?! DelegateeDRepNotRegisteredDELEG targetDRep
201199
in \case
202200
DelegStake targetPool -> checkPoolRegistered targetPool

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

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,12 @@ import Cardano.Ledger.Binary.Coders (
6060
)
6161
import Cardano.Ledger.Coin (Coin (..))
6262
import Cardano.Ledger.Conway.Core (ppGovActionDepositL, ppGovActionLifetimeL)
63-
import Cardano.Ledger.Conway.Era (ConwayEra, ConwayGOV)
63+
import Cardano.Ledger.Conway.Era (
64+
ConwayEra,
65+
ConwayGOV,
66+
hardforkConwayBootstrapPhase,
67+
hardforkConwayDisallowUnelectedCommitteeFromVoting,
68+
)
6469
import Cardano.Ledger.Conway.Governance (
6570
Committee,
6671
ConwayEraGov,
@@ -104,10 +109,6 @@ import Cardano.Ledger.Conway.TxCert
104109
import Cardano.Ledger.Core
105110
import Cardano.Ledger.Credential (Credential)
106111
import Cardano.Ledger.Rules.ValidationMode (Test, runTest)
107-
import qualified Cardano.Ledger.Shelley.HardForks as HF (
108-
bootstrapPhase,
109-
disallowUnelectedCommitteeFromVoting,
110-
)
111112
import Cardano.Ledger.Shelley.LedgerState (dsUnifiedL)
112113
import Cardano.Ledger.Shelley.PParams (pvCanFollow)
113114
import Cardano.Ledger.State (
@@ -387,7 +388,7 @@ checkBootstrapVotes ::
387388
[(Voter, GovActionState era)] ->
388389
Test (ConwayGovPredFailure era)
389390
checkBootstrapVotes pp votes
390-
| HF.bootstrapPhase (pp ^. ppProtocolVersionL) =
391+
| hardforkConwayBootstrapPhase (pp ^. ppProtocolVersionL) =
391392
checkDisallowedVotes votes DisallowedVotesDuringBootstrap $ \gas ->
392393
\case
393394
DRepVoter {} | gasAction gas == InfoAction -> True
@@ -436,7 +437,7 @@ checkBootstrapProposal ::
436437
ProposalProcedure era ->
437438
Test (ConwayGovPredFailure era)
438439
checkBootstrapProposal pp proposal@ProposalProcedure {pProcGovAction}
439-
| HF.bootstrapPhase (pp ^. ppProtocolVersionL) =
440+
| hardforkConwayBootstrapPhase (pp ^. ppProtocolVersionL) =
440441
failureUnless (isBootstrapAction pProcGovAction) $ DisallowedProposalDuringBootstrap proposal
441442
| otherwise = pure ()
442443

@@ -474,7 +475,7 @@ govTransition = do
474475

475476
expectedNetworkId <- liftSTS $ asks networkId
476477

477-
when (HF.disallowUnelectedCommitteeFromVoting $ pp ^. ppProtocolVersionL) $
478+
when (hardforkConwayDisallowUnelectedCommitteeFromVoting $ pp ^. ppProtocolVersionL) $
478479
failOnNonEmpty
479480
(unelectedCommitteeVoters committee committeeState gsVotingProcedures)
480481
UnelectedCommitteeVoters
@@ -502,7 +503,7 @@ govTransition = do
502503
-- PParamsUpdate well-formedness check
503504
runTest $ actionWellFormed (pp ^. ppProtocolVersionL) pProcGovAction
504505

505-
unless (HF.bootstrapPhase $ pp ^. ppProtocolVersionL) $ do
506+
unless (hardforkConwayBootstrapPhase $ pp ^. ppProtocolVersionL) $ do
506507
let refundAddress = proposal ^. pProcReturnAddrL
507508
govAction = proposal ^. pProcGovActionL
508509
UMap.member' (raCredential refundAddress) (certDState ^. dsUnifiedL)
@@ -541,7 +542,7 @@ govTransition = do
541542
-- Policy check
542543
runTest $ checkPolicy @era constitutionPolicy proposalPolicy
543544

544-
unless (HF.bootstrapPhase (pp ^. ppProtocolVersionL)) $
545+
unless (hardforkConwayBootstrapPhase $ pp ^. ppProtocolVersionL) $
545546
-- The sum of all withdrawals must be positive
546547
F.fold wdrls /= mempty ?! ZeroTreasuryWithdrawals pProcGovAction
547548
UpdateCommittee _mPrevGovActionId membersToRemove membersToAdd _qrm -> do

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import Cardano.Ledger.Binary (
3838
import Cardano.Ledger.Binary.Coders
3939
import Cardano.Ledger.Coin (Coin)
4040
import Cardano.Ledger.Conway.Core
41-
import Cardano.Ledger.Conway.Era (ConwayEra, ConwayGOVCERT)
41+
import Cardano.Ledger.Conway.Era (ConwayEra, ConwayGOVCERT, hardforkConwayBootstrapPhase)
4242
import Cardano.Ledger.Conway.Governance (
4343
Committee (..),
4444
GovAction (..),
@@ -58,7 +58,6 @@ import Cardano.Ledger.Conway.State (
5858
import Cardano.Ledger.Conway.TxCert (ConwayGovCert (..))
5959
import Cardano.Ledger.Credential (Credential)
6060
import Cardano.Ledger.DRep (DRepState (..), drepAnchorL, drepDepositL, drepExpiryL)
61-
import qualified Cardano.Ledger.Shelley.HardForks as HF (bootstrapPhase)
6261
import Cardano.Ledger.State (
6362
CommitteeAuthorization (..),
6463
CommitteeState (..),
@@ -291,7 +290,7 @@ computeDRepExpiryVersioned ::
291290
computeDRepExpiryVersioned pp currentEpoch numDormantEpochs
292291
-- Starting with version 10, we correctly take into account the number of dormant epochs
293292
-- when registering a drep
294-
| HF.bootstrapPhase (pp ^. ppProtocolVersionL) =
293+
| hardforkConwayBootstrapPhase (pp ^. ppProtocolVersionL) =
295294
addEpochInterval currentEpoch (pp ^. ppDRepActivityL)
296295
| otherwise =
297296
computeDRepExpiry (pp ^. ppDRepActivityL) currentEpoch numDormantEpochs

0 commit comments

Comments
 (0)