@@ -33,8 +33,6 @@ import Cardano.Api
3333import Cardano.Api.Byron (GenesisData (.. ))
3434import qualified Cardano.Api.Byron as Byron
3535
36- import Cardano.Node.Configuration.Topology (RemoteAddress (.. ))
37- import qualified Cardano.Node.Configuration.Topology as Direct
3836import qualified Cardano.Node.Configuration.TopologyP2P as P2P
3937import Cardano.Prelude (canonicalEncodePretty )
4038import Ouroboros.Network.PeerSelection.RelayAccessPoint (RelayAccessPoint (.. ))
@@ -133,11 +131,6 @@ createTestnetEnv
133131 config <- case genesisHashesPolicy of
134132 WithHashes -> createConfigJson (TmpAbsolutePath tmpAbsPath) sbe
135133 WithoutHashes -> pure $ createConfigJsonNoHash sbe
136- -- Setup P2P configuration value
137- let config = A. insert
138- " EnableP2P"
139- (Bool $ topologyType == P2PTopology )
140- config'
141134
142135 liftIOAnnotated . LBS. writeFile configurationFile $ A. encodePretty $ Object config
143136
@@ -148,13 +141,8 @@ createTestnetEnv
148141 liftIOAnnotated $ IO. createDirectoryIfMissing True nodeDataDir
149142
150143 let producers = NodeId <$> filter (/= i) nodeIds
151- case topologyType of
152- DirectTopology ->
153- let topology = Direct. RealNodeTopology producers
154- in liftIOAnnotated . LBS. writeFile (nodeDataDir </> " topology.json" ) $ A. encodePretty topology
155- P2PTopology ->
156- let topology = Defaults. defaultP2PTopology producers
157- in liftIOAnnotated . LBS. writeFile (nodeDataDir </> " topology.json" ) $ A. encodePretty topology
144+ topology = Defaults. defaultP2PTopology producers
145+ liftIOAnnotated . LBS. writeFile (nodeDataDir </> " topology.json" ) $ A. encodePretty topology
158146
159147-- | Starts a number of nodes, as configured by the value of the 'cardanoNodes'
160148-- field in the 'CardanoTestnetOptions' argument. Regarding this field, you can either:
@@ -277,24 +265,6 @@ cardanoTestnet
277265
278266 let portNumbers = zip [1 .. ] $ snd <$> portNumbersWithNodeOptions
279267
280- forM_ portNumbers $ \ (i, portNumber) -> do
281- let nodeDataDir = tmpAbsPath </> Defaults. defaultNodeDataDir i
282- liftIOAnnotated $ IO. createDirectoryIfMissing True nodeDataDir
283- liftIOAnnotated $ writeFile (nodeDataDir </> " port" ) (show portNumber)
284-
285- let
286- idToRemoteAddressDirect :: ()
287- => HasCallStack
288- => MonadIO m
289- => NodeId -> m RemoteAddress
290- idToRemoteAddressDirect (NodeId i) = case lookup i portNumbers of
291- Just port -> pure $ RemoteAddress
292- { raAddress = showIpv4Address testnetDefaultIpv4Address
293- , raPort = port
294- , raValency = 1
295- }
296- Nothing -> do
297- throwString $ " Found node id that was unaccounted for: " ++ show i
298268 idToRemoteAddressP2P :: ()
299269 => MonadIO m
300270 => HasCallStack
@@ -306,27 +276,21 @@ cardanoTestnet
306276 Nothing -> do
307277 throwString $ " Found node id that was unaccounted for: " ++ show i
308278
309- -- Implement concrete topology from abstract one, if necessary
310- forM_ portNumbers $ \ (i, _port) -> do
279+ forM_ portNumbers $ \ (i, portNumber) -> do
280+ let nodeDataDir = tmpAbsPath </> Defaults. defaultNodeDataDir i
281+ liftIOAnnotated $ IO. createDirectoryIfMissing True nodeDataDir
282+ liftIOAnnotated $ writeFile (nodeDataDir </> " port" ) (show portNumber)
311283 let topologyPath = tmpAbsPath </> Defaults. defaultNodeDataDir i </> " topology.json"
312-
313- -- Try to decode either a direct topology file, or a P2P one
314284 tBytes <- liftIOAnnotated $ LBS. readFile topologyPath
315- case eitherDecode tBytes of
316- Right (abstractTopology :: Direct. NetworkTopology NodeId ) -> do
317- topology <- mapM idToRemoteAddressDirect abstractTopology
318- liftIOAnnotated . LBS. writeFile topologyPath $ encode topology
319- Left _ ->
320- case eitherDecode tBytes of
321- Right (abstractTopology :: P2P. NetworkTopology NodeId ) -> do
322- topology <- mapM idToRemoteAddressP2P abstractTopology
323- liftIOAnnotated . LBS. writeFile topologyPath $ encode topology
324- Left e ->
325- -- There can be multiple reasons for why both decodings have failed.
326- -- Here we assume, very optimistically, that the user has already
327- -- instantiated it with a concrete topology file.
328- -- TODO: It is suspicious that this decoding can fail. Investigate further.
329- liftIOAnnotated . putStrLn $ " Could not decode topology file: " <> topologyPath <> " . This may be okay. Reason for decoding failure is:\n " ++ e
285+ case eitherDecode tBytes of
286+ Right (abstractTopology :: P2P. NetworkTopology NodeId ) -> do
287+ topology <- mapM idToRemoteAddressP2P abstractTopology
288+ liftIOAnnotated $ LBS. writeFile topologyPath $ encode topology
289+ Left e -> do
290+ -- There can be multiple reasons for why both decodings have failed.
291+ -- Here we assume, very optimistically, that the user has already
292+ -- instantiated it with a concrete topology file.
293+ liftIOAnnotated . putStrLn $ " Could not decode topology file: " <> topologyPath <> " . This may be okay. Reason for decoding failure is:\n " ++ e
330294
331295 -- If necessary, update the time stamps in Byron and Shelley Genesis files.
332296 -- This is a QoL feature so that users who edit their configuration files don't
@@ -388,7 +352,7 @@ cardanoTestnet
388352 -- FIXME: use foldEpochState waiting for chain extensions
389353 now <- liftIOAnnotated DTC. getCurrentTime
390354 let deadline = DTC. addUTCTime 45 now
391- forM_ ( map nodeStdout testnetNodes') $ \ nodeStdoutFile -> do
355+ forM_ testnetNodes' $ \ nodeStdoutFile -> do
392356 assertChainExtended deadline nodeLoggingFormat nodeStdoutFile
393357
394358 let runtime = TestnetRuntime
0 commit comments