From d0ea45e3fc434cc8d02cd5bc48339c2ab2eeb9d5 Mon Sep 17 00:00:00 2001 From: Robert 'Probie' Offner Date: Tue, 16 Aug 2022 10:27:56 +1000 Subject: [PATCH] Rename TestEnableDevelopmentHardForkEras TestEnableDevelopmentHardForkEras has been renamed to TestEnableDevelopmentProtVer. An error is thrown if TestEnableDevelopmentHardForkEras is used to avoid it silently being set to False. Closes https://github.com/input-output-hk/cardano-node/issues/4043 --- .../src/Cardano/Node/Configuration/POM.hs | 25 ++++++++++++++++--- .../src/Cardano/Node/Protocol/Cardano.hs | 12 ++++----- cardano-node/src/Cardano/Node/Types.hs | 2 +- cardano-testnet/src/Testnet/Babbage.hs | 2 +- cardano-testnet/src/Testnet/Cardano.hs | 2 +- nix/workbench/profiles/node-services.nix | 2 +- 6 files changed, 32 insertions(+), 13 deletions(-) diff --git a/cardano-node/src/Cardano/Node/Configuration/POM.hs b/cardano-node/src/Cardano/Node/Configuration/POM.hs index 6216543412d..aaf08e33bcf 100644 --- a/cardano-node/src/Cardano/Node/Configuration/POM.hs +++ b/cardano-node/src/Cardano/Node/Configuration/POM.hs @@ -51,6 +51,17 @@ import qualified Ouroboros.Consensus.Node as Consensus (NetworkP2PMode (..)) import Ouroboros.Consensus.Storage.LedgerDB.DiskPolicy (SnapshotInterval (..)) import Ouroboros.Network.NodeToNode (AcceptedConnectionsLimit (..), DiffusionMode (..)) +-- Since we ignore unknown fields, if we've explictly removed or renamed +-- a field we should error out so that a user isn't surprised when they +-- upgrade. +data RemovedField = RemovedField { rfField :: Key, rfErr :: String } + deriving Show + +failOnRemovedFields :: Aeson.Object -> [RemovedField] -> Aeson.Parser () +failOnRemovedFields obj = mapM_ $ \(RemovedField field err) -> do + mVal :: Maybe Aeson.Value <- obj .:? field + when (isJust mVal) $ fail err + data NetworkP2PMode = EnabledP2PMode | DisabledP2PMode deriving (Eq, Show, Generic) @@ -374,8 +385,16 @@ instance FromJSON PartialNodeConfiguration where } parseHardForkProtocol v = do - npcTestEnableDevelopmentHardForkEras - <- v .:? "TestEnableDevelopmentHardForkEras" + + failOnRemovedFields v + [ RemovedField + { rfField = "TestEnableDevelopmentHardForkEras" + , rfErr = "TestEnableDevelopmentHardForkEras has been renamed to TestEnableAdvertiseDevelopmentProtVer" + } + ] + + npcTestEnableAdvertiseDevelopmentProtVer + <- v .:? "TestEnableAdvertiseDevelopmentProtVer" .!= False npcTestShelleyHardForkAtEpoch <- v .:? "TestShelleyHardForkAtEpoch" @@ -394,7 +413,7 @@ instance FromJSON PartialNodeConfiguration where npcTestBabbageHardForkAtVersion <- v .:? "TestBabbageHardForkAtVersion" pure NodeHardForkProtocolConfiguration { - npcTestEnableDevelopmentHardForkEras, + npcTestEnableAdvertiseDevelopmentProtVer, npcTestShelleyHardForkAtEpoch, npcTestShelleyHardForkAtVersion, diff --git a/cardano-node/src/Cardano/Node/Protocol/Cardano.hs b/cardano-node/src/Cardano/Node/Protocol/Cardano.hs index e62df0efe6d..8984cfb9f43 100644 --- a/cardano-node/src/Cardano/Node/Protocol/Cardano.hs +++ b/cardano-node/src/Cardano/Node/Protocol/Cardano.hs @@ -85,12 +85,12 @@ mkSomeConsensusProtocolCardano NodeByronProtocolConfiguration { npcAlonzoGenesisFileHash } NodeHardForkProtocolConfiguration { - -- 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 - -- not-yet-ready eras in released node versions without mainnet nodes - -- prematurely advertising that they could hard fork into the new era. + -- npcTestEnableDevelopmentProtVer + -- 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 + -- not-yet-ready eras in released node versions without mainnet nodes + -- prematurely advertising that they could hard fork into the new era. npcTestShelleyHardForkAtEpoch, npcTestShelleyHardForkAtVersion, npcTestAllegraHardForkAtEpoch, diff --git a/cardano-node/src/Cardano/Node/Types.hs b/cardano-node/src/Cardano/Node/Types.hs index 0753a5835eb..e380d886190 100644 --- a/cardano-node/src/Cardano/Node/Types.hs +++ b/cardano-node/src/Cardano/Node/Types.hs @@ -187,7 +187,7 @@ data NodeHardForkProtocolConfiguration = -- This flag should be set to true for nodes taking part in testnets for -- testing the new era. -- - npcTestEnableDevelopmentHardForkEras :: Bool + npcTestEnableAdvertiseDevelopmentProtVer :: Bool -- | For testing purposes we support specifying that the hard fork -- happens at an exact epoch number (ie the first epoch of the new era). diff --git a/cardano-testnet/src/Testnet/Babbage.hs b/cardano-testnet/src/Testnet/Babbage.hs index bf73e8af686..50e8e878a01 100644 --- a/cardano-testnet/src/Testnet/Babbage.hs +++ b/cardano-testnet/src/Testnet/Babbage.hs @@ -168,7 +168,7 @@ testnet testnetOptions H.Conf {..} = do . HM.insert "TestMaryHardForkAtEpoch" (toJSON @Int 0) . HM.insert "TestAlonzoHardForkAtEpoch" (toJSON @Int 0) . HM.insert "TestBabbageHardForkAtEpoch" (toJSON @Int 0) - . HM.insert "TestEnableDevelopmentHardForkEras" (toJSON True) + . HM.insert "TestEnableAdvertiseDevelopmentProtVer" (toJSON True) . flip HM.alter "setupScribes" ( fmap . J.rewriteArrayElements diff --git a/cardano-testnet/src/Testnet/Cardano.hs b/cardano-testnet/src/Testnet/Cardano.hs index cb8c90d1743..0016ea37ad8 100644 --- a/cardano-testnet/src/Testnet/Cardano.hs +++ b/cardano-testnet/src/Testnet/Cardano.hs @@ -246,7 +246,7 @@ testnet testnetOptions H.Conf {..} = do . HM.insert "LastKnownBlockVersion-Minor" (J.toJSON @Int 0) . HM.insert "TraceBlockchainTime" (J.toJSON True) . HM.delete "GenesisFile" - . HM.insert "TestEnableDevelopmentHardForkEras" (J.toJSON @Bool True) + . HM.insert "TestEnableAdvertiseDevelopmentProtVer" (J.toJSON @Bool True) . HM.insert "EnableP2P" (J.toJSON @Bool (enableP2P testnetOptions)) . flip HM.alter "setupScribes" ( fmap diff --git a/nix/workbench/profiles/node-services.nix b/nix/workbench/profiles/node-services.nix index a98c2efbef7..861dcfe5fa8 100644 --- a/nix/workbench/profiles/node-services.nix +++ b/nix/workbench/profiles/node-services.nix @@ -112,7 +112,7 @@ let ] // { - TestEnableDevelopmentHardForkEras = true; + TestEnableAdvertiseDevelopmentProtVer = true; TestEnableDevelopmentNetworkProtocols = true; TurnOnLogMetrics = true; };