Skip to content

Commit

Permalink
Review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Jimbo4350 committed May 12, 2021
1 parent 8c19e28 commit b33173e
Show file tree
Hide file tree
Showing 17 changed files with 147 additions and 168 deletions.
1 change: 1 addition & 0 deletions cardano-api/src/Cardano/Api/Eras.hs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ instance TestEquality CardanoEra where
testEquality ShelleyEra ShelleyEra = Just Refl
testEquality AllegraEra AllegraEra = Just Refl
testEquality MaryEra MaryEra = Just Refl
testEquality AlonzoEra AlonzoEra = Just Refl
testEquality _ _ = Nothing


Expand Down
2 changes: 2 additions & 0 deletions cardano-api/src/Cardano/Api/Fees.hs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ transactionFee txFeeFixed txFeePerByte tx =
in case tx of
ShelleyTx _ tx' -> let x = getField @"txsize" tx'
in Lovelace (a * x + b)
--TODO: This can be made to work for Byron txs too. Do that: fill in this case
-- and remove the IsShelleyBasedEra constraint.
ByronTx _ -> case shelleyBasedEra :: ShelleyBasedEra ByronEra of {}


Expand Down
6 changes: 3 additions & 3 deletions cardano-api/src/Cardano/Api/LedgerState.hs
Original file line number Diff line number Diff line change
Expand Up @@ -621,13 +621,13 @@ mkProtocolInfoCardano (GenesisCardano dnc byronGenesis shelleyGenesis)
{ Consensus.maryProtVer = shelleyProtVer dnc
}
Consensus.ProtocolParamsAlonzo
{ Consensus.alonzoGenesis = undefined
, Consensus.alonzoProtVer = undefined
{ Consensus.alonzoGenesis = error "mkProtocolInfoCardano: alonzoGenesis"
, Consensus.alonzoProtVer = error "mkProtocolInfoCardano: alonzoProtVer"
}
(ncByronToShelley dnc)
(ncShelleyToAllegra dnc)
(ncAllegraToMary dnc)
undefined
(error "mkProtocolInfoCardano: ProtocolParamsTransition (ShelleyBlock (MaryEra c)) (ShelleyBlock (AlonzoEra c))")

shelleyPraosNonce :: ShelleyConfig -> Shelley.Spec.Nonce
shelleyPraosNonce sCfg = Shelley.Spec.Nonce (Cardano.Crypto.Hash.Class.castHash . unGenesisHashShelley $ scGenesisHash sCfg)
Expand Down
10 changes: 5 additions & 5 deletions cardano-api/src/Cardano/Api/Tx.hs
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,7 @@ instance Eq (Tx era) where
ShelleyBasedEraShelley -> txA == txB
ShelleyBasedEraAllegra -> txA == txB
ShelleyBasedEraMary -> txA == txB
ShelleyBasedEraAlonzo ->
error "Eq (Tx era): Alonzo era not implemented yet"
ShelleyBasedEraAlonzo -> txA == txB

(==) ByronTx{} (ShelleyTx era _) = case era of {}

Expand All @@ -161,9 +160,10 @@ instance Show (Tx era) where
showString "ShelleyTx ShelleyBasedEraMary "
. showsPrec 11 tx

showsPrec _ (ShelleyTx ShelleyBasedEraAlonzo _) =
error "Show (Tx era): Alonzo era not implemented yet"

showsPrec p (ShelleyTx ShelleyBasedEraAlonzo tx) =
showParen (p >= 11) $
showString "ShelleyTx ShelleyBasedEraAlonzo "
. showsPrec 11 tx


instance HasTypeProxy era => HasTypeProxy (Tx era) where
Expand Down
16 changes: 13 additions & 3 deletions cardano-api/src/Cardano/Api/TxBody.hs
Original file line number Diff line number Diff line change
Expand Up @@ -952,8 +952,18 @@ instance Show (TxBody era) where
. showsPrec 11 txmetadata
)

showsPrec _ (ShelleyTxBody ShelleyBasedEraAlonzo _ _ _) =
error "Show (TxBody era): Alonzo not implemented yet"
showsPrec p (ShelleyTxBody ShelleyBasedEraAlonzo
txbody txscripts txmetadata) =
showParen (p >= 11)
( showString "ShelleyTxBody ShelleyBasedEraMary "
. showsPrec 11 txbody
. showChar ' '
. showsPrec 11 txscripts
. showChar ' '
. showsPrec 11 txmetadata
)


instance HasTypeProxy era => HasTypeProxy (TxBody era) where
data AsType (TxBody era) = AsTxBody (AsType era)
proxyToAsType _ = AsTxBody (proxyToAsType (Proxy :: Proxy era))
Expand Down Expand Up @@ -981,7 +991,7 @@ instance IsCardanoEra era => SerialiseAsCBOR (TxBody era) where
ShelleyBasedEraShelley -> serialiseShelleyBasedTxBody txbody txscripts txmetadata
ShelleyBasedEraAllegra -> serialiseShelleyBasedTxBody txbody txscripts txmetadata
ShelleyBasedEraMary -> serialiseShelleyBasedTxBody txbody txscripts txmetadata
ShelleyBasedEraAlonzo -> error ""
ShelleyBasedEraAlonzo -> error "serialiseToCBOR: Alonzo era not implemented yet"

deserialiseFromCBOR _ bs =
case cardanoEra :: CardanoEra era of
Expand Down
10 changes: 5 additions & 5 deletions cardano-cli/src/Cardano/CLI/Shelley/Orphans.hs
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,11 @@ deriving instance FromJSON Alonzo.Prices
-- of the genesis file.
instance FromJSON Alonzo.AlonzoGenesis where
parseJSON = withObject "Alonzo Genesis" $ \o -> do
adaPerWord <- o .: "alonzoAdaPerUTxOWord"
execPrices <- o .: "alonzoExecutionPrices"
maxTxExUnits' <- o .: "alonzoMaxTxExUnits"
maxBlockExUnits' <- o .: "alonzoMaxBlockExUnits"
maxMaSize <- o .: "alonzoMaxMultiAssetSize"
adaPerWord <- o .: "adaPerUTxOWord"
execPrices <- o .: "executionPrices"
maxTxExUnits' <- o .: "maxTxExUnits"
maxBlockExUnits' <- o .: "maxBlockExUnits"
maxMaSize <- o .: "maxMultiAssetSize"
return $ Alonzo.AlonzoGenesis
{ adaPerUTxOWord = adaPerWord
, costmdls = mempty
Expand Down
2 changes: 2 additions & 0 deletions cardano-cli/src/Cardano/CLI/Shelley/Run/Genesis.hs
Original file line number Diff line number Diff line change
Expand Up @@ -966,6 +966,8 @@ createAlonzoGenesis
createAlonzoGenesis (AlonzoGenWrapper costModelFp' alonzoGenesis) = do
costModel <- readAndDecode
case Plutus.extractModelParams costModel of
-- TODO: We should not be using functions directly from the plutus repo
-- These should be exposed via the ledger
Just m -> if Plutus.validateCostModelParams m
then left $ ShelleyGenesisCmdCostModelsError costModelFp'
else return $ alonzoGenesis { Alonzo.costmdls = Map.singleton Alonzo.PlutusV1 $ Alonzo.CostModel m }
Expand Down
3 changes: 2 additions & 1 deletion cardano-cli/src/Cardano/CLI/Shelley/Run/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -763,5 +763,6 @@ obtainLedgerEraClassConstraints
obtainLedgerEraClassConstraints ShelleyBasedEraShelley f = f
obtainLedgerEraClassConstraints ShelleyBasedEraAllegra f = f
obtainLedgerEraClassConstraints ShelleyBasedEraMary f = f
obtainLedgerEraClassConstraints ShelleyBasedEraAlonzo _ = panic "TODO"
obtainLedgerEraClassConstraints ShelleyBasedEraAlonzo _ =
panic "obtainLedgerEraClassConstraints: Alonzo era not implemented yet"

17 changes: 0 additions & 17 deletions cardano-node/src/Cardano/Node/Configuration/POM.hs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ instance FromJSON PartialNodeConfiguration where
CardanoProtocol ->
Last . Just <$> (NodeProtocolConfigurationCardano <$> parseByronProtocol v
<*> parseShelleyProtocol v
<*> parseAlonzoProtocol v
<*> parseHardForkProtocol v)
pure PartialNodeConfiguration {
pncProtocolConfig = pncProtocolConfig'
Expand Down Expand Up @@ -227,22 +226,6 @@ 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"

pure NodeAlonzoProtocolConfiguration {
npcAlonzoGenesisFile
}

parseHardForkProtocol v = do
npcTestShelleyHardForkAtEpoch <- v .:? "TestShelleyHardForkAtEpoch"
npcTestShelleyHardForkAtVersion <- v .:? "TestShelleyHardForkAtVersion"
Expand Down
21 changes: 13 additions & 8 deletions cardano-node/src/Cardano/Node/Orphans.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ import Cardano.Api.Orphans ()

import Data.Aeson (FromJSON (..), ToJSON (..), ToJSONKey, Value (..), withObject, (.:))
import qualified Data.Aeson as Aeson
import qualified Data.ByteString.Base16 as Base16
import qualified Data.ByteString.Short as SBS
import qualified Data.Text as Text
import qualified Data.Text.Encoding as Text



Expand Down Expand Up @@ -55,11 +57,14 @@ deriving instance ToJSON (MemoBytes.MemoBytes (Map ByteString Integer))
--TODO: I assume we are not interested in rendering
--plutus scripts as JSON.
instance ToJSON SBS.ShortByteString where
toJSON _plutusScriptBytes = Aeson.String "Plutus script placeholder"
toJSON plutusScriptBytes =
case Base16.decode $ SBS.fromShort plutusScriptBytes of
Right base16Bytes -> Aeson.String $ Text.decodeLatin1 base16Bytes
Left err -> panic $ "Failed to decode plutus script: " <> Text.pack err

-- Obviously incorrect. Need to fix.
-- TODO: Obviously incorrect. Need to fix.
deriving instance ToJSONKey SBS.ShortByteString
-- Obviously incorrect. Need to fix.
-- TODO: Obviously incorrect. Need to fix.
deriving instance ToJSONKey ByteString
deriving instance ToJSONKey Alonzo.Language
deriving instance ToJSON Alonzo.CostModel
Expand All @@ -84,11 +89,11 @@ instance FromJSON Update.ApplicationName where
-- of the genesis file.
instance FromJSON AlonzoGenesis where
parseJSON = withObject "Alonzo Genesis" $ \o -> do
adaPerWord <- o .: "alonzoAdaPerUTxOWord"
execPrices <- o .: "alonzoExecutionPrices"
maxTxExUnits' <- o .: "alonzoMaxTxExUnits"
maxBlockExUnits' <- o .: "alonzoMaxBlockExUnits"
maxMaSize <- o .: "alonzoMaxMultiAssetSize"
adaPerWord <- o .: "adaPerUTxOWord"
execPrices <- o .: "executionPrices"
maxTxExUnits' <- o .: "maxTxExUnits"
maxBlockExUnits' <- o .: "maxBlockExUnits"
maxMaSize <- o .: "maxMultiAssetSize"
return $ AlonzoGenesis
{ adaPerUTxOWord = adaPerWord
, costmdls = mempty
Expand Down
5 changes: 0 additions & 5 deletions cardano-node/src/Cardano/Node/Protocol.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import Cardano.Node.Configuration.POM (NodeConfiguration (..))
import Cardano.Node.Types

import Cardano.Node.Orphans ()
import Cardano.Node.Protocol.Alonzo
import Cardano.Node.Protocol.Byron
import Cardano.Node.Protocol.Cardano
import Cardano.Node.Protocol.Shelley
Expand All @@ -40,13 +39,11 @@ mkConsensusProtocol NodeConfiguration{ncProtocolConfig, ncProtocolFiles} =

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

Expand All @@ -57,7 +54,6 @@ mkConsensusProtocol NodeConfiguration{ncProtocolConfig, ncProtocolFiles} =
data ProtocolInstantiationError =
ByronProtocolInstantiationError ByronProtocolInstantiationError
| ShelleyProtocolInstantiationError ShelleyProtocolInstantiationError
| AlonzoProtocolInstantiationError AlonzoProtocolInstantiationError
| CardanoProtocolInstantiationError CardanoProtocolInstantiationError
deriving Show

Expand All @@ -73,4 +69,3 @@ renderProtocolInstantiationError pie =

CardanoProtocolInstantiationError cpie ->
renderCardanoProtocolInstantiationError cpie
AlonzoProtocolInstantiationError _ -> panic "FIX ME"
3 changes: 2 additions & 1 deletion cardano-node/src/Cardano/Node/Protocol/Alonzo.hs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ readAlonzoGenesis fpath = do
`catchError` \err ->
case err of
AlonzoGenesisFileError (FileIOError _ ioe)
| isDoesNotExistError ioe -> panic "Shelley genesis file not found."
| isDoesNotExistError ioe -> left $ GenesisFileNotFound fpath
_ -> left err
createAlonzoGenesis alonzoGenWrapper

Expand Down Expand Up @@ -104,6 +104,7 @@ data AlonzoProtocolInstantiationError
| AlonzoCostModelDecodeError !FilePath !Text
| AlonzoGenesisFileError !(FileError ())
| AlonzoGenesisDecodeError !FilePath !Text
| GenesisFileNotFound !FilePath
deriving Show


17 changes: 8 additions & 9 deletions cardano-node/src/Cardano/Node/Protocol/Cardano.hs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ import Cardano.Node.Protocol.Types
mkSomeConsensusProtocolCardano
:: NodeByronProtocolConfiguration
-> NodeShelleyProtocolConfiguration
-> NodeAlonzoProtocolConfiguration
-> NodeHardForkProtocolConfiguration
-> Maybe ProtocolFilepaths
-> ExceptT CardanoProtocolInstantiationError IO SomeConsensusProtocol
Expand All @@ -80,9 +79,6 @@ mkSomeConsensusProtocolCardano NodeByronProtocolConfiguration {
npcShelleyGenesisFile,
npcShelleyGenesisFileHash
}
NodeAlonzoProtocolConfiguration {
npcAlonzoGenesisFile
}
NodeHardForkProtocolConfiguration {
npcTestShelleyHardForkAtEpoch,
npcTestShelleyHardForkAtVersion,
Expand Down Expand Up @@ -113,9 +109,8 @@ mkSomeConsensusProtocolCardano NodeByronProtocolConfiguration {
firstExceptT CardanoProtocolInstantiationErrorShelley $
Shelley.readLeaderCredentials files

-- In order to avoid creating another genesis file, we can include
-- the Alonzo relevant fields in the Shelley genesis and therefore
--
-- We choose to include the Alonzo relevant fields in the Shelley genesis
-- and therefore avoid creating a separate Alonzo genesis file
let GenesisFile shelleyGenFile = npcShelleyGenesisFile
alonzoGen <- firstExceptT CardanoProtocolInstantiationErrorAlonzo
$ readAlonzoGenesis shelleyGenFile
Expand Down Expand Up @@ -177,13 +172,16 @@ mkSomeConsensusProtocolCardano NodeByronProtocolConfiguration {
-- is in the Mary era. Since Mary is currently the last known
-- protocol version then this is also the Mary protocol version.
maryProtVer =
ProtVer 4 0
ProtVer 3 0
}
-- TODO: TestEnableDevelopmentHardForkEras :: Bool. This bool
-- will tell use whether or not to change the 'maryProtVer' field
-- from version 4 to version 5 so that we can fork to version 5
Consensus.ProtocolParamsAlonzo {
-- This is /not/ the Alonzo protocol version. It is the protocol
-- version that this node will declare that it understands, when it
-- is in the Alonzo era. Since Alonzo is currently the last known
-- protocol version then this is a Consensus.ProtocolParamsTransition {
-- protocol version then this is also the Alonzo protocol version.
alonzoGenesis = alonzoGen,
alonzoProtVer = ProtVer 5 0
}
Expand All @@ -204,6 +202,7 @@ mkSomeConsensusProtocolCardano NodeByronProtocolConfiguration {
-- Version 2 is Shelley
-- Version 3 is Allegra
-- Version 4 is Mary
-- Version 5 is Alonzo
--
-- But we also provide an override to allow for simpler test setups
-- such as triggering at the 0 -> 1 transition .
Expand Down
20 changes: 2 additions & 18 deletions cardano-node/src/Cardano/Node/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ module Cardano.Node.Types
, NodeHardForkProtocolConfiguration(..)
, NodeProtocolConfiguration(..)
, NodeShelleyProtocolConfiguration(..)
, NodeAlonzoProtocolConfiguration(..)
, VRFPrivateKeyFilePermissionError(..)
, protocolName
, renderVRFPrivateKeyFilePermissionError
Expand Down Expand Up @@ -262,16 +261,9 @@ data NodeProtocolConfiguration =
| NodeProtocolConfigurationShelley NodeShelleyProtocolConfiguration
| NodeProtocolConfigurationCardano NodeByronProtocolConfiguration
NodeShelleyProtocolConfiguration
NodeAlonzoProtocolConfiguration
NodeHardForkProtocolConfiguration
deriving (Eq, Show)

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


data NodeShelleyProtocolConfiguration =
NodeShelleyProtocolConfiguration {
npcShelleyGenesisFile :: !GenesisFile
Expand Down Expand Up @@ -379,6 +371,7 @@ data NodeHardForkProtocolConfiguration =
-- configured the same, or they will disagree.
--
, npcTestAlonzoHardForkAtVersion :: Maybe Word
-- TODO: npcTestEnableDevelopmentHardForkEras :: Bool
}
deriving (Eq, Show)

Expand All @@ -399,10 +392,9 @@ instance AdjustFilePaths NodeProtocolConfiguration where
adjustFilePaths f (NodeProtocolConfigurationShelley pc) =
NodeProtocolConfigurationShelley (adjustFilePaths f pc)

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

instance AdjustFilePaths NodeByronProtocolConfiguration where
Expand All @@ -417,14 +409,6 @@ 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
Loading

0 comments on commit b33173e

Please sign in to comment.