Skip to content

Commit 450a650

Browse files
committed
Rebase changes
1 parent ea904de commit 450a650

File tree

7 files changed

+34
-121
lines changed

7 files changed

+34
-121
lines changed

cabal.project

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ package plutus-scripts-bench
6060

6161
allow-newer:
6262
, katip:Win32
63-
, hedgehog-extras
6463

6564
if impl (ghc >= 9.12)
6665
allow-newer:

cardano-testnet/cardano-testnet.cabal

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ library
103103
, transformers
104104
, transformers-except
105105
, unliftio
106-
, vector
107106
, yaml
108107

109108
hs-source-dirs: src

cardano-testnet/src/Testnet/Components/Configuration.hs

Lines changed: 7 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,7 @@ import qualified Cardano.Crypto.Hash.Blake2b as Crypto
2929
import qualified Cardano.Crypto.Hash.Class as Crypto
3030
import Cardano.Ledger.BaseTypes (unsafeNonZero)
3131
import Cardano.Ledger.Dijkstra.Genesis (DijkstraGenesis)
32-
import Cardano.Network.PeerSelection.Bootstrap
33-
import Cardano.Network.PeerSelection.PeerTrustable
34-
import qualified Cardano.Node.Configuration.Topology as NonP2P
35-
import qualified Cardano.Node.Configuration.TopologyP2P as P2P
3632
import Cardano.Node.Protocol.Byron
37-
import Ouroboros.Network.NodeToNode (DiffusionMode (..))
38-
import Ouroboros.Network.PeerSelection.LedgerPeers
39-
import Ouroboros.Network.PeerSelection.State.LocalRootPeers
4033

4134
import Control.Exception
4235
import Control.Monad
@@ -47,6 +40,7 @@ import qualified Data.Aeson.Encode.Pretty as A
4740
import Data.Aeson.Key hiding (fromString)
4841
import Data.Aeson.KeyMap hiding (map)
4942
import qualified Data.ByteString as BS
43+
import qualified Data.ByteString.Lazy as LBS
5044
import Data.Text (Text)
5145
import qualified Data.Text as Text
5246
import qualified Data.Time.Clock as DTC
@@ -146,10 +140,9 @@ getDefaultShelleyGenesis asbe maxSupply opts = do
146140
getDefaultAlonzoGenesis :: ()
147141
=> HasCallStack
148142
=> MonadThrow m
149-
=> ShelleyBasedEra era
150-
-> m AlonzoGenesis
151-
getDefaultAlonzoGenesis sbe =
152-
case Defaults.defaultAlonzoGenesis sbe of
143+
=> m AlonzoGenesis
144+
getDefaultAlonzoGenesis =
145+
case Defaults.defaultAlonzoGenesis of
153146
Right genesis -> return genesis
154147
Left err -> throwM err
155148

@@ -191,16 +184,16 @@ createSPOGenesisAndFiles
191184
let conwayGenesis' = Defaults.defaultConwayGenesis
192185
dijkstraGenesis' = dijkstraGenesisDefaults
193186

194-
(alonzoGenesis, conwayGenesis, shelleyGenesis)
187+
(shelleyGenesis, alonzoGenesis, conwayGenesis, dijkstraGenesis)
195188
<- resolveOnChainParams onChainParams
196-
(alonzoGenesis', conwayGenesis', shelleyGenesis')
189+
(shelleyGenesis', alonzoGenesis', conwayGenesis', dijkstraGenesis')
197190

198191
-- Write Genesis files to disk, so they can be picked up by create-testnet-data
199192
liftIOAnnotated $ do
200193
LBS.writeFile inputGenesisAlonzoFp $ A.encodePretty alonzoGenesis
201194
LBS.writeFile inputGenesisConwayFp $ A.encodePretty conwayGenesis
202195
LBS.writeFile inputGenesisShelleyFp $ A.encodePretty shelleyGenesis
203-
196+
LBS.writeFile inputGenesisDijkstraFp $ A.encodePretty dijkstraGenesis
204197
let era = toCardanoEra sbe
205198

206199
currentTime <- liftIOAnnotated DTC.getCurrentTime
@@ -244,51 +237,6 @@ createSPOGenesisAndFiles
244237
createTestnetDataFlag sbe =
245238
["--spec-" ++ eraToString sbe, genesisInputFilepath sbe]
246239

247-
ifaceAddress :: String
248-
ifaceAddress = "127.0.0.1"
249-
250-
-- TODO: Reconcile all other mkTopologyConfig functions. NB: We only intend
251-
-- to support current era on mainnet and the upcoming era.
252-
mkTopologyConfig :: Int -> [Int] -> Int -> Bool -> LBS.ByteString
253-
mkTopologyConfig numNodes allPorts port False = A.encodePretty topologyNonP2P
254-
where
255-
topologyNonP2P :: NonP2P.NetworkTopology NonP2P.RemoteAddress
256-
topologyNonP2P =
257-
NonP2P.RealNodeTopology
258-
[ NonP2P.RemoteAddress (fromString ifaceAddress)
259-
(fromIntegral peerPort)
260-
(numNodes - 1)
261-
| peerPort <- allPorts List.\\ [port]
262-
]
263-
mkTopologyConfig numNodes allPorts port True = A.encodePretty topologyP2P
264-
where
265-
rootConfig :: P2P.RootConfig RelayAccessPoint
266-
rootConfig =
267-
P2P.RootConfig
268-
[ RelayAccessAddress (fromString ifaceAddress)
269-
(fromIntegral peerPort)
270-
| peerPort <- allPorts List.\\ [port]
271-
]
272-
P2P.DoNotAdvertisePeer
273-
274-
localRootPeerGroups :: P2P.LocalRootPeersGroups RelayAccessPoint
275-
localRootPeerGroups =
276-
P2P.LocalRootPeersGroups
277-
[ P2P.LocalRootPeersGroup rootConfig
278-
(HotValency (numNodes - 1))
279-
(WarmValency (numNodes - 1))
280-
IsNotTrustable
281-
InitiatorAndResponderDiffusionMode
282-
]
283-
284-
topologyP2P :: P2P.NetworkTopology RelayAccessPoint
285-
topologyP2P =
286-
P2P.RealNodeTopology
287-
localRootPeerGroups
288-
[]
289-
DontUseLedgerPeers
290-
DontUseBootstrapPeers
291-
Nothing
292240

293241

294242
data BlockfrostParamsError = BlockfrostParamsDecodeError FilePath String

cardano-testnet/src/Testnet/Defaults.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,9 @@ instance Exception AlonzoGenesisError where
112112
displayException = Api.docToString . Api.prettyError
113113

114114

115-
defaultAlonzoGenesis :: ShelleyBasedEra era -> Either AlonzoGenesisError AlonzoGenesis
116-
defaultAlonzoGenesis sbe = do
117-
let genesis = Api.alonzoGenesisDefaults (toCardanoEra sbe)
115+
defaultAlonzoGenesis :: Either AlonzoGenesisError AlonzoGenesis
116+
defaultAlonzoGenesis = do
117+
let genesis = Api.alonzoGenesisDefaults
118118
prices = Ledger.agPrices genesis
119119

120120
-- double check that prices have correct values - they're set using unsafeBoundedRational in cardano-api

cardano-testnet/src/Testnet/Process/RunIO.hs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,10 +241,13 @@ binDist pkg binaryEnv = do
241241
<> binaryEnv
242242
<> " and have it point to the executable you want."
243243

244-
Plan{installPlan} <- eitherDecode <$> liftIOAnnotated (LBS.readFile planJsonFile)
245-
>>= \case
246-
Left message -> error $ "Cannot decode plan in " <> planJsonFile <> ": " <> message
247-
Right plan -> pure plan
244+
Plan{installPlan} <- liftIOAnnotated (LBS.readFile planJsonFile) >>=
245+
(\case
246+
Left message
247+
-> error
248+
$ "Cannot decode plan in " <> planJsonFile <> ": " <> message
249+
Right plan -> pure plan)
250+
. eitherDecode
248251

249252
let componentName = "exe:" <> fromString pkg
250253
case findComponent componentName installPlan of

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

Lines changed: 16 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ import Cardano.Api
3333
import Cardano.Api.Byron (GenesisData (..))
3434
import qualified Cardano.Api.Byron as Byron
3535

36-
import Cardano.Node.Configuration.Topology (RemoteAddress (..))
37-
import qualified Cardano.Node.Configuration.Topology as Direct
3836
import qualified Cardano.Node.Configuration.TopologyP2P as P2P
3937
import Cardano.Prelude (canonicalEncodePretty)
4038
import 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

cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Node/Shutdown.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ hprop_shutdown = integrationRetryWorkspace 2 "shutdown" $ \tempAbsBasePath' -> H
107107

108108
-- 2. Create Alonzo genesis
109109
alonzoBabbageTestGenesisJsonTargetFile <- H.noteShow $ tempAbsPath' </> shelleyDir </> "genesis.alonzo.spec.json"
110-
gen <- liftToIntegration $ Testnet.getDefaultAlonzoGenesis sbe
110+
gen <- liftToIntegration Testnet.getDefaultAlonzoGenesis
111111
liftIOAnnotated $ LBS.writeFile alonzoBabbageTestGenesisJsonTargetFile $ encode gen
112112

113113
-- 2. Create Conway genesis

0 commit comments

Comments
 (0)