1
1
{-# LANGUAGE DataKinds #-}
2
2
{-# LANGUAGE FlexibleContexts #-}
3
3
{-# LANGUAGE GADTs #-}
4
- {-# LANGUAGE NamedFieldPuns #-}
5
4
{-# LANGUAGE ScopedTypeVariables #-}
6
5
{-# LANGUAGE TypeApplications #-}
7
6
{-# LANGUAGE TypeOperators #-}
@@ -14,9 +13,8 @@ module Test.Consensus.Cardano.ProtocolInfo (
14
13
, ShelleySlotLengthInSeconds (.. )
15
14
-- ** Hard-fork specification
16
15
, Era (.. )
17
- , HardForkSpec (.. )
18
16
, hardForkInto
19
- , stayInByron
17
+ , hardForkOnDefaultProtocolVersions
20
18
-- * ProtocolInfo elaboration
21
19
, mkSimpleTestProtocolInfo
22
20
, mkTestProtocolInfo
@@ -31,6 +29,7 @@ import qualified Cardano.Ledger.BaseTypes as SL
31
29
import qualified Cardano.Protocol.TPraos.OCert as SL
32
30
import qualified Cardano.Slotting.Time as Time
33
31
import Data.Proxy (Proxy (.. ))
32
+ import Data.SOP.Strict
34
33
import Data.Word (Word64 )
35
34
import Ouroboros.Consensus.Block.Forging (BlockForging )
36
35
import Ouroboros.Consensus.BlockchainTime (SlotLength )
@@ -39,9 +38,8 @@ import Ouroboros.Consensus.Byron.Node (ByronLeaderCredentials,
39
38
byronPbftSignatureThreshold , byronSoftwareVersion )
40
39
import Ouroboros.Consensus.Cardano.Block (CardanoBlock )
41
40
import Ouroboros.Consensus.Cardano.Node (CardanoHardForkConstraints ,
42
- CardanoHardForkTriggers (.. ), CardanoProtocolParams (.. ),
43
- TriggerHardFork (TriggerHardForkAtEpoch , TriggerHardForkNotDuringThisExecution ),
44
- protocolInfoCardano )
41
+ CardanoHardForkTrigger (.. ), CardanoHardForkTriggers (.. ),
42
+ CardanoProtocolParams (.. ), protocolInfoCardano )
45
43
import Ouroboros.Consensus.Config (emptyCheckpointsMap )
46
44
import Ouroboros.Consensus.Config.SecurityParam (SecurityParam (.. ))
47
45
import Ouroboros.Consensus.Node.ProtocolInfo (NumCoreNodes (.. ),
@@ -77,19 +75,6 @@ instance ToSlotLength ByronSlotLengthInSeconds where
77
75
instance ToSlotLength ShelleySlotLengthInSeconds where
78
76
toSlotLength (ShelleySlotLengthInSeconds n) = Time. slotLengthFromSec $ fromIntegral n
79
77
80
- -- | This data structure is used to specify if and when hardforks should take
81
- -- place, and the version used at each era. See 'stayInByron' and 'hardForkInto'
82
- -- for examples.
83
- data HardForkSpec =
84
- HardForkSpec {
85
- shelleyHardForkSpec :: TriggerHardFork
86
- , allegraHardForkSpec :: TriggerHardFork
87
- , maryHardForkSpec :: TriggerHardFork
88
- , alonzoHardForkSpec :: TriggerHardFork
89
- , babbageHardForkSpec :: TriggerHardFork
90
- , conwayHardForkSpec :: TriggerHardFork
91
- }
92
-
93
78
data Era = Byron
94
79
| Shelley
95
80
| Allegra
@@ -99,52 +84,37 @@ data Era = Byron
99
84
| Conway
100
85
deriving (Show , Eq , Ord , Enum )
101
86
102
- selectEra :: Era -> HardForkSpec -> TriggerHardFork
103
- selectEra Byron _ = error " Byron is the first era, therefore there is no hard fork spec."
104
- selectEra Shelley HardForkSpec { shelleyHardForkSpec } = shelleyHardForkSpec
105
- selectEra Allegra HardForkSpec { allegraHardForkSpec } = allegraHardForkSpec
106
- selectEra Mary HardForkSpec { maryHardForkSpec } = maryHardForkSpec
107
- selectEra Alonzo HardForkSpec { alonzoHardForkSpec } = alonzoHardForkSpec
108
- selectEra Babbage HardForkSpec { babbageHardForkSpec } = babbageHardForkSpec
109
- selectEra Conway HardForkSpec { conwayHardForkSpec } = conwayHardForkSpec
110
-
111
- stayInByron :: HardForkSpec
112
- stayInByron =
113
- HardForkSpec {
114
- shelleyHardForkSpec = TriggerHardForkNotDuringThisExecution
115
- , allegraHardForkSpec = TriggerHardForkNotDuringThisExecution
116
- , maryHardForkSpec = TriggerHardForkNotDuringThisExecution
117
- , alonzoHardForkSpec = TriggerHardForkNotDuringThisExecution
118
- , babbageHardForkSpec = TriggerHardForkNotDuringThisExecution
119
- , conwayHardForkSpec = TriggerHardForkNotDuringThisExecution
120
- }
121
-
122
87
protocolVersionZero :: SL. ProtVer
123
88
protocolVersionZero = SL. ProtVer versionZero 0
124
89
where
125
90
versionZero :: SL. Version
126
91
versionZero = SL. natVersion @ 0
127
92
128
- hardForkInto :: Era -> HardForkSpec
129
- hardForkInto Byron = stayInByron
93
+ hardForkOnDefaultProtocolVersions :: CardanoHardForkTriggers
94
+ hardForkOnDefaultProtocolVersions =
95
+ CardanoHardForkTriggers
96
+ $ hpure CardanoTriggerHardForkAtDefaultVersion
97
+
98
+ hardForkInto :: Era -> CardanoHardForkTriggers
99
+ hardForkInto Byron = hardForkOnDefaultProtocolVersions
130
100
hardForkInto Shelley =
131
- stayInByron
132
- { shelleyHardForkSpec = TriggerHardForkAtEpoch 0 }
101
+ hardForkOnDefaultProtocolVersions
102
+ { triggerHardForkShelley = CardanoTriggerHardForkAtEpoch 0 }
133
103
hardForkInto Allegra =
134
104
(hardForkInto Shelley )
135
- { allegraHardForkSpec = TriggerHardForkAtEpoch 0 }
105
+ { triggerHardForkAllegra = CardanoTriggerHardForkAtEpoch 0 }
136
106
hardForkInto Mary =
137
107
(hardForkInto Allegra )
138
- { maryHardForkSpec = TriggerHardForkAtEpoch 0 }
108
+ { triggerHardForkMary = CardanoTriggerHardForkAtEpoch 0 }
139
109
hardForkInto Alonzo =
140
110
(hardForkInto Mary )
141
- { alonzoHardForkSpec = TriggerHardForkAtEpoch 0 }
111
+ { triggerHardForkAlonzo = CardanoTriggerHardForkAtEpoch 0 }
142
112
hardForkInto Babbage =
143
113
(hardForkInto Alonzo )
144
- { babbageHardForkSpec = TriggerHardForkAtEpoch 0 }
114
+ { triggerHardForkBabbage = CardanoTriggerHardForkAtEpoch 0 }
145
115
hardForkInto Conway =
146
116
(hardForkInto Babbage )
147
- { conwayHardForkSpec = TriggerHardForkAtEpoch 0 }
117
+ { triggerHardForkConway = CardanoTriggerHardForkAtEpoch 0 }
148
118
149
119
{- ------------------------------------------------------------------------------
150
120
ProtocolInfo elaboration
@@ -167,9 +137,10 @@ hardForkInto Conway =
167
137
-- If you want to tweak the resulting protocol info further see
168
138
-- 'mkTestProtocolInfo'.
169
139
--
170
- -- The resulting 'ProtocolInfo' contains a ledger state. The 'HardForkSpec'
171
- -- parameter will determine to which era this ledger state belongs. See
172
- -- 'HardForkSpec' for more details on how to specify a value of this type.
140
+ -- The resulting 'ProtocolInfo' contains a ledger state. The
141
+ -- 'CardanoHardForkTriggers' parameter will determine to which era this ledger
142
+ -- state belongs. See 'hardForkInto' and 'hardForkOnDefaultProtocolVersions' for
143
+ -- more details on how to specify a value of this type.
173
144
--
174
145
mkSimpleTestProtocolInfo ::
175
146
forall c
@@ -180,15 +151,15 @@ mkSimpleTestProtocolInfo ::
180
151
-> ByronSlotLengthInSeconds
181
152
-> ShelleySlotLengthInSeconds
182
153
-> SL. ProtVer
183
- -> HardForkSpec
154
+ -> CardanoHardForkTriggers
184
155
-> ProtocolInfo (CardanoBlock c )
185
156
mkSimpleTestProtocolInfo
186
157
decentralizationParam
187
158
securityParam
188
159
byronSlotLenghtInSeconds
189
160
shelleySlotLengthInSeconds
190
161
protocolVersion
191
- hardForkSpec
162
+ hardForkTriggers
192
163
= fst
193
164
$ mkTestProtocolInfo @ IO
194
165
(CoreNodeId 0 , coreNodeShelley)
@@ -199,7 +170,7 @@ mkSimpleTestProtocolInfo
199
170
generatedSecretsByron
200
171
(Just $ PBftSignatureThreshold 1 )
201
172
protocolVersion
202
- hardForkSpec
173
+ hardForkTriggers
203
174
where
204
175
byronProtocolVersion =
205
176
CC.Update. ProtocolVersion 0 0 0
@@ -258,8 +229,8 @@ mkTestProtocolInfo ::
258
229
-> SL. ProtVer
259
230
-- ^ See 'protocolInfoCardano' for the details of what is the
260
231
-- relation between this version and any 'TriggerHardForkAtVersion'
261
- -- that __might__ appear in the 'HardForkSpec ' parameter.
262
- -> HardForkSpec
232
+ -- that __might__ appear in the 'CardanoHardForkTriggers ' parameter.
233
+ -> CardanoHardForkTriggers
263
234
-- ^ Specification of the era to which the initial state should hard-fork to.
264
235
-> (ProtocolInfo (CardanoBlock c ), m [BlockForging m (CardanoBlock c )])
265
236
mkTestProtocolInfo
@@ -271,7 +242,7 @@ mkTestProtocolInfo
271
242
generatedSecretsByron
272
243
aByronPbftSignatureThreshold
273
244
protocolVersion
274
- hardForkSpec
245
+ hardForkTriggers
275
246
=
276
247
protocolInfoCardano
277
248
(CardanoProtocolParams
@@ -286,14 +257,7 @@ mkTestProtocolInfo
286
257
shelleyBasedInitialNonce = initialNonce
287
258
, shelleyBasedLeaderCredentials = [leaderCredentialsShelley]
288
259
}
289
- CardanoHardForkTriggers' {
290
- triggerHardForkShelley = selectEra Shelley hardForkSpec
291
- , triggerHardForkAllegra = selectEra Allegra hardForkSpec
292
- , triggerHardForkMary = selectEra Mary hardForkSpec
293
- , triggerHardForkAlonzo = selectEra Alonzo hardForkSpec
294
- , triggerHardForkBabbage = selectEra Babbage hardForkSpec
295
- , triggerHardForkConway = selectEra Conway hardForkSpec
296
- }
260
+ hardForkTriggers
297
261
( L. mkLatestTransitionConfig
298
262
shelleyGenesis
299
263
-- These example genesis objects might need to become more
0 commit comments