-
Notifications
You must be signed in to change notification settings - Fork 720
/
GenesisParameters.hs
139 lines (113 loc) · 4.97 KB
/
GenesisParameters.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
-- | Parameters fixed in the genesis file: 'GenesisParameters'
--
module Cardano.Api.GenesisParameters (
-- * Protocol parameters fixed in the genesis file
GenesisParameters(..),
EpochSize(..),
-- * Internal conversion functions
fromShelleyGenesis,
) where
import Prelude
import Data.Time (NominalDiffTime, UTCTime)
import Cardano.Slotting.Slot (EpochSize (..))
import qualified Cardano.Ledger.BaseTypes as Ledger
import qualified Cardano.Ledger.Shelley.Genesis as Shelley
import Cardano.Api.NetworkId
import Cardano.Api.ProtocolParameters
import Cardano.Api.Value
-- ----------------------------------------------------------------------------
-- Genesis parameters
--
data GenesisParameters =
GenesisParameters {
-- | The reference time the system started. The time of slot zero.
-- The time epoch against which all Ouroboros time slots are measured.
--
protocolParamSystemStart :: UTCTime,
-- | The network identifier for this blockchain instance. This
-- distinguishes the mainnet from testnets, and different testnets from
-- each other.
--
protocolParamNetworkId :: NetworkId,
-- | The Ouroboros Praos active slot coefficient, aka @f@.
--
protocolParamActiveSlotsCoefficient :: Rational,
-- | The Ouroboros security parameters, aka @k@. This is the maximum
-- number of blocks the node would ever be prepared to roll back by.
--
-- Clients of the node following the chain should be prepared to handle
-- the node switching forks up to this long.
--
protocolParamSecurity :: Int,
-- | The number of Ouroboros time slots in an Ouroboros epoch.
--
protocolParamEpochLength :: EpochSize,
-- | The time duration of a slot.
--
protocolParamSlotLength :: NominalDiffTime,
-- | For Ouroboros Praos, the length of a KES period as a number of time
-- slots. The KES keys get evolved once per KES period.
--
protocolParamSlotsPerKESPeriod :: Int,
-- | The maximum number of times a KES key can be evolved before it is
-- no longer considered valid. This can be less than the maximum number
-- of times given the KES key size. For example the mainnet KES key size
-- would allow 64 evolutions, but the max KES evolutions param is 62.
--
protocolParamMaxKESEvolutions :: Int,
-- | In the Shelley era, prior to decentralised governance, this is the
-- number of genesis key delegates that need to agree for an update
-- proposal to be enacted.
--
protocolParamUpdateQuorum :: Int,
-- | The maximum supply for Lovelace. This determines the initial value
-- of the reserves.
--
protocolParamMaxLovelaceSupply :: Lovelace,
-- | The initial values of the updateable 'ProtocolParameters'.
--
protocolInitialUpdateableProtocolParameters :: ProtocolParameters
}
-- ----------------------------------------------------------------------------
-- Conversion functions
--
fromShelleyGenesis :: Shelley.ShelleyGenesis era -> GenesisParameters
fromShelleyGenesis
Shelley.ShelleyGenesis {
Shelley.sgSystemStart
, Shelley.sgNetworkMagic
, Shelley.sgNetworkId
, Shelley.sgActiveSlotsCoeff
, Shelley.sgSecurityParam
, Shelley.sgEpochLength
, Shelley.sgSlotsPerKESPeriod
, Shelley.sgMaxKESEvolutions
, Shelley.sgSlotLength
, Shelley.sgUpdateQuorum
, Shelley.sgMaxLovelaceSupply
, Shelley.sgProtocolParams
, Shelley.sgGenDelegs = _ -- unused, might be of interest
, Shelley.sgInitialFunds = _ -- unused, not retained by the node
, Shelley.sgStaking = _ -- unused, not retained by the node
} =
GenesisParameters {
protocolParamSystemStart = sgSystemStart
, protocolParamNetworkId = fromShelleyNetwork sgNetworkId
(NetworkMagic sgNetworkMagic)
, protocolParamActiveSlotsCoefficient = Ledger.unboundRational
sgActiveSlotsCoeff
, protocolParamSecurity = fromIntegral sgSecurityParam
, protocolParamEpochLength = sgEpochLength
, protocolParamSlotLength = sgSlotLength
, protocolParamSlotsPerKESPeriod = fromIntegral sgSlotsPerKESPeriod
, protocolParamMaxKESEvolutions = fromIntegral sgMaxKESEvolutions
, protocolParamUpdateQuorum = fromIntegral sgUpdateQuorum
, protocolParamMaxLovelaceSupply = Lovelace
(fromIntegral sgMaxLovelaceSupply)
, protocolInitialUpdateableProtocolParameters = fromShelleyPParams
sgProtocolParams
}