Skip to content

Commit 404554a

Browse files
committed
Make DijkstraGenesis optional in unstable-cardano-tools
1 parent e3c52b7 commit 404554a

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

ouroboros-consensus-cardano/ouroboros-consensus-cardano.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,7 @@ library unstable-cardano-tools
566566
cardano-ledger-byron,
567567
cardano-ledger-conway,
568568
cardano-ledger-core,
569+
cardano-ledger-dijkstra,
569570
cardano-ledger-mary,
570571
cardano-ledger-shelley,
571572
cardano-prelude,

ouroboros-consensus-cardano/src/unstable-cardano-tools/Cardano/Tools/DBAnalyser/Block/Cardano.hs

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ import qualified Cardano.Crypto.Hash.Class as CryptoClass
3131
import Cardano.Crypto.Raw (Raw)
3232
import qualified Cardano.Ledger.Api.Era as L
3333
import qualified Cardano.Ledger.Api.Transition as SL
34+
import Cardano.Ledger.BaseTypes (boundRational, unsafeNonZero)
3435
import Cardano.Ledger.Core (TxOut)
36+
import Cardano.Ledger.Dijkstra.PParams
3537
import qualified Cardano.Ledger.Shelley.LedgerState as Shelley.LedgerState
3638
import qualified Cardano.Ledger.Shelley.UTxO as Shelley.UTxO
3739
import Cardano.Ledger.TxIn (TxIn)
@@ -47,7 +49,7 @@ import qualified Data.ByteString as BS
4749
import qualified Data.Compact as Compact
4850
import Data.Map.Strict (Map)
4951
import qualified Data.Map.Strict as Map
50-
import Data.Maybe (fromJust)
52+
import Data.Maybe (fromJust, fromMaybe)
5153
import Data.SOP.BasicFunctors
5254
import Data.SOP.Functors
5355
import Data.SOP.Strict
@@ -157,9 +159,11 @@ instance HasProtocolInfo (CardanoBlock StandardCrypto) where
157159
genesisConway <-
158160
either (error . show) return
159161
=<< Aeson.eitherDecodeFileStrict' (conwayGenesisPath cc)
160-
genesisDijkstra <-
161-
either (error . show) return
162-
=<< Aeson.eitherDecodeFileStrict' (dijkstraGenesisPath cc)
162+
genesisDijkstra <- case dijkstraGenesisPath cc of
163+
Nothing -> pure emptyDijkstraGenesis
164+
Just fp ->
165+
either (error . show) return
166+
=<< Aeson.eitherDecodeFileStrict' fp
163167

164168
let transCfg =
165169
SL.mkLatestTransitionConfig genesisShelley genesisAlonzo genesisConway genesisDijkstra
@@ -182,6 +186,18 @@ instance HasProtocolInfo (CardanoBlock StandardCrypto) where
182186
initialNonce
183187
(cfgHardForkTriggers cc)
184188

189+
-- | An empty Dijkstra genesis to be provided when none is specified in the config.
190+
emptyDijkstraGenesis :: SL.DijkstraGenesis
191+
emptyDijkstraGenesis =
192+
let upgradePParamsDef =
193+
UpgradeDijkstraPParams
194+
{ udppMaxRefScriptSizePerBlock = 1048576
195+
, udppMaxRefScriptSizePerTx = 204800
196+
, udppRefScriptCostStride = unsafeNonZero 25600
197+
, udppRefScriptCostMultiplier = fromMaybe (error "impossible") $ boundRational 1.2
198+
}
199+
in SL.DijkstraGenesis{SL.dgUpgradePParams = upgradePParamsDef}
200+
185201
data CardanoConfig = CardanoConfig
186202
{ requiresNetworkMagic :: RequiresNetworkMagic
187203
-- ^ @RequiresNetworkMagic@ field
@@ -197,7 +213,7 @@ data CardanoConfig = CardanoConfig
197213
-- ^ @AlonzoGenesisFile@ field
198214
, conwayGenesisPath :: FilePath
199215
-- ^ @ConwayGenesisFile@ field
200-
, dijkstraGenesisPath :: FilePath
216+
, dijkstraGenesisPath :: Maybe FilePath
201217
-- ^ @DijkstraGenesisFile@ field
202218
, cfgHardForkTriggers :: CardanoHardForkTriggers
203219
-- ^ @Test*HardForkAtEpoch@ for each Shelley era
@@ -210,7 +226,7 @@ instance AdjustFilePaths CardanoConfig where
210226
, shelleyGenesisPath = f $ shelleyGenesisPath cc
211227
, alonzoGenesisPath = f $ alonzoGenesisPath cc
212228
, conwayGenesisPath = f $ conwayGenesisPath cc
213-
, dijkstraGenesisPath = f $ dijkstraGenesisPath cc
229+
, dijkstraGenesisPath = f <$> dijkstraGenesisPath cc
214230
-- Byron, Shelley, Alonzo, and Conway are the only eras that have genesis
215231
-- data. The actual genesis block is a Byron block, therefore we needed a
216232
-- genesis file. To transition to Shelley, we needed to add some additional
@@ -241,7 +257,7 @@ instance Aeson.FromJSON CardanoConfig where
241257

242258
conwayGenesisPath <- v Aeson..: "ConwayGenesisFile"
243259

244-
dijkstraGenesisPath <- v Aeson..: "DijkstraGenesisFile"
260+
dijkstraGenesisPath <- v Aeson..:? "DijkstraGenesisFile"
245261

246262
triggers <- do
247263
let parseTrigger ::

0 commit comments

Comments
 (0)