{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}

{-# OPTIONS_GHC -Wno-noncanonical-monoid-instances #-}

module Cardano.Node.Configuration.POM
  ( NodeConfiguration (..)
  , NetworkP2PMode (..)
  , SomeNetworkP2PMode (..)
  , PartialNodeConfiguration(..)
  , defaultPartialNodeConfiguration
  , lastOption
  , makeNodeConfiguration
  , parseNodeConfigurationFP
  , pncProtocol
  , ncProtocol
  )
where

import           Cardano.Prelude
import qualified GHC.Show as Show
import           Prelude (String)

import           Control.Monad (fail)
import           Data.Aeson
import qualified Data.Aeson.Types as Aeson
import qualified Data.Text as Text
import           Data.Time.Clock (DiffTime)
import           Data.Yaml (decodeFileThrow)
import           Generic.Data (gmappend)
import           Generic.Data.Orphans ()
import           Options.Applicative
import           System.FilePath (takeDirectory, (</>))

import qualified Cardano.Chain.Update as Byron
import           Cardano.Crypto (RequiresNetworkMagic (..))
import           Cardano.Logging.Types
import           Cardano.Node.Configuration.NodeAddress (SocketPath)
import           Cardano.Node.Configuration.Socket (SocketConfig (..))
import           Cardano.Node.Handlers.Shutdown
import           Cardano.Node.Protocol.Types (Protocol (..))
import           Cardano.Node.Types
import           Cardano.Tracing.Config
import           Ouroboros.Consensus.Mempool.API (MempoolCapacityBytes (..),
                   MempoolCapacityBytesOverride (..))
import qualified Ouroboros.Consensus.Node as Consensus (NetworkP2PMode (..))
import           Ouroboros.Consensus.Storage.LedgerDB.DiskPolicy (SnapshotInterval (..))
import           Ouroboros.Network.NodeToNode (AcceptedConnectionsLimit (..), DiffusionMode (..))

data NetworkP2PMode = EnabledP2PMode | DisabledP2PMode
  deriving (NetworkP2PMode -> NetworkP2PMode -> Bool
(NetworkP2PMode -> NetworkP2PMode -> Bool)
-> (NetworkP2PMode -> NetworkP2PMode -> Bool) -> Eq NetworkP2PMode
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: NetworkP2PMode -> NetworkP2PMode -> Bool
$c/= :: NetworkP2PMode -> NetworkP2PMode -> Bool
== :: NetworkP2PMode -> NetworkP2PMode -> Bool
$c== :: NetworkP2PMode -> NetworkP2PMode -> Bool
Eq, Int -> NetworkP2PMode -> ShowS
[NetworkP2PMode] -> ShowS
NetworkP2PMode -> String
(Int -> NetworkP2PMode -> ShowS)
-> (NetworkP2PMode -> String)
-> ([NetworkP2PMode] -> ShowS)
-> Show NetworkP2PMode
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [NetworkP2PMode] -> ShowS
$cshowList :: [NetworkP2PMode] -> ShowS
show :: NetworkP2PMode -> String
$cshow :: NetworkP2PMode -> String
showsPrec :: Int -> NetworkP2PMode -> ShowS
$cshowsPrec :: Int -> NetworkP2PMode -> ShowS
Show, (forall x. NetworkP2PMode -> Rep NetworkP2PMode x)
-> (forall x. Rep NetworkP2PMode x -> NetworkP2PMode)
-> Generic NetworkP2PMode
forall x. Rep NetworkP2PMode x -> NetworkP2PMode
forall x. NetworkP2PMode -> Rep NetworkP2PMode x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep NetworkP2PMode x -> NetworkP2PMode
$cfrom :: forall x. NetworkP2PMode -> Rep NetworkP2PMode x
Generic)

data SomeNetworkP2PMode where
    SomeNetworkP2PMode :: forall p2p.
                          Consensus.NetworkP2PMode p2p
                       -> SomeNetworkP2PMode

instance Eq SomeNetworkP2PMode where
    == :: SomeNetworkP2PMode -> SomeNetworkP2PMode -> Bool
(==) (SomeNetworkP2PMode NetworkP2PMode p2p
Consensus.EnabledP2PMode)
         (SomeNetworkP2PMode NetworkP2PMode p2p
Consensus.EnabledP2PMode)
       = Bool
True
    (==) (SomeNetworkP2PMode NetworkP2PMode p2p
Consensus.DisabledP2PMode)
         (SomeNetworkP2PMode NetworkP2PMode p2p
Consensus.DisabledP2PMode)
       = Bool
True
    (==) SomeNetworkP2PMode
_ SomeNetworkP2PMode
_
       = Bool
False

instance Show SomeNetworkP2PMode where
    show :: SomeNetworkP2PMode -> String
show (SomeNetworkP2PMode mode :: NetworkP2PMode p2p
mode@NetworkP2PMode p2p
Consensus.EnabledP2PMode)  = NetworkP2PMode p2p -> String
forall a b. (Show a, ConvertText String b) => a -> b
show NetworkP2PMode p2p
mode
    show (SomeNetworkP2PMode mode :: NetworkP2PMode p2p
mode@NetworkP2PMode p2p
Consensus.DisabledP2PMode) = NetworkP2PMode p2p -> String
forall a b. (Show a, ConvertText String b) => a -> b
show NetworkP2PMode p2p
mode

data NodeConfiguration
  = NodeConfiguration
      {  NodeConfiguration -> SocketConfig
ncSocketConfig    :: !SocketConfig
           -- | Filepath of the configuration yaml file. This file determines
          -- all the configuration settings required for the cardano node
          -- (logging, tracing, protocol, slot length etc)
       , NodeConfiguration -> ConfigYamlFilePath
ncConfigFile      :: !ConfigYamlFilePath
       , NodeConfiguration -> TopologyFile
ncTopologyFile    :: !TopologyFile
       , NodeConfiguration -> DbFile
ncDatabaseFile    :: !DbFile
       , NodeConfiguration -> ProtocolFilepaths
ncProtocolFiles   :: !ProtocolFilepaths
       , NodeConfiguration -> Bool
ncValidateDB      :: !Bool
       , NodeConfiguration -> ShutdownConfig
ncShutdownConfig  :: !ShutdownConfig

        -- Protocol-specific parameters:
       , NodeConfiguration -> NodeProtocolConfiguration
ncProtocolConfig :: !NodeProtocolConfiguration

         -- Node parameters, not protocol-specific:
       , NodeConfiguration -> DiffusionMode
ncDiffusionMode    :: !DiffusionMode
       , NodeConfiguration -> SnapshotInterval
ncSnapshotInterval :: !SnapshotInterval

         -- | During the development and integration of new network protocols
         -- (node-to-node and node-to-client) we wish to be able to test them
         -- but not have everybody use them by default on the mainnet. Avoiding
         -- enabling them by default makes it practical to include such
         -- not-yet-ready protocol versions into released versions of the node
         -- without the danger that node operators on the mainnet will start
         -- using them prematurely, before the testing is complete.
         --
         -- The flag defaults to 'False'
         --
         -- This flag should be set to 'True' when testing the new protocol
         -- versions.
       , NodeConfiguration -> Bool
ncTestEnableDevelopmentNetworkProtocols :: !Bool

         -- BlockFetch configuration
       , NodeConfiguration -> Maybe MaxConcurrencyBulkSync
ncMaxConcurrencyBulkSync :: !(Maybe MaxConcurrencyBulkSync)
       , NodeConfiguration -> Maybe MaxConcurrencyDeadline
ncMaxConcurrencyDeadline :: !(Maybe MaxConcurrencyDeadline)

         -- Logging parameters:
       , NodeConfiguration -> Bool
ncLoggingSwitch  :: !Bool
       , NodeConfiguration -> Bool
ncLogMetrics     :: !Bool
       , NodeConfiguration -> TraceOptions
ncTraceConfig    :: !TraceOptions
       , NodeConfiguration -> Maybe (SocketPath, ForwarderMode)
ncTraceForwardSocket :: !(Maybe (SocketPath, ForwarderMode))

       , NodeConfiguration -> Maybe MempoolCapacityBytesOverride
ncMaybeMempoolCapacityOverride :: !(Maybe MempoolCapacityBytesOverride)

         -- | Protocol idleness timeout, see
         -- 'Ouroboros.Network.Diffusion.daProtocolIdleTimeout'.
         --
       , NodeConfiguration -> DiffTime
ncProtocolIdleTimeout   :: DiffTime
         -- | Wait time timeout, see
         -- 'Ouroboros.Network.Diffusion.daTimeWaitTimeout'.
         --
       , NodeConfiguration -> DiffTime
ncTimeWaitTimeout       :: DiffTime

         -- | Node AcceptedConnectionsLimit
       , NodeConfiguration -> AcceptedConnectionsLimit
ncAcceptedConnectionsLimit :: !AcceptedConnectionsLimit

         -- P2P governor targets
       , NodeConfiguration -> Int
ncTargetNumberOfRootPeers        :: Int
       , NodeConfiguration -> Int
ncTargetNumberOfKnownPeers       :: Int
       , NodeConfiguration -> Int
ncTargetNumberOfEstablishedPeers :: Int
       , NodeConfiguration -> Int
ncTargetNumberOfActivePeers      :: Int

         -- Enable experimental P2P mode
       , NodeConfiguration -> SomeNetworkP2PMode
ncEnableP2P :: SomeNetworkP2PMode
       } deriving (NodeConfiguration -> NodeConfiguration -> Bool
(NodeConfiguration -> NodeConfiguration -> Bool)
-> (NodeConfiguration -> NodeConfiguration -> Bool)
-> Eq NodeConfiguration
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: NodeConfiguration -> NodeConfiguration -> Bool
$c/= :: NodeConfiguration -> NodeConfiguration -> Bool
== :: NodeConfiguration -> NodeConfiguration -> Bool
$c== :: NodeConfiguration -> NodeConfiguration -> Bool
Eq, Int -> NodeConfiguration -> ShowS
[NodeConfiguration] -> ShowS
NodeConfiguration -> String
(Int -> NodeConfiguration -> ShowS)
-> (NodeConfiguration -> String)
-> ([NodeConfiguration] -> ShowS)
-> Show NodeConfiguration
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [NodeConfiguration] -> ShowS
$cshowList :: [NodeConfiguration] -> ShowS
show :: NodeConfiguration -> String
$cshow :: NodeConfiguration -> String
showsPrec :: Int -> NodeConfiguration -> ShowS
$cshowsPrec :: Int -> NodeConfiguration -> ShowS
Show)


data PartialNodeConfiguration
  = PartialNodeConfiguration
      {  PartialNodeConfiguration -> Last SocketConfig
pncSocketConfig    :: !(Last SocketConfig)
         -- | Filepath of the configuration yaml file. This file determines
         -- all the configuration settings required for the cardano node
         -- (logging, tracing, protocol, slot length etc)
       , PartialNodeConfiguration -> Last ConfigYamlFilePath
pncConfigFile      :: !(Last ConfigYamlFilePath)
       , PartialNodeConfiguration -> Last TopologyFile
pncTopologyFile    :: !(Last TopologyFile)
       , PartialNodeConfiguration -> Last DbFile
pncDatabaseFile    :: !(Last DbFile)
       , PartialNodeConfiguration -> Last ProtocolFilepaths
pncProtocolFiles   :: !(Last ProtocolFilepaths)
       , PartialNodeConfiguration -> Last Bool
pncValidateDB      :: !(Last Bool)
       , PartialNodeConfiguration -> Last ShutdownConfig
pncShutdownConfig  :: !(Last ShutdownConfig)

         -- Protocol-specific parameters:
       , PartialNodeConfiguration -> Last NodeProtocolConfiguration
pncProtocolConfig :: !(Last NodeProtocolConfiguration)

         -- Node parameters, not protocol-specific:
       , PartialNodeConfiguration -> Last DiffusionMode
pncDiffusionMode    :: !(Last DiffusionMode)
       , PartialNodeConfiguration -> Last SnapshotInterval
pncSnapshotInterval :: !(Last SnapshotInterval)
       , PartialNodeConfiguration -> Last Bool
pncTestEnableDevelopmentNetworkProtocols :: !(Last Bool)

         -- BlockFetch configuration
       , PartialNodeConfiguration -> Last MaxConcurrencyBulkSync
pncMaxConcurrencyBulkSync :: !(Last MaxConcurrencyBulkSync)
       , PartialNodeConfiguration -> Last MaxConcurrencyDeadline
pncMaxConcurrencyDeadline :: !(Last MaxConcurrencyDeadline)

         -- Logging parameters:
       , PartialNodeConfiguration -> Last Bool
pncLoggingSwitch  :: !(Last Bool)
       , PartialNodeConfiguration -> Last Bool
pncLogMetrics     :: !(Last Bool)
       , PartialNodeConfiguration -> Last PartialTraceOptions
pncTraceConfig    :: !(Last PartialTraceOptions)
       , PartialNodeConfiguration -> Last (SocketPath, ForwarderMode)
pncTraceForwardSocket :: !(Last (SocketPath, ForwarderMode))

         -- Configuration for testing purposes
       , PartialNodeConfiguration -> Last MempoolCapacityBytesOverride
pncMaybeMempoolCapacityOverride :: !(Last MempoolCapacityBytesOverride)

         -- Network timeouts
       , PartialNodeConfiguration -> Last DiffTime
pncProtocolIdleTimeout   :: !(Last DiffTime)
       , PartialNodeConfiguration -> Last DiffTime
pncTimeWaitTimeout       :: !(Last DiffTime)

         -- AcceptedConnectionsLimit
       , PartialNodeConfiguration -> Last AcceptedConnectionsLimit
pncAcceptedConnectionsLimit :: !(Last AcceptedConnectionsLimit)

         -- P2P governor targets
       , PartialNodeConfiguration -> Last Int
pncTargetNumberOfRootPeers        :: !(Last Int)
       , PartialNodeConfiguration -> Last Int
pncTargetNumberOfKnownPeers       :: !(Last Int)
       , PartialNodeConfiguration -> Last Int
pncTargetNumberOfEstablishedPeers :: !(Last Int)
       , PartialNodeConfiguration -> Last Int
pncTargetNumberOfActivePeers      :: !(Last Int)

         -- Enable experimental P2P mode
       , PartialNodeConfiguration -> Last NetworkP2PMode
pncEnableP2P :: !(Last NetworkP2PMode)
       } deriving (PartialNodeConfiguration -> PartialNodeConfiguration -> Bool
(PartialNodeConfiguration -> PartialNodeConfiguration -> Bool)
-> (PartialNodeConfiguration -> PartialNodeConfiguration -> Bool)
-> Eq PartialNodeConfiguration
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PartialNodeConfiguration -> PartialNodeConfiguration -> Bool
$c/= :: PartialNodeConfiguration -> PartialNodeConfiguration -> Bool
== :: PartialNodeConfiguration -> PartialNodeConfiguration -> Bool
$c== :: PartialNodeConfiguration -> PartialNodeConfiguration -> Bool
Eq, (forall x.
 PartialNodeConfiguration -> Rep PartialNodeConfiguration x)
-> (forall x.
    Rep PartialNodeConfiguration x -> PartialNodeConfiguration)
-> Generic PartialNodeConfiguration
forall x.
Rep PartialNodeConfiguration x -> PartialNodeConfiguration
forall x.
PartialNodeConfiguration -> Rep PartialNodeConfiguration x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep PartialNodeConfiguration x -> PartialNodeConfiguration
$cfrom :: forall x.
PartialNodeConfiguration -> Rep PartialNodeConfiguration x
Generic, Int -> PartialNodeConfiguration -> ShowS
[PartialNodeConfiguration] -> ShowS
PartialNodeConfiguration -> String
(Int -> PartialNodeConfiguration -> ShowS)
-> (PartialNodeConfiguration -> String)
-> ([PartialNodeConfiguration] -> ShowS)
-> Show PartialNodeConfiguration
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PartialNodeConfiguration] -> ShowS
$cshowList :: [PartialNodeConfiguration] -> ShowS
show :: PartialNodeConfiguration -> String
$cshow :: PartialNodeConfiguration -> String
showsPrec :: Int -> PartialNodeConfiguration -> ShowS
$cshowsPrec :: Int -> PartialNodeConfiguration -> ShowS
Show)

instance AdjustFilePaths PartialNodeConfiguration where
  adjustFilePaths :: ShowS -> PartialNodeConfiguration -> PartialNodeConfiguration
adjustFilePaths ShowS
f PartialNodeConfiguration
x =
    PartialNodeConfiguration
x { pncProtocolConfig :: Last NodeProtocolConfiguration
pncProtocolConfig = ShowS
-> Last NodeProtocolConfiguration -> Last NodeProtocolConfiguration
forall a. AdjustFilePaths a => ShowS -> a -> a
adjustFilePaths ShowS
f (PartialNodeConfiguration -> Last NodeProtocolConfiguration
pncProtocolConfig PartialNodeConfiguration
x)
      , pncSocketConfig :: Last SocketConfig
pncSocketConfig   = ShowS -> Last SocketConfig -> Last SocketConfig
forall a. AdjustFilePaths a => ShowS -> a -> a
adjustFilePaths ShowS
f (PartialNodeConfiguration -> Last SocketConfig
pncSocketConfig PartialNodeConfiguration
x)
      }

instance Semigroup PartialNodeConfiguration where
  <> :: PartialNodeConfiguration
-> PartialNodeConfiguration -> PartialNodeConfiguration
(<>) = PartialNodeConfiguration
-> PartialNodeConfiguration -> PartialNodeConfiguration
forall a. (Generic a, Semigroup (Rep a ())) => a -> a -> a
gmappend

instance FromJSON PartialNodeConfiguration where
  parseJSON :: Value -> Parser PartialNodeConfiguration
parseJSON =
    String
-> (Object -> Parser PartialNodeConfiguration)
-> Value
-> Parser PartialNodeConfiguration
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"PartialNodeConfiguration" ((Object -> Parser PartialNodeConfiguration)
 -> Value -> Parser PartialNodeConfiguration)
-> (Object -> Parser PartialNodeConfiguration)
-> Value
-> Parser PartialNodeConfiguration
forall a b. (a -> b) -> a -> b
$ \Object
v -> do

      -- Node parameters, not protocol-specific
      Last SocketPath
pncSocketPath <- Maybe SocketPath -> Last SocketPath
forall a. Maybe a -> Last a
Last (Maybe SocketPath -> Last SocketPath)
-> Parser (Maybe SocketPath) -> Parser (Last SocketPath)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Key -> Parser (Maybe SocketPath)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"SocketPath"
      Last DiffusionMode
pncDiffusionMode
        <- Maybe DiffusionMode -> Last DiffusionMode
forall a. Maybe a -> Last a
Last (Maybe DiffusionMode -> Last DiffusionMode)
-> (Maybe NodeDiffusionMode -> Maybe DiffusionMode)
-> Maybe NodeDiffusionMode
-> Last DiffusionMode
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. (NodeDiffusionMode -> DiffusionMode)
-> Maybe NodeDiffusionMode -> Maybe DiffusionMode
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap NodeDiffusionMode -> DiffusionMode
getDiffusionMode (Maybe NodeDiffusionMode -> Last DiffusionMode)
-> Parser (Maybe NodeDiffusionMode) -> Parser (Last DiffusionMode)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Key -> Parser (Maybe NodeDiffusionMode)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"DiffusionMode"
      Last SnapshotInterval
pncSnapshotInterval
        <- Maybe SnapshotInterval -> Last SnapshotInterval
forall a. Maybe a -> Last a
Last (Maybe SnapshotInterval -> Last SnapshotInterval)
-> (Maybe DiffTime -> Maybe SnapshotInterval)
-> Maybe DiffTime
-> Last SnapshotInterval
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. (DiffTime -> SnapshotInterval)
-> Maybe DiffTime -> Maybe SnapshotInterval
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap DiffTime -> SnapshotInterval
RequestedSnapshotInterval (Maybe DiffTime -> Last SnapshotInterval)
-> Parser (Maybe DiffTime) -> Parser (Last SnapshotInterval)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Key -> Parser (Maybe DiffTime)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"SnapshotInterval"
      Last Bool
pncTestEnableDevelopmentNetworkProtocols
        <- Maybe Bool -> Last Bool
forall a. Maybe a -> Last a
Last (Maybe Bool -> Last Bool)
-> Parser (Maybe Bool) -> Parser (Last Bool)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"TestEnableDevelopmentNetworkProtocols"

      -- Blockfetch parameters
      Last MaxConcurrencyBulkSync
pncMaxConcurrencyBulkSync <- Maybe MaxConcurrencyBulkSync -> Last MaxConcurrencyBulkSync
forall a. Maybe a -> Last a
Last (Maybe MaxConcurrencyBulkSync -> Last MaxConcurrencyBulkSync)
-> Parser (Maybe MaxConcurrencyBulkSync)
-> Parser (Last MaxConcurrencyBulkSync)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Key -> Parser (Maybe MaxConcurrencyBulkSync)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"MaxConcurrencyBulkSync"
      Last MaxConcurrencyDeadline
pncMaxConcurrencyDeadline <- Maybe MaxConcurrencyDeadline -> Last MaxConcurrencyDeadline
forall a. Maybe a -> Last a
Last (Maybe MaxConcurrencyDeadline -> Last MaxConcurrencyDeadline)
-> Parser (Maybe MaxConcurrencyDeadline)
-> Parser (Last MaxConcurrencyDeadline)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Key -> Parser (Maybe MaxConcurrencyDeadline)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"MaxConcurrencyDeadline"

      -- Logging parameters
      Bool
pncLoggingSwitch'  <-                 Object
v Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"TurnOnLogging" Parser (Maybe Bool) -> Bool -> Parser Bool
forall a. Parser (Maybe a) -> a -> Parser a
.!= Bool
True
      Last Bool
pncLogMetrics      <- Maybe Bool -> Last Bool
forall a. Maybe a -> Last a
Last        (Maybe Bool -> Last Bool)
-> Parser (Maybe Bool) -> Parser (Last Bool)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"TurnOnLogMetrics"
      Bool
useTraceDispatcher <-                 Object
v Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"UseTraceDispatcher" Parser (Maybe Bool) -> Bool -> Parser Bool
forall a. Parser (Maybe a) -> a -> Parser a
.!= Bool
False
      Last PartialTraceOptions
pncTraceConfig     <-  if Bool
pncLoggingSwitch'
                             then do
                               PartialTraceSelection
partialTraceSelection <- Value -> Parser PartialTraceSelection
forall a. FromJSON a => Value -> Parser a
parseJSON (Value -> Parser PartialTraceSelection)
-> Value -> Parser PartialTraceSelection
forall a b. (a -> b) -> a -> b
$ Object -> Value
Object Object
v
                               if Bool
useTraceDispatcher
                               then Maybe PartialTraceOptions -> Last PartialTraceOptions
forall a. Maybe a -> Last a
Last (Maybe PartialTraceOptions -> Last PartialTraceOptions)
-> (PartialTraceOptions -> Maybe PartialTraceOptions)
-> PartialTraceOptions
-> Last PartialTraceOptions
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. PartialTraceOptions -> Maybe PartialTraceOptions
forall a. a -> Maybe a
Just (PartialTraceOptions -> Last PartialTraceOptions)
-> Parser PartialTraceOptions -> Parser (Last PartialTraceOptions)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> PartialTraceOptions -> Parser PartialTraceOptions
forall (m :: * -> *) a. Monad m => a -> m a
return (PartialTraceSelection -> PartialTraceOptions
PartialTraceDispatcher PartialTraceSelection
partialTraceSelection)
                               else Maybe PartialTraceOptions -> Last PartialTraceOptions
forall a. Maybe a -> Last a
Last (Maybe PartialTraceOptions -> Last PartialTraceOptions)
-> (PartialTraceOptions -> Maybe PartialTraceOptions)
-> PartialTraceOptions
-> Last PartialTraceOptions
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. PartialTraceOptions -> Maybe PartialTraceOptions
forall a. a -> Maybe a
Just (PartialTraceOptions -> Last PartialTraceOptions)
-> Parser PartialTraceOptions -> Parser (Last PartialTraceOptions)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> PartialTraceOptions -> Parser PartialTraceOptions
forall (m :: * -> *) a. Monad m => a -> m a
return (PartialTraceSelection -> PartialTraceOptions
PartialTracingOnLegacy PartialTraceSelection
partialTraceSelection)
                             else Maybe PartialTraceOptions -> Last PartialTraceOptions
forall a. Maybe a -> Last a
Last (Maybe PartialTraceOptions -> Last PartialTraceOptions)
-> (PartialTraceOptions -> Maybe PartialTraceOptions)
-> PartialTraceOptions
-> Last PartialTraceOptions
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. PartialTraceOptions -> Maybe PartialTraceOptions
forall a. a -> Maybe a
Just (PartialTraceOptions -> Last PartialTraceOptions)
-> Parser PartialTraceOptions -> Parser (Last PartialTraceOptions)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> PartialTraceOptions -> Parser PartialTraceOptions
forall (m :: * -> *) a. Monad m => a -> m a
return PartialTraceOptions
PartialTracingOff

      -- Protocol parameters
      Protocol
protocol <-  Object
v Object -> Key -> Parser (Maybe Protocol)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"Protocol" Parser (Maybe Protocol) -> Protocol -> Parser Protocol
forall a. Parser (Maybe a) -> a -> Parser a
.!= Protocol
ByronProtocol
      Last NodeProtocolConfiguration
pncProtocolConfig <-
        case Protocol
protocol of
          Protocol
ByronProtocol ->
            Maybe NodeProtocolConfiguration -> Last NodeProtocolConfiguration
forall a. Maybe a -> Last a
Last (Maybe NodeProtocolConfiguration -> Last NodeProtocolConfiguration)
-> (NodeByronProtocolConfiguration
    -> Maybe NodeProtocolConfiguration)
-> NodeByronProtocolConfiguration
-> Last NodeProtocolConfiguration
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. NodeProtocolConfiguration -> Maybe NodeProtocolConfiguration
forall a. a -> Maybe a
Just (NodeProtocolConfiguration -> Maybe NodeProtocolConfiguration)
-> (NodeByronProtocolConfiguration -> NodeProtocolConfiguration)
-> NodeByronProtocolConfiguration
-> Maybe NodeProtocolConfiguration
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. NodeByronProtocolConfiguration -> NodeProtocolConfiguration
NodeProtocolConfigurationByron (NodeByronProtocolConfiguration -> Last NodeProtocolConfiguration)
-> Parser NodeByronProtocolConfiguration
-> Parser (Last NodeProtocolConfiguration)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object -> Parser NodeByronProtocolConfiguration
parseByronProtocol Object
v

          Protocol
ShelleyProtocol ->
            Maybe NodeProtocolConfiguration -> Last NodeProtocolConfiguration
forall a. Maybe a -> Last a
Last (Maybe NodeProtocolConfiguration -> Last NodeProtocolConfiguration)
-> (NodeShelleyProtocolConfiguration
    -> Maybe NodeProtocolConfiguration)
-> NodeShelleyProtocolConfiguration
-> Last NodeProtocolConfiguration
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. NodeProtocolConfiguration -> Maybe NodeProtocolConfiguration
forall a. a -> Maybe a
Just (NodeProtocolConfiguration -> Maybe NodeProtocolConfiguration)
-> (NodeShelleyProtocolConfiguration -> NodeProtocolConfiguration)
-> NodeShelleyProtocolConfiguration
-> Maybe NodeProtocolConfiguration
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. NodeShelleyProtocolConfiguration -> NodeProtocolConfiguration
NodeProtocolConfigurationShelley (NodeShelleyProtocolConfiguration
 -> Last NodeProtocolConfiguration)
-> Parser NodeShelleyProtocolConfiguration
-> Parser (Last NodeProtocolConfiguration)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object -> Parser NodeShelleyProtocolConfiguration
parseShelleyProtocol Object
v

          Protocol
CardanoProtocol ->
            Maybe NodeProtocolConfiguration -> Last NodeProtocolConfiguration
forall a. Maybe a -> Last a
Last (Maybe NodeProtocolConfiguration -> Last NodeProtocolConfiguration)
-> (NodeProtocolConfiguration -> Maybe NodeProtocolConfiguration)
-> NodeProtocolConfiguration
-> Last NodeProtocolConfiguration
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. NodeProtocolConfiguration -> Maybe NodeProtocolConfiguration
forall a. a -> Maybe a
Just  (NodeProtocolConfiguration -> Last NodeProtocolConfiguration)
-> Parser NodeProtocolConfiguration
-> Parser (Last NodeProtocolConfiguration)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (NodeByronProtocolConfiguration
-> NodeShelleyProtocolConfiguration
-> NodeAlonzoProtocolConfiguration
-> NodeHardForkProtocolConfiguration
-> NodeProtocolConfiguration
NodeProtocolConfigurationCardano (NodeByronProtocolConfiguration
 -> NodeShelleyProtocolConfiguration
 -> NodeAlonzoProtocolConfiguration
 -> NodeHardForkProtocolConfiguration
 -> NodeProtocolConfiguration)
-> Parser NodeByronProtocolConfiguration
-> Parser
     (NodeShelleyProtocolConfiguration
      -> NodeAlonzoProtocolConfiguration
      -> NodeHardForkProtocolConfiguration
      -> NodeProtocolConfiguration)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object -> Parser NodeByronProtocolConfiguration
parseByronProtocol Object
v
                                                               Parser
  (NodeShelleyProtocolConfiguration
   -> NodeAlonzoProtocolConfiguration
   -> NodeHardForkProtocolConfiguration
   -> NodeProtocolConfiguration)
-> Parser NodeShelleyProtocolConfiguration
-> Parser
     (NodeAlonzoProtocolConfiguration
      -> NodeHardForkProtocolConfiguration -> NodeProtocolConfiguration)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object -> Parser NodeShelleyProtocolConfiguration
parseShelleyProtocol Object
v
                                                               Parser
  (NodeAlonzoProtocolConfiguration
   -> NodeHardForkProtocolConfiguration -> NodeProtocolConfiguration)
-> Parser NodeAlonzoProtocolConfiguration
-> Parser
     (NodeHardForkProtocolConfiguration -> NodeProtocolConfiguration)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object -> Parser NodeAlonzoProtocolConfiguration
parseAlonzoProtocol Object
v
                                                               Parser
  (NodeHardForkProtocolConfiguration -> NodeProtocolConfiguration)
-> Parser NodeHardForkProtocolConfiguration
-> Parser NodeProtocolConfiguration
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object -> Parser NodeHardForkProtocolConfiguration
parseHardForkProtocol Object
v)
      Last MempoolCapacityBytesOverride
pncMaybeMempoolCapacityOverride <- Maybe MempoolCapacityBytesOverride
-> Last MempoolCapacityBytesOverride
forall a. Maybe a -> Last a
Last (Maybe MempoolCapacityBytesOverride
 -> Last MempoolCapacityBytesOverride)
-> Parser (Maybe MempoolCapacityBytesOverride)
-> Parser (Last MempoolCapacityBytesOverride)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object -> Parser (Maybe MempoolCapacityBytesOverride)
parseMempoolCapacityBytesOverride Object
v

      -- Network timeouts
      Last DiffTime
pncProtocolIdleTimeout   <- Maybe DiffTime -> Last DiffTime
forall a. Maybe a -> Last a
Last (Maybe DiffTime -> Last DiffTime)
-> Parser (Maybe DiffTime) -> Parser (Last DiffTime)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Key -> Parser (Maybe DiffTime)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"ProtocolIdleTimeout"
      Last DiffTime
pncTimeWaitTimeout       <- Maybe DiffTime -> Last DiffTime
forall a. Maybe a -> Last a
Last (Maybe DiffTime -> Last DiffTime)
-> Parser (Maybe DiffTime) -> Parser (Last DiffTime)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Key -> Parser (Maybe DiffTime)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"TimeWaitTimeout"


      -- AcceptedConnectionsLimit
      Last AcceptedConnectionsLimit
pncAcceptedConnectionsLimit
        <- Maybe AcceptedConnectionsLimit -> Last AcceptedConnectionsLimit
forall a. Maybe a -> Last a
Last (Maybe AcceptedConnectionsLimit -> Last AcceptedConnectionsLimit)
-> Parser (Maybe AcceptedConnectionsLimit)
-> Parser (Last AcceptedConnectionsLimit)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Key -> Parser (Maybe AcceptedConnectionsLimit)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"AcceptedConnectionsLimit"

      -- P2P Governor parameters, with conservative defaults.
      Last Int
pncTargetNumberOfRootPeers        <- Maybe Int -> Last Int
forall a. Maybe a -> Last a
Last (Maybe Int -> Last Int) -> Parser (Maybe Int) -> Parser (Last Int)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"TargetNumberOfRootPeers"
      Last Int
pncTargetNumberOfKnownPeers       <- Maybe Int -> Last Int
forall a. Maybe a -> Last a
Last (Maybe Int -> Last Int) -> Parser (Maybe Int) -> Parser (Last Int)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"TargetNumberOfKnownPeers"
      Last Int
pncTargetNumberOfEstablishedPeers <- Maybe Int -> Last Int
forall a. Maybe a -> Last a
Last (Maybe Int -> Last Int) -> Parser (Maybe Int) -> Parser (Last Int)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"TargetNumberOfEstablishedPeers"
      Last Int
pncTargetNumberOfActivePeers      <- Maybe Int -> Last Int
forall a. Maybe a -> Last a
Last (Maybe Int -> Last Int) -> Parser (Maybe Int) -> Parser (Last Int)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"TargetNumberOfActivePeers"

      -- Enable P2P switch
      Maybe Bool
p2pSwitch <- Object
v Object -> Key -> Parser (Maybe (Maybe Bool))
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"EnableP2P" Parser (Maybe (Maybe Bool)) -> Maybe Bool -> Parser (Maybe Bool)
forall a. Parser (Maybe a) -> a -> Parser a
.!= Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
False
      let pncEnableP2P :: Last NetworkP2PMode
pncEnableP2P =
            case Maybe Bool
p2pSwitch of
              Maybe Bool
Nothing    -> Last NetworkP2PMode
forall a. Monoid a => a
mempty
              Just Bool
False -> Maybe NetworkP2PMode -> Last NetworkP2PMode
forall a. Maybe a -> Last a
Last (Maybe NetworkP2PMode -> Last NetworkP2PMode)
-> Maybe NetworkP2PMode -> Last NetworkP2PMode
forall a b. (a -> b) -> a -> b
$ NetworkP2PMode -> Maybe NetworkP2PMode
forall a. a -> Maybe a
Just NetworkP2PMode
DisabledP2PMode
              Just Bool
True  -> Maybe NetworkP2PMode -> Last NetworkP2PMode
forall a. Maybe a -> Last a
Last (Maybe NetworkP2PMode -> Last NetworkP2PMode)
-> Maybe NetworkP2PMode -> Last NetworkP2PMode
forall a b. (a -> b) -> a -> b
$ NetworkP2PMode -> Maybe NetworkP2PMode
forall a. a -> Maybe a
Just NetworkP2PMode
EnabledP2PMode

      PartialNodeConfiguration -> Parser PartialNodeConfiguration
forall (f :: * -> *) a. Applicative f => a -> f a
pure PartialNodeConfiguration :: Last SocketConfig
-> Last ConfigYamlFilePath
-> Last TopologyFile
-> Last DbFile
-> Last ProtocolFilepaths
-> Last Bool
-> Last ShutdownConfig
-> Last NodeProtocolConfiguration
-> Last DiffusionMode
-> Last SnapshotInterval
-> Last Bool
-> Last MaxConcurrencyBulkSync
-> Last MaxConcurrencyDeadline
-> Last Bool
-> Last Bool
-> Last PartialTraceOptions
-> Last (SocketPath, ForwarderMode)
-> Last MempoolCapacityBytesOverride
-> Last DiffTime
-> Last DiffTime
-> Last AcceptedConnectionsLimit
-> Last Int
-> Last Int
-> Last Int
-> Last Int
-> Last NetworkP2PMode
-> PartialNodeConfiguration
PartialNodeConfiguration {
             Last NodeProtocolConfiguration
pncProtocolConfig :: Last NodeProtocolConfiguration
pncProtocolConfig :: Last NodeProtocolConfiguration
pncProtocolConfig
           , pncSocketConfig :: Last SocketConfig
pncSocketConfig = Maybe SocketConfig -> Last SocketConfig
forall a. Maybe a -> Last a
Last (Maybe SocketConfig -> Last SocketConfig)
-> (SocketConfig -> Maybe SocketConfig)
-> SocketConfig
-> Last SocketConfig
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. SocketConfig -> Maybe SocketConfig
forall a. a -> Maybe a
Just (SocketConfig -> Last SocketConfig)
-> SocketConfig -> Last SocketConfig
forall a b. (a -> b) -> a -> b
$ Last NodeHostIPv4Address
-> Last NodeHostIPv6Address
-> Last PortNumber
-> Last SocketPath
-> SocketConfig
SocketConfig Last NodeHostIPv4Address
forall a. Monoid a => a
mempty Last NodeHostIPv6Address
forall a. Monoid a => a
mempty Last PortNumber
forall a. Monoid a => a
mempty Last SocketPath
pncSocketPath
           , Last DiffusionMode
pncDiffusionMode :: Last DiffusionMode
pncDiffusionMode :: Last DiffusionMode
pncDiffusionMode
           , Last SnapshotInterval
pncSnapshotInterval :: Last SnapshotInterval
pncSnapshotInterval :: Last SnapshotInterval
pncSnapshotInterval
           , Last Bool
pncTestEnableDevelopmentNetworkProtocols :: Last Bool
pncTestEnableDevelopmentNetworkProtocols :: Last Bool
pncTestEnableDevelopmentNetworkProtocols
           , Last MaxConcurrencyBulkSync
pncMaxConcurrencyBulkSync :: Last MaxConcurrencyBulkSync
pncMaxConcurrencyBulkSync :: Last MaxConcurrencyBulkSync
pncMaxConcurrencyBulkSync
           , Last MaxConcurrencyDeadline
pncMaxConcurrencyDeadline :: Last MaxConcurrencyDeadline
pncMaxConcurrencyDeadline :: Last MaxConcurrencyDeadline
pncMaxConcurrencyDeadline
           , pncLoggingSwitch :: Last Bool
pncLoggingSwitch = Maybe Bool -> Last Bool
forall a. Maybe a -> Last a
Last (Maybe Bool -> Last Bool) -> Maybe Bool -> Last Bool
forall a b. (a -> b) -> a -> b
$ Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
pncLoggingSwitch'
           , Last Bool
pncLogMetrics :: Last Bool
pncLogMetrics :: Last Bool
pncLogMetrics
           , Last PartialTraceOptions
pncTraceConfig :: Last PartialTraceOptions
pncTraceConfig :: Last PartialTraceOptions
pncTraceConfig
           , pncTraceForwardSocket :: Last (SocketPath, ForwarderMode)
pncTraceForwardSocket = Last (SocketPath, ForwarderMode)
forall a. Monoid a => a
mempty
           , pncConfigFile :: Last ConfigYamlFilePath
pncConfigFile = Last ConfigYamlFilePath
forall a. Monoid a => a
mempty
           , pncTopologyFile :: Last TopologyFile
pncTopologyFile = Last TopologyFile
forall a. Monoid a => a
mempty
           , pncDatabaseFile :: Last DbFile
pncDatabaseFile = Last DbFile
forall a. Monoid a => a
mempty
           , pncProtocolFiles :: Last ProtocolFilepaths
pncProtocolFiles = Last ProtocolFilepaths
forall a. Monoid a => a
mempty
           , pncValidateDB :: Last Bool
pncValidateDB = Last Bool
forall a. Monoid a => a
mempty
           , pncShutdownConfig :: Last ShutdownConfig
pncShutdownConfig = Last ShutdownConfig
forall a. Monoid a => a
mempty
           , Last MempoolCapacityBytesOverride
pncMaybeMempoolCapacityOverride :: Last MempoolCapacityBytesOverride
pncMaybeMempoolCapacityOverride :: Last MempoolCapacityBytesOverride
pncMaybeMempoolCapacityOverride
           , Last DiffTime
pncProtocolIdleTimeout :: Last DiffTime
pncProtocolIdleTimeout :: Last DiffTime
pncProtocolIdleTimeout
           , Last DiffTime
pncTimeWaitTimeout :: Last DiffTime
pncTimeWaitTimeout :: Last DiffTime
pncTimeWaitTimeout
           , Last AcceptedConnectionsLimit
pncAcceptedConnectionsLimit :: Last AcceptedConnectionsLimit
pncAcceptedConnectionsLimit :: Last AcceptedConnectionsLimit
pncAcceptedConnectionsLimit
           , Last Int
pncTargetNumberOfRootPeers :: Last Int
pncTargetNumberOfRootPeers :: Last Int
pncTargetNumberOfRootPeers
           , Last Int
pncTargetNumberOfKnownPeers :: Last Int
pncTargetNumberOfKnownPeers :: Last Int
pncTargetNumberOfKnownPeers
           , Last Int
pncTargetNumberOfEstablishedPeers :: Last Int
pncTargetNumberOfEstablishedPeers :: Last Int
pncTargetNumberOfEstablishedPeers
           , Last Int
pncTargetNumberOfActivePeers :: Last Int
pncTargetNumberOfActivePeers :: Last Int
pncTargetNumberOfActivePeers
           , Last NetworkP2PMode
pncEnableP2P :: Last NetworkP2PMode
pncEnableP2P :: Last NetworkP2PMode
pncEnableP2P
           }
    where
      parseMempoolCapacityBytesOverride :: Object -> Parser (Maybe MempoolCapacityBytesOverride)
parseMempoolCapacityBytesOverride Object
v = Parser (Maybe MempoolCapacityBytesOverride)
parseNoOverride Parser (Maybe MempoolCapacityBytesOverride)
-> Parser (Maybe MempoolCapacityBytesOverride)
-> Parser (Maybe MempoolCapacityBytesOverride)
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parser (Maybe MempoolCapacityBytesOverride)
parseOverride
        where
          parseNoOverride :: Parser (Maybe MempoolCapacityBytesOverride)
parseNoOverride = (Word32 -> MempoolCapacityBytesOverride)
-> Maybe Word32 -> Maybe MempoolCapacityBytesOverride
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (MempoolCapacityBytes -> MempoolCapacityBytesOverride
MempoolCapacityBytesOverride (MempoolCapacityBytes -> MempoolCapacityBytesOverride)
-> (Word32 -> MempoolCapacityBytes)
-> Word32
-> MempoolCapacityBytesOverride
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Word32 -> MempoolCapacityBytes
MempoolCapacityBytes) (Maybe Word32 -> Maybe MempoolCapacityBytesOverride)
-> Parser (Maybe Word32)
-> Parser (Maybe MempoolCapacityBytesOverride)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Key -> Parser (Maybe Word32)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"MempoolCapacityBytesOverride"
          parseOverride :: Parser (Maybe MempoolCapacityBytesOverride)
parseOverride = do
            Maybe String
maybeString :: Maybe String <- Object
v Object -> Key -> Parser (Maybe String)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"MempoolCapacityBytesOverride"
            case Maybe String
maybeString of
              Just String
"NoOverride" -> Maybe MempoolCapacityBytesOverride
-> Parser (Maybe MempoolCapacityBytesOverride)
forall (m :: * -> *) a. Monad m => a -> m a
return (MempoolCapacityBytesOverride -> Maybe MempoolCapacityBytesOverride
forall a. a -> Maybe a
Just MempoolCapacityBytesOverride
NoMempoolCapacityBytesOverride)
              Just String
invalid ->  (MempoolCapacityBytesOverride
 -> Maybe MempoolCapacityBytesOverride)
-> Parser MempoolCapacityBytesOverride
-> Parser (Maybe MempoolCapacityBytesOverride)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap MempoolCapacityBytesOverride -> Maybe MempoolCapacityBytesOverride
forall a. a -> Maybe a
Just (Parser MempoolCapacityBytesOverride
 -> Parser (Maybe MempoolCapacityBytesOverride))
-> (String -> Parser MempoolCapacityBytesOverride)
-> String
-> Parser (Maybe MempoolCapacityBytesOverride)
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. String -> Parser MempoolCapacityBytesOverride
forall a. String -> Parser a
Aeson.parseFail (String -> Parser (Maybe MempoolCapacityBytesOverride))
-> String -> Parser (Maybe MempoolCapacityBytesOverride)
forall a b. (a -> b) -> a -> b
$
                    String
"Invalid value for 'MempoolCapacityBytesOverride'.  \
                    \Expecting byte count or NoOverride.  Value was: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> ShowS
forall a b. (Show a, ConvertText String b) => a -> b
show String
invalid
              Maybe String
Nothing -> Maybe MempoolCapacityBytesOverride
-> Parser (Maybe MempoolCapacityBytesOverride)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe MempoolCapacityBytesOverride
forall a. Maybe a
Nothing
      parseByronProtocol :: Object -> Parser NodeByronProtocolConfiguration
parseByronProtocol Object
v = do
        Maybe GenesisFile
primary   <- Object
v Object -> Key -> Parser (Maybe GenesisFile)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"ByronGenesisFile"
        Maybe GenesisFile
secondary <- Object
v Object -> Key -> Parser (Maybe GenesisFile)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"GenesisFile"
        GenesisFile
npcByronGenesisFile <-
          case (Maybe GenesisFile
primary, Maybe GenesisFile
secondary) of
            (Just GenesisFile
g, Maybe GenesisFile
Nothing)  -> GenesisFile -> Parser GenesisFile
forall (m :: * -> *) a. Monad m => a -> m a
return GenesisFile
g
            (Maybe GenesisFile
Nothing, Just GenesisFile
g)  -> GenesisFile -> Parser GenesisFile
forall (m :: * -> *) a. Monad m => a -> m a
return GenesisFile
g
            (Maybe GenesisFile
Nothing, Maybe GenesisFile
Nothing) -> String -> Parser GenesisFile
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Parser GenesisFile) -> String -> Parser GenesisFile
forall a b. (a -> b) -> a -> b
$ String
"Missing required field, either "
                                      String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
"ByronGenesisFile or GenesisFile"
            (Just GenesisFile
_, Just GenesisFile
_)   -> String -> Parser GenesisFile
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Parser GenesisFile) -> String -> Parser GenesisFile
forall a b. (a -> b) -> a -> b
$ String
"Specify either ByronGenesisFile"
                                      String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
"or GenesisFile, but not both"
        Maybe GenesisHash
npcByronGenesisFileHash <- Object
v Object -> Key -> Parser (Maybe GenesisHash)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"ByronGenesisHash"

        RequiresNetworkMagic
npcByronReqNetworkMagic     <- Object
v Object -> Key -> Parser (Maybe RequiresNetworkMagic)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"RequiresNetworkMagic"
                                         Parser (Maybe RequiresNetworkMagic)
-> RequiresNetworkMagic -> Parser RequiresNetworkMagic
forall a. Parser (Maybe a) -> a -> Parser a
.!= RequiresNetworkMagic
RequiresNoMagic
        Maybe Double
npcByronPbftSignatureThresh <- Object
v Object -> Key -> Parser (Maybe Double)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"PBftSignatureThreshold"
        ApplicationName
npcByronApplicationName     <- Object
v Object -> Key -> Parser (Maybe ApplicationName)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"ApplicationName"
                                         Parser (Maybe ApplicationName)
-> ApplicationName -> Parser ApplicationName
forall a. Parser (Maybe a) -> a -> Parser a
.!= Text -> ApplicationName
Byron.ApplicationName Text
"cardano-sl"
        Word32
npcByronApplicationVersion  <- Object
v Object -> Key -> Parser (Maybe Word32)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"ApplicationVersion" Parser (Maybe Word32) -> Word32 -> Parser Word32
forall a. Parser (Maybe a) -> a -> Parser a
.!= Word32
1
        Word16
protVerMajor                <- Object
v Object -> Key -> Parser Word16
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"LastKnownBlockVersion-Major"
        Word16
protVerMinor                <- Object
v Object -> Key -> Parser Word16
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"LastKnownBlockVersion-Minor"
        Word8
protVerAlt                  <- Object
v Object -> Key -> Parser (Maybe Word8)
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"LastKnownBlockVersion-Alt" Parser (Maybe Word8) -> Word8 -> Parser Word8
forall a. Parser (Maybe a) -> a -> Parser a
.!= Word8
0

        NodeByronProtocolConfiguration
-> Parser NodeByronProtocolConfiguration
forall (f :: * -> *) a. Applicative f => a -> f a
pure NodeByronProtocolConfiguration :: GenesisFile
-> Maybe GenesisHash
-> RequiresNetworkMagic
-> Maybe Double
-> ApplicationName
-> Word32
-> Word16
-> Word16
-> Word8
-> NodeByronProtocolConfiguration
NodeByronProtocolConfiguration {
               GenesisFile
npcByronGenesisFile :: GenesisFile
npcByronGenesisFile :: GenesisFile
npcByronGenesisFile
             , Maybe GenesisHash
npcByronGenesisFileHash :: Maybe GenesisHash
npcByronGenesisFileHash :: Maybe GenesisHash
npcByronGenesisFileHash
             , RequiresNetworkMagic
npcByronReqNetworkMagic :: RequiresNetworkMagic
npcByronReqNetworkMagic :: RequiresNetworkMagic
npcByronReqNetworkMagic
             , Maybe Double
npcByronPbftSignatureThresh :: Maybe Double
npcByronPbftSignatureThresh :: Maybe Double
npcByronPbftSignatureThresh
             , ApplicationName
npcByronApplicationName :: ApplicationName
npcByronApplicationName :: ApplicationName
npcByronApplicationName
             , Word32
npcByronApplicationVersion :: Word32
npcByronApplicationVersion :: Word32
npcByronApplicationVersion
             , npcByronSupportedProtocolVersionMajor :: Word16
npcByronSupportedProtocolVersionMajor = Word16
protVerMajor
             , npcByronSupportedProtocolVersionMinor :: Word16
npcByronSupportedProtocolVersionMinor = Word16
protVerMinor
             , npcByronSupportedProtocolVersionAlt :: Word8
npcByronSupportedProtocolVersionAlt   = Word8
protVerAlt
             }

      parseShelleyProtocol :: Object -> Parser NodeShelleyProtocolConfiguration
parseShelleyProtocol Object
v = do
        Maybe GenesisFile
primary   <- Object
v Object -> Key -> Parser (Maybe GenesisFile)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"ShelleyGenesisFile"
        Maybe GenesisFile
secondary <- Object
v Object -> Key -> Parser (Maybe GenesisFile)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"GenesisFile"
        GenesisFile
npcShelleyGenesisFile <-
          case (Maybe GenesisFile
primary, Maybe GenesisFile
secondary) of
            (Just GenesisFile
g, Maybe GenesisFile
Nothing)  -> GenesisFile -> Parser GenesisFile
forall (m :: * -> *) a. Monad m => a -> m a
return GenesisFile
g
            (Maybe GenesisFile
Nothing, Just GenesisFile
g)  -> GenesisFile -> Parser GenesisFile
forall (m :: * -> *) a. Monad m => a -> m a
return GenesisFile
g
            (Maybe GenesisFile
Nothing, Maybe GenesisFile
Nothing) -> String -> Parser GenesisFile
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Parser GenesisFile) -> String -> Parser GenesisFile
forall a b. (a -> b) -> a -> b
$ String
"Missing required field, either "
                                      String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
"ShelleyGenesisFile or GenesisFile"
            (Just GenesisFile
_, Just GenesisFile
_)   -> String -> Parser GenesisFile
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Parser GenesisFile) -> String -> Parser GenesisFile
forall a b. (a -> b) -> a -> b
$ String
"Specify either ShelleyGenesisFile"
                                      String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
"or GenesisFile, but not both"
        Maybe GenesisHash
npcShelleyGenesisFileHash <- Object
v Object -> Key -> Parser (Maybe GenesisHash)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"ShelleyGenesisHash"

        NodeShelleyProtocolConfiguration
-> Parser NodeShelleyProtocolConfiguration
forall (f :: * -> *) a. Applicative f => a -> f a
pure NodeShelleyProtocolConfiguration :: GenesisFile
-> Maybe GenesisHash -> NodeShelleyProtocolConfiguration
NodeShelleyProtocolConfiguration {
               GenesisFile
npcShelleyGenesisFile :: GenesisFile
npcShelleyGenesisFile :: GenesisFile
npcShelleyGenesisFile
             , Maybe GenesisHash
npcShelleyGenesisFileHash :: Maybe GenesisHash
npcShelleyGenesisFileHash :: Maybe GenesisHash
npcShelleyGenesisFileHash
             }

      parseAlonzoProtocol :: Object -> Parser NodeAlonzoProtocolConfiguration
parseAlonzoProtocol Object
v = do
        GenesisFile
npcAlonzoGenesisFile     <- Object
v Object -> Key -> Parser GenesisFile
forall a. FromJSON a => Object -> Key -> Parser a
.:  Key
"AlonzoGenesisFile"
        Maybe GenesisHash
npcAlonzoGenesisFileHash <- Object
v Object -> Key -> Parser (Maybe GenesisHash)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"AlonzoGenesisHash"

        NodeAlonzoProtocolConfiguration
-> Parser NodeAlonzoProtocolConfiguration
forall (f :: * -> *) a. Applicative f => a -> f a
pure NodeAlonzoProtocolConfiguration :: GenesisFile -> Maybe GenesisHash -> NodeAlonzoProtocolConfiguration
NodeAlonzoProtocolConfiguration {
               GenesisFile
npcAlonzoGenesisFile :: GenesisFile
npcAlonzoGenesisFile :: GenesisFile
npcAlonzoGenesisFile
             , Maybe GenesisHash
npcAlonzoGenesisFileHash :: Maybe GenesisHash
npcAlonzoGenesisFileHash :: Maybe GenesisHash
npcAlonzoGenesisFileHash
             }

      parseHardForkProtocol :: Object -> Parser NodeHardForkProtocolConfiguration
parseHardForkProtocol Object
v = do
        Bool
npcTestEnableDevelopmentHardForkEras
          <- Object
v Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"TestEnableDevelopmentHardForkEras"
               Parser (Maybe Bool) -> Bool -> Parser Bool
forall a. Parser (Maybe a) -> a -> Parser a
.!= Bool
False

        Maybe EpochNo
npcTestShelleyHardForkAtEpoch   <- Object
v Object -> Key -> Parser (Maybe EpochNo)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"TestShelleyHardForkAtEpoch"
        Maybe Word
npcTestShelleyHardForkAtVersion <- Object
v Object -> Key -> Parser (Maybe Word)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"TestShelleyHardForkAtVersion"

        Maybe EpochNo
npcTestAllegraHardForkAtEpoch   <- Object
v Object -> Key -> Parser (Maybe EpochNo)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"TestAllegraHardForkAtEpoch"
        Maybe Word
npcTestAllegraHardForkAtVersion <- Object
v Object -> Key -> Parser (Maybe Word)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"TestAllegraHardForkAtVersion"

        Maybe EpochNo
npcTestMaryHardForkAtEpoch   <- Object
v Object -> Key -> Parser (Maybe EpochNo)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"TestMaryHardForkAtEpoch"
        Maybe Word
npcTestMaryHardForkAtVersion <- Object
v Object -> Key -> Parser (Maybe Word)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"TestMaryHardForkAtVersion"

        Maybe EpochNo
npcTestAlonzoHardForkAtEpoch   <- Object
v Object -> Key -> Parser (Maybe EpochNo)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"TestAlonzoHardForkAtEpoch"
        Maybe Word
npcTestAlonzoHardForkAtVersion <- Object
v Object -> Key -> Parser (Maybe Word)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"TestAlonzoHardForkAtVersion"

        Maybe EpochNo
npcTestBabbageHardForkAtEpoch   <- Object
v Object -> Key -> Parser (Maybe EpochNo)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"TestBabbageHardForkAtEpoch"
        Maybe Word
npcTestBabbageHardForkAtVersion <- Object
v Object -> Key -> Parser (Maybe Word)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"TestBabbageHardForkAtVersion"

        NodeHardForkProtocolConfiguration
-> Parser NodeHardForkProtocolConfiguration
forall (f :: * -> *) a. Applicative f => a -> f a
pure NodeHardForkProtocolConfiguration :: Bool
-> Maybe EpochNo
-> Maybe Word
-> Maybe EpochNo
-> Maybe Word
-> Maybe EpochNo
-> Maybe Word
-> Maybe EpochNo
-> Maybe Word
-> Maybe EpochNo
-> Maybe Word
-> NodeHardForkProtocolConfiguration
NodeHardForkProtocolConfiguration {
               Bool
npcTestEnableDevelopmentHardForkEras :: Bool
npcTestEnableDevelopmentHardForkEras :: Bool
npcTestEnableDevelopmentHardForkEras,

               Maybe EpochNo
npcTestShelleyHardForkAtEpoch :: Maybe EpochNo
npcTestShelleyHardForkAtEpoch :: Maybe EpochNo
npcTestShelleyHardForkAtEpoch,
               Maybe Word
npcTestShelleyHardForkAtVersion :: Maybe Word
npcTestShelleyHardForkAtVersion :: Maybe Word
npcTestShelleyHardForkAtVersion,

               Maybe EpochNo
npcTestAllegraHardForkAtEpoch :: Maybe EpochNo
npcTestAllegraHardForkAtEpoch :: Maybe EpochNo
npcTestAllegraHardForkAtEpoch,
               Maybe Word
npcTestAllegraHardForkAtVersion :: Maybe Word
npcTestAllegraHardForkAtVersion :: Maybe Word
npcTestAllegraHardForkAtVersion,

               Maybe EpochNo
npcTestMaryHardForkAtEpoch :: Maybe EpochNo
npcTestMaryHardForkAtEpoch :: Maybe EpochNo
npcTestMaryHardForkAtEpoch,
               Maybe Word
npcTestMaryHardForkAtVersion :: Maybe Word
npcTestMaryHardForkAtVersion :: Maybe Word
npcTestMaryHardForkAtVersion,

               Maybe EpochNo
npcTestAlonzoHardForkAtEpoch :: Maybe EpochNo
npcTestAlonzoHardForkAtEpoch :: Maybe EpochNo
npcTestAlonzoHardForkAtEpoch,
               Maybe Word
npcTestAlonzoHardForkAtVersion :: Maybe Word
npcTestAlonzoHardForkAtVersion :: Maybe Word
npcTestAlonzoHardForkAtVersion,

               Maybe EpochNo
npcTestBabbageHardForkAtEpoch :: Maybe EpochNo
npcTestBabbageHardForkAtEpoch :: Maybe EpochNo
npcTestBabbageHardForkAtEpoch,
               Maybe Word
npcTestBabbageHardForkAtVersion :: Maybe Word
npcTestBabbageHardForkAtVersion :: Maybe Word
npcTestBabbageHardForkAtVersion
             }

-- | Default configuration is mainnet
defaultPartialNodeConfiguration :: PartialNodeConfiguration
defaultPartialNodeConfiguration :: PartialNodeConfiguration
defaultPartialNodeConfiguration =
  PartialNodeConfiguration :: Last SocketConfig
-> Last ConfigYamlFilePath
-> Last TopologyFile
-> Last DbFile
-> Last ProtocolFilepaths
-> Last Bool
-> Last ShutdownConfig
-> Last NodeProtocolConfiguration
-> Last DiffusionMode
-> Last SnapshotInterval
-> Last Bool
-> Last MaxConcurrencyBulkSync
-> Last MaxConcurrencyDeadline
-> Last Bool
-> Last Bool
-> Last PartialTraceOptions
-> Last (SocketPath, ForwarderMode)
-> Last MempoolCapacityBytesOverride
-> Last DiffTime
-> Last DiffTime
-> Last AcceptedConnectionsLimit
-> Last Int
-> Last Int
-> Last Int
-> Last Int
-> Last NetworkP2PMode
-> PartialNodeConfiguration
PartialNodeConfiguration
    { pncConfigFile :: Last ConfigYamlFilePath
pncConfigFile = Maybe ConfigYamlFilePath -> Last ConfigYamlFilePath
forall a. Maybe a -> Last a
Last (Maybe ConfigYamlFilePath -> Last ConfigYamlFilePath)
-> (ConfigYamlFilePath -> Maybe ConfigYamlFilePath)
-> ConfigYamlFilePath
-> Last ConfigYamlFilePath
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. ConfigYamlFilePath -> Maybe ConfigYamlFilePath
forall a. a -> Maybe a
Just (ConfigYamlFilePath -> Last ConfigYamlFilePath)
-> ConfigYamlFilePath -> Last ConfigYamlFilePath
forall a b. (a -> b) -> a -> b
$ String -> ConfigYamlFilePath
ConfigYamlFilePath String
"configuration/cardano/mainnet-config.json"
    , pncDatabaseFile :: Last DbFile
pncDatabaseFile = Maybe DbFile -> Last DbFile
forall a. Maybe a -> Last a
Last (Maybe DbFile -> Last DbFile)
-> (DbFile -> Maybe DbFile) -> DbFile -> Last DbFile
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. DbFile -> Maybe DbFile
forall a. a -> Maybe a
Just (DbFile -> Last DbFile) -> DbFile -> Last DbFile
forall a b. (a -> b) -> a -> b
$ String -> DbFile
DbFile String
"mainnet/db/"
    , pncLoggingSwitch :: Last Bool
pncLoggingSwitch = Maybe Bool -> Last Bool
forall a. Maybe a -> Last a
Last (Maybe Bool -> Last Bool) -> Maybe Bool -> Last Bool
forall a b. (a -> b) -> a -> b
$ Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
True
    , pncSocketConfig :: Last SocketConfig
pncSocketConfig = Maybe SocketConfig -> Last SocketConfig
forall a. Maybe a -> Last a
Last (Maybe SocketConfig -> Last SocketConfig)
-> (SocketConfig -> Maybe SocketConfig)
-> SocketConfig
-> Last SocketConfig
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. SocketConfig -> Maybe SocketConfig
forall a. a -> Maybe a
Just (SocketConfig -> Last SocketConfig)
-> SocketConfig -> Last SocketConfig
forall a b. (a -> b) -> a -> b
$ Last NodeHostIPv4Address
-> Last NodeHostIPv6Address
-> Last PortNumber
-> Last SocketPath
-> SocketConfig
SocketConfig Last NodeHostIPv4Address
forall a. Monoid a => a
mempty Last NodeHostIPv6Address
forall a. Monoid a => a
mempty Last PortNumber
forall a. Monoid a => a
mempty Last SocketPath
forall a. Monoid a => a
mempty
    , pncDiffusionMode :: Last DiffusionMode
pncDiffusionMode = Maybe DiffusionMode -> Last DiffusionMode
forall a. Maybe a -> Last a
Last (Maybe DiffusionMode -> Last DiffusionMode)
-> Maybe DiffusionMode -> Last DiffusionMode
forall a b. (a -> b) -> a -> b
$ DiffusionMode -> Maybe DiffusionMode
forall a. a -> Maybe a
Just DiffusionMode
InitiatorAndResponderDiffusionMode
    , pncSnapshotInterval :: Last SnapshotInterval
pncSnapshotInterval = Maybe SnapshotInterval -> Last SnapshotInterval
forall a. Maybe a -> Last a
Last (Maybe SnapshotInterval -> Last SnapshotInterval)
-> Maybe SnapshotInterval -> Last SnapshotInterval
forall a b. (a -> b) -> a -> b
$ SnapshotInterval -> Maybe SnapshotInterval
forall a. a -> Maybe a
Just SnapshotInterval
DefaultSnapshotInterval
    , pncTestEnableDevelopmentNetworkProtocols :: Last Bool
pncTestEnableDevelopmentNetworkProtocols = Maybe Bool -> Last Bool
forall a. Maybe a -> Last a
Last (Maybe Bool -> Last Bool) -> Maybe Bool -> Last Bool
forall a b. (a -> b) -> a -> b
$ Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
False
    , pncTopologyFile :: Last TopologyFile
pncTopologyFile = Maybe TopologyFile -> Last TopologyFile
forall a. Maybe a -> Last a
Last (Maybe TopologyFile -> Last TopologyFile)
-> (TopologyFile -> Maybe TopologyFile)
-> TopologyFile
-> Last TopologyFile
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. TopologyFile -> Maybe TopologyFile
forall a. a -> Maybe a
Just (TopologyFile -> Last TopologyFile)
-> TopologyFile -> Last TopologyFile
forall a b. (a -> b) -> a -> b
$ String -> TopologyFile
TopologyFile String
"configuration/cardano/mainnet-topology.json"
    , pncProtocolFiles :: Last ProtocolFilepaths
pncProtocolFiles = Last ProtocolFilepaths
forall a. Monoid a => a
mempty
    , pncValidateDB :: Last Bool
pncValidateDB = Last Bool
forall a. Monoid a => a
mempty
    , pncShutdownConfig :: Last ShutdownConfig
pncShutdownConfig = Last ShutdownConfig
forall a. Monoid a => a
mempty
    , pncProtocolConfig :: Last NodeProtocolConfiguration
pncProtocolConfig = Last NodeProtocolConfiguration
forall a. Monoid a => a
mempty
    , pncMaxConcurrencyBulkSync :: Last MaxConcurrencyBulkSync
pncMaxConcurrencyBulkSync = Last MaxConcurrencyBulkSync
forall a. Monoid a => a
mempty
    , pncMaxConcurrencyDeadline :: Last MaxConcurrencyDeadline
pncMaxConcurrencyDeadline = Last MaxConcurrencyDeadline
forall a. Monoid a => a
mempty
    , pncLogMetrics :: Last Bool
pncLogMetrics = Last Bool
forall a. Monoid a => a
mempty
    , pncTraceConfig :: Last PartialTraceOptions
pncTraceConfig = Last PartialTraceOptions
forall a. Monoid a => a
mempty
    , pncTraceForwardSocket :: Last (SocketPath, ForwarderMode)
pncTraceForwardSocket = Last (SocketPath, ForwarderMode)
forall a. Monoid a => a
mempty
    , pncMaybeMempoolCapacityOverride :: Last MempoolCapacityBytesOverride
pncMaybeMempoolCapacityOverride = Last MempoolCapacityBytesOverride
forall a. Monoid a => a
mempty
    , pncProtocolIdleTimeout :: Last DiffTime
pncProtocolIdleTimeout   = Maybe DiffTime -> Last DiffTime
forall a. Maybe a -> Last a
Last (DiffTime -> Maybe DiffTime
forall a. a -> Maybe a
Just DiffTime
5)
    , pncTimeWaitTimeout :: Last DiffTime
pncTimeWaitTimeout       = Maybe DiffTime -> Last DiffTime
forall a. Maybe a -> Last a
Last (DiffTime -> Maybe DiffTime
forall a. a -> Maybe a
Just DiffTime
60)
    , pncAcceptedConnectionsLimit :: Last AcceptedConnectionsLimit
pncAcceptedConnectionsLimit =
        Maybe AcceptedConnectionsLimit -> Last AcceptedConnectionsLimit
forall a. Maybe a -> Last a
Last
      (Maybe AcceptedConnectionsLimit -> Last AcceptedConnectionsLimit)
-> Maybe AcceptedConnectionsLimit -> Last AcceptedConnectionsLimit
forall a b. (a -> b) -> a -> b
$ AcceptedConnectionsLimit -> Maybe AcceptedConnectionsLimit
forall a. a -> Maybe a
Just
      (AcceptedConnectionsLimit -> Maybe AcceptedConnectionsLimit)
-> AcceptedConnectionsLimit -> Maybe AcceptedConnectionsLimit
forall a b. (a -> b) -> a -> b
$ AcceptedConnectionsLimit :: Word32 -> Word32 -> DiffTime -> AcceptedConnectionsLimit
AcceptedConnectionsLimit
        { acceptedConnectionsHardLimit :: Word32
acceptedConnectionsHardLimit = Word32
512
        , acceptedConnectionsSoftLimit :: Word32
acceptedConnectionsSoftLimit = Word32
384
        , acceptedConnectionsDelay :: DiffTime
acceptedConnectionsDelay     = DiffTime
5
        }
    , pncTargetNumberOfRootPeers :: Last Int
pncTargetNumberOfRootPeers        = Maybe Int -> Last Int
forall a. Maybe a -> Last a
Last (Int -> Maybe Int
forall a. a -> Maybe a
Just Int
100)
    , pncTargetNumberOfKnownPeers :: Last Int
pncTargetNumberOfKnownPeers       = Maybe Int -> Last Int
forall a. Maybe a -> Last a
Last (Int -> Maybe Int
forall a. a -> Maybe a
Just Int
100)
    , pncTargetNumberOfEstablishedPeers :: Last Int
pncTargetNumberOfEstablishedPeers = Maybe Int -> Last Int
forall a. Maybe a -> Last a
Last (Int -> Maybe Int
forall a. a -> Maybe a
Just Int
50)
    , pncTargetNumberOfActivePeers :: Last Int
pncTargetNumberOfActivePeers      = Maybe Int -> Last Int
forall a. Maybe a -> Last a
Last (Int -> Maybe Int
forall a. a -> Maybe a
Just Int
20)
    , pncEnableP2P :: Last NetworkP2PMode
pncEnableP2P                      = Maybe NetworkP2PMode -> Last NetworkP2PMode
forall a. Maybe a -> Last a
Last (NetworkP2PMode -> Maybe NetworkP2PMode
forall a. a -> Maybe a
Just NetworkP2PMode
DisabledP2PMode)
    }

lastOption :: Parser a -> Parser (Last a)
lastOption :: Parser a -> Parser (Last a)
lastOption = (Maybe a -> Last a) -> Parser (Maybe a) -> Parser (Last a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Maybe a -> Last a
forall a. Maybe a -> Last a
Last (Parser (Maybe a) -> Parser (Last a))
-> (Parser a -> Parser (Maybe a)) -> Parser a -> Parser (Last a)
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Parser a -> Parser (Maybe a)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional

makeNodeConfiguration :: PartialNodeConfiguration -> Either String NodeConfiguration
makeNodeConfiguration :: PartialNodeConfiguration -> Either String NodeConfiguration
makeNodeConfiguration PartialNodeConfiguration
pnc = do
  ConfigYamlFilePath
configFile <- String
-> Last ConfigYamlFilePath -> Either String ConfigYamlFilePath
forall a. String -> Last a -> Either String a
lastToEither String
"Missing YAML config file" (Last ConfigYamlFilePath -> Either String ConfigYamlFilePath)
-> Last ConfigYamlFilePath -> Either String ConfigYamlFilePath
forall a b. (a -> b) -> a -> b
$ PartialNodeConfiguration -> Last ConfigYamlFilePath
pncConfigFile PartialNodeConfiguration
pnc
  TopologyFile
topologyFile <- String -> Last TopologyFile -> Either String TopologyFile
forall a. String -> Last a -> Either String a
lastToEither String
"Missing TopologyFile" (Last TopologyFile -> Either String TopologyFile)
-> Last TopologyFile -> Either String TopologyFile
forall a b. (a -> b) -> a -> b
$ PartialNodeConfiguration -> Last TopologyFile
pncTopologyFile PartialNodeConfiguration
pnc
  DbFile
databaseFile <- String -> Last DbFile -> Either String DbFile
forall a. String -> Last a -> Either String a
lastToEither String
"Missing DatabaseFile" (Last DbFile -> Either String DbFile)
-> Last DbFile -> Either String DbFile
forall a b. (a -> b) -> a -> b
$ PartialNodeConfiguration -> Last DbFile
pncDatabaseFile PartialNodeConfiguration
pnc
  Bool
validateDB <- String -> Last Bool -> Either String Bool
forall a. String -> Last a -> Either String a
lastToEither String
"Missing ValidateDB" (Last Bool -> Either String Bool)
-> Last Bool -> Either String Bool
forall a b. (a -> b) -> a -> b
$ PartialNodeConfiguration -> Last Bool
pncValidateDB PartialNodeConfiguration
pnc
  NodeProtocolConfiguration
protocolConfig <- String
-> Last NodeProtocolConfiguration
-> Either String NodeProtocolConfiguration
forall a. String -> Last a -> Either String a
lastToEither String
"Missing ProtocolConfig" (Last NodeProtocolConfiguration
 -> Either String NodeProtocolConfiguration)
-> Last NodeProtocolConfiguration
-> Either String NodeProtocolConfiguration
forall a b. (a -> b) -> a -> b
$ PartialNodeConfiguration -> Last NodeProtocolConfiguration
pncProtocolConfig PartialNodeConfiguration
pnc
  Bool
loggingSwitch <- String -> Last Bool -> Either String Bool
forall a. String -> Last a -> Either String a
lastToEither String
"Missing LoggingSwitch" (Last Bool -> Either String Bool)
-> Last Bool -> Either String Bool
forall a b. (a -> b) -> a -> b
$ PartialNodeConfiguration -> Last Bool
pncLoggingSwitch PartialNodeConfiguration
pnc
  Bool
logMetrics <- String -> Last Bool -> Either String Bool
forall a. String -> Last a -> Either String a
lastToEither String
"Missing LogMetrics" (Last Bool -> Either String Bool)
-> Last Bool -> Either String Bool
forall a b. (a -> b) -> a -> b
$ PartialNodeConfiguration -> Last Bool
pncLogMetrics PartialNodeConfiguration
pnc
  TraceOptions
traceConfig <- (Text -> String)
-> Either Text TraceOptions -> Either String TraceOptions
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first Text -> String
Text.unpack (Either Text TraceOptions -> Either String TraceOptions)
-> Either Text TraceOptions -> Either String TraceOptions
forall a b. (a -> b) -> a -> b
$ Last PartialTraceOptions -> Either Text TraceOptions
partialTraceSelectionToEither (Last PartialTraceOptions -> Either Text TraceOptions)
-> Last PartialTraceOptions -> Either Text TraceOptions
forall a b. (a -> b) -> a -> b
$ PartialNodeConfiguration -> Last PartialTraceOptions
pncTraceConfig PartialNodeConfiguration
pnc
  DiffusionMode
diffusionMode <- String -> Last DiffusionMode -> Either String DiffusionMode
forall a. String -> Last a -> Either String a
lastToEither String
"Missing DiffusionMode" (Last DiffusionMode -> Either String DiffusionMode)
-> Last DiffusionMode -> Either String DiffusionMode
forall a b. (a -> b) -> a -> b
$ PartialNodeConfiguration -> Last DiffusionMode
pncDiffusionMode PartialNodeConfiguration
pnc
  SnapshotInterval
snapshotInterval <- String -> Last SnapshotInterval -> Either String SnapshotInterval
forall a. String -> Last a -> Either String a
lastToEither String
"Missing SnapshotInterval" (Last SnapshotInterval -> Either String SnapshotInterval)
-> Last SnapshotInterval -> Either String SnapshotInterval
forall a b. (a -> b) -> a -> b
$ PartialNodeConfiguration -> Last SnapshotInterval
pncSnapshotInterval PartialNodeConfiguration
pnc
  ShutdownConfig
shutdownConfig <- String -> Last ShutdownConfig -> Either String ShutdownConfig
forall a. String -> Last a -> Either String a
lastToEither String
"Missing ShutdownConfig" (Last ShutdownConfig -> Either String ShutdownConfig)
-> Last ShutdownConfig -> Either String ShutdownConfig
forall a b. (a -> b) -> a -> b
$ PartialNodeConfiguration -> Last ShutdownConfig
pncShutdownConfig PartialNodeConfiguration
pnc
  SocketConfig
socketConfig <- String -> Last SocketConfig -> Either String SocketConfig
forall a. String -> Last a -> Either String a
lastToEither String
"Missing SocketConfig" (Last SocketConfig -> Either String SocketConfig)
-> Last SocketConfig -> Either String SocketConfig
forall a b. (a -> b) -> a -> b
$ PartialNodeConfiguration -> Last SocketConfig
pncSocketConfig PartialNodeConfiguration
pnc

  Int
ncTargetNumberOfRootPeers <-
    String -> Last Int -> Either String Int
forall a. String -> Last a -> Either String a
lastToEither String
"Missing TargetNumberOfRootPeers"
    (Last Int -> Either String Int) -> Last Int -> Either String Int
forall a b. (a -> b) -> a -> b
$ PartialNodeConfiguration -> Last Int
pncTargetNumberOfRootPeers PartialNodeConfiguration
pnc
  Int
ncTargetNumberOfKnownPeers <-
    String -> Last Int -> Either String Int
forall a. String -> Last a -> Either String a
lastToEither String
"Missing TargetNumberOfKnownPeers"
    (Last Int -> Either String Int) -> Last Int -> Either String Int
forall a b. (a -> b) -> a -> b
$ PartialNodeConfiguration -> Last Int
pncTargetNumberOfKnownPeers PartialNodeConfiguration
pnc
  Int
ncTargetNumberOfEstablishedPeers <-
    String -> Last Int -> Either String Int
forall a. String -> Last a -> Either String a
lastToEither String
"Missing TargetNumberOfEstablishedPeers"
    (Last Int -> Either String Int) -> Last Int -> Either String Int
forall a b. (a -> b) -> a -> b
$ PartialNodeConfiguration -> Last Int
pncTargetNumberOfEstablishedPeers PartialNodeConfiguration
pnc
  Int
ncTargetNumberOfActivePeers <-
    String -> Last Int -> Either String Int
forall a. String -> Last a -> Either String a
lastToEither String
"Missing TargetNumberOfActivePeers"
    (Last Int -> Either String Int) -> Last Int -> Either String Int
forall a b. (a -> b) -> a -> b
$ PartialNodeConfiguration -> Last Int
pncTargetNumberOfActivePeers PartialNodeConfiguration
pnc
  DiffTime
ncProtocolIdleTimeout <-
    String -> Last DiffTime -> Either String DiffTime
forall a. String -> Last a -> Either String a
lastToEither String
"Missing ProtocolIdleTimeout"
    (Last DiffTime -> Either String DiffTime)
-> Last DiffTime -> Either String DiffTime
forall a b. (a -> b) -> a -> b
$ PartialNodeConfiguration -> Last DiffTime
pncProtocolIdleTimeout PartialNodeConfiguration
pnc
  DiffTime
ncTimeWaitTimeout <-
    String -> Last DiffTime -> Either String DiffTime
forall a. String -> Last a -> Either String a
lastToEither String
"Missing TimeWaitTimeout"
    (Last DiffTime -> Either String DiffTime)
-> Last DiffTime -> Either String DiffTime
forall a b. (a -> b) -> a -> b
$ PartialNodeConfiguration -> Last DiffTime
pncTimeWaitTimeout PartialNodeConfiguration
pnc
  AcceptedConnectionsLimit
ncAcceptedConnectionsLimit <-
    String
-> Last AcceptedConnectionsLimit
-> Either String AcceptedConnectionsLimit
forall a. String -> Last a -> Either String a
lastToEither String
"Missing AcceptedConnectionsLimit" (Last AcceptedConnectionsLimit
 -> Either String AcceptedConnectionsLimit)
-> Last AcceptedConnectionsLimit
-> Either String AcceptedConnectionsLimit
forall a b. (a -> b) -> a -> b
$
      PartialNodeConfiguration -> Last AcceptedConnectionsLimit
pncAcceptedConnectionsLimit PartialNodeConfiguration
pnc
  NetworkP2PMode
enableP2P <-
    String -> Last NetworkP2PMode -> Either String NetworkP2PMode
forall a. String -> Last a -> Either String a
lastToEither String
"Missing EnableP2P"
    (Last NetworkP2PMode -> Either String NetworkP2PMode)
-> Last NetworkP2PMode -> Either String NetworkP2PMode
forall a b. (a -> b) -> a -> b
$ PartialNodeConfiguration -> Last NetworkP2PMode
pncEnableP2P PartialNodeConfiguration
pnc

  -- TODO: This is not mandatory
  Bool
testEnableDevelopmentNetworkProtocols <-
    String -> Last Bool -> Either String Bool
forall a. String -> Last a -> Either String a
lastToEither String
"Missing TestEnableDevelopmentNetworkProtocols" (Last Bool -> Either String Bool)
-> Last Bool -> Either String Bool
forall a b. (a -> b) -> a -> b
$
      PartialNodeConfiguration -> Last Bool
pncTestEnableDevelopmentNetworkProtocols PartialNodeConfiguration
pnc
  NodeConfiguration -> Either String NodeConfiguration
forall (m :: * -> *) a. Monad m => a -> m a
return (NodeConfiguration -> Either String NodeConfiguration)
-> NodeConfiguration -> Either String NodeConfiguration
forall a b. (a -> b) -> a -> b
$ NodeConfiguration :: SocketConfig
-> ConfigYamlFilePath
-> TopologyFile
-> DbFile
-> ProtocolFilepaths
-> Bool
-> ShutdownConfig
-> NodeProtocolConfiguration
-> DiffusionMode
-> SnapshotInterval
-> Bool
-> Maybe MaxConcurrencyBulkSync
-> Maybe MaxConcurrencyDeadline
-> Bool
-> Bool
-> TraceOptions
-> Maybe (SocketPath, ForwarderMode)
-> Maybe MempoolCapacityBytesOverride
-> DiffTime
-> DiffTime
-> AcceptedConnectionsLimit
-> Int
-> Int
-> Int
-> Int
-> SomeNetworkP2PMode
-> NodeConfiguration
NodeConfiguration
             { ncConfigFile :: ConfigYamlFilePath
ncConfigFile = ConfigYamlFilePath
configFile
             , ncTopologyFile :: TopologyFile
ncTopologyFile = TopologyFile
topologyFile
             , ncDatabaseFile :: DbFile
ncDatabaseFile = DbFile
databaseFile
             , ncProtocolFiles :: ProtocolFilepaths
ncProtocolFiles =
                 -- TODO: ncProtocolFiles should be Maybe ProtocolFiles
                 -- as relay nodes don't need the protocol files because
                 -- they are not minting blocks.
                 case Last ProtocolFilepaths -> Maybe ProtocolFilepaths
forall a. Last a -> Maybe a
getLast (Last ProtocolFilepaths -> Maybe ProtocolFilepaths)
-> Last ProtocolFilepaths -> Maybe ProtocolFilepaths
forall a b. (a -> b) -> a -> b
$ PartialNodeConfiguration -> Last ProtocolFilepaths
pncProtocolFiles PartialNodeConfiguration
pnc of
                   Just ProtocolFilepaths
pFiles -> ProtocolFilepaths
pFiles
                   Maybe ProtocolFilepaths
Nothing -> Maybe String
-> Maybe String
-> Maybe String
-> Maybe String
-> Maybe String
-> Maybe String
-> ProtocolFilepaths
ProtocolFilepaths Maybe String
forall a. Maybe a
Nothing Maybe String
forall a. Maybe a
Nothing Maybe String
forall a. Maybe a
Nothing Maybe String
forall a. Maybe a
Nothing Maybe String
forall a. Maybe a
Nothing Maybe String
forall a. Maybe a
Nothing
             , ncValidateDB :: Bool
ncValidateDB = Bool
validateDB
             , ncShutdownConfig :: ShutdownConfig
ncShutdownConfig = ShutdownConfig
shutdownConfig
             , ncProtocolConfig :: NodeProtocolConfiguration
ncProtocolConfig = NodeProtocolConfiguration
protocolConfig
             , ncSocketConfig :: SocketConfig
ncSocketConfig = SocketConfig
socketConfig
             , ncDiffusionMode :: DiffusionMode
ncDiffusionMode = DiffusionMode
diffusionMode
             , ncSnapshotInterval :: SnapshotInterval
ncSnapshotInterval = SnapshotInterval
snapshotInterval
             , ncTestEnableDevelopmentNetworkProtocols :: Bool
ncTestEnableDevelopmentNetworkProtocols = Bool
testEnableDevelopmentNetworkProtocols
             , ncMaxConcurrencyBulkSync :: Maybe MaxConcurrencyBulkSync
ncMaxConcurrencyBulkSync = Last MaxConcurrencyBulkSync -> Maybe MaxConcurrencyBulkSync
forall a. Last a -> Maybe a
getLast (Last MaxConcurrencyBulkSync -> Maybe MaxConcurrencyBulkSync)
-> Last MaxConcurrencyBulkSync -> Maybe MaxConcurrencyBulkSync
forall a b. (a -> b) -> a -> b
$ PartialNodeConfiguration -> Last MaxConcurrencyBulkSync
pncMaxConcurrencyBulkSync PartialNodeConfiguration
pnc
             , ncMaxConcurrencyDeadline :: Maybe MaxConcurrencyDeadline
ncMaxConcurrencyDeadline = Last MaxConcurrencyDeadline -> Maybe MaxConcurrencyDeadline
forall a. Last a -> Maybe a
getLast (Last MaxConcurrencyDeadline -> Maybe MaxConcurrencyDeadline)
-> Last MaxConcurrencyDeadline -> Maybe MaxConcurrencyDeadline
forall a b. (a -> b) -> a -> b
$ PartialNodeConfiguration -> Last MaxConcurrencyDeadline
pncMaxConcurrencyDeadline PartialNodeConfiguration
pnc
             , ncLoggingSwitch :: Bool
ncLoggingSwitch = Bool
loggingSwitch
             , ncLogMetrics :: Bool
ncLogMetrics = Bool
logMetrics
             , ncTraceConfig :: TraceOptions
ncTraceConfig = if Bool
loggingSwitch then TraceOptions
traceConfig
                                                else TraceOptions
TracingOff
             , ncTraceForwardSocket :: Maybe (SocketPath, ForwarderMode)
ncTraceForwardSocket = Last (SocketPath, ForwarderMode)
-> Maybe (SocketPath, ForwarderMode)
forall a. Last a -> Maybe a
getLast (Last (SocketPath, ForwarderMode)
 -> Maybe (SocketPath, ForwarderMode))
-> Last (SocketPath, ForwarderMode)
-> Maybe (SocketPath, ForwarderMode)
forall a b. (a -> b) -> a -> b
$ PartialNodeConfiguration -> Last (SocketPath, ForwarderMode)
pncTraceForwardSocket PartialNodeConfiguration
pnc
             , ncMaybeMempoolCapacityOverride :: Maybe MempoolCapacityBytesOverride
ncMaybeMempoolCapacityOverride = Last MempoolCapacityBytesOverride
-> Maybe MempoolCapacityBytesOverride
forall a. Last a -> Maybe a
getLast (Last MempoolCapacityBytesOverride
 -> Maybe MempoolCapacityBytesOverride)
-> Last MempoolCapacityBytesOverride
-> Maybe MempoolCapacityBytesOverride
forall a b. (a -> b) -> a -> b
$ PartialNodeConfiguration -> Last MempoolCapacityBytesOverride
pncMaybeMempoolCapacityOverride PartialNodeConfiguration
pnc
             , DiffTime
ncProtocolIdleTimeout :: DiffTime
ncProtocolIdleTimeout :: DiffTime
ncProtocolIdleTimeout
             , DiffTime
ncTimeWaitTimeout :: DiffTime
ncTimeWaitTimeout :: DiffTime
ncTimeWaitTimeout
             , AcceptedConnectionsLimit
ncAcceptedConnectionsLimit :: AcceptedConnectionsLimit
ncAcceptedConnectionsLimit :: AcceptedConnectionsLimit
ncAcceptedConnectionsLimit
             , Int
ncTargetNumberOfRootPeers :: Int
ncTargetNumberOfRootPeers :: Int
ncTargetNumberOfRootPeers
             , Int
ncTargetNumberOfKnownPeers :: Int
ncTargetNumberOfKnownPeers :: Int
ncTargetNumberOfKnownPeers
             , Int
ncTargetNumberOfEstablishedPeers :: Int
ncTargetNumberOfEstablishedPeers :: Int
ncTargetNumberOfEstablishedPeers
             , Int
ncTargetNumberOfActivePeers :: Int
ncTargetNumberOfActivePeers :: Int
ncTargetNumberOfActivePeers
             , ncEnableP2P :: SomeNetworkP2PMode
ncEnableP2P = case NetworkP2PMode
enableP2P of
                 NetworkP2PMode
EnabledP2PMode  -> NetworkP2PMode 'P2P -> SomeNetworkP2PMode
forall (p2p :: P2P). NetworkP2PMode p2p -> SomeNetworkP2PMode
SomeNetworkP2PMode NetworkP2PMode 'P2P
Consensus.EnabledP2PMode
                 NetworkP2PMode
DisabledP2PMode -> NetworkP2PMode 'NonP2P -> SomeNetworkP2PMode
forall (p2p :: P2P). NetworkP2PMode p2p -> SomeNetworkP2PMode
SomeNetworkP2PMode NetworkP2PMode 'NonP2P
Consensus.DisabledP2PMode
             }

ncProtocol :: NodeConfiguration -> Protocol
ncProtocol :: NodeConfiguration -> Protocol
ncProtocol NodeConfiguration
nc =
  case NodeConfiguration -> NodeProtocolConfiguration
ncProtocolConfig NodeConfiguration
nc of
    NodeProtocolConfigurationByron{}   -> Protocol
ByronProtocol
    NodeProtocolConfigurationShelley{} -> Protocol
ShelleyProtocol
    NodeProtocolConfigurationCardano{} -> Protocol
CardanoProtocol

pncProtocol :: PartialNodeConfiguration -> Either Text Protocol
pncProtocol :: PartialNodeConfiguration -> Either Text Protocol
pncProtocol PartialNodeConfiguration
pnc =
  case PartialNodeConfiguration -> Last NodeProtocolConfiguration
pncProtocolConfig PartialNodeConfiguration
pnc of
    Last Maybe NodeProtocolConfiguration
Nothing -> Text -> Either Text Protocol
forall a b. a -> Either a b
Left Text
"Node protocol configuration not found"
    Last (Just NodeProtocolConfigurationByron{})   -> Protocol -> Either Text Protocol
forall a b. b -> Either a b
Right Protocol
ByronProtocol
    Last (Just NodeProtocolConfigurationShelley{}) -> Protocol -> Either Text Protocol
forall a b. b -> Either a b
Right Protocol
ShelleyProtocol
    Last (Just NodeProtocolConfigurationCardano{}) -> Protocol -> Either Text Protocol
forall a b. b -> Either a b
Right Protocol
CardanoProtocol

parseNodeConfigurationFP :: Maybe ConfigYamlFilePath -> IO PartialNodeConfiguration
parseNodeConfigurationFP :: Maybe ConfigYamlFilePath -> IO PartialNodeConfiguration
parseNodeConfigurationFP Maybe ConfigYamlFilePath
Nothing = Maybe ConfigYamlFilePath -> IO PartialNodeConfiguration
parseNodeConfigurationFP (Maybe ConfigYamlFilePath -> IO PartialNodeConfiguration)
-> (Last ConfigYamlFilePath -> Maybe ConfigYamlFilePath)
-> Last ConfigYamlFilePath
-> IO PartialNodeConfiguration
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Last ConfigYamlFilePath -> Maybe ConfigYamlFilePath
forall a. Last a -> Maybe a
getLast (Last ConfigYamlFilePath -> IO PartialNodeConfiguration)
-> Last ConfigYamlFilePath -> IO PartialNodeConfiguration
forall a b. (a -> b) -> a -> b
$ PartialNodeConfiguration -> Last ConfigYamlFilePath
pncConfigFile PartialNodeConfiguration
defaultPartialNodeConfiguration
parseNodeConfigurationFP (Just (ConfigYamlFilePath String
fp)) = do
    PartialNodeConfiguration
nc <- String -> IO PartialNodeConfiguration
forall (m :: * -> *) a. (MonadIO m, FromJSON a) => String -> m a
decodeFileThrow String
fp
    -- Make all the files be relative to the location of the config file.
    PartialNodeConfiguration -> IO PartialNodeConfiguration
forall (f :: * -> *) a. Applicative f => a -> f a
pure (PartialNodeConfiguration -> IO PartialNodeConfiguration)
-> PartialNodeConfiguration -> IO PartialNodeConfiguration
forall a b. (a -> b) -> a -> b
$ ShowS -> PartialNodeConfiguration -> PartialNodeConfiguration
forall a. AdjustFilePaths a => ShowS -> a -> a
adjustFilePaths (ShowS
takeDirectory String
fp String -> ShowS
</>) PartialNodeConfiguration
nc