Skip to content

Commit

Permalink
Move location of genesis file from command line to config file
Browse files Browse the repository at this point in the history
The HFC/Cardano mode requires both a Byron genesis and a Shelley
genesis files, so move the specification of these to the db-sync
config file.
  • Loading branch information
erikd committed Jul 16, 2020
1 parent 5fa0520 commit 30f674f
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 44 deletions.
14 changes: 2 additions & 12 deletions cardano-db-sync-extended/app/cardano-db-sync-extended.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import Cardano.Prelude

import Cardano.Db (MigrationDir (..))
import Cardano.DbSync (ConfigFile (..), DbSyncNodeParams (..), GenesisFile (..),
SocketPath (..), runDbSyncNode)
import Cardano.DbSync (ConfigFile (..), DbSyncNodeParams (..), SocketPath (..),
runDbSyncNode)
import Cardano.DbSync.Plugin.Extended (extendedDbSyncNodePlugin)

import Cardano.Slotting.Slot (SlotNo (..))
Expand All @@ -30,7 +30,6 @@ pCommandLine :: Parser DbSyncNodeParams
pCommandLine =
DbSyncNodeParams
<$> pConfigFile
<*> pGenesisFile
<*> pSocketPath
<*> pMigrationDir
<*> optional pSlotNo
Expand All @@ -44,15 +43,6 @@ pConfigFile =
<> Opt.metavar "FILEPATH"
)

pGenesisFile :: Parser GenesisFile
pGenesisFile =
GenesisFile <$> Opt.strOption
( Opt.long "genesis-file"
<> Opt.help "Path to the genesis JSON file"
<> Opt.completer (Opt.bashCompleter "file")
<> Opt.metavar "FILEPATH"
)

pMigrationDir :: Parser MigrationDir
pMigrationDir =
MigrationDir <$> Opt.strOption
Expand Down
14 changes: 2 additions & 12 deletions cardano-db-sync/app/cardano-db-sync.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import Cardano.Prelude

import Cardano.Db (MigrationDir (..))
import Cardano.DbSync (ConfigFile (..), DbSyncNodeParams (..), GenesisFile (..),
SocketPath (..), defDbSyncNodePlugin, runDbSyncNode)
import Cardano.DbSync (ConfigFile (..), DbSyncNodeParams (..), SocketPath (..),
defDbSyncNodePlugin, runDbSyncNode)

import Cardano.Slotting.Slot (SlotNo (..))

Expand All @@ -29,7 +29,6 @@ pCommandLine :: Parser DbSyncNodeParams
pCommandLine =
DbSyncNodeParams
<$> pConfigFile
<*> pGenesisFile
<*> pSocketPath
<*> pMigrationDir
<*> optional pSlotNo
Expand All @@ -43,15 +42,6 @@ pConfigFile =
<> Opt.metavar "FILEPATH"
)

pGenesisFile :: Parser GenesisFile
pGenesisFile =
GenesisFile <$> Opt.strOption
( Opt.long "genesis-file"
<> Opt.help "Path to the genesis JSON file"
<> Opt.completer (Opt.bashCompleter "file")
<> Opt.metavar "FILEPATH"
)

pMigrationDir :: Parser MigrationDir
pMigrationDir =
MigrationDir <$> Opt.strOption
Expand Down
2 changes: 1 addition & 1 deletion cardano-db-sync/src/Cardano/DbSync.hs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ runDbSyncNode plugin enp =
Nothing -> pure ()

orDie renderDbSyncNodeError $ do
genCfg <- readGenesisConfig enp enc
genCfg <- readGenesisConfig enc
logProtocolMagic trce $ genesisProtocolMagic genCfg

-- If the DB is empty it will be inserted, otherwise it will be validated (to make
Expand Down
15 changes: 13 additions & 2 deletions cardano-db-sync/src/Cardano/DbSync/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

module Cardano.DbSync.Config
( DbSyncNodeConfig
, GenesisFile (..)
, GenesisHash (..)
, GenDbSyncNodeConfig (..)
, NetworkName (..)
Expand Down Expand Up @@ -34,12 +35,19 @@ type DbSyncNodeConfig = GenDbSyncNodeConfig Logging.Configuration
data GenDbSyncNodeConfig a = GenDbSyncNodeConfig
{ encNetworkName :: !NetworkName
, encLoggingConfig :: !a
, encGenesisHash :: !GenesisHash
, encByronGenesisFile :: !GenesisFile
, encByronGenesisHash :: !GenesisHash
, encShelleyGenesisFile :: !GenesisFile
, encShelleyGenesisHash :: !GenesisHash
, encEnableLogging :: !Bool
, encEnableMetrics :: !Bool
, encRequiresNetworkMagic :: !RequiresNetworkMagic
}

newtype GenesisFile = GenesisFile
{ unGenesisFile :: FilePath
}

newtype GenesisHash = GenesisHash
{ unGenesisHash :: Text
}
Expand Down Expand Up @@ -77,7 +85,10 @@ parseGenDbSyncNodeConfig o =
GenDbSyncNodeConfig
<$> fmap NetworkName (o .: "NetworkName")
<*> parseJSON (Object o)
<*> fmap GenesisHash (o .: "GenesisHash")
<*> fmap GenesisFile (o .: "ByronGenesisFile")
<*> fmap GenesisHash (o .: "ByronGenesisHash")
<*> fmap GenesisFile (o .: "ShelleyGenesisFile")
<*> fmap GenesisHash (o .: "ShelleyGenesisHash")
<*> o .: "EnableLogging"
<*> o .: "EnableLogMetrics"
<*> o .: "RequiresNetworkMagic"
22 changes: 11 additions & 11 deletions cardano-db-sync/src/Cardano/DbSync/Era.hs
Original file line number Diff line number Diff line change
Expand Up @@ -92,29 +92,29 @@ insertValidateGenesisDist trce nname genCfg =
-- -----------------------------------------------------------------------------

readGenesisConfig
:: DbSyncNodeParams -> DbSyncNodeConfig
:: DbSyncNodeConfig
-> ExceptT DbSyncNodeError IO GenesisEra
readGenesisConfig enp enc = do
res <- liftIO $ runExceptT (readByronGenesisConfig enp enc)
readGenesisConfig enc = do
res <- liftIO $ runExceptT (readByronGenesisConfig enc)
case res of
Right gb -> pure $ GenesisByron gb
Left _ -> GenesisShelley <$> readShelleyGenesisConfig enp enc
Left _ -> GenesisShelley <$> readShelleyGenesisConfig enc


readByronGenesisConfig
:: DbSyncNodeParams -> DbSyncNodeConfig
:: DbSyncNodeConfig
-> ExceptT DbSyncNodeError IO Byron.Config
readByronGenesisConfig enp enc = do
let file = unGenesisFile $ enpGenesisFile enp
readByronGenesisConfig enc = do
let file = unGenesisFile $ encByronGenesisFile enc
genHash <- firstExceptT NEError
. hoistEither $ decodeAbstractHash (unGenesisHash $ encGenesisHash enc)
. hoistEither $ decodeAbstractHash (unGenesisHash $ encByronGenesisHash enc)
firstExceptT (NEByronConfig file)
$ Byron.mkConfigFromFile (encRequiresNetworkMagic enc) file genHash

readShelleyGenesisConfig
:: DbSyncNodeParams -> DbSyncNodeConfig
:: DbSyncNodeConfig
-> ExceptT DbSyncNodeError IO (ShelleyGenesis TPraosStandardCrypto)
readShelleyGenesisConfig enp _enc = do
let file = unGenesisFile $ enpGenesisFile enp
readShelleyGenesisConfig enc = do
let file = unGenesisFile $ encShelleyGenesisFile enc
firstExceptT (NEShelleyConfig file . Text.pack)
. newExceptT $ Aeson.eitherDecodeFileStrict' file
6 changes: 0 additions & 6 deletions cardano-db-sync/src/Cardano/DbSync/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ module Cardano.DbSync.Types
, ConfigFile (..)
, DbSyncEnv (..)
, DbSyncNodeParams (..)
, GenesisFile (..)
, ShelleyAddress
, ShelleyBlock
, ShelleyDCert
Expand Down Expand Up @@ -60,7 +59,6 @@ newtype ConfigFile = ConfigFile
-- | The product type of all command line arguments
data DbSyncNodeParams = DbSyncNodeParams
{ enpConfigFile :: !ConfigFile
, enpGenesisFile :: !GenesisFile
, enpSocketPath :: !SocketPath
, enpMigrationDir :: !MigrationDir
, enpMaybeRollback :: !(Maybe SlotNo)
Expand All @@ -70,10 +68,6 @@ data DbSyncEnv
= ByronEnv
| ShelleyEnv !Shelley.Network

newtype GenesisFile = GenesisFile
{ unGenesisFile :: FilePath
}

type ShelleyAddress = Shelley.Addr Shelley.TPraosStandardCrypto
type ShelleyBlock = Shelley.ShelleyBlock Shelley.TPraosStandardCrypto
type ShelleyDCert = Shelley.DCert Shelley.TPraosStandardCrypto
Expand Down

0 comments on commit 30f674f

Please sign in to comment.