Skip to content
This repository has been archived by the owner on Dec 8, 2022. It is now read-only.

Commit

Permalink
Merge pull request #100 from input-output-hk/ksaric/CAD-2088
Browse files Browse the repository at this point in the history
[CAD-2088] Resolve paths relative to the config file, not the executable
  • Loading branch information
ksaric authored Oct 21, 2020
2 parents d335fed + 51d58c4 commit c0d9e1b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 12 deletions.
4 changes: 2 additions & 2 deletions config/mainnet-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ Protocol: Cardano

RequiresNetworkMagic: RequiresNoMagic

ByronGenesisFile: config/mainnet-byron-genesis.json
ByronGenesisFile: mainnet-byron-genesis.json
ByronGenesisHash: 5f20df933584822601f9e3f8c024eb5eb252fe8cefb24d1317dc3d432e940ebb

# Shelley genesis is not actully used but to specify Protocol Cardano, we need to sepcify one.
ShelleyGenesisFile: config/mainnet-shelley-genesis.json
ShelleyGenesisFile: mainnet-shelley-genesis.json
ShelleyGenesisHash: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

# ------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion config/testnet-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Protocol: Byron

RequiresNetworkMagic: RequiresMagic

ByronGenesisFile: ../cardano-node/configuration/defaults/byron-testnet/genesis.json
ByronGenesisFile: ../../cardano-node/configuration/defaults/byron-testnet/genesis.json
ByronGenesisHash: 96fceff972c2c06bd3bb5243c39215333be6d56aaf4823073dca31afe5038471

ShelleyGenesisFile: not/applicable
Expand Down
35 changes: 26 additions & 9 deletions src/Cardano/SmashDbSync.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@ import Prelude (String)
import qualified Prelude

import Control.Monad.Trans.Except.Extra (firstExceptT,
newExceptT,
hoistEither)
hoistEither,
newExceptT)
import Control.Tracer (Tracer)

import Cardano.BM.Data.Tracer (ToLogObject (..))
import qualified Cardano.BM.Setup as Logging
import Cardano.BM.Trace (Trace, appendName,
modifyName, logInfo)
logInfo,
modifyName)
import qualified Cardano.BM.Trace as Logging

import Cardano.Client.Subscription (subscribe)
Expand All @@ -49,9 +50,9 @@ import Cardano.DbSync.Plugin (DbSyncNo
import Cardano.DbSync.Tracing.ToObjectOrphans ()
import Cardano.DbSync.Types (ConfigFile (..),
DbSyncEnv (..),
SocketPath (..),
SlotDetails(..),
EpochSlot(..))
EpochSlot (..),
SlotDetails (..),
SocketPath (..))
import Cardano.DbSync.Util

import Cardano.Prelude hiding
Expand Down Expand Up @@ -85,7 +86,7 @@ import Network.Socket (SockAddr

import Network.TypedProtocol.Pipelined (Nat (Succ, Zero))

import Offline (runOfflineFetchThread)
import Offline (runOfflineFetchThread)

import Ouroboros.Network.Driver.Simple (runPipelinedPeer)

Expand Down Expand Up @@ -149,11 +150,12 @@ import Ouroboros.Network.Protocol.ChainSync.Type (ChainSyn
import qualified Ouroboros.Network.Snocket as Snocket
import Ouroboros.Network.Subscription (SubscriptionTrace)

import Ouroboros.Consensus.Cardano.Block
import Ouroboros.Consensus.Shelley.Node (ShelleyGenesis (..))
import Ouroboros.Consensus.Shelley.Protocol (TPraosStandardCrypto)
import Ouroboros.Consensus.Cardano.Block

import qualified Shelley.Spec.Ledger.Genesis as Shelley
import System.FilePath

import qualified System.Metrics.Prometheus.Metric.Gauge as Gauge

Expand All @@ -171,17 +173,32 @@ data SmashDbSyncNodeParams = SmashDbSyncNodeParams
, senpMaybeRollback :: !(Maybe SlotNo)
}

adjustGenesisFilePath :: (FilePath -> FilePath) -> GenesisFile -> GenesisFile
adjustGenesisFilePath f (GenesisFile p) = GenesisFile (f p)

mkAdjustPath :: ConfigFile -> (FilePath -> FilePath)
mkAdjustPath (ConfigFile configFile) fp = takeDirectory configFile </> fp

runDbSyncNode :: DbSyncNodePlugin -> SmashDbSyncNodeParams -> IO ()
runDbSyncNode plugin enp =
withIOManager $ \iomgr -> do

enc <- readDbSyncNodeConfig (unConfigFile $ senpConfigFile enp)
let configFile = senpConfigFile enp
readEnc <- readDbSyncNodeConfig (unConfigFile configFile)

-- Fix genesis paths to be relative to the config file directory.
let enc = readEnc
{ encByronGenesisFile = adjustGenesisFilePath (mkAdjustPath configFile) (encByronGenesisFile readEnc)
, encShelleyGenesisFile = adjustGenesisFilePath (mkAdjustPath configFile) (encShelleyGenesisFile readEnc)
}

trce <- if not (encEnableLogging enc)
then pure Logging.nullTracer
else liftIO $ Logging.setupTrace (Right $ encLoggingConfig enc) "smash-node"

logInfo trce $ "Using byron genesis file from: " <> (show . unGenesisFile $ encByronGenesisFile enc)
logInfo trce $ "Using shelley genesis file from: " <> (show . unGenesisFile $ encShelleyGenesisFile enc)

logInfo trce $ "Running migrations."

DB.runMigrations Prelude.id True (senpMigrationDir enp) (Just $ DB.SmashLogFileDir "/tmp")
Expand Down

0 comments on commit c0d9e1b

Please sign in to comment.