Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simpler topology #318

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ stack.yaml.lock
/genesis.*
/logs

/db
/db-[0-9]
launch_*
state-*
2 changes: 1 addition & 1 deletion benchmarking/trace-acceptor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ CMD="cabal new-run exe:trace-acceptor -- "
set -x
${CMD} \
--config ${BASEDIR}/launch_mainnet.d/log-config-acceptor.yaml \
--topology "./configuration/simple-topology.json" \
--topology "./configuration/simple-topology-0.json" \
--database-path "./db/" \
--genesis-file "configuration/mainnet-genesis.json" \
--socket-dir "./socket" \
Expand Down
4 changes: 2 additions & 2 deletions cardano-config/src/Cardano/Config/Partial.hs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ data PartialCardanoConfiguration = PartialCardanoConfiguration
, pccDBPath :: !(Last FilePath)
, pccSocketDir :: !(Last FilePath)
, pccApplicationLockFile :: !(Last FilePath)
, pccTopologyInfo :: !(Last TopologyInfo)
, pccNodeSetup :: !(Last FilePath)
, pccNodeAddress :: !(Last NodeAddress)
, pccProtocol :: !(Last Protocol)
, pccViewMode :: !(Last ViewMode)
Expand Down Expand Up @@ -233,7 +233,7 @@ mkCardanoConfiguration PartialCardanoConfiguration{..} = do
ccApplicationLockFile <- mkComplete "ccApplicationLockFile"
pccApplicationLockFile

ccTopologyInfo <- mkComplete "ccTopologyInfo" pccTopologyInfo
ccNodeSetup <- mkComplete "ccNodeSetup" pccNodeSetup
ccNodeAddress <- mkComplete "ccNodeAddress" pccNodeAddress
ccProtocol <- mkComplete "ccProtocol" pccProtocol
ccViewMode <- mkComplete "ccViewMode" pccViewMode
Expand Down
9 changes: 3 additions & 6 deletions cardano-config/src/Cardano/Config/Presets.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ module Cardano.Config.Presets

import Cardano.Prelude

import Ouroboros.Consensus.NodeId

import Cardano.Config.Defaults (traceOptionsDefault)
import Cardano.Config.Partial ( NodeProtocol (..)
, PartialBlock (..)
Expand All @@ -25,8 +23,7 @@ import Cardano.Config.Partial ( NodeProtocol (..)
, PartialWallet (..)
, RequireNetworkMagic (..)
)
import Cardano.Config.Topology (NodeAddress(..), NodeHostAddress(..),
TopologyInfo(..))
import Cardano.Config.Topology (NodeAddress(..), NodeHostAddress(..))
import Cardano.Config.Types (Protocol(..), ViewMode(..))

--------------------------------------------------------------------------------
Expand All @@ -40,7 +37,7 @@ mainnetConfiguration =
, pccLogConfig = pure "./configuration/log-configuration.yaml"
, pccDBPath = pure "./db/"
, pccApplicationLockFile = pure ""
, pccTopologyInfo = pure $ TopologyInfo (RelayId 0) "./configuration/simple-topology.json"
, pccNodeSetup = pure $ "./configuration/simple-topology-0.json"
, pccNodeAddress = pure $ NodeAddress (NodeHostAddress Nothing) 7000
, pccProtocol = pure ByronLegacy
, pccViewMode = pure LiveView
Expand Down Expand Up @@ -158,7 +155,7 @@ devConfiguration =
, pccLogConfig = pure "./log-config.yaml"
, pccSocketDir = pure "./socket/"
, pccApplicationLockFile = pure ""
, pccTopologyInfo = pure $ TopologyInfo (RelayId 0) "./configuration/simple-topology.json"
, pccNodeSetup = pure $ "./configuration/simple-topology-0.json"
, pccNodeAddress = pure $ NodeAddress (NodeHostAddress Nothing) 7000
, pccProtocol = pure ByronLegacy
, pccViewMode = pure LiveView
Expand Down
57 changes: 9 additions & 48 deletions cardano-config/src/Cardano/Config/Topology.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,13 @@
{-# OPTIONS_GHC -Wno-all-missed-specialisations #-}

module Cardano.Config.Topology
( TopologyError(..)
, TopologyInfo(..)
, NetworkTopology(..)
, NodeAddress(..)
( NodeAddress(..)
, NodeHostAddress(..)
, NodeSetup(..)
, RemoteAddress(..)
, createNodeAddress
, nodeAddressInfo
, nodeAddressToSockAddr
, readTopologyFile
, readNodeSetup
, remoteAddressToNodeAddress
)
where
Expand All @@ -39,15 +35,6 @@ import Ouroboros.Consensus.NodeId (NodeId(..))
import Ouroboros.Consensus.Util.Condense (Condense (..))


newtype TopologyError = NodeIdNotFoundInToplogyFile FilePath deriving Show

-- | A data structure bundling together a node identifier and the path to
-- the topology file.
data TopologyInfo = TopologyInfo
{ node :: NodeId
, topologyFile :: FilePath
} deriving (Eq, Show)

-- | IPv4 address with a port number.
data NodeAddress = NodeAddress
{ naHostAddress :: !NodeHostAddress
Expand Down Expand Up @@ -108,15 +95,14 @@ data RemoteAddress = RemoteAddress
-- | Parse 'raAddress' field as an IP address; if it parses and the valency is
-- non zero return corresponding NodeAddress.
--
remoteAddressToNodeAddress:: RemoteAddress-> Maybe NodeAddress
remoteAddressToNodeAddress :: RemoteAddress -> Maybe NodeAddress
remoteAddressToNodeAddress (RemoteAddress addrStr port val) =
case readMaybe addrStr of
Nothing -> Nothing
Just addr -> if val /= 0
then Just $ NodeAddress (NodeHostAddress $ Just addr) port
else Nothing


instance Condense RemoteAddress where
condense (RemoteAddress addr port val) =
addr ++ ":" ++ show port ++ " (" ++ show val ++ ")"
Expand All @@ -129,47 +115,22 @@ instance FromJSON RemoteAddress where
<*> (v .: "valency")

data NodeSetup = NodeSetup
{ nodeId :: !Int
, nodeAddress :: !NodeAddress
{ nodeAddress :: !NodeAddress
, producers :: ![RemoteAddress]
} deriving Show
} deriving (Show)

instance FromJSON NodeId where
parseJSON v = CoreId <$> parseJSON v

deriveFromJSON defaultOptions ''NodeSetup

data NetworkTopology = NetworkTopology [NodeSetup]
deriving Show

deriveFromJSON defaultOptions ''NetworkTopology

-- | Creates a 'NodeAddress' if it exists in a given 'NetworkTopology'.
createNodeAddress
:: NodeId
-> NetworkTopology
-> FilePath
-> Either TopologyError NodeAddress
createNodeAddress _nodeId (NetworkTopology nodeSetups) fp =
case maybeNode of
Nothing -> Left $ NodeIdNotFoundInToplogyFile fp
Just (NodeSetup _ anAddress _) -> Right anAddress
where
idInt :: Int
idInt = case _nodeId of
CoreId i -> i
RelayId i -> i
-- Search 'NetworkTopology' for a given 'NodeId'
maybeNode :: Maybe NodeSetup
maybeNode = find (\(NodeSetup nId _ _) -> idInt == nId) nodeSetups

readTopologyFile :: FilePath -> IO (Either String NetworkTopology)
readTopologyFile topo = do
eBs <- Exception.try $ BS.readFile topo
readNodeSetup :: FilePath -> IO (Either String NodeSetup)
readNodeSetup f = do
eBs <- Exception.try $ BS.readFile f
case eBs of
Left e -> pure . Left $ handler e
Right bs -> pure . eitherDecode $ toS bs
where
handler :: IOException -> String
handler e = "Cardano.Node.Configuration.Topology.readTopologyFile: "
handler e = "Cardano.Node.Configuration.Topology.readNodeSetup: "
++ displayException e
4 changes: 2 additions & 2 deletions cardano-config/src/Cardano/Config/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ data CardanoConfiguration = CardanoConfiguration
-- instance at a time.
, ccTraceOptions :: !TraceOptions
-- ^ Tracer options
, ccTopologyInfo :: !TopologyInfo
-- ^ The network topology.
, ccNodeSetup :: !FilePath
-- ^ Location of the node's network setup file.
, ccNodeAddress :: !NodeAddress
-- ^ The node ip address and port number.
, ccProtocol :: !Protocol
Expand Down
8 changes: 4 additions & 4 deletions cardano-node/src/Cardano/CLI/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ import qualified Cardano.Crypto.Signing as Crypto

import qualified Test.Cardano.Chain.Genesis.Dummy as Dummy

import Ouroboros.Consensus.NodeId (NodeId(..))
import qualified Ouroboros.Consensus.Protocol as Consensus

import Cardano.CLI.Delegation
Expand All @@ -86,7 +87,6 @@ import Cardano.Config.Types (CardanoConfiguration(..), ConfigYamlFileP
SigningKeyFile(..), TopologyFile(..),
parseNodeConfiguration)
import Cardano.Config.Logging (LoggingLayer (..))
import Cardano.Config.Topology (TopologyInfo(..))

-- | Sub-commands of 'cardano-cli'.
data ClientCommand
Expand Down Expand Up @@ -230,9 +230,8 @@ runCommand _ _(CheckDelegation magic cert issuerVF delegateVF) = do

runCommand _ _(SubmitTx fp nCli) = do
nc <- liftIO . parseNodeConfiguration . unConfigPath $ configFp nCli
let topologyFp = unTopology . topFile $ mscFp nCli
tx <- liftIO $ readByronTx fp
liftIO $ nodeSubmitTx (TopologyInfo (ncNodeId nc) topologyFp) nc nCli tx
liftIO $ nodeSubmitTx (ncNodeId nc) nc nCli tx

runCommand _ _(SpendGenesisUTxO (NewTxFile ctTx) ctKey genRichAddr outs nCli) = do
nc <- liftIO . parseNodeConfiguration . unConfigPath $ configFp nCli
Expand Down Expand Up @@ -265,7 +264,8 @@ runCommand _ loggingLayer
loggingLayer
nCli
protocol
(TopologyInfo (ncNodeId nc) topologyFp)
topologyFp
(CoreId 0)
targetNodeIds
numOfTxs
numOfInsPerTx
Expand Down
15 changes: 9 additions & 6 deletions cardano-node/src/Cardano/CLI/Tx.hs
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,16 @@ import qualified Cardano.Crypto.Signing as Crypto

import qualified Ouroboros.Consensus.Ledger.Byron as Byron
import Ouroboros.Consensus.Ledger.Byron (GenTx(..), ByronBlock)
import qualified Ouroboros.Consensus.Protocol as Consensus
import Ouroboros.Consensus.Node.ProtocolInfo ( ProtocolInfo(..)
, protocolInfo)
import Ouroboros.Consensus.Node.Run (RunNode)
import Ouroboros.Consensus.NodeId (NodeId(..))
import qualified Ouroboros.Consensus.Protocol as Consensus

import Cardano.CLI.Ops
import Cardano.CLI.Tx.Submission
import Cardano.Config.Protocol
import Cardano.Config.Types (NodeCLI, NodeConfiguration(..))
import Cardano.Config.Topology
import Cardano.Common.Orphans ()


Expand Down Expand Up @@ -223,17 +225,18 @@ issueUTxOExpenditure ins outs nc nCli key = do
throwIO $ InvariantViolation $
"Invariant violation: a non-ByronTx GenTx out of 'txSpendUTxOByronPBFT': " <> show x

-- | Submit a transaction to a node specified by topology info.
-- | Submit a transaction to a node specified by node setup,
-- using the local submission protocol.
nodeSubmitTx
:: TopologyInfo
:: NodeId
-> NodeConfiguration
-> NodeCLI
-> GenTx ByronBlock
-> IO ()
nodeSubmitTx topology nc nCli gentx =
nodeSubmitTx targetNodeId nc nCli gentx =
withRealPBFT nc nCli $
\[email protected]{} -> do
case gentx of
ByronTx txid _ -> putStrLn $ sformat ("TxId: "%Crypto.hashHexF) txid
_ -> pure ()
handleTxSubmission nCli p topology gentx stdoutTracer
submitTx nCli (pInfoConfig (protocolInfo p)) targetNodeId gentx stdoutTracer
Loading