Skip to content

Commit

Permalink
Update NodeProtocolConfiguration to include Alonzo
Browse files Browse the repository at this point in the history
  • Loading branch information
Jimbo4350 committed Apr 27, 2021
1 parent d096efd commit 682d158
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 3 deletions.
19 changes: 19 additions & 0 deletions cardano-node/src/Cardano/Node/Configuration/POM.hs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ instance FromJSON PartialNodeConfiguration where
CardanoProtocol ->
Last . Just <$> (NodeProtocolConfigurationCardano <$> parseByronProtocol v
<*> parseShelleyProtocol v
<*> parseAlonzoProtocol v
<*> parseHardForkProtocol v)
pure PartialNodeConfiguration {
pncProtocolConfig = pncProtocolConfig'
Expand Down Expand Up @@ -220,6 +221,24 @@ instance FromJSON PartialNodeConfiguration where
, npcShelleyGenesisFileHash
}

parseAlonzoProtocol v = do
primary <- v .:? "AlonzoGenesisFile"
secondary <- v .:? "GenesisFile"
npcAlonzoGenesisFile <-
case (primary, secondary) of
(Just g, Nothing) -> return g
(Nothing, Just g) -> return g
(Nothing, Nothing) -> fail $ "Missing required field, either "
++ "AlonzoGenesisFile or GenesisFile"
(Just _, Just _) -> fail $ "Specify either AlonzoGenesisFile"
++ "or GenesisFile, but not both"
npcAlonzoGenesisFileHash <- v .:? "AlonzoGenesisHash"

pure NodeAlonzoProtocolConfiguration {
npcAlonzoGenesisFile
, npcAlonzoGenesisFileHash
}

parseHardForkProtocol v = do
npcTestShelleyHardForkAtEpoch <- v .:? "TestShelleyHardForkAtEpoch"
npcTestShelleyHardForkAtVersion <- v .:? "TestShelleyHardForkAtVersion"
Expand Down
2 changes: 2 additions & 0 deletions cardano-node/src/Cardano/Node/Protocol.hs
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,13 @@ mkConsensusProtocol NodeConfiguration{ncProtocolConfig, ncProtocolFiles} =

NodeProtocolConfigurationCardano byronConfig
shelleyConfig
alonzoConfig
hardForkConfig ->
firstExceptT CardanoProtocolInstantiationError $
mkSomeConsensusProtocolCardano
byronConfig
shelleyConfig
alonzoConfig
hardForkConfig
(Just ncProtocolFiles)

Expand Down
2 changes: 2 additions & 0 deletions cardano-node/src/Cardano/Node/Protocol/Cardano.hs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ import Cardano.Node.Protocol.Types
mkSomeConsensusProtocolCardano
:: NodeByronProtocolConfiguration
-> NodeShelleyProtocolConfiguration
-> NodeAlonzoProtocolConfiguration
-> NodeHardForkProtocolConfiguration
-> Maybe ProtocolFilepaths
-> ExceptT CardanoProtocolInstantiationError IO SomeConsensusProtocol
Expand All @@ -78,6 +79,7 @@ mkSomeConsensusProtocolCardano NodeByronProtocolConfiguration {
npcShelleyGenesisFile,
npcShelleyGenesisFileHash
}
_AlonzoProtocolConfig
NodeHardForkProtocolConfiguration {
npcTestShelleyHardForkAtEpoch,
npcTestShelleyHardForkAtVersion,
Expand Down
31 changes: 28 additions & 3 deletions cardano-node/src/Cardano/Node/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ module Cardano.Node.Types
, NodeHardForkProtocolConfiguration(..)
, NodeProtocolConfiguration(..)
, NodeShelleyProtocolConfiguration(..)
, NodeAlonzoProtocolConfiguration(..)
, VRFPrivateKeyFilePermissionError(..)
, protocolName
, renderVRFPrivateKeyFilePermissionError
Expand Down Expand Up @@ -261,9 +262,17 @@ data NodeProtocolConfiguration =
| NodeProtocolConfigurationShelley NodeShelleyProtocolConfiguration
| NodeProtocolConfigurationCardano NodeByronProtocolConfiguration
NodeShelleyProtocolConfiguration
NodeAlonzoProtocolConfiguration
NodeHardForkProtocolConfiguration
deriving (Eq, Show)

data NodeAlonzoProtocolConfiguration =
NodeAlonzoProtocolConfiguration
{ npcAlonzoGenesisFile :: !GenesisFile
, npcAlonzoGenesisFileHash :: !(Maybe GenesisHash)
} deriving (Eq, Show)


data NodeShelleyProtocolConfiguration =
NodeShelleyProtocolConfiguration {
npcShelleyGenesisFile :: !GenesisFile
Expand Down Expand Up @@ -348,17 +357,24 @@ data NodeHardForkProtocolConfiguration =
, npcTestMaryHardForkAtEpoch :: Maybe EpochNo

-- | For testing purposes we support specifying that the hard fork
-- happens at an exact epoch number (ie the first epoch of the new era).
-- happens at a given major protocol version.
--
-- Obviously if this is used, all the nodes in the test cluster must be
-- configured the same, or they will disagree.
--
--
, npcTestMaryHardForkAtVersion :: Maybe Word

-- | For testing purposes we support specifying that the hard fork
-- happens at an exact epoch number (ie the first epoch of the new era).
--
-- Obviously if this is used, all the nodes in the test cluster must be
-- configured the same, or they will disagree.
--
, npcTestAlonzoHardForkAtEpoch :: Maybe EpochNo

-- | For testing purposes we support specifying that the hard fork
-- happens at an exact epoch number (ie the first epoch of the new era).
-- happens at a given major protocol version.
--
-- Obviously if this is used, all the nodes in the test cluster must be
-- configured the same, or they will disagree.
Expand All @@ -384,9 +400,10 @@ instance AdjustFilePaths NodeProtocolConfiguration where
adjustFilePaths f (NodeProtocolConfigurationShelley pc) =
NodeProtocolConfigurationShelley (adjustFilePaths f pc)

adjustFilePaths f (NodeProtocolConfigurationCardano pcb pcs pch) =
adjustFilePaths f (NodeProtocolConfigurationCardano pcb pcs pca pch) =
NodeProtocolConfigurationCardano (adjustFilePaths f pcb)
(adjustFilePaths f pcs)
(adjustFilePaths f pca)
pch

instance AdjustFilePaths NodeByronProtocolConfiguration where
Expand All @@ -401,6 +418,14 @@ instance AdjustFilePaths NodeShelleyProtocolConfiguration where
} =
x { npcShelleyGenesisFile = adjustFilePaths f npcShelleyGenesisFile }


instance AdjustFilePaths NodeAlonzoProtocolConfiguration where
adjustFilePaths f x@NodeAlonzoProtocolConfiguration {
npcAlonzoGenesisFile
} =
x { npcAlonzoGenesisFile = adjustFilePaths f npcAlonzoGenesisFile }


instance AdjustFilePaths SocketPath where
adjustFilePaths f (SocketPath p) = SocketPath (f p)

Expand Down

0 comments on commit 682d158

Please sign in to comment.