Skip to content

Commit

Permalink
cardano-node Alonzo era updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Jimbo4350 committed Apr 15, 2021
1 parent cef24fe commit 002c1e4
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 13 deletions.
2 changes: 2 additions & 0 deletions cardano-node/cardano-node.cabal
Expand Up @@ -103,6 +103,7 @@ library
, cardano-config
, cardano-crypto-class
, cardano-crypto-wrapper
, cardano-ledger-alonzo
, cardano-ledger-byron
, cardano-ledger-shelley-ma
, cardano-prelude
Expand Down Expand Up @@ -138,6 +139,7 @@ library
, safe-exceptions
, scientific
, shelley-spec-ledger
, small-steps
, stm
, text
, time
Expand Down
3 changes: 2 additions & 1 deletion cardano-node/src/Cardano/Node/Configuration/Logging.hs
Expand Up @@ -321,11 +321,12 @@ nodeBasicInfo nc p nodeStartTime' = do
let DegenLedgerConfig cfgShelley = Consensus.configLedger cfg
in getGenesisValues "Shelley" cfgShelley
Consensus.ProtocolCardano {} ->
let CardanoLedgerConfig cfgByron cfgShelley cfgAllegra cfgMary = Consensus.configLedger cfg
let CardanoLedgerConfig cfgByron cfgShelley cfgAllegra cfgMary cfgAlonzo = Consensus.configLedger cfg
in getGenesisValuesByron cfg cfgByron
++ getGenesisValues "Shelley" cfgShelley
++ getGenesisValues "Allegra" cfgAllegra
++ getGenesisValues "Mary" cfgMary
++ getGenesisValues "Alonzo" cfgAlonzo
items = nub $
[ ("protocol", pack . protocolName $ ncProtocol nc)
, ("version", pack . showVersion $ version)
Expand Down
8 changes: 7 additions & 1 deletion cardano-node/src/Cardano/Node/Configuration/POM.hs
Expand Up @@ -230,6 +230,9 @@ instance FromJSON PartialNodeConfiguration where
npcTestMaryHardForkAtEpoch <- v .:? "TestMaryHardForkAtEpoch"
npcTestMaryHardForkAtVersion <- v .:? "TestMaryHardForkAtVersion"

npcTestAlonzoHardForkAtEpoch <- v .:? "TestAlonzoHardForkAtEpoch"
npcTestAlonzoHardForkAtVersion <- v .:? "TestAlonzoHardForkAtVersion"

pure NodeHardForkProtocolConfiguration {
npcTestShelleyHardForkAtEpoch,
npcTestShelleyHardForkAtVersion,
Expand All @@ -238,7 +241,10 @@ instance FromJSON PartialNodeConfiguration where
npcTestAllegraHardForkAtVersion,

npcTestMaryHardForkAtEpoch,
npcTestMaryHardForkAtVersion
npcTestMaryHardForkAtVersion,

npcTestAlonzoHardForkAtEpoch,
npcTestAlonzoHardForkAtVersion
}

-- | Default configuration is mainnet
Expand Down
44 changes: 43 additions & 1 deletion cardano-node/src/Cardano/Node/Orphans.hs
@@ -1,4 +1,6 @@

{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE StandaloneDeriving #-}

{-# OPTIONS_GHC -Wno-orphans #-}
Expand All @@ -8,11 +10,25 @@ module Cardano.Node.Orphans () where
import Cardano.Prelude
import Prelude (fail)

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



import Cardano.BM.Data.Tracer (TracingVerbosity (..))
import qualified Cardano.Chain.Update as Update
import qualified Cardano.Ledger.Alonzo as Alonzo
import qualified Cardano.Ledger.Alonzo.Language as Alonzo
import qualified Cardano.Ledger.Alonzo.PParams as Alonzo
import qualified Cardano.Ledger.Alonzo.Scripts as Alonzo
import qualified Cardano.Ledger.Alonzo.TxBody as Alonzo
import qualified Cardano.Ledger.Compactible as Ledger
import qualified Cardano.Ledger.Mary.Value as Mary
import qualified Cardano.Ledger.SafeHash as SafeHash
import qualified Data.MemoBytes as MemoBytes
import Ouroboros.Consensus.Shelley.Protocol.Crypto (StandardCrypto)
import qualified Shelley.Spec.Ledger.CompactAddr as Shelley

instance FromJSON TracingVerbosity where
parseJSON (String str) = case str of
Expand All @@ -26,6 +42,32 @@ instance FromJSON TracingVerbosity where

deriving instance Show TracingVerbosity

deriving instance ToJSON (Alonzo.PParamsUpdate (Alonzo.AlonzoEra StandardCrypto))
deriving instance ToJSON Alonzo.ExUnits
deriving instance ToJSON Alonzo.Prices
deriving instance ToJSON Alonzo.Language
deriving instance ToJSON (MemoBytes.MemoBytes (Map ByteString Integer))

-- Obviously incorrect. Need to fix.
instance ToJSON SBS.ShortByteString where
toJSON = panic "placeholder"
-- Obviously incorrect. Need to fix.
deriving instance ToJSONKey SBS.ShortByteString
-- Obviously incorrect. Need to fix.
deriving instance ToJSONKey ByteString
deriving instance ToJSONKey Alonzo.Language
deriving instance ToJSON Alonzo.CostModel


deriving instance ToJSON (Alonzo.TxOut (Alonzo.AlonzoEra StandardCrypto))
instance ToJSON (Shelley.CompactAddr StandardCrypto) where
toJSON = panic ""
instance ToJSON (Ledger.CompactForm (Mary.Value StandardCrypto)) where
toJSON = panic ""
instance ToJSON (SafeHash.SafeHash StandardCrypto SafeHash.EraIndependentData) where
toJSON = panic ""


instance FromJSON Update.ApplicationName where
parseJSON (String x) = pure $ Update.ApplicationName x
parseJSON invalid =
Expand Down
25 changes: 23 additions & 2 deletions cardano-node/src/Cardano/Node/Protocol/Cardano.hs
@@ -1,3 +1,4 @@
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE NamedFieldPuns #-}
Expand Down Expand Up @@ -112,7 +113,9 @@ mkConsensusProtocolCardano NodeByronProtocolConfiguration {
npcTestAllegraHardForkAtEpoch,
npcTestAllegraHardForkAtVersion,
npcTestMaryHardForkAtEpoch,
npcTestMaryHardForkAtVersion
npcTestMaryHardForkAtVersion,
npcTestAlonzoHardForkAtEpoch,
npcTestAlonzoHardForkAtVersion
}
files = do
byronGenesis <-
Expand Down Expand Up @@ -167,7 +170,8 @@ mkConsensusProtocolCardano NodeByronProtocolConfiguration {
shelleyBasedGenesis = shelleyGenesis,
shelleyBasedInitialNonce =
Shelley.genesisHashToPraosNonce shelleyGenesisHash,
shelleyBasedLeaderCredentials = shelleyLeaderCredentials
shelleyBasedLeaderCredentials = shelleyLeaderCredentials,
shelleyTranslationContext = ()
}
Consensus.ProtocolParamsShelley {
-- This is /not/ the Shelley protocol version. It is the protocol
Expand All @@ -193,6 +197,15 @@ mkConsensusProtocolCardano NodeByronProtocolConfiguration {
maryProtVer =
ProtVer 4 0
}
Consensus.ProtocolParamsAlonzo {
-- This is /not/ the Mary protocol version. It is the protocol
-- version that this node will declare that it understands, when it
-- is in the Mary era. Since Mary is currently the last known
-- protocol version then this is also the Mary protocol version.
alonzoProtVer =
ProtVer 4 0,
alonzoTranslationContext = 42
}
-- ProtocolParamsTransition specifies the parameters needed to transition between two eras
-- The comments below also apply for the Shelley -> Allegra and Allegra -> Mary hard forks.
-- Byron to Shelley hard fork parameters
Expand Down Expand Up @@ -236,6 +249,14 @@ mkConsensusProtocolCardano NodeByronProtocolConfiguration {
(maybe 4 fromIntegral npcTestMaryHardForkAtVersion)
Just epochNo -> Consensus.TriggerHardForkAtEpoch epochNo
}
-- Mary to Alonzo hard fork parameters
Consensus.ProtocolParamsTransition {
transitionTrigger =
case npcTestAlonzoHardForkAtEpoch of
Nothing -> Consensus.TriggerHardForkAtVersion
(maybe 5 fromIntegral npcTestAlonzoHardForkAtVersion)
Just epochNo -> Consensus.TriggerHardForkAtEpoch epochNo
}

------------------------------------------------------------------------------
-- Errors
Expand Down
4 changes: 2 additions & 2 deletions cardano-node/src/Cardano/Node/Protocol/Shelley.hs
Expand Up @@ -59,7 +59,6 @@ import Cardano.Tracing.OrphanInstances.Shelley ()

import Cardano.Node.Protocol.Types


------------------------------------------------------------------------------
-- Shelley protocol
--
Expand Down Expand Up @@ -108,7 +107,8 @@ mkConsensusProtocolShelley NodeShelleyProtocolConfiguration {
shelleyBasedGenesis = genesis,
shelleyBasedInitialNonce = genesisHashToPraosNonce genesisHash,
shelleyBasedLeaderCredentials =
leaderCredentials
leaderCredentials,
shelleyTranslationContext = ()
}
Consensus.ProtocolParamsShelley {
shelleyProtVer =
Expand Down
3 changes: 2 additions & 1 deletion cardano-node/src/Cardano/Node/Protocol/Types.hs
Expand Up @@ -22,8 +22,9 @@ import Ouroboros.Consensus.Block (BlockProtocol)
import qualified Ouroboros.Consensus.Cardano as Consensus (Protocol)
import Ouroboros.Consensus.Node.Run (RunNode)

import Cardano.Node.Orphans ()
import Cardano.Tracing.Constraints (TraceConstraints)
import Cardano.Tracing.Metrics (HasKESMetricsData, HasKESInfo)
import Cardano.Tracing.Metrics (HasKESInfo, HasKESMetricsData)

data Protocol = ByronProtocol
| ShelleyProtocol
Expand Down
9 changes: 9 additions & 0 deletions cardano-node/src/Cardano/Node/Types.hs
Expand Up @@ -355,6 +355,15 @@ data NodeHardForkProtocolConfiguration =
--
, npcTestMaryHardForkAtVersion :: Maybe Word

, 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).
--
-- Obviously if this is used, all the nodes in the test cluster must be
-- configured the same, or they will disagree.
--
, npcTestAlonzoHardForkAtVersion :: Maybe Word
}
deriving (Eq, Show)

Expand Down
9 changes: 4 additions & 5 deletions cardano-node/src/Cardano/Tracing/Constraints.hs
Expand Up @@ -13,17 +13,16 @@ import Cardano.BM.Tracing (ToObject)
import Cardano.Tracing.ConvertTxId (ConvertTxId)
import Cardano.Tracing.Queries (LedgerQueries)

import Ouroboros.Consensus.Block (BlockProtocol, CannotForge,
ForgeStateUpdateError, Header)
import Cardano.Node.Orphans ()
import Ouroboros.Consensus.Block (BlockProtocol, CannotForge, ForgeStateUpdateError,
Header)
import Ouroboros.Consensus.HeaderValidation (OtherHeaderEnvelopeError)
import Ouroboros.Consensus.Ledger.Abstract (LedgerError)
import Ouroboros.Consensus.Ledger.Inspect (LedgerEvent)
import Ouroboros.Consensus.Ledger.SupportsMempool (ApplyTxErr, HasTxId,
HasTxs (..))
import Ouroboros.Consensus.Ledger.SupportsMempool (ApplyTxErr, HasTxId, HasTxs (..))
import Ouroboros.Consensus.Protocol.Abstract (ValidationErr)
import Ouroboros.Consensus.Shelley.Ledger.Mempool (GenTx, TxId)


-- | Tracing-related constraints for monitoring purposes.
type TraceConstraints blk =
( ConvertTxId blk
Expand Down
2 changes: 2 additions & 0 deletions cardano-node/src/Cardano/Tracing/Queries.hs
Expand Up @@ -62,8 +62,10 @@ instance LedgerQueries (Cardano.CardanoBlock c) where
Cardano.LedgerStateShelley ledgerShelley -> ledgerUtxoSize ledgerShelley
Cardano.LedgerStateAllegra ledgerAllegra -> ledgerUtxoSize ledgerAllegra
Cardano.LedgerStateMary ledgerMary -> ledgerUtxoSize ledgerMary
Cardano.LedgerStateAlonzo ledgerAlonzo -> ledgerUtxoSize ledgerAlonzo
ledgerDelegMapSize = \case
Cardano.LedgerStateByron ledgerByron -> ledgerDelegMapSize ledgerByron
Cardano.LedgerStateShelley ledgerShelley -> ledgerDelegMapSize ledgerShelley
Cardano.LedgerStateAllegra ledgerAllegra -> ledgerDelegMapSize ledgerAllegra
Cardano.LedgerStateMary ledgerMary -> ledgerDelegMapSize ledgerMary
Cardano.LedgerStateAlonzo ledgerAlonzo -> ledgerDelegMapSize ledgerAlonzo

0 comments on commit 002c1e4

Please sign in to comment.