From 8c1d6c4199af5c497e7dbf95894e1b3e943c0cb4 Mon Sep 17 00:00:00 2001 From: Sean D Gillespie Date: Tue, 16 Apr 2024 14:01:21 -0400 Subject: [PATCH] feature(cardano-db-sync): Add optional "enable_conway" config flag --- .../test/Test/Cardano/Db/Mock/Unit/Conway.hs | 3 + .../Db/Mock/Unit/Conway/Config/Parse.hs | 52 ++++++++ .../test-db-sync-config-disable-conway.json | 115 ++++++++++++++++++ .../test-db-sync-config-enable-conway.json | 115 ++++++++++++++++++ cardano-db-sync/src/Cardano/DbSync/Config.hs | 9 +- .../src/Cardano/DbSync/Config/Types.hs | 2 + cardano-db-sync/test/Cardano/DbSync/Gen.hs | 1 + 7 files changed, 295 insertions(+), 2 deletions(-) create mode 100644 cardano-chain-gen/test/testfiles/config-conway/test-db-sync-config-disable-conway.json create mode 100644 cardano-chain-gen/test/testfiles/config-conway/test-db-sync-config-enable-conway.json diff --git a/cardano-chain-gen/test/Test/Cardano/Db/Mock/Unit/Conway.hs b/cardano-chain-gen/test/Test/Cardano/Db/Mock/Unit/Conway.hs index 147e75986..f5e01b804 100644 --- a/cardano-chain-gen/test/Test/Cardano/Db/Mock/Unit/Conway.hs +++ b/cardano-chain-gen/test/Test/Cardano/Db/Mock/Unit/Conway.hs @@ -33,6 +33,9 @@ unitTests iom knownMigrations = , testCase "mismatched conway genesis hash" Config.wrongConwayGenesisHash , testCase "default insert config" Config.defaultInsertConfig , testCase "insert config" Config.insertConfig + , testCase "disable conway" Config.disableConway + , testCase "enable conway" Config.enableConway + , testCase "enable conway by default" Config.enableConwayDefault , testGroup "tx-out" [ test "consumed_by_tx_id column check" MigrateConsumedPruneTxOut.txConsumedColumnCheck diff --git a/cardano-chain-gen/test/Test/Cardano/Db/Mock/Unit/Conway/Config/Parse.hs b/cardano-chain-gen/test/Test/Cardano/Db/Mock/Unit/Conway/Config/Parse.hs index 1b464086b..aa90d09a1 100644 --- a/cardano-chain-gen/test/Test/Cardano/Db/Mock/Unit/Conway/Config/Parse.hs +++ b/cardano-chain-gen/test/Test/Cardano/Db/Mock/Unit/Conway/Config/Parse.hs @@ -8,6 +8,9 @@ module Test.Cardano.Db.Mock.Unit.Conway.Config.Parse ( wrongConwayGenesisHash, insertConfig, defaultInsertConfig, + disableConway, + enableConway, + enableConwayDefault, ) where import Cardano.DbSync.Config @@ -106,3 +109,52 @@ insertConfig = do dncInsertOptions cfg @?= expected where configDir = "config-conway-insert-options" + +disableConway :: Assertion +disableConway = do + cfg <- mkSyncNodeConfig configDir args + + -- Make the conway genesis invalid + hash <- Aeson.throwDecode "\"0000000000000000000000000000000000000000000000000000000000000000\"" + let cfg' = cfg {dncConwayGenesisHash = Just hash} + -- Should not throw + void $ mkConfig configDir mutableDir args cfg' + where + configDir = "config-conway" + mutableDir = mkMutableDir "configDisableConway" + args = + initCommandLineArgs + { claConfigFilename = "test-db-sync-config-disable-conway.json" + } + +enableConway :: Assertion +enableConway = do + cfg <- mkSyncNodeConfig configDir args + + -- There's no way to verify the file was actually loaded + isJust (dncConwayGenesisHash cfg) @?= True + isJust (dncConwayGenesisFile cfg) @?= True + + -- Should not throw + void $ mkConfig configDir mutableDir args cfg + where + configDir = "config-conway" + mutableDir = mkMutableDir "configDisableConway" + args = + initCommandLineArgs + { claConfigFilename = "test-db-sync-config-enable-conway.json" + } + +enableConwayDefault :: Assertion +enableConwayDefault = do + cfg <- mkSyncNodeConfig configDir initCommandLineArgs + + -- There's no way to verify the file was actually loaded + isJust (dncConwayGenesisHash cfg) @?= True + isJust (dncConwayGenesisFile cfg) @?= True + + -- Should not throw + void $ mkConfig configDir mutableDir initCommandLineArgs cfg + where + configDir = "config-conway" + mutableDir = mkMutableDir "configDisableConway" diff --git a/cardano-chain-gen/test/testfiles/config-conway/test-db-sync-config-disable-conway.json b/cardano-chain-gen/test/testfiles/config-conway/test-db-sync-config-disable-conway.json new file mode 100644 index 000000000..3d1be46a4 --- /dev/null +++ b/cardano-chain-gen/test/testfiles/config-conway/test-db-sync-config-disable-conway.json @@ -0,0 +1,115 @@ +{ + "EnableLogMetrics": false, + "EnableLogging": true, + "NetworkName": "testing", + "NodeConfigFile": "test-config.json", + "PrometheusPort": 8080, + "RequiresNetworkMagic": "RequiresMagic", + "defaultBackends": [ + "KatipBK" + ], + "defaultScribes": [ + [ + "StdoutSK", + "stdout" + ] + ], + "minSeverity": "Info", + "options": { + "cfokey": { + "value": "Release-1.0.0" + }, + "mapBackends": {}, + "mapSeverity": { + "db-sync-node": "Info", + "db-sync-node.Mux": "Error", + "db-sync-node.Subscription": "Error" + }, + "mapSubtrace": { + "#ekgview": { + "contents": [ + [ + { + "contents": "cardano.epoch-validation.benchmark", + "tag": "Contains" + }, + [ + { + "contents": ".monoclock.basic.", + "tag": "Contains" + } + ] + ], + [ + { + "contents": "cardano.epoch-validation.benchmark", + "tag": "Contains" + }, + [ + { + "contents": "diff.RTS.cpuNs.timed.", + "tag": "Contains" + } + ] + ], + [ + { + "contents": "#ekgview.#aggregation.cardano.epoch-validation.benchmark", + "tag": "StartsWith" + }, + [ + { + "contents": "diff.RTS.gcNum.timed.", + "tag": "Contains" + } + ] + ] + ], + "subtrace": "FilterTrace" + }, + "#messagecounters.aggregation": { + "subtrace": "NoTrace" + }, + "#messagecounters.ekgview": { + "subtrace": "NoTrace" + }, + "#messagecounters.katip": { + "subtrace": "NoTrace" + }, + "#messagecounters.monitoring": { + "subtrace": "NoTrace" + }, + "#messagecounters.switchboard": { + "subtrace": "NoTrace" + }, + "benchmark": { + "contents": [ + "GhcRtsStats", + "MonotonicClock" + ], + "subtrace": "ObservableTrace" + }, + "cardano.epoch-validation.utxo-stats": { + "subtrace": "NoTrace" + } + } + }, + "rotation": { + "rpKeepFilesNum": 10, + "rpLogLimitBytes": 5000000, + "rpMaxAgeHours": 24 + }, + "setupBackends": [ + "AggregationBK", + "KatipBK" + ], + "setupScribes": [ + { + "scFormat": "ScText", + "scKind": "StdoutSK", + "scName": "stdout", + "scRotation": null + } + ], + "enable_conway": false +} diff --git a/cardano-chain-gen/test/testfiles/config-conway/test-db-sync-config-enable-conway.json b/cardano-chain-gen/test/testfiles/config-conway/test-db-sync-config-enable-conway.json new file mode 100644 index 000000000..174def7f6 --- /dev/null +++ b/cardano-chain-gen/test/testfiles/config-conway/test-db-sync-config-enable-conway.json @@ -0,0 +1,115 @@ +{ + "EnableLogMetrics": false, + "EnableLogging": true, + "NetworkName": "testing", + "NodeConfigFile": "test-config.json", + "PrometheusPort": 8080, + "RequiresNetworkMagic": "RequiresMagic", + "defaultBackends": [ + "KatipBK" + ], + "defaultScribes": [ + [ + "StdoutSK", + "stdout" + ] + ], + "minSeverity": "Info", + "options": { + "cfokey": { + "value": "Release-1.0.0" + }, + "mapBackends": {}, + "mapSeverity": { + "db-sync-node": "Info", + "db-sync-node.Mux": "Error", + "db-sync-node.Subscription": "Error" + }, + "mapSubtrace": { + "#ekgview": { + "contents": [ + [ + { + "contents": "cardano.epoch-validation.benchmark", + "tag": "Contains" + }, + [ + { + "contents": ".monoclock.basic.", + "tag": "Contains" + } + ] + ], + [ + { + "contents": "cardano.epoch-validation.benchmark", + "tag": "Contains" + }, + [ + { + "contents": "diff.RTS.cpuNs.timed.", + "tag": "Contains" + } + ] + ], + [ + { + "contents": "#ekgview.#aggregation.cardano.epoch-validation.benchmark", + "tag": "StartsWith" + }, + [ + { + "contents": "diff.RTS.gcNum.timed.", + "tag": "Contains" + } + ] + ] + ], + "subtrace": "FilterTrace" + }, + "#messagecounters.aggregation": { + "subtrace": "NoTrace" + }, + "#messagecounters.ekgview": { + "subtrace": "NoTrace" + }, + "#messagecounters.katip": { + "subtrace": "NoTrace" + }, + "#messagecounters.monitoring": { + "subtrace": "NoTrace" + }, + "#messagecounters.switchboard": { + "subtrace": "NoTrace" + }, + "benchmark": { + "contents": [ + "GhcRtsStats", + "MonotonicClock" + ], + "subtrace": "ObservableTrace" + }, + "cardano.epoch-validation.utxo-stats": { + "subtrace": "NoTrace" + } + } + }, + "rotation": { + "rpKeepFilesNum": 10, + "rpLogLimitBytes": 5000000, + "rpMaxAgeHours": 24 + }, + "setupBackends": [ + "AggregationBK", + "KatipBK" + ], + "setupScribes": [ + { + "scFormat": "ScText", + "scKind": "StdoutSK", + "scName": "stdout", + "scRotation": null + } + ], + "enable_conway": true +} diff --git a/cardano-db-sync/src/Cardano/DbSync/Config.hs b/cardano-db-sync/src/Cardano/DbSync/Config.hs index 2ff8cec79..5daf60e1a 100644 --- a/cardano-db-sync/src/Cardano/DbSync/Config.hs +++ b/cardano-db-sync/src/Cardano/DbSync/Config.hs @@ -58,6 +58,11 @@ coalesceConfig :: IO SyncNodeConfig coalesceConfig pcfg ncfg adjustGenesisPath = do lc <- Logging.setupFromRepresentation $ pcLoggingConfig pcfg + + let (conwayGenesisFile', conwayGenesisHash') + | pcEnableConway pcfg = (ncConwayGenesisFile ncfg, ncConwayGenesisHash ncfg) + | otherwise = (Nothing, Nothing) + pure $ SyncNodeConfig { dncNetworkName = pcNetworkName pcfg @@ -76,8 +81,8 @@ coalesceConfig pcfg ncfg adjustGenesisPath = do , dncAlonzoGenesisFile = adjustGenesisFilePath adjustGenesisPath (ncAlonzoGenesisFile ncfg) , dncAlonzoGenesisHash = ncAlonzoGenesisHash ncfg , dncConwayGenesisFile = - adjustGenesisFilePath adjustGenesisPath <$> ncConwayGenesisFile ncfg - , dncConwayGenesisHash = ncConwayGenesisHash ncfg + adjustGenesisFilePath adjustGenesisPath <$> conwayGenesisFile' + , dncConwayGenesisHash = conwayGenesisHash' , dncByronProtocolVersion = ncByronProtocolVersion ncfg , dncShelleyHardFork = ncShelleyHardFork ncfg , dncAllegraHardFork = ncAllegraHardFork ncfg diff --git a/cardano-db-sync/src/Cardano/DbSync/Config/Types.hs b/cardano-db-sync/src/Cardano/DbSync/Config/Types.hs index 4814deb2f..4857d45d2 100644 --- a/cardano-db-sync/src/Cardano/DbSync/Config/Types.hs +++ b/cardano-db-sync/src/Cardano/DbSync/Config/Types.hs @@ -143,6 +143,7 @@ data SyncPreConfig = SyncPreConfig , pcEnableMetrics :: !Bool , pcPrometheusPort :: !Int , pcInsertConfig :: !SyncInsertConfig + , pcEnableConway :: !Bool } deriving (Show) @@ -356,6 +357,7 @@ parseGenSyncNodeConfig o = <*> o .: "EnableLogMetrics" <*> fmap (fromMaybe 8080) (o .:? "PrometheusPort") <*> o .:? "insert_options" .!= def + <*> o .:? "enable_conway" .!= True instance FromJSON SyncProtocol where parseJSON o = diff --git a/cardano-db-sync/test/Cardano/DbSync/Gen.hs b/cardano-db-sync/test/Cardano/DbSync/Gen.hs index ef8c75829..b59a20b67 100644 --- a/cardano-db-sync/test/Cardano/DbSync/Gen.hs +++ b/cardano-db-sync/test/Cardano/DbSync/Gen.hs @@ -54,6 +54,7 @@ syncPreConfig = <*> Gen.bool <*> Gen.int (Range.linear 0 10000) <*> syncInsertConfig + <*> Gen.bool syncNodeParams :: MonadGen m => m SyncNodeParams syncNodeParams =