Skip to content

Commit

Permalink
try to use p2p topology - fail
Browse files Browse the repository at this point in the history
  • Loading branch information
carbolymer committed Sep 30, 2024
1 parent 5a67a0c commit 33b4d42
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
4 changes: 1 addition & 3 deletions cardano-testnet/cardano-testnet.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@ library
, cardano-ledger-shelley
, cardano-node
, cardano-ping ^>= 0.4
, contra-tracer
, containers
, data-default-class
, cborg
, containers
, contra-tracer
Expand All @@ -63,6 +60,7 @@ library
, filepath
, hedgehog
, hedgehog-extras ^>= 0.6.4
, iproute
, lens-aeson
, microlens
, mtl
Expand Down
35 changes: 27 additions & 8 deletions cardano-testnet/src/Testnet/Start/Cardano.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ import Cardano.Api.Ledger (StandardCrypto)
import Cardano.Ledger.Alonzo.Genesis (AlonzoGenesis)
import Cardano.Ledger.Conway.Genesis (ConwayGenesis)
import Cardano.Node.Configuration.Topology
import qualified Cardano.Node.Configuration.TopologyP2P as P2P
import qualified Ouroboros.Network.PeerSelection.Bootstrap as P2P
import qualified Ouroboros.Network.PeerSelection.LedgerPeers as P2P
import qualified Ouroboros.Network.PeerSelection.PeerTrustable as P2P

import Prelude hiding (lines)

Expand All @@ -40,6 +44,7 @@ import qualified Data.Aeson as Aeson
import Data.Bifunctor (first)
import qualified Data.ByteString.Lazy as LBS
import Data.Either
import Data.IP as IP
import qualified Data.List as L
import Data.Maybe
import qualified Data.Text as Text
Expand All @@ -49,6 +54,7 @@ import qualified Data.Time.Clock as DTC
import Data.Word (Word64)
import GHC.Stack
import qualified GHC.Stack as GHC
import qualified System.Directory as IO
import System.FilePath ((</>))
import qualified System.Info as OS
import Text.Printf (printf)
Expand Down Expand Up @@ -191,8 +197,7 @@ cardanoTestnet
let (CardanoTestnetOptions _cardanoNodes asbe maxSupply _p2p nodeLoggingFormat _numDReps newEpochStateLogging) = testnetOptions
startTime = sgSystemStart shelleyGenesis
testnetMagic = fromIntegral $ sgNetworkMagic shelleyGenesis
numPoolNodes = length $ cardanoNodes testnetOptions
nPools = numPools testnetOptions
nPools@(NumPools numPoolNodes) = numPools testnetOptions
nDReps = numDReps testnetOptions
AnyShelleyBasedEra sbe <- pure asbe

Expand Down Expand Up @@ -231,15 +236,15 @@ cardanoTestnet

configurationFile <- H.noteShow . File $ tmpAbsPath </> "configuration.yaml"

_ <- createSPOGenesisAndFiles nPools nDReps maxSupply asbe shelleyGenesis alonzoGenesis conwayGenesis (TmpAbsolutePath tmpAbsPath)
_ <- createSPOGenesisAndFiles 1 nDReps maxSupply asbe shelleyGenesis alonzoGenesis conwayGenesis (TmpAbsolutePath tmpAbsPath)

-- TODO: This should come from the configuration!
let poolKeyDir :: Int -> FilePath
poolKeyDir i = "pools-keys" </> mkNodeName i
mkNodeName :: Int -> String
mkNodeName i = "pool" <> show i

poolKeys <- H.noteShow $ flip fmap [1..numPoolNodes] $ \n ->
poolKeys <- H.noteShow $ flip fmap [1..1] $ \n ->
-- TODO: use Testnet.Defaults.defaultSpoKeys here
PoolNodeKeys
{ poolNodeKeysCold =
Expand Down Expand Up @@ -308,8 +313,10 @@ cardanoTestnet
-- Byron related
forM_ (zip [1..] portNumbers) $ \(i, portNumber) -> do
let iStr = printf "%03d" (i - 1)
H.renameFile (tmpAbsPath </> "byron-gen-command" </> "delegate-keys." <> iStr <> ".key") (tmpAbsPath </> poolKeyDir i </> "byron-delegate.key")
H.renameFile (tmpAbsPath </> "byron-gen-command" </> "delegation-cert." <> iStr <> ".json") (tmpAbsPath </> poolKeyDir i </> "byron-delegation.cert")
when (i == 1) $ do
H.renameFile (tmpAbsPath </> "byron-gen-command" </> "delegate-keys." <> iStr <> ".key") (tmpAbsPath </> poolKeyDir i </> "byron-delegate.key")
H.renameFile (tmpAbsPath </> "byron-gen-command" </> "delegation-cert." <> iStr <> ".json") (tmpAbsPath </> poolKeyDir i </> "byron-delegation.cert")
H.evalIO $ IO.createDirectoryIfMissing True $ tmpAbsPath </> poolKeyDir i
H.writeFile (tmpAbsPath </> poolKeyDir i </> "port") (show portNumber)

-- Make topology files
Expand All @@ -320,9 +327,21 @@ cardanoTestnet
, raPort = otherProducerPort
, raValency = 1
}

H.lbsWriteFile (tmpAbsPath </> poolKeyDir i </> "topology.json") . encode $
RealNodeTopology producers
-- P2P.RelayAccessAddress
-- (IP.IPv4 $ IP.fromHostAddress testnetDefaultIpv4Address)
-- otherProducerPort
-- rootConfig = P2P.RootConfig peers P2P.DoNotAdvertisePeer
-- peersGroup = P2P.LocalRootPeersGroup rootConfig 2 2 P2P.IsTrustable
-- H.lbsWriteFile (tmpAbsPath </> poolKeyDir i </> "topology.json") . encode $
-- P2P.RealNodeTopology
-- (P2P.LocalRootPeersGroups [peersGroup])
-- []
-- (if i == 1
-- then P2P.DontUseLedgerPeers
-- else P2P.UseLedgerPeers P2P.Always)
-- P2P.DontUseBootstrapPeers

let keysWithPorts = L.zip3 [1..] poolKeys portNumbers
ePoolNodes <- H.forConcurrently keysWithPorts $ \(i, key, port) -> do
Expand Down Expand Up @@ -393,7 +412,7 @@ cardanoTestnet

stakePoolsFp <- H.note $ tmpAbsPath </> "current-stake-pools.json"

assertExpectedSposInLedgerState stakePoolsFp nPools execConfig
assertExpectedSposInLedgerState stakePoolsFp 1 execConfig

when newEpochStateLogging $
TR.startLedgerNewEpochStateLogging runtime tempBaseAbsPath
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ prop_check_if_treasury_is_growing = integrationRetryWorkspace 0 "growing-treasur
}

TestnetRuntime{testnetMagic, configurationFile, poolNodes} <- cardanoTestnetDefault options shelleyOptions conf
H.failure

(execConfig, socketPathAbs) <- do
PoolNode{poolRuntime} <- H.headM poolNodes
Expand Down

0 comments on commit 33b4d42

Please sign in to comment.