From ce9fcf3041fa9a10fe34c2a58c69deeff8f5348d 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 ++++++++++++++++--- cardano-node/src/Cardano/Node/Types.hs | 2 +- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/cardano-node/src/Cardano/Node/Configuration/POM.hs b/cardano-node/src/Cardano/Node/Configuration/POM.hs index 6216543412d..852bb6305b6 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 = "TestEnableDecelopmentHardForkEras 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/Types.hs b/cardano-node/src/Cardano/Node/Types.hs index 3510dc30b7e..46d8f78c56e 100644 --- a/cardano-node/src/Cardano/Node/Types.hs +++ b/cardano-node/src/Cardano/Node/Types.hs @@ -188,7 +188,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).