Skip to content

Commit

Permalink
Re-enable development eras configuration flag so we can hardfork to
Browse files Browse the repository at this point in the history
Babbage without advertising that we know about Babbage
Co-authored-by: Nicolas Frisby <nick.frisby@iohk.io>
  • Loading branch information
Jimbo4350 committed May 20, 2022
1 parent e0dbc2e commit e424031
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 29 deletions.
4 changes: 1 addition & 3 deletions cardano-api/src/Cardano/Api/Eras.hs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ import qualified Data.Text as Text
import Data.Type.Equality (TestEquality (..), (:~:) (Refl))

import Ouroboros.Consensus.Shelley.Eras as Consensus (StandardAllegra, StandardAlonzo,
StandardCrypto, StandardMary, StandardShelley)

import qualified Cardano.Ledger.Babbage as Babbage
StandardBabbage, StandardMary, StandardShelley)

import Cardano.Api.HasTypeProxy

Expand Down
2 changes: 1 addition & 1 deletion cardano-api/src/Cardano/Api/Script.hs
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,7 @@ hashScript (PlutusScript PlutusScriptV1 (PlutusScriptSerialised script)) =
ScriptHash
. Ledger.hashScript @(ShelleyLedgerEra AlonzoEra)
$ Alonzo.PlutusScript Alonzo.PlutusV1 script

-- TODO: Babbage era PV2 only exists in Babbage era onwards!
hashScript (PlutusScript PlutusScriptV2 (PlutusScriptSerialised script)) =
ScriptHash
. Ledger.hashScript @(ShelleyLedgerEra AlonzoEra)
Expand Down
9 changes: 8 additions & 1 deletion cardano-node/src/Cardano/Node/Configuration/POM.hs
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,9 @@ instance FromJSON PartialNodeConfiguration where
npcTestAlonzoHardForkAtEpoch <- v .:? "TestAlonzoHardForkAtEpoch"
npcTestAlonzoHardForkAtVersion <- v .:? "TestAlonzoHardForkAtVersion"

npcTestBabbageHardForkAtEpoch <- v .:? "TestBabbageHardForkAtEpoch"
npcTestBabbageHardForkAtVersion <- v .:? "TestBabbageHardForkAtVersion"

pure NodeHardForkProtocolConfiguration {
npcTestEnableDevelopmentHardForkEras,

Expand All @@ -398,7 +401,10 @@ instance FromJSON PartialNodeConfiguration where
npcTestMaryHardForkAtVersion,

npcTestAlonzoHardForkAtEpoch,
npcTestAlonzoHardForkAtVersion
npcTestAlonzoHardForkAtVersion,

npcTestBabbageHardForkAtEpoch,
npcTestBabbageHardForkAtVersion
}

-- | Default configuration is mainnet
Expand Down Expand Up @@ -482,6 +488,7 @@ makeNodeConfiguration pnc = do
lastToEither "Missing EnableP2P"
$ pncEnableP2P pnc

-- TODO: This is not mandatory
testEnableDevelopmentNetworkProtocols <-
lastToEither "Missing TestEnableDevelopmentNetworkProtocols" $
pncTestEnableDevelopmentNetworkProtocols pnc
Expand Down
43 changes: 34 additions & 9 deletions cardano-node/src/Cardano/Node/Protocol/Cardano.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE ScopedTypeVariables #-}

{-# OPTIONS_GHC -Wno-orphans #-}
Expand All @@ -24,6 +24,7 @@ import Ouroboros.Consensus.Cardano
import qualified Ouroboros.Consensus.Cardano as Consensus
import qualified Ouroboros.Consensus.Cardano.CanHardFork as Consensus
import Ouroboros.Consensus.HardFork.Combinator.Condense ()
import qualified Ouroboros.Consensus.Shelley.Node.Praos as Praos

import Ouroboros.Consensus.Cardano.Condense ()
import qualified Ouroboros.Consensus.Mempool.TxLimits as TxLimits
Expand Down Expand Up @@ -84,7 +85,7 @@ mkSomeConsensusProtocolCardano NodeByronProtocolConfiguration {
npcAlonzoGenesisFileHash
}
NodeHardForkProtocolConfiguration {
-- npcTestEnableDevelopmentHardForkEras,
npcTestEnableDevelopmentHardForkEras,
-- During testing of the Alonzo era, we conditionally declared that we
-- knew about the Alonzo era. We do so only when a config option for
-- testing development/unstable eras is used. This lets us include
Expand All @@ -97,7 +98,9 @@ mkSomeConsensusProtocolCardano NodeByronProtocolConfiguration {
npcTestMaryHardForkAtEpoch,
npcTestMaryHardForkAtVersion,
npcTestAlonzoHardForkAtEpoch,
npcTestAlonzoHardForkAtVersion
npcTestAlonzoHardForkAtVersion,
npcTestBabbageHardForkAtEpoch,
npcTestBabbageHardForkAtVersion
}
files = do
byronGenesis <-
Expand Down Expand Up @@ -193,13 +196,24 @@ mkSomeConsensusProtocolCardano NodeByronProtocolConfiguration {
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 also the Alonzo protocol version.
-- is in the Alonzo era. That is, it is the version of protocol
-- /after/ Alonzo, i.e. Babbage.
alonzoProtVer = ProtVer 6 0,
alonzoMaxTxCapacityOverrides =
TxLimits.mkOverrides TxLimits.noOverridesMeasure
}

Praos.ProtocolParamsBabbage {
-- This is /not/ the Babbage protocol version. It is the protocol
-- version that this node will declare that it understands, when it
-- is in the Babbage era. Since Babbage is currently the last known
-- protocol version then this is also the Babbage protocol version.
Praos.babbageProtVer =
if npcTestEnableDevelopmentHardForkEras
then ProtVer 7 0 -- Advertise we can support Babbage
else ProtVer 6 0, -- Otherwise we only advertise we know about (the second) Alonzo
Praos.babbageMaxTxCapacityOverrides =
TxLimits.mkOverrides TxLimits.noOverridesMeasure
}
-- 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 All @@ -218,6 +232,8 @@ mkSomeConsensusProtocolCardano NodeByronProtocolConfiguration {
-- Version 3 is Allegra
-- Version 4 is Mary
-- Version 5 is Alonzo
-- Version 6 is Alonzo (intra era hardfork)
-- Version 7 is Babbage
--
-- But we also provide an override to allow for simpler test setups
-- such as triggering at the 0 -> 1 transition .
Expand Down Expand Up @@ -256,7 +272,16 @@ mkSomeConsensusProtocolCardano NodeByronProtocolConfiguration {
(maybe 5 fromIntegral npcTestAlonzoHardForkAtVersion)
Just epochNo -> Consensus.TriggerHardForkAtEpoch epochNo
}
-- Alonzo to Babbage hard fork parameters
Consensus.ProtocolTransitionParamsShelleyBased {
transitionTranslationContext = alonzoGenesis,
transitionTrigger =
case npcTestBabbageHardForkAtEpoch of
Nothing -> Consensus.TriggerHardForkAtVersion
(maybe 7 fromIntegral npcTestBabbageHardForkAtVersion)
Just epochNo -> Consensus.TriggerHardForkAtEpoch epochNo

}

------------------------------------------------------------------------------
-- Errors
Expand Down
30 changes: 15 additions & 15 deletions cardano-node/src/Cardano/Node/Protocol/Shelley.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ import Cardano.Ledger.Keys (coerceKeyRole)

import qualified Ouroboros.Consensus.Cardano as Consensus
import qualified Ouroboros.Consensus.Mempool.TxLimits as TxLimits
import Ouroboros.Consensus.Protocol.TPraos (TPraosCanBeLeader (..))
import Ouroboros.Consensus.Protocol.Praos.Common (PraosCanBeLeader (..))
import Ouroboros.Consensus.Shelley.Eras (StandardShelley)
import Ouroboros.Consensus.Shelley.Node (Nonce (..), ProtocolParamsShelley (..),
ProtocolParamsShelleyBased (..), TPraosLeaderCredentials (..))
ProtocolParamsShelleyBased (..), ShelleyLeaderCredentials (..))

import Cardano.Ledger.BaseTypes (ProtVer (..))
import qualified Cardano.Ledger.Shelley.Genesis as Shelley
Expand Down Expand Up @@ -139,7 +139,7 @@ validateGenesis genesis =

readLeaderCredentials
:: Maybe ProtocolFilepaths
-> ExceptT PraosLeaderCredentialsError IO [TPraosLeaderCredentials StandardCrypto]
-> ExceptT PraosLeaderCredentialsError IO [ShelleyLeaderCredentials StandardCrypto]
readLeaderCredentials Nothing = return []
readLeaderCredentials (Just pfp) =
-- The set of credentials is a sum total of what comes from the CLI,
Expand All @@ -150,7 +150,7 @@ readLeaderCredentials (Just pfp) =
readLeaderCredentialsSingleton ::
ProtocolFilepaths ->
ExceptT PraosLeaderCredentialsError IO
[TPraosLeaderCredentials StandardCrypto]
[ShelleyLeaderCredentials StandardCrypto]
-- It's OK to supply none of the files on the CLI
readLeaderCredentialsSingleton
ProtocolFilepaths
Expand Down Expand Up @@ -207,13 +207,13 @@ data ShelleyCredentials

readLeaderCredentialsBulk
:: ProtocolFilepaths
-> ExceptT PraosLeaderCredentialsError IO [TPraosLeaderCredentials StandardCrypto]
-> ExceptT PraosLeaderCredentialsError IO [ShelleyLeaderCredentials StandardCrypto]
readLeaderCredentialsBulk ProtocolFilepaths { shelleyBulkCredsFile = mfp } =
mapM parseShelleyCredentials =<< readBulkFile mfp
where
parseShelleyCredentials
:: ShelleyCredentials
-> ExceptT PraosLeaderCredentialsError IO (TPraosLeaderCredentials StandardCrypto)
-> ExceptT PraosLeaderCredentialsError IO (ShelleyLeaderCredentials StandardCrypto)
parseShelleyCredentials ShelleyCredentials { scCert, scVrf, scKes } = do
mkPraosLeaderCredentials
<$> parseEnvelope AsOperationalCertificate scCert
Expand Down Expand Up @@ -243,20 +243,20 @@ mkPraosLeaderCredentials ::
OperationalCertificate
-> SigningKey VrfKey
-> SigningKey KesKey
-> TPraosLeaderCredentials StandardCrypto
-> ShelleyLeaderCredentials StandardCrypto
mkPraosLeaderCredentials
(OperationalCertificate opcert (StakePoolVerificationKey vkey))
(VrfSigningKey vrfKey)
(KesSigningKey kesKey) =
TPraosLeaderCredentials
{ tpraosLeaderCredentialsCanBeLeader =
TPraosCanBeLeader {
tpraosCanBeLeaderOpCert = opcert,
tpraosCanBeLeaderColdVerKey = coerceKeyRole vkey,
tpraosCanBeLeaderSignKeyVRF = vrfKey
ShelleyLeaderCredentials
{ shelleyLeaderCredentialsCanBeLeader =
PraosCanBeLeader {
praosCanBeLeaderOpCert = opcert,
praosCanBeLeaderColdVerKey = coerceKeyRole vkey,
praosCanBeLeaderSignKeyVRF = vrfKey
},
tpraosLeaderCredentialsInitSignKey = kesKey,
tpraosLeaderCredentialsLabel = "Shelley"
shelleyLeaderCredentialsInitSignKey = kesKey,
shelleyLeaderCredentialsLabel = "Shelley"
}

parseEnvelope ::
Expand Down
10 changes: 10 additions & 0 deletions cardano-node/src/Cardano/Node/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,16 @@ data NodeHardForkProtocolConfiguration =
-- configured the same, or they will disagree.
--
, npcTestAlonzoHardForkAtVersion :: Maybe Word

, npcTestBabbageHardForkAtEpoch :: Maybe EpochNo

-- | For testing purposes we support specifying that the hard fork
-- 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.
--
, npcTestBabbageHardForkAtVersion :: Maybe Word
}
deriving (Eq, Show)

Expand Down

0 comments on commit e424031

Please sign in to comment.