Skip to content

Commit 38db4bf

Browse files
committed
Move types/functions to cardano-testnet
1 parent 48307ca commit 38db4bf

File tree

6 files changed

+65
-51
lines changed

6 files changed

+65
-51
lines changed

cardano-node/src/Cardano/Node/Configuration/Topology.hs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ module Cardano.Node.Configuration.Topology
1111
, NodeHostIPv4Address(..)
1212
, NodeHostIPv6Address(..)
1313
, NodeSetup(..)
14-
, NodeId(..)
1514
, RemoteAddress(..)
1615
, nodeAddressToSockAddr
1716
, readTopologyFile
@@ -28,7 +27,6 @@ import Ouroboros.Consensus.Util.Condense (Condense (..))
2827
import Control.Exception (Exception (..), IOException)
2928
import qualified Control.Exception as Exception
3029
import Data.Aeson
31-
import Data.Aeson.Types (parseFail)
3230
import Data.Bifunctor (Bifunctor (..))
3331
import qualified Data.ByteString as BS
3432
import qualified Data.ByteString.Lazy.Char8 as LBS
@@ -59,19 +57,6 @@ data RemoteAddress = RemoteAddress
5957
-- a Boolean value, @0@ means to ignore the address;
6058
} deriving (Eq, Ord, Show)
6159

62-
newtype NodeId = NodeId Int
63-
deriving (Eq, Ord, Show)
64-
65-
instance ToJSON NodeId where
66-
toJSON (NodeId i) = String $ Text.pack $ "node_" ++ show i
67-
68-
instance FromJSON NodeId where
69-
parseJSON = withText "NodeId" $ \t -> case Text.breakOn "_" t of
70-
("node", textId) -> case eitherDecodeStrictText textId of
71-
Right i -> pure $ NodeId i
72-
Left _ -> parseFail $ "Incorrect format for NodeId: " ++ show t
73-
_ -> parseFail $ "Incorrect format for NodeId: " ++ show t
74-
7560
-- | Parse 'raAddress' field as an IP address; if it parses and the valency is
7661
-- non zero return corresponding NodeAddress.
7762
--

cardano-node/src/Cardano/Node/Configuration/TopologyP2P.hs

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ module Cardano.Node.Configuration.TopologyP2P
1919
, NodeHostIPv6Address(..)
2020
, NodeSetup(..)
2121
, PeerAdvertise(..)
22-
, defaultTopology
2322
, nodeAddressToSockAddr
2423
, readTopologyFile
2524
, readPeerSnapshotFile
@@ -297,34 +296,6 @@ readPeerSnapshotFile (PeerSnapshotFile peerSnapshotFile) =
297296
where
298297
handleException = handleAny $ \e -> error $ "Cardano.Node.Configuration.TopologyP2P.readPeerSnapshotFile: " <> displayException e
299298

300-
defaultTopology :: [adr] -> NetworkTopology adr
301-
defaultTopology addresses = RealNodeTopology
302-
{ ntLocalRootPeersGroups = LocalRootPeersGroups
303-
{ groups = [
304-
LocalRootPeersGroup
305-
{ localRoots = RootConfig
306-
{ rootAccessPoints = addresses
307-
, rootAdvertise = DoNotAdvertisePeer
308-
}
309-
, hotValency = HotValency 1
310-
, warmValency = WarmValency 1
311-
, trustable = IsTrustable
312-
, rootDiffusionMode = InitiatorAndResponderDiffusionMode
313-
}
314-
]
315-
}
316-
, ntPublicRootPeers =
317-
[ PublicRootPeers
318-
RootConfig
319-
{ rootAccessPoints = []
320-
, rootAdvertise = DoNotAdvertisePeer
321-
}
322-
]
323-
, ntUseLedgerPeers = DontUseLedgerPeers
324-
, ntUseBootstrapPeers = DontUseBootstrapPeers
325-
, ntPeerSnapshotPath = Nothing
326-
}
327-
328299
--
329300
-- Checking for chance of progress in bootstrap phase
330301
--

cardano-testnet/src/Testnet/Defaults.hs

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ module Testnet.Defaults
2323
, defaultDelegatorStakeKeyPair
2424
, defaultNodeName
2525
, defaultNodeDataDir
26+
, defaultP2PTopology
2627
, defaultSpoColdKeyPair
2728
, defaultSpoColdVKeyFp
2829
, defaultSpoColdSKeyFp
@@ -56,8 +57,19 @@ import qualified Cardano.Ledger.Core as Ledger
5657
import qualified Cardano.Ledger.Plutus as Ledger
5758
import qualified Cardano.Ledger.Shelley as Ledger
5859
import Cardano.Ledger.Shelley.Genesis
59-
import Cardano.Node.Configuration.Topology
60+
import Cardano.Network.PeerSelection.Bootstrap (UseBootstrapPeers (..))
61+
import Cardano.Network.PeerSelection.PeerTrustable (PeerTrustable (..))
62+
import qualified Cardano.Node.Configuration.Topology as Topology
63+
import Cardano.Node.Configuration.Topology (RemoteAddress(..))
64+
import qualified Cardano.Node.Configuration.TopologyP2P as P2P
65+
import Cardano.Node.Configuration.TopologyP2P (LocalRootPeersGroups (..),
66+
LocalRootPeersGroup (..), NetworkTopology(..), PublicRootPeers (..),
67+
RootConfig (..))
6068
import Cardano.Tracing.Config
69+
import Ouroboros.Network.NodeToNode (DiffusionMode (..), PeerAdvertise (..))
70+
import Ouroboros.Network.PeerSelection.LedgerPeers.Type (UseLedgerPeers (..))
71+
import Ouroboros.Network.PeerSelection.State.LocalRootPeers (HotValency (..),
72+
WarmValency (..))
6173

6274
import Prelude
6375

@@ -428,14 +440,14 @@ mkProtVer (majorProtVer, minorProtVer) =
428440
ppProtocolVersionL' :: Lens' (PParams Ledger.ShelleyEra) ProtVer
429441
ppProtocolVersionL' = Ledger.ppLens . Ledger.hkdProtocolVersionL @Ledger.ShelleyEra @Identity
430442

431-
defaultMainnetTopology :: NetworkTopology RemoteAddress
443+
defaultMainnetTopology :: Topology.NetworkTopology RemoteAddress
432444
defaultMainnetTopology =
433445
let single = RemoteAddress
434446
{ raAddress = "relays-new.cardano-mainnet.iohk.io"
435447
, raPort = 3_001
436448
, raValency = 2
437449
}
438-
in RealNodeTopology [single]
450+
in Topology.RealNodeTopology [single]
439451

440452
defaultGenesisFilepath :: CardanoEra a -> FilePath
441453
defaultGenesisFilepath era =
@@ -557,3 +569,30 @@ plutusV2StakeScript :: Text
557569
plutusV2StakeScript =
558570
"{ \"type\": \"PlutusScriptV2\", \"description\": \"\", \"cborHex\": \"5907655907620100003232323232323232323232323232332232323232322232325335320193333573466e1cd55cea80124000466442466002006004646464646464646464646464646666ae68cdc39aab9d500c480008cccccccccccc88888888888848cccccccccccc00403403002c02802402001c01801401000c008cd4050054d5d0a80619a80a00a9aba1500b33501401635742a014666aa030eb9405cd5d0a804999aa80c3ae501735742a01066a02803e6ae85401cccd54060081d69aba150063232323333573466e1cd55cea801240004664424660020060046464646666ae68cdc39aab9d5002480008cc8848cc00400c008cd40a9d69aba15002302b357426ae8940088c98c80b4cd5ce01701681589aab9e5001137540026ae854008c8c8c8cccd5cd19b8735573aa004900011991091980080180119a8153ad35742a00460566ae84d5d1280111931901699ab9c02e02d02b135573ca00226ea8004d5d09aba2500223263202933573805405204e26aae7940044dd50009aba1500533501475c6ae854010ccd540600708004d5d0a801999aa80c3ae200135742a004603c6ae84d5d1280111931901299ab9c026025023135744a00226ae8940044d5d1280089aba25001135744a00226ae8940044d5d1280089aba25001135744a00226ae8940044d55cf280089baa00135742a004601c6ae84d5d1280111931900b99ab9c018017015101613263201633573892010350543500016135573ca00226ea800448c88c008dd6000990009aa80a911999aab9f0012500a233500930043574200460066ae880080508c8c8cccd5cd19b8735573aa004900011991091980080180118061aba150023005357426ae8940088c98c8050cd5ce00a80a00909aab9e5001137540024646464646666ae68cdc39aab9d5004480008cccc888848cccc00401401000c008c8c8c8cccd5cd19b8735573aa0049000119910919800801801180a9aba1500233500f014357426ae8940088c98c8064cd5ce00d00c80b89aab9e5001137540026ae854010ccd54021d728039aba150033232323333573466e1d4005200423212223002004357426aae79400c8cccd5cd19b875002480088c84888c004010dd71aba135573ca00846666ae68cdc3a801a400042444006464c6403666ae7007006c06406005c4d55cea80089baa00135742a00466a016eb8d5d09aba2500223263201533573802c02a02626ae8940044d5d1280089aab9e500113754002266aa002eb9d6889119118011bab00132001355012223233335573e0044a010466a00e66442466002006004600c6aae754008c014d55cf280118021aba200301213574200222440042442446600200800624464646666ae68cdc3a800a40004642446004006600a6ae84d55cf280191999ab9a3370ea0049001109100091931900819ab9c01101000e00d135573aa00226ea80048c8c8cccd5cd19b875001480188c848888c010014c01cd5d09aab9e500323333573466e1d400920042321222230020053009357426aae7940108cccd5cd19b875003480088c848888c004014c01cd5d09aab9e500523333573466e1d40112000232122223003005375c6ae84d55cf280311931900819ab9c01101000e00d00c00b135573aa00226ea80048c8c8cccd5cd19b8735573aa004900011991091980080180118029aba15002375a6ae84d5d1280111931900619ab9c00d00c00a135573ca00226ea80048c8cccd5cd19b8735573aa002900011bae357426aae7940088c98c8028cd5ce00580500409baa001232323232323333573466e1d4005200c21222222200323333573466e1d4009200a21222222200423333573466e1d400d2008233221222222233001009008375c6ae854014dd69aba135744a00a46666ae68cdc3a8022400c4664424444444660040120106eb8d5d0a8039bae357426ae89401c8cccd5cd19b875005480108cc8848888888cc018024020c030d5d0a8049bae357426ae8940248cccd5cd19b875006480088c848888888c01c020c034d5d09aab9e500b23333573466e1d401d2000232122222223005008300e357426aae7940308c98c804ccd5ce00a00980880800780700680600589aab9d5004135573ca00626aae7940084d55cf280089baa0012323232323333573466e1d400520022333222122333001005004003375a6ae854010dd69aba15003375a6ae84d5d1280191999ab9a3370ea0049000119091180100198041aba135573ca00c464c6401866ae700340300280244d55cea80189aba25001135573ca00226ea80048c8c8cccd5cd19b875001480088c8488c00400cdd71aba135573ca00646666ae68cdc3a8012400046424460040066eb8d5d09aab9e500423263200933573801401200e00c26aae7540044dd500089119191999ab9a3370ea00290021091100091999ab9a3370ea00490011190911180180218031aba135573ca00846666ae68cdc3a801a400042444004464c6401466ae7002c02802001c0184d55cea80089baa0012323333573466e1d40052002200723333573466e1d40092000212200123263200633573800e00c00800626aae74dd5000a4c2400292010350543100122002112323001001223300330020020011\" }"
559571

572+
defaultP2PTopology :: [adr] -> P2P.NetworkTopology adr
573+
defaultP2PTopology addresses = P2P.RealNodeTopology
574+
{ ntLocalRootPeersGroups = LocalRootPeersGroups
575+
{ groups = [
576+
LocalRootPeersGroup
577+
{ localRoots = RootConfig
578+
{ rootAccessPoints = addresses
579+
, rootAdvertise = DoNotAdvertisePeer
580+
}
581+
, hotValency = HotValency 1
582+
, warmValency = WarmValency 1
583+
, trustable = IsTrustable
584+
, rootDiffusionMode = InitiatorAndResponderDiffusionMode
585+
}
586+
]
587+
}
588+
, ntPublicRootPeers =
589+
[ PublicRootPeers
590+
RootConfig
591+
{ rootAccessPoints = []
592+
, rootAdvertise = DoNotAdvertisePeer
593+
}
594+
]
595+
, ntUseLedgerPeers = DontUseLedgerPeers
596+
, ntUseBootstrapPeers = DontUseBootstrapPeers
597+
, ntPeerSnapshotPath = Nothing
598+
}

cardano-testnet/src/Testnet/Start/Cardano.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import Cardano.Api
3030

3131
import Cardano.Ledger.Alonzo.Genesis (AlonzoGenesis)
3232
import Cardano.Ledger.Conway.Genesis (ConwayGenesis)
33-
import Cardano.Node.Configuration.Topology (NodeId(..), RemoteAddress(..))
33+
import Cardano.Node.Configuration.Topology (RemoteAddress(..))
3434
import qualified Cardano.Node.Configuration.Topology as Direct
3535
import qualified Cardano.Node.Configuration.TopologyP2P as P2P
3636
import Ouroboros.Network.PeerSelection.RelayAccessPoint (RelayAccessPoint(..))
@@ -137,7 +137,7 @@ createTestnetEnv
137137
let topology = Direct.RealNodeTopology producers
138138
in H.lbsWriteFile (nodeDataDir </> "topology.json") $ A.encodePretty topology
139139
P2PTopology ->
140-
let topology = P2P.defaultTopology producers
140+
let topology = Defaults.defaultP2PTopology producers
141141
in H.lbsWriteFile (nodeDataDir </> "topology.json") $ A.encodePretty topology
142142

143143
-- | Starts a number of nodes, as configured by the value of the 'cardanoNodes'

cardano-testnet/src/Testnet/Start/Types.hs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22
{-# LANGUAGE DerivingVia #-}
33
{-# LANGUAGE NamedFieldPuns #-}
44
{-# LANGUAGE NumericUnderscores #-}
5+
{-# LANGUAGE OverloadedStrings #-}
56
{-# LANGUAGE ScopedTypeVariables #-}
67

78
module Testnet.Start.Types
89
( CardanoTestnetCliOptions(..)
910
, CardanoTestnetCreateEnvOptions (..)
1011
, CardanoTestnetOptions(..)
1112
, InputNodeConfigFile(..)
13+
, NodeId(..)
1214
, NumDReps(..)
1315
, NumPools(..)
1416
, NumRelays(..)
@@ -39,8 +41,11 @@ import Cardano.Api hiding (cardanoEra)
3941

4042
import Prelude
4143

44+
import qualified Data.Aeson as Aeson
45+
import Data.Aeson.Types (parseFail)
4246
import Data.Char (toLower)
4347
import Data.Default.Class
48+
import qualified Data.Text as Text
4449
import Data.Word
4550
import GHC.Stack
4651
import System.FilePath (addTrailingPathSeparator)
@@ -83,6 +88,21 @@ data TopologyType
8388
instance Default TopologyType where
8489
def = DirectTopology
8590

91+
-- | An abstract node id, used as placeholder in topology files
92+
-- when the actual ports/addresses aren't known yet (i.e. before runtime)
93+
newtype NodeId = NodeId Int
94+
deriving (Eq, Ord, Show)
95+
96+
instance ToJSON NodeId where
97+
toJSON (NodeId i) = Aeson.String $ Text.pack $ "node_" ++ show i
98+
99+
instance FromJSON NodeId where
100+
parseJSON = Aeson.withText "NodeId" $ \t -> case Text.breakOn "_" t of
101+
("node", textId) -> case Aeson.eitherDecodeStrictText (Text.drop 1 textId) of
102+
Right i -> pure $ NodeId i
103+
Left _ -> parseFail $ "Incorrect format for NodeId: " ++ show t
104+
_ -> parseFail $ "Incorrect format for NodeId: " ++ show t
105+
86106
data CardanoTestnetCreateEnvOptions = CardanoTestnetCreateEnvOptions
87107
{ createEnvTestnetOptions :: CardanoTestnetOptions
88108
, createEnvGenesisOptions :: GenesisOptions

cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/P2PTopology.hs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ module Cardano.Testnet.Test.P2PTopology
99

1010
import Cardano.Api (BlockNo (..), ChainTip (..))
1111
import Cardano.CLI.Type.Output (QueryTipLocalStateOutput (..))
12-
import Cardano.Node.Configuration.Topology (NodeId)
1312
import qualified Cardano.Node.Configuration.TopologyP2P as P2P
1413
import Cardano.Testnet hiding (shelleyGenesisFile)
1514

@@ -24,7 +23,7 @@ import qualified System.Process as IO
2423

2524
import Testnet.Process.Run (execCli', mkExecConfig)
2625
import Testnet.Property.Util (integrationRetryWorkspace)
27-
import Testnet.Start.Types (GenesisOptions (..),
26+
import Testnet.Start.Types (GenesisOptions (..), NodeId,
2827
UserProvidedData (..), UserProvidedEnv (..), TopologyType (..))
2928

3029
import Hedgehog ((===))

0 commit comments

Comments
 (0)