From 51c08bce23fefce208f9af5c479a56f12b692ed1 Mon Sep 17 00:00:00 2001 From: Jordan Millar Date: Fri, 20 Jan 2023 11:37:46 -0400 Subject: [PATCH] Add Testnet.Genesis module and implement defaultByronGenesisJsonValue --- cardano-testnet/cardano-testnet.cabal | 1 + cardano-testnet/src/Testnet/Babbage.hs | 26 ++--------------- cardano-testnet/src/Testnet/Cardano.hs | 27 ++--------------- cardano-testnet/src/Testnet/Genesis.hs | 40 ++++++++++++++++++++++++++ 4 files changed, 47 insertions(+), 47 deletions(-) create mode 100644 cardano-testnet/src/Testnet/Genesis.hs diff --git a/cardano-testnet/cardano-testnet.cabal b/cardano-testnet/cardano-testnet.cabal index 0065b316fae..3a8f8fd820a 100644 --- a/cardano-testnet/cardano-testnet.cabal +++ b/cardano-testnet/cardano-testnet.cabal @@ -80,6 +80,7 @@ library Testnet.Babbage Testnet.Cardano Testnet.Conf + Testnet.Genesis Testnet.Run Testnet.Shelley Testnet.Utils diff --git a/cardano-testnet/src/Testnet/Babbage.hs b/cardano-testnet/src/Testnet/Babbage.hs index 8988058718a..487389bdd1c 100644 --- a/cardano-testnet/src/Testnet/Babbage.hs +++ b/cardano-testnet/src/Testnet/Babbage.hs @@ -32,6 +32,7 @@ import qualified Hedgehog.Extras.Test.File as H import qualified System.Info as OS import qualified Testnet.Conf as H +import Testnet.Genesis import qualified Testnet.Util.Assert as H import Testnet.Util.Process (execCli_) import Testnet.Util.Runtime (Delegator (..), NodeLoggingFormat (..), PaymentKeyPair (..), @@ -67,29 +68,8 @@ babbageTestnet :: BabbageTestnetOptions -> H.Conf -> H.Integration TestnetRuntim babbageTestnet testnetOptions H.Conf {..} = do H.createDirectoryIfMissing (tempAbsPath "logs") - H.lbsWriteFile (tempAbsPath "byron.genesis.spec.json") . encode $ object - [ "heavyDelThd" .= ("300000000000" :: String) - , "maxBlockSize" .= ("2000000" :: String) - , "maxTxSize" .= ("4096" :: String) - , "maxHeaderSize" .= ("2000000" :: String) - , "maxProposalSize" .= ("700" :: String) - , "mpcThd" .= ("20000000000000" :: String) - , "scriptVersion" .= (0 :: Int) - , "slotDuration" .= show @Int (babbageSlotDuration testnetOptions) - , "unlockStakeEpoch" .= ("18446744073709551615" :: String) - , "updateImplicit" .= ("10000" :: String) - , "updateProposalThd" .= ("100000000000000" :: String) - , "updateVoteThd" .= ("1000000000000" :: String) - , "softforkRule" .= object - [ "initThd" .= ("900000000000000" :: String) - , "minThd" .= ("600000000000000" :: String) - , "thdDecrement" .= ("50000000000000" :: String) - ] - , "txFeePolicy" .= object - [ "multiplier" .= ("43946000000" :: String) - , "summand" .= ("155381000000000" :: String) - ] - ] + H.lbsWriteFile (tempAbsPath "byron.genesis.spec.json") + . encode $ defaultByronGenesisJsonValue void $ H.note OS.os currentTime <- H.noteShowIO DTC.getCurrentTime diff --git a/cardano-testnet/src/Testnet/Cardano.hs b/cardano-testnet/src/Testnet/Cardano.hs index 5a9f8a96367..266689879bc 100644 --- a/cardano-testnet/src/Testnet/Cardano.hs +++ b/cardano-testnet/src/Testnet/Cardano.hs @@ -26,7 +26,6 @@ import Prelude import Control.Monad import Control.Monad.IO.Class (MonadIO, liftIO) import Control.Monad.Trans.Except -import Data.Aeson ((.=)) import qualified Data.Aeson as J import qualified Data.ByteString as BS import Data.ByteString.Lazy (ByteString) @@ -65,6 +64,7 @@ import qualified Hedgehog.Extras.Test.File as H import qualified Hedgehog.Extras.Test.Network as H import qualified Testnet.Conf as H +import Testnet.Genesis import qualified Testnet.Util.Assert as H import qualified Testnet.Util.Process as H import Testnet.Util.Process (execCli_) @@ -280,29 +280,8 @@ cardanoTestnet testnetOptions H.Conf {..} = do H.writeFile (tempAbsPath node "port") (show port) - H.lbsWriteFile (tempAbsPath "byron.genesis.spec.json") . J.encode $ J.object - [ "heavyDelThd" .= J.toJSON @String "300000000000" - , "maxBlockSize" .= J.toJSON @String "2000000" - , "maxTxSize" .= J.toJSON @String "4096" - , "maxHeaderSize" .= J.toJSON @String "2000000" - , "maxProposalSize" .= J.toJSON @String "700" - , "mpcThd" .= J.toJSON @String "20000000000000" - , "scriptVersion" .= J.toJSON @Int 0 - , "slotDuration" .= J.toJSON @String "1000" - , "softforkRule" .= J.object - [ "initThd" .= J.toJSON @String "900000000000000" - , "minThd" .= J.toJSON @String "600000000000000" - , "thdDecrement" .= J.toJSON @String "50000000000000" - ] - , "txFeePolicy" .= J.object - [ "multiplier" .= J.toJSON @String "43946000000" - , "summand" .= J.toJSON @String "155381000000000" - ] - , "unlockStakeEpoch" .= J.toJSON @String "18446744073709551615" - , "updateImplicit" .= J.toJSON @String "10000" - , "updateProposalThd" .= J.toJSON @String "100000000000000" - , "updateVoteThd" .= J.toJSON @String "1000000000000" - ] + H.lbsWriteFile (tempAbsPath "byron.genesis.spec.json") + . J.encode $ defaultByronGenesisJsonValue -- stuff execCli_ diff --git a/cardano-testnet/src/Testnet/Genesis.hs b/cardano-testnet/src/Testnet/Genesis.hs new file mode 100644 index 00000000000..80b32e9eba2 --- /dev/null +++ b/cardano-testnet/src/Testnet/Genesis.hs @@ -0,0 +1,40 @@ +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE TypeApplications #-} + +-- | All Byron and Shelley Genesis related functionality +module Testnet.Genesis + ( defaultByronGenesisJsonValue + ) where + +import Prelude + +import Data.Aeson + +-- | We need a Byron genesis in order to be able to hardfork to the later Shelley based eras. +-- The values here don't matter as the testnet conditions are ultimately determined +-- by the Shelley genesis. +defaultByronGenesisJsonValue :: Value +defaultByronGenesisJsonValue = + 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" .= object + [ "initThd" .= toJSON @String "900000000000000" + , "minThd" .= toJSON @String "600000000000000" + , "thdDecrement" .= toJSON @String "50000000000000" + ] + , "txFeePolicy" .= 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" + ]