Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
3337: [CAD-3383] Bring db analyser back to life r=EncodePanda a=EncodePanda * Add FromJSON instance to AlonzoGenesis This instances was copied from node. But it should really live in ledger spec. Same as ShelleyGenesis does. This should be addressed in the near future. Issue was created IntersectMBO/cardano-ledger#2452 * Bring db-analyser back to life Once we have AlonzoGenesis FromJSON, providing it to mkCardanoProtocolInfo is just a matter of reading the configuration file provided by the user Examples usage: ``` λ cabal run ouroboros-consensus-cardano:db-analyser -- \ --db db_mainnet cardano \ --configByron dbacfg/mainnet-byron-genesis.json \ --configShelley dbacfg/mainnet-shelley-genesis.json \ --configAlonzo dbacfg/mainnet-alonzo-genesis.json \ --show-slot-block-no (...) BlockNo 73752 SlotNo 73780 BlockNo 73753 SlotNo 73781 BlockNo 73754 SlotNo 73782 BlockNo 73755 SlotNo 73783 BlockNo 73756 SlotNo 73784 (...) ``` Not tested with Alonzo yet, because the mainnet chain (that this tool was tested with) does not yet hold alonzo blocks. Co-authored-by: EncodePanda <paul.szulc@gmail.com>
- Loading branch information
Showing
3 changed files
with
134 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 119 additions & 0 deletions
119
ouroboros-consensus-cardano/tools/db-analyser/Block/Alonzo.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
{-# LANGUAGE DeriveAnyClass #-} | ||
{-# LANGUAGE DerivingStrategies #-} | ||
{-# LANGUAGE FlexibleInstances #-} | ||
{-# LANGUAGE GeneralizedNewtypeDeriving #-} | ||
{-# LANGUAGE NamedFieldPuns #-} | ||
{-# LANGUAGE OverloadedStrings #-} | ||
{-# LANGUAGE StandaloneDeriving #-} | ||
{-# LANGUAGE TypeFamilies #-} | ||
|
||
{-# OPTIONS_GHC -Wno-orphans #-} | ||
module Block.Alonzo ( | ||
AlonzoBlockArgs | ||
, Args (..) | ||
) where | ||
|
||
import Control.Applicative | ||
import qualified Data.Map.Strict as Map | ||
import Data.Text (Text) | ||
import Options.Applicative | ||
import Prelude | ||
|
||
import Data.Aeson (FromJSON (..), (.:), (.:?)) | ||
import qualified Data.Aeson as Aeson | ||
import Data.Aeson.Types (FromJSONKey (..)) | ||
|
||
import qualified Cardano.Ledger.Alonzo.Genesis as Alonzo | ||
import qualified Cardano.Ledger.Alonzo.Language as Alonzo | ||
import qualified Cardano.Ledger.Alonzo.Scripts as Alonzo | ||
import qualified Cardano.Ledger.BaseTypes as Ledger | ||
import HasAnalysis (HasProtocolInfo (..)) | ||
import Ouroboros.Consensus.Shelley.Eras (StandardAlonzo) | ||
import Ouroboros.Consensus.Shelley.Ledger.Block (ShelleyBlock) | ||
|
||
import Plutus.V1.Ledger.Api (defaultCostModelParams) | ||
|
||
instance HasProtocolInfo (ShelleyBlock StandardAlonzo) where | ||
data Args (ShelleyBlock StandardAlonzo) = AlonzoBlockArgs { | ||
configFileAlonzo :: FilePath | ||
} | ||
deriving (Show) | ||
|
||
argsParser _ = AlonzoBlockArgs | ||
<$> strOption (mconcat [ | ||
long "configAlonzo" | ||
, help "Path to config file" | ||
, metavar "PATH" | ||
]) | ||
|
||
-- | This function would only be used if we run an | ||
-- Alonzo only chain. This should be dead code really. | ||
mkProtocolInfo _ = | ||
error $ "Not implemented because we don't " | ||
<> "anticipate running an 'Alonzo only' chain." | ||
|
||
type AlonzoBlockArgs = Args (ShelleyBlock StandardAlonzo) | ||
|
||
instance FromJSON Alonzo.AlonzoGenesis where | ||
parseJSON = Aeson.withObject "Alonzo Genesis" $ \o -> do | ||
coinsPerUTxOWord <- o .: "lovelacePerUTxOWord" | ||
<|> o .: "adaPerUTxOWord" | ||
cModels <- o .:? "costModels" | ||
prices <- o .: "executionPrices" | ||
maxTxExUnits <- o .: "maxTxExUnits" | ||
maxBlockExUnits <- o .: "maxBlockExUnits" | ||
maxValSize <- o .: "maxValueSize" | ||
collateralPercentage <- o .: "collateralPercentage" | ||
maxCollateralInputs <- o .: "maxCollateralInputs" | ||
case cModels of | ||
Nothing -> case Alonzo.CostModel <$> defaultCostModelParams of | ||
Just m -> return Alonzo.AlonzoGenesis | ||
{ Alonzo.coinsPerUTxOWord | ||
, Alonzo.costmdls = Map.singleton Alonzo.PlutusV1 m | ||
, Alonzo.prices | ||
, Alonzo.maxTxExUnits | ||
, Alonzo.maxBlockExUnits | ||
, Alonzo.maxValSize | ||
, Alonzo.collateralPercentage | ||
, Alonzo.maxCollateralInputs | ||
} | ||
Nothing -> fail "Failed to extract the cost model params from defaultCostModel" | ||
Just costmdls -> return Alonzo.AlonzoGenesis | ||
{ Alonzo.coinsPerUTxOWord | ||
, Alonzo.costmdls | ||
, Alonzo.prices | ||
, Alonzo.maxTxExUnits | ||
, Alonzo.maxBlockExUnits | ||
, Alonzo.maxValSize | ||
, Alonzo.collateralPercentage | ||
, Alonzo.maxCollateralInputs | ||
} | ||
|
||
deriving instance FromJSON Alonzo.ExUnits | ||
|
||
instance FromJSON Alonzo.Language where | ||
parseJSON = Aeson.withText "Language" languageFromText | ||
|
||
instance FromJSONKey Alonzo.Language where | ||
fromJSONKey = Aeson.FromJSONKeyTextParser languageFromText | ||
|
||
instance FromJSON Alonzo.Prices where | ||
parseJSON = | ||
Aeson.withObject "prices" $ \o -> do | ||
steps <- o .: "prSteps" | ||
mem <- o .: "prMem" | ||
prSteps <- checkBoundedRational steps | ||
prMem <- checkBoundedRational mem | ||
return Alonzo.Prices { Alonzo.prSteps, Alonzo.prMem } | ||
where | ||
-- We cannot round-trip via NonNegativeInterval, so we go via Rational | ||
checkBoundedRational r = | ||
case Ledger.boundRational r of | ||
Nothing -> fail ("too much precision for bounded rational: " ++ show r) | ||
Just s -> return s | ||
|
||
deriving newtype instance FromJSON Alonzo.CostModel | ||
|
||
languageFromText :: MonadFail m => Text -> m Alonzo.Language | ||
languageFromText "PlutusV1" = pure Alonzo.PlutusV1 | ||
languageFromText lang = fail $ "Error decoding Language: " ++ show lang |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters