diff --git a/ouroboros-consensus-cardano/README.md b/ouroboros-consensus-cardano/README.md index ca267dc9dd..5db3429acd 100644 --- a/ouroboros-consensus-cardano/README.md +++ b/ouroboros-consensus-cardano/README.md @@ -68,21 +68,6 @@ A block with the corresponding slot number must exist in the ImmutableDB. For certain analyses, a snapshot at that slot number must exist in `DB_PATH/ledger/SLOT_NUMBER_db-analyser` - where `SLOT_NUMBER` is the value provided by the user with the `--analyse-from` flag. The user can use snapshots created by the node or they can create their own snapshots via db-analyser - see the `--store-ledger` command -#### COMMAND - -There are three options: `byron`, `shelley`, `cardano`. When in doubt which one to use, use `cardano`. - -* `byron` - -User should run this if they are dealing with Byron only chain. When the command is `byron` then user must provide `--configByron PATH` pointing to a byron configuration file. - -* `shelley` - -User should run this if they are dealing with Shelley only chain (neither Byron nor Allegra or any other era that comes after). When the command is `shelley` then user must provide `--configShelley PATH` pointing to a shelley configuration file. They may also provide `--genesisHash HASH` and `--threshold THRESHOLD` - -* `cardano` -User should run this if they are dealing with a `cardano` chain. - #### --num-blocks-to-process ``` @@ -215,7 +200,7 @@ Suppose we have a local chain database in reachable from `$NODE_HOME`, and we want to take a snapshot of the ledger state for slot `100`. Then we can run: ```sh -cabal run exe:db-analyser -- cardano \ +cabal run exe:db-analyser -- \ --config $NODE_HOME/configuration/cardano/mainnet-config.json \ --db $NODE_HOME/mainnet/db \ --store-ledger 100 @@ -225,7 +210,7 @@ If we had a previous snapshot of the ledger state, say corresponding to slot `50`, it is possible to tell `db-analyser` to start from this snapshot: ```sh -cabal run exe:db-analyser -- cardano \ +cabal run exe:db-analyser -- \ --config $NODE_HOME/configuration/cardano/mainnet-config.json \ --db $NODE_HOME/mainnet/db \ --analyse-from 50 \ @@ -238,7 +223,7 @@ To benchmark the ledger operations, using the setup mentioned in the foregoing examples, one could run the tool as follows: ```sh -cabal run exe:db-analyser -- cardano +cabal run exe:db-analyser -- \ --config $NODE_HOME/configuration/cardano/mainnet-config.json \ --db $NODE_HOME/mainnet/db \ --analyse-from 100 \ @@ -250,7 +235,7 @@ The benchmarking command can be combined with `--num-blocks-to-process` to specify the application of how many blocks we want to process. Eg: ```sh -cabal run exe:db-analyser -- cardano +cabal run exe:db-analyser -- \ --config $NODE_HOME/configuration/cardano/mainnet-config.json \ --db $NODE_HOME/mainnet/db \ --analyse-from 100 \ @@ -284,7 +269,7 @@ First, run the following command for both of your ChainDBs: ``` db-analyser --analyse-from 1234 --db /path/to/dbX --show-slot-block-no \ - cardano --config /path/to/config.json | cut -d ' ' -f 2- > dbX.log + --config /path/to/config.json | cut -d ' ' -f 2- > dbX.log ``` Note that specificying `--analyse-from` is optional; it means that you are diff --git a/ouroboros-consensus-cardano/app/DBAnalyser/Parsers.hs b/ouroboros-consensus-cardano/app/DBAnalyser/Parsers.hs index d9c0bcd41a..1b3587289a 100644 --- a/ouroboros-consensus-cardano/app/DBAnalyser/Parsers.hs +++ b/ouroboros-consensus-cardano/app/DBAnalyser/Parsers.hs @@ -2,29 +2,25 @@ {-# LANGUAGE LambdaCase #-} module DBAnalyser.Parsers - ( BlockType (..) - , blockTypeParser - , parseCmdLine + ( parseCmdLine + , parseCardanoArgs + , CardanoBlockArgs ) where -import Cardano.Crypto (RequiresNetworkMagic (..)) import Cardano.Tools.DBAnalyser.Analysis -import Cardano.Tools.DBAnalyser.Block.Byron import Cardano.Tools.DBAnalyser.Block.Cardano -import Cardano.Tools.DBAnalyser.Block.Shelley import Cardano.Tools.DBAnalyser.Types import qualified Data.Foldable as Foldable import Options.Applicative import Ouroboros.Consensus.Block (SlotNo (..), WithOrigin (..)) import Ouroboros.Consensus.Byron.Node (PBftSignatureThreshold (..)) -import Ouroboros.Consensus.Shelley.Node (Nonce (..)) {------------------------------------------------------------------------------- Parsing -------------------------------------------------------------------------------} -parseCmdLine :: Parser (DBAnalyserConfig, BlockType) -parseCmdLine = (,) <$> parseDBAnalyserConfig <*> blockTypeParser +parseCmdLine :: Parser (DBAnalyserConfig, CardanoBlockArgs) +parseCmdLine = (,) <$> parseDBAnalyserConfig <*> parseCardanoArgs parseDBAnalyserConfig :: Parser DBAnalyserConfig parseDBAnalyserConfig = @@ -259,65 +255,12 @@ pMaybeOutputFile = Parse BlockType-specific arguments -------------------------------------------------------------------------------} -data BlockType - = ByronBlock ByronBlockArgs - | ShelleyBlock ShelleyBlockArgs - | CardanoBlock CardanoBlockArgs - -blockTypeParser :: Parser BlockType -blockTypeParser = - subparser $ - mconcat - [ command - "byron" - (info (parseByronType <**> helper) (progDesc "Analyse a Byron-only DB")) - , command - "shelley" - (info (parseShelleyType <**> helper) (progDesc "Analyse a Shelley-only DB")) - , command - "cardano" - (info (parseCardanoType <**> helper) (progDesc "Analyse a Cardano DB")) - ] - -parseByronType :: Parser BlockType -parseByronType = ByronBlock <$> parseByronArgs - -parseShelleyType :: Parser BlockType -parseShelleyType = ShelleyBlock <$> parseShelleyArgs - -parseCardanoType :: Parser BlockType -parseCardanoType = CardanoBlock <$> parseCardanoArgs - parseCardanoArgs :: Parser CardanoBlockArgs parseCardanoArgs = CardanoBlockArgs <$> parseConfigFile <*> parsePBftSignatureThreshold -parseShelleyArgs :: Parser ShelleyBlockArgs -parseShelleyArgs = - ShelleyBlockArgs - <$> strOption - ( mconcat - [ long "configShelley" - , help "Path to config file" - , metavar "PATH" - ] - ) - <*> Foldable.asum - [ Nonce <$> parseNonce - , pure NeutralNonce - ] - where - parseNonce = - strOption - ( mconcat - [ long "nonce" - , help "Initial nonce, i.e., hash of the genesis config file" - , metavar "NONCE" - ] - ) - parseConfigFile :: Parser FilePath parseConfigFile = strOption $ @@ -337,27 +280,3 @@ parsePBftSignatureThreshold = , help "PBftSignatureThreshold" , metavar "THRESHOLD" ] - -parseByronArgs :: Parser ByronBlockArgs -parseByronArgs = - ByronBlockArgs - <$> parseConfigFile - <*> flag - RequiresNoMagic - RequiresMagic - ( mconcat - [ long "requires-magic" - , help "The DB contains blocks from a testnet, requiring network magic, rather than mainnet" - ] - ) - <*> optional - ( option - auto - ( mconcat - [ long "genesisHash" - , help "Expected genesis hash" - , metavar "HASH" - ] - ) - ) - <*> parsePBftSignatureThreshold diff --git a/ouroboros-consensus-cardano/app/DBTruncater/Parsers.hs b/ouroboros-consensus-cardano/app/DBTruncater/Parsers.hs index 135492a0c5..6bb7b79009 100644 --- a/ouroboros-consensus-cardano/app/DBTruncater/Parsers.hs +++ b/ouroboros-consensus-cardano/app/DBTruncater/Parsers.hs @@ -5,8 +5,8 @@ import DBAnalyser.Parsers import Options.Applicative import Ouroboros.Consensus.Block.Abstract -commandLineParser :: Parser (DBTruncaterConfig, BlockType) -commandLineParser = (,) <$> parseDBTruncaterConfig <*> blockTypeParser +commandLineParser :: Parser (DBTruncaterConfig, CardanoBlockArgs) +commandLineParser = (,) <$> parseDBTruncaterConfig <*> parseCardanoArgs parseDBTruncaterConfig :: Parser DBTruncaterConfig parseDBTruncaterConfig = @@ -23,6 +23,7 @@ parseDBTruncaterConfig = , metavar "PATH" ] parseVerbose = switch (long "verbose" <> help "Enable verbose logging") + parseTruncateAfter :: Parser TruncateAfter parseTruncateAfter = fmap TruncateAfterSlot slotNoOption <|> fmap TruncateAfterBlock blockNoOption diff --git a/ouroboros-consensus-cardano/app/db-analyser.hs b/ouroboros-consensus-cardano/app/db-analyser.hs index 44821c8942..9b2910cc5b 100644 --- a/ouroboros-consensus-cardano/app/db-analyser.hs +++ b/ouroboros-consensus-cardano/app/db-analyser.hs @@ -3,21 +3,10 @@ {-# LANGUAGE ScopedTypeVariables #-} -- | Database analysis tool. --- --- Usage: db-analyser --db PATH [--verbose] [--analyse-from SLOT_NUMBER] --- [--db-validation ARG] --- [--show-slot-block-no | --count-tx-outputs | --- --show-block-header-size | --show-block-txs-size | --- --show-ebbs | --store-ledger SLOT_NUMBER --- [--full-ledger-validation] | --- --count-blocks | --checkThunks BLOCK_COUNT | --- --trace-ledger | --repro-mempool-and-forge INT | --- --benchmark-ledger-ops [--out-file FILE] [--reapply] | --- --get-block-application-metrics NUM [--out-file FILE]] --- [--num-blocks-to-process INT] COMMAND module Main (main) where import Cardano.Crypto.Init (cryptoInit) +import Cardano.Tools.DBAnalyser.Block.Cardano import Cardano.Tools.DBAnalyser.Run import Cardano.Tools.DBAnalyser.Types import Cardano.Tools.GitRev (gitRev) @@ -38,13 +27,9 @@ import Options.Applicative main :: IO () main = withStdTerminalHandles $ do cryptoInit - (conf, blocktype) <- getCmdLine - void $ case blocktype of - ByronBlock args -> analyse conf args - ShelleyBlock args -> analyse conf args - CardanoBlock args -> analyse conf args + void $ uncurry analyse =<< getCmdLine -getCmdLine :: IO (DBAnalyserConfig, BlockType) +getCmdLine :: IO (DBAnalyserConfig, CardanoBlockArgs) getCmdLine = execParser opts where opts = diff --git a/ouroboros-consensus-cardano/app/db-truncater.hs b/ouroboros-consensus-cardano/app/db-truncater.hs index 333a8e9c58..2fbb3d5b9d 100644 --- a/ouroboros-consensus-cardano/app/db-truncater.hs +++ b/ouroboros-consensus-cardano/app/db-truncater.hs @@ -3,7 +3,7 @@ module Main (main) where import Cardano.Crypto.Init (cryptoInit) import Cardano.Tools.DBTruncater.Run import Cardano.Tools.DBTruncater.Types -import DBAnalyser.Parsers (BlockType (..)) +import DBAnalyser.Parsers import qualified DBTruncater.Parsers as DBTruncater import Main.Utf8 (withStdTerminalHandles) import Options.Applicative @@ -20,13 +20,9 @@ import Prelude hiding (truncate) main :: IO () main = withStdTerminalHandles $ do cryptoInit - (conf, blocktype) <- getCommandLineConfig - case blocktype of - ByronBlock args -> truncate conf args - ShelleyBlock args -> truncate conf args - CardanoBlock args -> truncate conf args + uncurry truncate =<< getCommandLineConfig -getCommandLineConfig :: IO (DBTruncaterConfig, BlockType) +getCommandLineConfig :: IO (DBTruncaterConfig, CardanoBlockArgs) getCommandLineConfig = execParser opts where opts = diff --git a/ouroboros-consensus-cardano/app/snapshot-converter.hs b/ouroboros-consensus-cardano/app/snapshot-converter.hs index cfc070e4cc..2dce04b5a6 100644 --- a/ouroboros-consensus-cardano/app/snapshot-converter.hs +++ b/ouroboros-consensus-cardano/app/snapshot-converter.hs @@ -66,11 +66,11 @@ data Config = Config -- ^ Path to the output snapshot } -getCommandLineConfig :: IO (Config, BlockType) +getCommandLineConfig :: IO (Config, CardanoBlockArgs) getCommandLineConfig = execParser $ info - ((,) <$> parseConfig <*> blockTypeParser <**> helper) + ((,) <$> parseConfig <*> parseCardanoArgs <**> helper) (fullDesc <> progDesc "Utility for converting snapshots to and from UTxO-HD") parseConfig :: Parser Config @@ -260,11 +260,7 @@ store _ _ _ _ = error "Malformed output path!" main :: IO () main = withStdTerminalHandles $ do cryptoInit - (conf, blocktype) <- getCommandLineConfig - case blocktype of - ByronBlock args -> run conf args - ShelleyBlock args -> run conf args - CardanoBlock args -> run conf args + uncurry run =<< getCommandLineConfig where run conf args = do ccfg <- configCodec . pInfoConfig <$> mkProtocolInfo args diff --git a/ouroboros-consensus-cardano/changelog.d/20250826_131450_javier.sagredo_remove_shelley_byron.md b/ouroboros-consensus-cardano/changelog.d/20250826_131450_javier.sagredo_remove_shelley_byron.md new file mode 100644 index 0000000000..41b1fa620d --- /dev/null +++ b/ouroboros-consensus-cardano/changelog.d/20250826_131450_javier.sagredo_remove_shelley_byron.md @@ -0,0 +1,25 @@ + + + + + diff --git a/ouroboros-consensus-cardano/ouroboros-consensus-cardano.cabal b/ouroboros-consensus-cardano/ouroboros-consensus-cardano.cabal index e9a6eaa9c9..47472f1d8e 100644 --- a/ouroboros-consensus-cardano/ouroboros-consensus-cardano.cabal +++ b/ouroboros-consensus-cardano/ouroboros-consensus-cardano.cabal @@ -505,9 +505,6 @@ library unstable-cardano-tools hs-source-dirs: src/unstable-cardano-tools exposed-modules: Cardano.Api.Any - Cardano.Api.Protocol.Types - Cardano.Node.Protocol - Cardano.Node.Protocol.Types Cardano.Node.Types Cardano.Tools.DBAnalyser.Analysis Cardano.Tools.DBAnalyser.Analysis.BenchmarkLedgerOps.FileWriting @@ -608,7 +605,6 @@ executable db-analyser build-depends: base, cardano-crypto-class, - cardano-crypto-wrapper, optparse-applicative, ouroboros-consensus, ouroboros-consensus-cardano:{ouroboros-consensus-cardano, unstable-cardano-tools}, @@ -666,7 +662,6 @@ executable db-truncater build-depends: base, cardano-crypto-class, - cardano-crypto-wrapper, optparse-applicative, ouroboros-consensus, ouroboros-consensus-cardano:{ouroboros-consensus-cardano, unstable-cardano-tools}, @@ -697,7 +692,6 @@ executable snapshot-converter base, bytestring, cardano-crypto-class, - cardano-crypto-wrapper, contra-tracer, filepath, fs-api, diff --git a/ouroboros-consensus-cardano/src/unstable-cardano-tools/Cardano/Api/Protocol/Types.hs b/ouroboros-consensus-cardano/src/unstable-cardano-tools/Cardano/Api/Protocol/Types.hs deleted file mode 100644 index 2cb542220c..0000000000 --- a/ouroboros-consensus-cardano/src/unstable-cardano-tools/Cardano/Api/Protocol/Types.hs +++ /dev/null @@ -1,127 +0,0 @@ -{-# LANGUAGE ConstraintKinds #-} -{-# LANGUAGE ExistentialQuantification #-} -{-# LANGUAGE FlexibleContexts #-} -{-# LANGUAGE FlexibleInstances #-} -{-# LANGUAGE GADTs #-} -{-# LANGUAGE MultiParamTypeClasses #-} -{-# LANGUAGE StandaloneDeriving #-} -{-# LANGUAGE TypeFamilies #-} - --- DUPLICATE -- adapted from: cardano-api/src/Cardano/Api/Protocol/Types.hs - -module Cardano.Api.Protocol.Types - ( BlockType (..) - , Protocol (..) - , ProtocolClient (..) - , ProtocolClientInfoArgs (..) - , ProtocolInfoArgs (..) - ) where - -import Cardano.Chain.Slotting (EpochSlots) -import Data.Bifunctor (bimap) -import Ouroboros.Consensus.Block.Forging (BlockForging) -import Ouroboros.Consensus.Byron.ByronHFC (ByronBlockHFC) -import Ouroboros.Consensus.Cardano -import Ouroboros.Consensus.Cardano.Block -import Ouroboros.Consensus.Cardano.Node -import Ouroboros.Consensus.HardFork.Combinator.Embed.Unary -import qualified Ouroboros.Consensus.Ledger.SupportsProtocol as Consensus - ( LedgerSupportsProtocol - ) -import Ouroboros.Consensus.Node.ProtocolInfo - ( ProtocolClientInfo (..) - , ProtocolInfo (..) - ) -import Ouroboros.Consensus.Node.Run (RunNode) -import qualified Ouroboros.Consensus.Protocol.TPraos as Consensus -import qualified Ouroboros.Consensus.Shelley.Eras as Consensus (ShelleyEra) -import Ouroboros.Consensus.Shelley.HFEras () -import qualified Ouroboros.Consensus.Shelley.Ledger.Block as Consensus - ( ShelleyBlock - ) -import Ouroboros.Consensus.Shelley.Ledger.SupportsProtocol () -import Ouroboros.Consensus.Shelley.ShelleyHFC (ShelleyBlockHFC) -import Ouroboros.Consensus.Util.IOLike (IOLike) - -class (RunNode blk, IOLike m) => Protocol m blk where - data ProtocolInfoArgs m blk - protocolInfo :: - ProtocolInfoArgs m blk -> - ( ProtocolInfo blk - , m [BlockForging m blk] - ) - --- | Node client support for each consensus protocol. --- --- This is like 'Protocol' but for clients of the node, so with less onerous --- requirements than to run a node. -class RunNode blk => ProtocolClient blk where - data ProtocolClientInfoArgs blk - protocolClientInfo :: ProtocolClientInfoArgs blk -> ProtocolClientInfo blk - --- | Run PBFT against the Byron ledger -instance IOLike m => Protocol m ByronBlockHFC where - data ProtocolInfoArgs m ByronBlockHFC = ProtocolInfoArgsByron ProtocolParamsByron - protocolInfo (ProtocolInfoArgsByron params) = - ( inject $ protocolInfoByron params - , pure . map inject $ blockForgingByron params - ) - -instance (CardanoHardForkConstraints StandardCrypto, IOLike m) => Protocol m (CardanoBlock StandardCrypto) where - data ProtocolInfoArgs m (CardanoBlock StandardCrypto) - = ProtocolInfoArgsCardano - (CardanoProtocolParams StandardCrypto) - - protocolInfo (ProtocolInfoArgsCardano paramsCardano) = - protocolInfoCardano paramsCardano - -instance ProtocolClient ByronBlockHFC where - data ProtocolClientInfoArgs ByronBlockHFC - = ProtocolClientInfoArgsByron EpochSlots - protocolClientInfo (ProtocolClientInfoArgsByron epochSlots) = - inject $ protocolClientInfoByron epochSlots - -instance CardanoHardForkConstraints StandardCrypto => ProtocolClient (CardanoBlock StandardCrypto) where - data ProtocolClientInfoArgs (CardanoBlock StandardCrypto) - = ProtocolClientInfoArgsCardano EpochSlots - protocolClientInfo (ProtocolClientInfoArgsCardano epochSlots) = - protocolClientInfoCardano epochSlots - -instance - ( IOLike m - , Consensus.LedgerSupportsProtocol - ( Consensus.ShelleyBlock - (Consensus.TPraos StandardCrypto) - ShelleyEra - ) - ) => - Protocol m (ShelleyBlockHFC (Consensus.TPraos StandardCrypto) ShelleyEra) - where - data ProtocolInfoArgs m (ShelleyBlockHFC (Consensus.TPraos StandardCrypto) ShelleyEra) - = ProtocolInfoArgsShelley - ShelleyGenesis - (ProtocolParamsShelleyBased StandardCrypto) - ProtVer - protocolInfo (ProtocolInfoArgsShelley genesis shelleyBasedProtocolParams' protVer) = - bimap inject (fmap $ map inject) $ protocolInfoShelley genesis shelleyBasedProtocolParams' protVer - -instance - Consensus.LedgerSupportsProtocol - ( Consensus.ShelleyBlock - (Consensus.TPraos StandardCrypto) - Consensus.ShelleyEra - ) => - ProtocolClient (ShelleyBlockHFC (Consensus.TPraos StandardCrypto) ShelleyEra) - where - data ProtocolClientInfoArgs (ShelleyBlockHFC (Consensus.TPraos StandardCrypto) ShelleyEra) - = ProtocolClientInfoArgsShelley - protocolClientInfo ProtocolClientInfoArgsShelley = - inject protocolClientInfoShelley - -data BlockType blk where - ByronBlockType :: BlockType ByronBlockHFC - ShelleyBlockType :: BlockType (ShelleyBlockHFC (Consensus.TPraos StandardCrypto) ShelleyEra) - CardanoBlockType :: BlockType (CardanoBlock StandardCrypto) - -deriving instance Eq (BlockType blk) -deriving instance Show (BlockType blk) diff --git a/ouroboros-consensus-cardano/src/unstable-cardano-tools/Cardano/Node/Protocol.hs b/ouroboros-consensus-cardano/src/unstable-cardano-tools/Cardano/Node/Protocol.hs deleted file mode 100644 index 48a91c1442..0000000000 --- a/ouroboros-consensus-cardano/src/unstable-cardano-tools/Cardano/Node/Protocol.hs +++ /dev/null @@ -1,64 +0,0 @@ --- DUPLICATE -- adapted from: cardano-node/src/Cardano/Node/Protocol.hs - -module Cardano.Node.Protocol - ( ProtocolInstantiationError (..) - , SomeConsensusProtocol (..) - , mkConsensusProtocol - ) where - -import Cardano.Api.Any -import Cardano.Node.Protocol.Byron -import Cardano.Node.Protocol.Cardano -import Cardano.Node.Protocol.Shelley -import Cardano.Node.Protocol.Types (SomeConsensusProtocol (..)) -import Cardano.Node.Types -import Control.Monad.Trans.Except (ExceptT) -import Control.Monad.Trans.Except.Extra (firstExceptT) - ------------------------------------------------------------------------------- --- Conversions from configuration into specific protocols and their params --- - -mkConsensusProtocol :: - NodeProtocolConfiguration -> - Maybe ProtocolFilepaths -> - ExceptT ProtocolInstantiationError IO SomeConsensusProtocol -mkConsensusProtocol ncProtocolConfig mProtocolFiles = - case ncProtocolConfig of - NodeProtocolConfigurationByron config -> - firstExceptT ByronProtocolInstantiationError $ - mkSomeConsensusProtocolByron config mProtocolFiles - NodeProtocolConfigurationShelley config -> - firstExceptT ShelleyProtocolInstantiationError $ - mkSomeConsensusProtocolShelley config mProtocolFiles - NodeProtocolConfigurationCardano - byronConfig - shelleyConfig - alonzoConfig - conwayConfig - dijkstraConfig - hardForkConfig -> - firstExceptT CardanoProtocolInstantiationError $ - mkSomeConsensusProtocolCardano - byronConfig - shelleyConfig - alonzoConfig - conwayConfig - dijkstraConfig - hardForkConfig - mProtocolFiles - ------------------------------------------------------------------------------- --- Errors --- - -data ProtocolInstantiationError - = ByronProtocolInstantiationError ByronProtocolInstantiationError - | ShelleyProtocolInstantiationError ShelleyProtocolInstantiationError - | CardanoProtocolInstantiationError CardanoProtocolInstantiationError - deriving Show - -instance Error ProtocolInstantiationError where - displayError (ByronProtocolInstantiationError err) = displayError err - displayError (ShelleyProtocolInstantiationError err) = displayError err - displayError (CardanoProtocolInstantiationError err) = displayError err diff --git a/ouroboros-consensus-cardano/src/unstable-cardano-tools/Cardano/Node/Protocol/Byron.hs b/ouroboros-consensus-cardano/src/unstable-cardano-tools/Cardano/Node/Protocol/Byron.hs index 32c18fefed..15c783fe4a 100644 --- a/ouroboros-consensus-cardano/src/unstable-cardano-tools/Cardano/Node/Protocol/Byron.hs +++ b/ouroboros-consensus-cardano/src/unstable-cardano-tools/Cardano/Node/Protocol/Byron.hs @@ -7,10 +7,8 @@ -- DUPLICATE -- adapted from: cardano-node/src/Cardano/Node/Protocol/Byron.hs module Cardano.Node.Protocol.Byron - ( mkSomeConsensusProtocolByron - - -- * Errors - , ByronProtocolInstantiationError (..) + ( -- * Errors + ByronProtocolInstantiationError (..) -- * Reusable parts , readGenesis @@ -19,14 +17,11 @@ module Cardano.Node.Protocol.Byron import Cardano.Api.Any import Cardano.Api.KeysByron -import qualified Cardano.Api.Protocol.Types as Protocol import qualified Cardano.Chain.Genesis as Genesis import qualified Cardano.Chain.UTxO as UTxO -import qualified Cardano.Chain.Update as Update import qualified Cardano.Crypto.Hash as Crypto import qualified Cardano.Crypto.Hashing as Byron.Crypto import Cardano.Crypto.ProtocolMagic (RequiresNetworkMagic) -import Cardano.Node.Protocol.Types import Cardano.Node.Types import Cardano.Prelude import Control.Monad.Trans.Except.Extra @@ -39,63 +34,12 @@ import Control.Monad.Trans.Except.Extra import qualified Data.ByteString.Lazy as LB import Data.Text as Text (unpack) import Ouroboros.Consensus.Cardano -import qualified Ouroboros.Consensus.Cardano as Consensus import Prelude hiding (show, (.)) ------------------------------------------------------------------------------ -- Byron protocol -- --- | Make 'SomeConsensusProtocol' using the Byron instance. --- --- This lets us handle multiple protocols in a generic way. --- --- This also serves a purpose as a sanity check that we have all the necessary --- type class instances available. -mkSomeConsensusProtocolByron :: - NodeByronProtocolConfiguration -> - Maybe ProtocolFilepaths -> - ExceptT ByronProtocolInstantiationError IO SomeConsensusProtocol -mkSomeConsensusProtocolByron - NodeByronProtocolConfiguration - { npcByronGenesisFile - , npcByronGenesisFileHash - , npcByronReqNetworkMagic - , npcByronPbftSignatureThresh - , npcByronApplicationName - , npcByronApplicationVersion - , npcByronSupportedProtocolVersionMajor - , npcByronSupportedProtocolVersionMinor - , npcByronSupportedProtocolVersionAlt - } - files = do - genesisConfig <- - readGenesis - npcByronGenesisFile - npcByronGenesisFileHash - npcByronReqNetworkMagic - - optionalLeaderCredentials <- readLeaderCredentials genesisConfig files - - return $ - SomeConsensusProtocol Protocol.ByronBlockType $ - Protocol.ProtocolInfoArgsByron $ - Consensus.ProtocolParamsByron - { byronGenesis = genesisConfig - , byronPbftSignatureThreshold = - PBftSignatureThreshold <$> npcByronPbftSignatureThresh - , byronProtocolVersion = - Update.ProtocolVersion - npcByronSupportedProtocolVersionMajor - npcByronSupportedProtocolVersionMinor - npcByronSupportedProtocolVersionAlt - , byronSoftwareVersion = - Update.SoftwareVersion - npcByronApplicationName - npcByronApplicationVersion - , byronLeaderCredentials = optionalLeaderCredentials - } - readGenesis :: GenesisFile -> Maybe GenesisHash -> diff --git a/ouroboros-consensus-cardano/src/unstable-cardano-tools/Cardano/Node/Protocol/Cardano.hs b/ouroboros-consensus-cardano/src/unstable-cardano-tools/Cardano/Node/Protocol/Cardano.hs index 3f754788b4..4dc83c8d2c 100644 --- a/ouroboros-consensus-cardano/src/unstable-cardano-tools/Cardano/Node/Protocol/Cardano.hs +++ b/ouroboros-consensus-cardano/src/unstable-cardano-tools/Cardano/Node/Protocol/Cardano.hs @@ -11,14 +11,12 @@ module Cardano.Node.Protocol.Cardano ( mkConsensusProtocolCardano - , mkSomeConsensusProtocolCardano -- * Errors , CardanoProtocolInstantiationError (..) ) where -import Cardano.Api.Any -import Cardano.Api.Protocol.Types +import Cardano.Api.Any (Error (..)) import qualified Cardano.Chain.Update as Byron import qualified Cardano.Ledger.Api.Era as L import qualified Cardano.Ledger.Api.Transition as SL @@ -27,7 +25,6 @@ import qualified Cardano.Node.Protocol.Byron as Byron import qualified Cardano.Node.Protocol.Conway as Conway import Cardano.Node.Protocol.Shelley (readGenesisAny) import qualified Cardano.Node.Protocol.Shelley as Shelley -import Cardano.Node.Protocol.Types import Cardano.Node.Types import Control.Monad.Trans.Except (ExceptT) import Control.Monad.Trans.Except.Extra (firstExceptT) @@ -54,21 +51,6 @@ import Ouroboros.Consensus.Shelley.Crypto (StandardCrypto) -- -- This also serves a purpose as a sanity check that we have all the necessary -- type class instances available. -mkSomeConsensusProtocolCardano :: - NodeByronProtocolConfiguration -> - NodeShelleyProtocolConfiguration -> - NodeAlonzoProtocolConfiguration -> - NodeConwayProtocolConfiguration -> - NodeDijkstraProtocolConfiguration -> - NodeHardForkProtocolConfiguration -> - Maybe ProtocolFilepaths -> - ExceptT CardanoProtocolInstantiationError IO SomeConsensusProtocol -mkSomeConsensusProtocolCardano nbpc nspc napc ncpc ndpc nhpc files = do - params <- mkConsensusProtocolCardano nbpc nspc napc ncpc ndpc nhpc files - return $! - SomeConsensusProtocol CardanoBlockType $ - ProtocolInfoArgsCardano params - mkConsensusProtocolCardano :: NodeByronProtocolConfiguration -> NodeShelleyProtocolConfiguration -> diff --git a/ouroboros-consensus-cardano/src/unstable-cardano-tools/Cardano/Node/Protocol/Shelley.hs b/ouroboros-consensus-cardano/src/unstable-cardano-tools/Cardano/Node/Protocol/Shelley.hs index 86cea0bf79..13475e12b1 100644 --- a/ouroboros-consensus-cardano/src/unstable-cardano-tools/Cardano/Node/Protocol/Shelley.hs +++ b/ouroboros-consensus-cardano/src/unstable-cardano-tools/Cardano/Node/Protocol/Shelley.hs @@ -3,15 +3,12 @@ {-# LANGUAGE NamedFieldPuns #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ScopedTypeVariables #-} -{-# LANGUAGE TypeApplications #-} -- DUPLICATE -- adapted from: cardano-node/src/Cardano/Node/Protocol/Shelley.hs module Cardano.Node.Protocol.Shelley - ( mkSomeConsensusProtocolShelley - - -- * Errors - , GenesisReadError (..) + ( -- * Errors + GenesisReadError (..) , GenesisValidationError (..) , PraosLeaderCredentialsError (..) , ShelleyProtocolInstantiationError (..) @@ -30,13 +27,10 @@ import Cardano.Api.Key import Cardano.Api.KeysPraos as Praos import Cardano.Api.KeysShelley import Cardano.Api.OperationalCertificate -import qualified Cardano.Api.Protocol.Types as Protocol import Cardano.Api.SerialiseTextEnvelope import qualified Cardano.Crypto.Hash.Class as Crypto -import Cardano.Ledger.BaseTypes (ProtVer (..), natVersion) import Cardano.Ledger.Keys (coerceKeyRole) import qualified Cardano.Ledger.Shelley.Genesis as Shelley -import Cardano.Node.Protocol.Types import Cardano.Node.Types import Cardano.Prelude import Cardano.Protocol.Crypto (StandardCrypto) @@ -50,13 +44,11 @@ import Control.Monad.Trans.Except.Extra import qualified Data.Aeson as Aeson (FromJSON (..), eitherDecodeStrict') import qualified Data.ByteString as BS import qualified Data.Text as T -import qualified Ouroboros.Consensus.Cardano as Consensus import Ouroboros.Consensus.Protocol.Praos.Common ( PraosCanBeLeader (..) ) import Ouroboros.Consensus.Shelley.Node ( Nonce (..) - , ProtocolParamsShelleyBased (..) , ShelleyGenesis (..) , ShelleyLeaderCredentials (..) ) @@ -66,43 +58,6 @@ import Prelude (String, id) -- Shelley protocol -- --- | Make 'SomeConsensusProtocol' using the Shelley instance. --- --- This lets us handle multiple protocols in a generic way. --- --- This also serves a purpose as a sanity check that we have all the necessary --- type class instances available. -mkSomeConsensusProtocolShelley :: - NodeShelleyProtocolConfiguration -> - Maybe ProtocolFilepaths -> - ExceptT ShelleyProtocolInstantiationError IO SomeConsensusProtocol -mkSomeConsensusProtocolShelley - NodeShelleyProtocolConfiguration - { npcShelleyGenesisFile - , npcShelleyGenesisFileHash - } - files = do - (genesis, genesisHash) <- - firstExceptT GenesisReadError - $ readGenesis - npcShelleyGenesisFile - npcShelleyGenesisFileHash - firstExceptT GenesisValidationError $ validateGenesis genesis - leaderCredentials <- - firstExceptT PraosLeaderCredentialsError - $ readLeaderCredentials files - - return - $ SomeConsensusProtocol Protocol.ShelleyBlockType - $ Protocol.ProtocolInfoArgsShelley - genesis - Consensus.ProtocolParamsShelleyBased - { shelleyBasedInitialNonce = genesisHashToPraosNonce genesisHash - , shelleyBasedLeaderCredentials = - leaderCredentials - } - (ProtVer (natVersion @2) 0) - genesisHashToPraosNonce :: GenesisHash -> Nonce genesisHashToPraosNonce (GenesisHash h) = Nonce (Crypto.castHash h) diff --git a/ouroboros-consensus-cardano/src/unstable-cardano-tools/Cardano/Node/Protocol/Types.hs b/ouroboros-consensus-cardano/src/unstable-cardano-tools/Cardano/Node/Protocol/Types.hs deleted file mode 100644 index 0e25280489..0000000000 --- a/ouroboros-consensus-cardano/src/unstable-cardano-tools/Cardano/Node/Protocol/Types.hs +++ /dev/null @@ -1,58 +0,0 @@ -{-# LANGUAGE ConstraintKinds #-} -{-# LANGUAGE DeriveAnyClass #-} -{-# LANGUAGE DeriveGeneric #-} -{-# LANGUAGE ExistentialQuantification #-} -{-# LANGUAGE FlexibleContexts #-} -{-# LANGUAGE GADTs #-} -{-# LANGUAGE OverloadedStrings #-} -{-# LANGUAGE StandaloneDeriving #-} - --- DUPLICATE -- adapted from: cardano-node/src/Cardano/Node/Protocol/Types.hs - -module Cardano.Node.Protocol.Types - ( Protocol (..) - , SomeConsensusProtocol (..) - ) where - -import qualified Cardano.Api.Protocol.Types as Cardano -import Cardano.Prelude (Generic, NFData) -import Data.Aeson -import NoThunks.Class (NoThunks) - -data Protocol - = ByronProtocol - | ShelleyProtocol - | CardanoProtocol - deriving (Eq, Generic) - -instance Show Protocol where - show ByronProtocol = "Byron" - show ShelleyProtocol = "Shelley" - show CardanoProtocol = "Byron; Shelley" - -deriving instance NFData Protocol -deriving instance NoThunks Protocol - -instance FromJSON Protocol where - parseJSON = - withText "Protocol" $ \str -> case str of - -- The new names - "Byron" -> pure ByronProtocol - "Shelley" -> pure ShelleyProtocol - "Cardano" -> pure CardanoProtocol - -- The old names - "RealPBFT" -> pure ByronProtocol - "TPraos" -> pure ShelleyProtocol - _ -> - fail $ - "Parsing of Protocol failed. " - <> show str - <> " is not a valid protocol" - -data SomeConsensusProtocol where - SomeConsensusProtocol :: - forall blk. - Cardano.Protocol IO blk => - Cardano.BlockType blk -> - Cardano.ProtocolInfoArgs IO blk -> - SomeConsensusProtocol diff --git a/ouroboros-consensus-cardano/src/unstable-cardano-tools/Cardano/Node/Types.hs b/ouroboros-consensus-cardano/src/unstable-cardano-tools/Cardano/Node/Types.hs index 0d8195b4b0..6ed28ccddb 100644 --- a/ouroboros-consensus-cardano/src/unstable-cardano-tools/Cardano/Node/Types.hs +++ b/ouroboros-consensus-cardano/src/unstable-cardano-tools/Cardano/Node/Types.hs @@ -25,7 +25,7 @@ module Cardano.Node.Types , NodeConwayProtocolConfiguration (..) , NodeDijkstraProtocolConfiguration (..) , NodeHardForkProtocolConfiguration (..) - , NodeProtocolConfiguration (..) + , NodeProtocolConfigurationCardano (..) , NodeShelleyProtocolConfiguration (..) , VRFPrivateKeyFilePermissionError (..) , renderVRFPrivateKeyFilePermissionError @@ -115,10 +115,8 @@ data ProtocolFilepaths newtype GenesisHash = GenesisHash (Crypto.Hash Crypto.Blake2b_256 Crypto.ByteString) deriving newtype (Eq, Show, ToJSON, FromJSON) -data NodeProtocolConfiguration - = NodeProtocolConfigurationByron NodeByronProtocolConfiguration - | NodeProtocolConfigurationShelley NodeShelleyProtocolConfiguration - | NodeProtocolConfigurationCardano +data NodeProtocolConfigurationCardano + = NodeProtocolConfigurationCardano NodeByronProtocolConfiguration NodeShelleyProtocolConfiguration NodeAlonzoProtocolConfiguration @@ -229,11 +227,7 @@ data NodeHardForkProtocolConfiguration } deriving (Eq, Show) -instance AdjustFilePaths NodeProtocolConfiguration where - adjustFilePaths f (NodeProtocolConfigurationByron pc) = - NodeProtocolConfigurationByron (adjustFilePaths f pc) - adjustFilePaths f (NodeProtocolConfigurationShelley pc) = - NodeProtocolConfigurationShelley (adjustFilePaths f pc) +instance AdjustFilePaths NodeProtocolConfigurationCardano where adjustFilePaths f (NodeProtocolConfigurationCardano pcb pcs pca pcc pcd pch) = NodeProtocolConfigurationCardano (adjustFilePaths f pcb) diff --git a/ouroboros-consensus-cardano/src/unstable-cardano-tools/Cardano/Tools/DBSynthesizer/Run.hs b/ouroboros-consensus-cardano/src/unstable-cardano-tools/Cardano/Tools/DBSynthesizer/Run.hs index c327c8ab9a..dc9c0db13c 100644 --- a/ouroboros-consensus-cardano/src/unstable-cardano-tools/Cardano/Tools/DBSynthesizer/Run.hs +++ b/ouroboros-consensus-cardano/src/unstable-cardano-tools/Cardano/Tools/DBSynthesizer/Run.hs @@ -41,6 +41,7 @@ import qualified Ouroboros.Consensus.Node.InitStorage as Node ( nodeImmutableDbChunkInfo ) import Ouroboros.Consensus.Node.ProtocolInfo (ProtocolInfo (..)) +import Ouroboros.Consensus.Shelley.Ledger.SupportsProtocol () import Ouroboros.Consensus.Shelley.Node ( ShelleyGenesis (..) , validateGenesis