Skip to content

Commit

Permalink
Merge pull request #992 from IntersectMBO/smelc/create-testnet-data-b…
Browse files Browse the repository at this point in the history
…yron-ostracism

create-testnet-data: move Byron handling to its own file
  • Loading branch information
smelc authored Dec 12, 2024
2 parents d96e800 + 723da98 commit e68b762
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 63 deletions.
1 change: 1 addition & 0 deletions cardano-cli/cardano-cli.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ library
Cardano.CLI.EraBased.Options.Transaction
Cardano.CLI.EraBased.Run
Cardano.CLI.EraBased.Run.Genesis
Cardano.CLI.EraBased.Run.Genesis.Byron
Cardano.CLI.EraBased.Run.Genesis.Common
Cardano.CLI.EraBased.Run.Genesis.CreateTestnetData
Cardano.CLI.EraBased.Run.Governance
Expand Down
75 changes: 75 additions & 0 deletions cardano-cli/src/Cardano/CLI/EraBased/Run/Genesis/Byron.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{-# LANGUAGE NumericUnderscores #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TypeApplications #-}

module Cardano.CLI.EraBased.Run.Genesis.Byron where

import Cardano.Api.Byron (rationalToLovelacePortion)
import qualified Cardano.Api.Byron as Byron hiding (GenesisParameters)
import qualified Cardano.Api.Ledger as L
import qualified Cardano.Api.Shelley as Shelley

import qualified Cardano.CLI.Byron.Genesis as Byron
import qualified Cardano.Crypto.ProtocolMagic as Crypto

import Data.Aeson (toJSON, (.=))
import qualified Data.Aeson as Aeson
import Data.Maybe (fromJust)
import Data.Ratio ((%))
import GHC.Word (Word32)

-- | We need to pass these values to create the Byron genesis file.
-- The values here don't matter as the testnet conditions are ultimately determined
-- by the Shelley genesis.
defaultProtocolParamsJsonValue :: Aeson.Value
defaultProtocolParamsJsonValue =
Aeson.object
[ "heavyDelThd" .= toJSON @String "300000000000"
, "maxBlockSize" .= toJSON @String "2000000"
, "maxTxSize" .= toJSON @String "4096"
, "maxHeaderSize" .= toJSON @String "2000000"
, "maxProposalSize" .= toJSON @String "700"
, "mpcThd" .= toJSON @String "20000000000000"
, "scriptVersion" .= toJSON @Int 0
, "slotDuration" .= toJSON @String "1000"
, "softforkRule"
.= Aeson.object
[ "initThd" .= toJSON @String "900000000000000"
, "minThd" .= toJSON @String "600000000000000"
, "thdDecrement" .= toJSON @String "50000000000000"
]
, "txFeePolicy"
.= Aeson.object
[ "multiplier" .= toJSON @String "43946000000"
, "summand" .= toJSON @String "155381000000000"
]
, "unlockStakeEpoch" .= toJSON @String "18446744073709551615"
, "updateImplicit" .= toJSON @String "10000"
, "updateProposalThd" .= toJSON @String "100000000000000"
, "updateVoteThd" .= toJSON @String "1000000000000"
]

mkGenesisParameters
:: Word -> Word32 -> FilePath -> Shelley.ShelleyGenesis c -> Byron.GenesisParameters
mkGenesisParameters numPools actualNetworkWord32 byronGenesisFp shelleyGenesis =
Byron.GenesisParameters{..}
where
-- All arbitrary values come from cardano-testnet
byronPoolNumber = max 1 numPools -- byron genesis creation needs a >= 1 number of pools
gpStartTime = Shelley.sgSystemStart shelleyGenesis
gpProtocolParamsFile = byronGenesisFp
gpK = Byron.BlockCount 10
protocolMagicId = Crypto.ProtocolMagicId actualNetworkWord32
gpProtocolMagic = Crypto.AProtocolMagic (L.Annotated protocolMagicId ()) Crypto.RequiresMagic
gpTestnetBalance =
Byron.TestnetBalanceOptions
0 -- poor adresses
byronPoolNumber -- delegate addresses (BFT nodes)
(fromJust $ Byron.toByronLovelace $ L.Coin $ 3_000_000_000 * fromIntegral byronPoolNumber)
1
gpFakeAvvmOptions =
Byron.FakeAvvmOptions
0 -- avvm entry count
(fromJust $ Byron.toByronLovelace $ L.Coin 0) -- avvm entry balance
gpAvvmBalanceFactor = rationalToLovelacePortion $ 1 % 1
gpSeed = Nothing
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ module Cardano.CLI.EraBased.Run.Genesis.CreateTestnetData
where

import Cardano.Api hiding (ConwayEra)
import Cardano.Api.Byron (rationalToLovelacePortion)
import qualified Cardano.Api.Byron as Byron hiding (GenesisParameters)
import Cardano.Api.Consensus (ShelleyGenesisStaking (..))
import Cardano.Api.Ledger (StrictMaybe (SNothing))
import qualified Cardano.Api.Ledger as L
Expand All @@ -43,6 +41,7 @@ import qualified Cardano.CLI.Commands.Node as Cmd
import Cardano.CLI.EraBased.Commands.Genesis as Cmd
import qualified Cardano.CLI.EraBased.Commands.Governance.Committee as CC
import qualified Cardano.CLI.EraBased.Commands.Governance.DRep as DRep
import Cardano.CLI.EraBased.Run.Genesis.Byron as Byron
import Cardano.CLI.EraBased.Run.Genesis.Common
import qualified Cardano.CLI.EraBased.Run.Governance.Committee as CC
import qualified Cardano.CLI.EraBased.Run.Governance.DRep as DRep
Expand All @@ -57,14 +56,11 @@ import Cardano.CLI.Types.Errors.GenesisCmdError
import Cardano.CLI.Types.Errors.NodeCmdError
import Cardano.CLI.Types.Errors.StakePoolCmdError
import Cardano.CLI.Types.Key
import qualified Cardano.Crypto as Crypto hiding (Hash)
import qualified Cardano.Crypto.Hash as Crypto
import Cardano.Prelude (canonicalEncodePretty)

import Control.DeepSeq (NFData, deepseq)
import Control.Monad (forM, forM_, unless, void, when)
import Data.Aeson (toJSON, (.=))
import qualified Data.Aeson as Aeson
import qualified Data.Aeson.Encode.Pretty as Aeson
import Data.Bifunctor (Bifunctor (..))
import Data.ByteString (ByteString)
Expand All @@ -75,8 +71,7 @@ import Data.Functor.Identity (Identity)
import Data.ListMap (ListMap (..))
import Data.Map.Strict (Map)
import qualified Data.Map.Strict as Map
import Data.Maybe (fromJust, fromMaybe)
import Data.Ratio ((%))
import Data.Maybe (fromMaybe)
import qualified Data.Sequence.Strict as Seq
import qualified Data.Set as Set
import Data.String (fromString)
Expand Down Expand Up @@ -391,9 +386,9 @@ runGenesisCreateTestNetDataCmd
shelleyGenesis

let byronGenesisFp = outputDir </> "byron.genesis.spec.json" -- This file is used by the performance testing team.
void $ writeFileGenesis byronGenesisFp $ WritePretty defaultByronProtocolParamsJsonValue
void $ writeFileGenesis byronGenesisFp $ WritePretty Byron.defaultProtocolParamsJsonValue

let byronGenesisParameters = mkByronGenesisParameters actualNetworkWord32 byronGenesisFp shelleyGenesis'
let byronGenesisParameters = Byron.mkGenesisParameters numPools actualNetworkWord32 byronGenesisFp shelleyGenesis'
byronOutputDir = outputDir </> "byron-gen-command"
(byronGenesis, byronSecrets) <-
firstExceptT GenesisCmdByronError $ Byron.mkGenesis byronGenesisParameters
Expand Down Expand Up @@ -431,29 +426,6 @@ runGenesisCreateTestNetDataCmd
poolsDir = outputDir </> "pools-keys"
stakeDelegatorsDir = outputDir </> "stake-delegators"
mkPoolDir idx = poolsDir </> ("pool" <> show idx)
byronPoolNumber = max 1 numPools -- byron genesis creation needs a >= 1 number of pools

-- All arbitrary values come from cardano-testnet
mkByronGenesisParameters actualNetworkWord32 byronGenesisFp shelleyGenesis =
Byron.GenesisParameters{..}
where
gpStartTime = sgSystemStart shelleyGenesis
gpProtocolParamsFile = byronGenesisFp
gpK = Byron.BlockCount 10
protocolMagicId = Crypto.ProtocolMagicId actualNetworkWord32
gpProtocolMagic = Crypto.AProtocolMagic (L.Annotated protocolMagicId ()) Crypto.RequiresMagic
gpTestnetBalance =
Byron.TestnetBalanceOptions
0 -- poor adresses
byronPoolNumber -- delegate addresses (BFT nodes)
(fromJust $ Byron.toByronLovelace $ L.Coin $ 3_000_000_000 * fromIntegral byronPoolNumber)
1
gpFakeAvvmOptions =
Byron.FakeAvvmOptions
0 -- avvm entry count
(fromJust $ Byron.toByronLovelace $ L.Coin 0) -- avvm entry balance
gpAvvmBalanceFactor = rationalToLovelacePortion $ 1 % 1
gpSeed = Nothing

mkDelegationMapEntry
:: Delegation -> (L.KeyHash L.Staking L.StandardCrypto, L.PoolParams L.StandardCrypto)
Expand Down Expand Up @@ -561,37 +533,6 @@ runGenesisCreateTestNetDataCmd
desiredKeyOutputFormat :: KeyOutputFormat
desiredKeyOutputFormat = KeyOutputFormatTextEnvelope

-- | We need to pass these values to create the Byron genesis file.
-- The values here don't matter as the testnet conditions are ultimately determined
-- by the Shelley genesis.
defaultByronProtocolParamsJsonValue :: Aeson.Value
defaultByronProtocolParamsJsonValue =
Aeson.object
[ "heavyDelThd" .= toJSON @String "300000000000"
, "maxBlockSize" .= toJSON @String "2000000"
, "maxTxSize" .= toJSON @String "4096"
, "maxHeaderSize" .= toJSON @String "2000000"
, "maxProposalSize" .= toJSON @String "700"
, "mpcThd" .= toJSON @String "20000000000000"
, "scriptVersion" .= toJSON @Int 0
, "slotDuration" .= toJSON @String "1000"
, "softforkRule"
.= Aeson.object
[ "initThd" .= toJSON @String "900000000000000"
, "minThd" .= toJSON @String "600000000000000"
, "thdDecrement" .= toJSON @String "50000000000000"
]
, "txFeePolicy"
.= Aeson.object
[ "multiplier" .= toJSON @String "43946000000"
, "summand" .= toJSON @String "155381000000000"
]
, "unlockStakeEpoch" .= toJSON @String "18446744073709551615"
, "updateImplicit" .= toJSON @String "10000"
, "updateProposalThd" .= toJSON @String "100000000000000"
, "updateVoteThd" .= toJSON @String "1000000000000"
]

writeREADME
:: ()
=> FilePath
Expand Down

0 comments on commit e68b762

Please sign in to comment.