diff --git a/cardano-config/src/Cardano/Config/CommonCLI.hs b/cardano-config/src/Cardano/Config/CommonCLI.hs index 49e6566ebd9..65098df9211 100644 --- a/cardano-config/src/Cardano/Config/CommonCLI.hs +++ b/cardano-config/src/Cardano/Config/CommonCLI.hs @@ -25,11 +25,14 @@ module Cardano.Config.CommonCLI , parseDbPathLast , parseDelegationCert , parseDelegationCertLast + , parseGenesisHash , parseGenesisHashLast , parseGenesisPath , parseGenesisPathLast + , parsePbftSigThreshold , parsePbftSigThresholdLast - , parseRequireNetworkMagicLast + , parseRequiresNetworkMagic + , parseRequiresNetworkMagicLast , parseSigningKey , parseSlotLengthLast , parseSocketDir @@ -45,6 +48,7 @@ import qualified Prelude import Options.Applicative hiding (command) import qualified Options.Applicative as OA +import Cardano.Crypto (RequiresNetworkMagic(..)) import qualified Ouroboros.Consensus.BlockchainTime as Consensus import Cardano.Config.Partial @@ -63,7 +67,7 @@ data CommonCLI = CommonCLI data CommonCLIAdvanced = CommonCLIAdvanced { ccaPBftSigThd :: !(Last Double) - , ccaRequiresNetworkMagic :: !(Last RequireNetworkMagic) + , ccaRequiresNetworkMagic :: !(Last RequiresNetworkMagic) , ccaSlotLength :: !(Last Consensus.SlotLength) --TODO cliUpdate :: !PartialUpdate } @@ -95,6 +99,14 @@ parseGenesisPathLast = <> help "The filepath to the genesis file." ) +parseGenesisHash :: Parser Text +parseGenesisHash = + strOption + ( long "genesis-hash" + <> metavar "GENESIS-HASH" + <> help "The genesis hash value." + ) + parseGenesisHashLast :: Parser (Last Text) parseGenesisHashLast = lastStrOption @@ -187,6 +199,16 @@ parseCommonCLI = <> help "Directory with local sockets: ${dir}/node-{core,relay}-${node-id}.socket" ) +parsePbftSigThreshold :: Parser (Maybe Double) +parsePbftSigThreshold = + optional $ option auto + ( long "pbft-signature-threshold" + <> metavar "DOUBLE" + <> help "The PBFT signature threshold." + <> hidden + ) + + parsePbftSigThresholdLast :: Parser (Last Double) parsePbftSigThresholdLast = lastDoubleOption @@ -195,9 +217,18 @@ parsePbftSigThresholdLast = <> help "The PBFT signature threshold." <> hidden ) -parseRequireNetworkMagicLast :: Parser (Last RequireNetworkMagic) -parseRequireNetworkMagicLast = - lastFlag NoRequireNetworkMagic RequireNetworkMagic + +parseRequiresNetworkMagic :: Parser RequiresNetworkMagic +parseRequiresNetworkMagic = + flag RequiresNoMagic RequiresMagic + ( long "require-network-magic" + <> help "Require network magic in transactions." + <> hidden + ) + +parseRequiresNetworkMagicLast :: Parser (Last RequiresNetworkMagic) +parseRequiresNetworkMagicLast = + lastFlag RequiresNoMagic RequiresMagic ( long "require-network-magic" <> help "Require network magic in transactions." <> hidden @@ -225,7 +256,7 @@ parseCommonCLIAdvanced = <> help "The PBFT signature threshold." <> hidden ) - <*> lastFlag NoRequireNetworkMagic RequireNetworkMagic + <*> lastFlag RequiresNoMagic RequiresMagic ( long "require-network-magic" <> help "Require network magic in transactions." <> hidden diff --git a/cardano-config/src/Cardano/Config/Partial.hs b/cardano-config/src/Cardano/Config/Partial.hs index a0289c562f2..e9bc3cbf5a3 100644 --- a/cardano-config/src/Cardano/Config/Partial.hs +++ b/cardano-config/src/Cardano/Config/Partial.hs @@ -20,7 +20,6 @@ module Cardano.Config.Partial , PartialCertificate (..) , PartialWallet (..) -- * re-exports - , RequireNetworkMagic (..) , NodeProtocol (..) , mkCardanoConfiguration ) where @@ -34,6 +33,7 @@ import qualified Ouroboros.Consensus.BlockchainTime as Consensus import Cardano.Config.Types import Cardano.Config.Topology +import Cardano.Crypto (RequiresNetworkMagic) -- | Partial @CardanoConfiguration@ configuration. data PartialCardanoConfiguration = PartialCardanoConfiguration @@ -73,7 +73,7 @@ data PartialCore = PartialCore -- ^ The type of protocol run on the node. , pcoStaticKeySigningKeyFile :: !(Last FilePath) , pcoStaticKeyDlgCertFile :: !(Last FilePath) - , pcoRequiresNetworkMagic :: !(Last RequireNetworkMagic) + , pcoRequiresNetworkMagic :: !(Last RequiresNetworkMagic) , pcoPBftSigThd :: !(Last Double) } deriving (Eq, Show, Generic) deriving Semigroup via GenericSemigroup PartialCore diff --git a/cardano-config/src/Cardano/Config/Presets.hs b/cardano-config/src/Cardano/Config/Presets.hs index 67a4a5180fe..fda7b846bed 100644 --- a/cardano-config/src/Cardano/Config/Presets.hs +++ b/cardano-config/src/Cardano/Config/Presets.hs @@ -23,11 +23,11 @@ import Cardano.Config.Partial ( NodeProtocol (..) , PartialTXP (..) , PartialUpdate (..) , PartialWallet (..) - , RequireNetworkMagic (..) ) import Cardano.Config.Topology (NodeAddress(..), NodeHostAddress(..), TopologyInfo(..)) import Cardano.Config.Types (Protocol(..), ViewMode(..)) +import Cardano.Crypto (RequiresNetworkMagic(..)) -------------------------------------------------------------------------------- -- Cardano Mainnet Configuration @@ -40,7 +40,7 @@ mainnetConfiguration = , pccLogConfig = pure "./configuration/log-configuration.yaml" , pccDBPath = pure "./db/" , pccApplicationLockFile = pure "" - , pccTopologyInfo = pure $ TopologyInfo (RelayId 0) "./configuration/simple-topology.json" + , pccTopologyInfo = pure $ TopologyInfo (CoreId 0) "./configuration/simple-topology.json" , pccNodeAddress = pure $ NodeAddress (NodeHostAddress Nothing) 7000 , pccProtocol = pure ByronLegacy , pccViewMode = pure LiveView @@ -56,7 +56,7 @@ mainnetConfiguration = , pcoNodeProtocol = pure BFTProtocol , pcoStaticKeySigningKeyFile = mempty , pcoStaticKeyDlgCertFile = mempty - , pcoRequiresNetworkMagic = pure NoRequireNetworkMagic + , pcoRequiresNetworkMagic = pure RequiresNoMagic , pcoPBftSigThd = mempty } , pccNTP = @@ -158,7 +158,7 @@ devConfiguration = , pccLogConfig = pure "./log-config.yaml" , pccSocketDir = pure "./socket/" , pccApplicationLockFile = pure "" - , pccTopologyInfo = pure $ TopologyInfo (RelayId 0) "./configuration/simple-topology.json" + , pccTopologyInfo = pure $ TopologyInfo (CoreId 0) "./configuration/simple-topology.json" , pccNodeAddress = pure $ NodeAddress (NodeHostAddress Nothing) 7000 , pccProtocol = pure ByronLegacy , pccViewMode = pure LiveView @@ -173,7 +173,7 @@ devConfiguration = , pcoNodeProtocol = pure BFTProtocol , pcoStaticKeySigningKeyFile = mempty , pcoStaticKeyDlgCertFile = mempty - , pcoRequiresNetworkMagic = pure RequireNetworkMagic + , pcoRequiresNetworkMagic = pure RequiresMagic , pcoPBftSigThd = mempty } , pccNTP = diff --git a/cardano-config/src/Cardano/Config/Protocol.hs b/cardano-config/src/Cardano/Config/Protocol.hs index c02de7cdc72..39e6c6394e6 100644 --- a/cardano-config/src/Cardano/Config/Protocol.hs +++ b/cardano-config/src/Cardano/Config/Protocol.hs @@ -22,15 +22,13 @@ import Prelude (error, fail) import Test.Cardano.Prelude (canonicalDecodePretty) import Codec.CBOR.Read (deserialiseFromBytes, DeserialiseFailure) -import Control.Exception hiding (throwIO) import qualified Data.ByteString.Lazy as LB import Data.Text (unpack) import qualified Cardano.Chain.Genesis as Genesis import qualified Cardano.Chain.Update as Update -import Cardano.Crypto (decodeAbstractHash) +import Cardano.Crypto (RequiresNetworkMagic, decodeHash) import qualified Cardano.Crypto.Signing as Signing -import Cardano.Shell.Lib (GeneralException (..)) import Ouroboros.Consensus.Block (Header) import Ouroboros.Consensus.Mempool.API (ApplyTxErr, GenTx, GenTxId) @@ -51,9 +49,8 @@ import Ouroboros.Network.Block import Cardano.Config.Types (DelegationCertFile (..), GenesisFile (..), - MiscellaneousFilepaths (..), NodeCLI (..), - NodeConfiguration (..), LastKnownBlockVersion (..), - Update (..), Protocol (..), SigningKeyFile (..)) + LastKnownBlockVersion (..), Update (..), + Protocol (..), SigningKeyFile (..)) -- TODO: consider not throwing this, or wrap it in a local error type here -- that has proper error messages. @@ -90,63 +87,72 @@ mockSecurityParam = SecurityParam 5 -- 'CardanoConfiguration', a 'MissingNodeInfo' exception is thrown. mockSomeProtocol :: (RunNode blk, TraceConstraints blk) - => NodeConfiguration + => Maybe NodeId + -> Maybe Int + -- ^ Number of core nodes -> (CoreNodeId -> NumCoreNodes -> Consensus.Protocol blk) -> IO SomeProtocol -mockSomeProtocol nc mkConsensusProtocol = do - (cid, numCoreNodes) <- either throwIO return $ extractNodeInfo nc +mockSomeProtocol nId mNumCoreNodes mkConsensusProtocol = do + (cid, numCoreNodes) <- either throwIO return $ extractNodeInfo nId mNumCoreNodes let p = mkConsensusProtocol cid numCoreNodes case Consensus.runProtocol p of Dict -> return $ SomeProtocol p - - data SomeProtocol where SomeProtocol :: (RunNode blk, TraceConstraints blk) => Consensus.Protocol blk -> SomeProtocol -fromProtocol :: NodeConfiguration - -> NodeCLI - -> IO SomeProtocol -fromProtocol nc nCli = case ncProtocol nc of - ByronLegacy -> - error "Byron Legacy protocol is not implemented." - - BFT -> mockSomeProtocol nc $ \cid numCoreNodes -> +fromProtocol + :: Text + -> Maybe NodeId + -> Maybe Int + -- ^ Number of core nodes + -> GenesisFile + -> RequiresNetworkMagic + -> Maybe Double + -> Maybe DelegationCertFile + -> Maybe SigningKeyFile + -> Update + -> Protocol + -> IO SomeProtocol +fromProtocol _ _ _ _ _ _ _ _ _ ByronLegacy = + error "Byron Legacy protocol is not implemented." +fromProtocol _ nId mNumCoreNodes _ _ _ _ _ _ BFT = + mockSomeProtocol nId mNumCoreNodes $ \cid numCoreNodes -> Consensus.ProtocolMockBFT numCoreNodes cid mockSecurityParam - - Praos -> mockSomeProtocol nc $ \cid numCoreNodes -> +fromProtocol _ nId mNumCoreNodes _ _ _ _ _ _ Praos = + mockSomeProtocol nId mNumCoreNodes $ \cid numCoreNodes -> Consensus.ProtocolMockPraos numCoreNodes cid PraosParams { praosSecurityParam = mockSecurityParam , praosSlotsPerEpoch = 3 , praosLeaderF = 0.5 , praosLifetimeKES = 1000000 - } - - MockPBFT -> mockSomeProtocol nc $ \cid numCoreNodes@(NumCoreNodes numNodes) -> - Consensus.ProtocolMockPBFT numCoreNodes cid PBftParams { - pbftSecurityParam = mockSecurityParam - , pbftNumNodes = fromIntegral numNodes - , pbftSignatureThreshold = (1.0 / fromIntegral numNodes) + 0.1 - } - - RealPBFT -> do - let NodeConfiguration { ncGenesisHash } = nc - genHash = either (throw . ConfigurationError) identity $ - decodeAbstractHash ncGenesisHash + } +fromProtocol _ nId mNumCoreNodes _ _ _ _ _ _ MockPBFT = + mockSomeProtocol nId mNumCoreNodes $ \cid numCoreNodes@(NumCoreNodes numNodes) -> + Consensus.ProtocolMockPBFT numCoreNodes cid + PBftParams { pbftSecurityParam = mockSecurityParam + , pbftNumNodes = fromIntegral numNodes + , pbftSignatureThreshold = (1.0 / fromIntegral numNodes) + 0.1 + } +fromProtocol gHash _ _ genFile nMagic sigThresh delCertFp sKeyFp update RealPBFT = do + let genHash = either panic identity $ decodeHash gHash gcE <- runExceptT (Genesis.mkConfigFromFile - (ncReqNetworkMagic nc) - (unGenesisFile . genesisFile $ mscFp nCli) + nMagic + (unGenesisFile genFile) genHash ) let gc = case gcE of - Left err -> throw err -- TODO: no no no! - Right x -> x + Left err -> panic $ show err + Right x -> x - optionalLeaderCredentials <- readLeaderCredentials gc nCli + optionalLeaderCredentials <- readLeaderCredentials + gc + delCertFp + sKeyFp - let p = protocolConfigRealPbft nc gc optionalLeaderCredentials + let p = protocolConfigRealPbft update sigThresh gc optionalLeaderCredentials case Consensus.runProtocol p of Dict -> return $ SomeProtocol p @@ -155,25 +161,20 @@ fromProtocol nc nCli = case ncProtocol nc of -- | The plumbing to select and convert the appropriate configuration subset -- for the 'RealPBFT' protocol. -- -protocolConfigRealPbft :: NodeConfiguration +protocolConfigRealPbft :: Update + -> Maybe Double -> Genesis.Config -> Maybe PBftLeaderCredentials -> Consensus.Protocol Consensus.ByronBlock -protocolConfigRealPbft NodeConfiguration { - ncPbftSignatureThresh, - ncUpdate = Update { - upApplicationName, - upApplicationVersion, - upLastKnownBlockVersion - } - } +protocolConfigRealPbft (Update appName appVer lastKnownBlockVersion) + pbftSignatureThresh genesis leaderCredentials = Consensus.ProtocolRealPBFT genesis - (PBftSignatureThreshold <$> ncPbftSignatureThresh) - (convertProtocolVersion upLastKnownBlockVersion) - (Update.SoftwareVersion (Update.ApplicationName upApplicationName) - (toEnum upApplicationVersion)) + (PBftSignatureThreshold <$> pbftSignatureThresh) + (convertProtocolVersion lastKnownBlockVersion) + (Update.SoftwareVersion (Update.ApplicationName appName) + (toEnum appVer)) leaderCredentials where convertProtocolVersion @@ -184,11 +185,10 @@ protocolConfigRealPbft NodeConfiguration { readLeaderCredentials :: Genesis.Config - -> NodeCLI + -> Maybe DelegationCertFile + -> Maybe SigningKeyFile -> IO (Maybe PBftLeaderCredentials) -readLeaderCredentials gc nCli = do - let mDelCertFp = delegCertFile $ mscFp nCli - let mSKeyFp = signKeyFile $ mscFp nCli +readLeaderCredentials gc mDelCertFp mSKeyFp = do case (mDelCertFp, mSKeyFp) of (Nothing, Nothing) -> pure Nothing (Just _, Nothing) -> panic "Signing key filepath not specified" @@ -221,12 +221,13 @@ data MissingNodeInfo deriving (Show, Exception) extractNodeInfo - :: NodeConfiguration + :: Maybe NodeId + -> Maybe Int -> Either MissingNodeInfo (CoreNodeId, NumCoreNodes) -extractNodeInfo NodeConfiguration { ncNodeId, ncNumCoreNodes } = do +extractNodeInfo mNodeId ncNumCoreNodes = do - coreNodeId <- case ncNodeId of - CoreId coreNodeId -> pure coreNodeId - _ -> Left MissingCoreNodeId + coreNodeId <- case mNodeId of + Just (CoreId coreNodeId) -> pure coreNodeId + _ -> Left MissingCoreNodeId numCoreNodes <- maybe (Left MissingNumCoreNodes) Right ncNumCoreNodes return (CoreNodeId coreNodeId , NumCoreNodes numCoreNodes) diff --git a/cardano-config/src/Cardano/Config/Types.hs b/cardano-config/src/Cardano/Config/Types.hs index 2a3035e09e6..d1e4f3f329e 100644 --- a/cardano-config/src/Cardano/Config/Types.hs +++ b/cardano-config/src/Cardano/Config/Types.hs @@ -18,7 +18,6 @@ module Cardano.Config.Types , SocketFile (..) , TopologyFile( ..) -- * specific for @Core@ - , RequireNetworkMagic (..) , NodeProtocol (..) , Spec (..) , Initializer (..) @@ -173,7 +172,7 @@ newtype SigningKeyFile = SigningKeyFile data NodeConfiguration = NodeConfiguration { ncProtocol :: Protocol - , ncNodeId :: NodeId + , ncNodeId :: Maybe NodeId , ncGenesisHash :: Text , ncNumCoreNodes :: Maybe Int , ncReqNetworkMagic :: RequiresNetworkMagic @@ -192,7 +191,7 @@ data NodeConfiguration = instance FromJSON NodeConfiguration where parseJSON = withObject "NodeConfiguration" $ \v -> do - nId <- v .: "NodeId" + nId <- v .:? "NodeId" ptcl <- v .: "Protocol" genesisHash <- v .: "GenesisHash" numCoreNode <- v .:? "NumCoreNodes" @@ -270,14 +269,6 @@ instance FromJSON NodeConfiguration where parseNodeConfiguration :: FilePath -> IO NodeConfiguration parseNodeConfiguration fp = decodeFileThrow fp - --- | Do we require network magic or not? --- Network magic allows the differentiation from mainnet and testnet. -data RequireNetworkMagic - = RequireNetworkMagic - | NoRequireNetworkMagic - deriving (Eq, Show) - -- | The type of the protocol being run on the node. data NodeProtocol = BFTProtocol @@ -309,7 +300,7 @@ data Core = Core -- ^ Static key signing file. , coStaticKeyDlgCertFile :: !(Maybe FilePath) -- ^ Static key delegation certificate. - , coRequiresNetworkMagic :: !RequireNetworkMagic + , coRequiresNetworkMagic :: !RequiresNetworkMagic -- ^ Do we require the network byte indicator for mainnet, testnet or staging? , coPBftSigThd :: !(Maybe Double) -- ^ PBFT signature threshold system parameters diff --git a/cardano-node/app/cardano-cli.hs b/cardano-node/app/cardano-cli.hs index a77337d6d3a..f5bc0117e70 100644 --- a/cardano-node/app/cardano-cli.hs +++ b/cardano-node/app/cardano-cli.hs @@ -35,8 +35,7 @@ import Cardano.Config.Partial (PartialCardanoConfiguration (..), import Cardano.Config.Presets (mainnetConfiguration) import Cardano.Config.Protocol (Protocol) import Cardano.Config.Topology (NodeAddress (..), NodeHostAddress (..)) -import Cardano.Config.Types (CardanoEnvironment (..), GenesisFile(..), - RequireNetworkMagic) +import Cardano.Config.Types (CardanoEnvironment (..), GenesisFile(..)) import Cardano.Crypto ( AProtocolMagic(..) , ProtocolMagic , ProtocolMagicId(..) @@ -97,7 +96,7 @@ parseClient = do <*> parseSigningKeyLast <*> parseSocketDirLast <*> parsePbftSigThresholdLast - <*> parseRequireNetworkMagicLast + <*> parseRequiresNetworkMagicLast <*> parseSlotLengthLast <*> parseLogConfigFileLast <*> parseLogMetricsLast @@ -121,7 +120,7 @@ parseClient = do -- ^ Socket dir -> Last Double -- ^ PBFT Signature Threshold - -> Last RequireNetworkMagic + -> Last RequiresNetworkMagic -> Last Consensus.SlotLength -> Last FilePath -- ^ Log Configuration Path @@ -309,7 +308,8 @@ parseTxRelatedValues = "Submit a raw, signed transaction, in its on-wire representation." $ SubmitTx <$> parseTxFile "tx" - <*> nodeCliParser + <*> parseTopologyInfo "Target node that will receive the transaction" + <*> parseNodeId "Node Id of target node" , command' "issue-genesis-utxo-expenditure" "Write a file with a signed transaction, spending genesis UTxO." @@ -322,7 +322,6 @@ parseTxRelatedValues = "rich-addr-from" "Tx source: genesis UTxO richman address (non-HD)." <*> (NE.fromList <$> some parseTxOut) - <*> nodeCliParser , command' "issue-utxo-expenditure" @@ -334,7 +333,6 @@ parseTxRelatedValues = "Key that has access to all mentioned genesis UTxO inputs." <*> (NE.fromList <$> some parseTxIn) <*> (NE.fromList <$> some parseTxOut) - <*> nodeCliParser , command' "generate-txs" "Launch transactions generator." @@ -368,7 +366,7 @@ parseTxRelatedValues = <*> parseSigningKeysFiles "sig-key" "Path to signing key file, for genesis UTxO using by generator." - <*> nodeCliParser + <*> parseNodeId "Node Id of target node" ] diff --git a/cardano-node/app/chairman.hs b/cardano-node/app/chairman.hs index 9b7b97cb92e..f9b6391f0b3 100644 --- a/cardano-node/app/chairman.hs +++ b/cardano-node/app/chairman.hs @@ -10,8 +10,6 @@ import Control.Exception (Exception) import Control.Concurrent (threadDelay) import Options.Applicative -import Cardano.Config.Presets (mainnetConfiguration) - import Control.Tracer (stdoutTracer) import Ouroboros.Network.Block (BlockNo) @@ -20,9 +18,10 @@ import Ouroboros.Consensus.NodeId (CoreNodeId) import Cardano.Config.CommonCLI import Cardano.Config.Protocol (SomeProtocol(..), fromProtocol) -import Cardano.Config.Types (CardanoConfiguration (..), ConfigYamlFilePath(..), - NodeCLI(..), parseNodeConfiguration) -import Cardano.Common.Parsers (nodeCliParser, parseCoreNodeId) +import Cardano.Config.Types (ConfigYamlFilePath(..), DelegationCertFile(..), + GenesisFile (..), NodeConfiguration(..), + SigningKeyFile(..), SocketFile(..), parseNodeConfiguration) +import Cardano.Common.Parsers (parseConfigFile, parseCoreNodeId) import Cardano.Chairman (runChairman) main :: IO () @@ -31,22 +30,30 @@ main = do , caSecurityParam , caMaxBlockNo , caTimeout - , caCommonCLI - , caCommonCLIAdv - , caNodeCLI + , caGenesisFile + , caSocketDir + , caConfigYaml + , caSigningKeyFp + , caDelegationCertFp } <- execParser opts - cc <- case mkConfiguration mainnetConfiguration caCommonCLI caCommonCLIAdv of - Left e -> throwIO e - Right x -> pure x - - nc <- liftIO . parseNodeConfiguration . unConfigPath $ configFp caNodeCLI - SomeProtocol p <- fromProtocol nc caNodeCLI + nc <- liftIO . parseNodeConfiguration $ unConfigPath caConfigYaml + SomeProtocol p <- fromProtocol + (ncGenesisHash nc) + (ncNodeId nc) + (ncNumCoreNodes nc) + (caGenesisFile) + (ncReqNetworkMagic nc) + (ncPbftSignatureThresh nc) + (caDelegationCertFp) + (caSigningKeyFp) + (ncUpdate nc) + (ncProtocol nc) let run = runChairman p caCoreNodeIds caSecurityParam caMaxBlockNo - (ccSocketDir cc) + (unSocket caSocketDir) stdoutTracer case caTimeout of @@ -74,9 +81,11 @@ data ChairmanArgs = ChairmanArgs { -- detect progress errors when running 'chain-sync' protocol and we will -- be able to remove this option , caTimeout :: !(Maybe Int) - , caCommonCLI :: !CommonCLI - , caCommonCLIAdv :: !CommonCLIAdvanced - , caNodeCLI :: !(NodeCLI) + , caGenesisFile :: !GenesisFile + , caSocketDir :: !SocketFile + , caConfigYaml :: !ConfigYamlFilePath + , caSigningKeyFp :: !(Maybe SigningKeyFile) + , caDelegationCertFp :: !(Maybe DelegationCertFile) } parseSecurityParam :: Parser SecurityParam @@ -113,9 +122,11 @@ parseChairmanArgs = <*> parseSecurityParam <*> optional parseSlots <*> optional parseTimeout - <*> parseCommonCLI - <*> parseCommonCLIAdvanced - <*> nodeCliParser + <*> (GenesisFile <$> parseGenesisPath) + <*> (SocketFile <$> parseSocketDir) + <*> (ConfigYamlFilePath <$> parseConfigFile) + <*> (optional $ SigningKeyFile <$> parseSigningKey) + <*> (optional $ DelegationCertFile <$> parseDelegationCert) opts :: ParserInfo ChairmanArgs opts = info (parseChairmanArgs <**> helper) diff --git a/cardano-node/src/Cardano/CLI/Run.hs b/cardano-node/src/Cardano/CLI/Run.hs index 65c1c5172db..a4226618494 100644 --- a/cardano-node/src/Cardano/CLI/Run.hs +++ b/cardano-node/src/Cardano/CLI/Run.hs @@ -1,20 +1,10 @@ -{-# LANGUAGE BangPatterns #-} -{-# LANGUAGE FlexibleContexts #-} -{-# LANGUAGE FlexibleInstances #-} -{-# LANGUAGE GADTs #-} -{-# LANGUAGE GeneralisedNewtypeDeriving #-} -{-# LANGUAGE LambdaCase #-} -{-# LANGUAGE NoImplicitPrelude #-} -{-# LANGUAGE NumericUnderscores #-} -{-# LANGUAGE OverloadedStrings #-} -{-# LANGUAGE RankNTypes #-} -{-# LANGUAGE ScopedTypeVariables #-} -{-# LANGUAGE StandaloneDeriving #-} -{-# LANGUAGE StrictData #-} -{-# LANGUAGE TypeApplications #-} +{-# LANGUAGE GADTs #-} +{-# LANGUAGE NamedFieldPuns #-} +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE ScopedTypeVariables #-} +{-# LANGUAGE StrictData #-} {-# OPTIONS_GHC -Wno-all-missed-specialisations #-} -{-# OPTIONS_GHC -Wno-simplifiable-class-constraints #-} module Cardano.CLI.Run ( CliError (..) @@ -63,6 +53,7 @@ import qualified Cardano.Crypto.Signing as Crypto import qualified Test.Cardano.Chain.Genesis.Dummy as Dummy +import Ouroboros.Consensus.NodeId import qualified Ouroboros.Consensus.Protocol as Consensus import Cardano.CLI.Delegation @@ -78,11 +69,9 @@ import Cardano.CLI.Tx.Generation (NumberOfTxs (..), genesisBenchmarkRunner) import Cardano.Common.Orphans () import Cardano.Config.Protocol -import Cardano.Config.Types (CardanoConfiguration(..), ConfigYamlFilePath(..), - GenesisFile(..), MiscellaneousFilepaths(..), - NodeCLI(..), NodeConfiguration(..), - SigningKeyFile(..), TopologyFile(..), - parseNodeConfiguration) +import Cardano.Config.Types (CardanoConfiguration(..), Core(..), + DelegationCertFile(..), GenesisFile(..), + SigningKeyFile(..), SocketFile(..)) import Cardano.Config.Logging (LoggingLayer (..)) import Cardano.Config.Topology (NodeAddress(..), TopologyInfo(..)) @@ -134,8 +123,9 @@ data ClientCommand | SubmitTx TxFile - NodeCLI -- ^ Filepath of transaction to submit. + TopologyInfo + NodeId | SpendGenesisUTxO NewTxFile -- ^ Filepath of the newly created transaction. @@ -144,7 +134,6 @@ data ClientCommand Common.Address -- ^ Genesis UTxO address. (NonEmpty UTxO.TxOut) - NodeCLI -- ^ Tx output. | SpendUTxO NewTxFile @@ -155,7 +144,6 @@ data ClientCommand -- ^ Inputs available for spending to the Tx underwriter's key. (NonEmpty UTxO.TxOut) -- ^ Genesis UTxO output Address. - NodeCLI --- Tx Generator Command ---------- @@ -168,7 +156,7 @@ data ClientCommand TPSRate (Maybe TxAdditionalSize) [SigningKeyFile] - NodeCLI + NodeId deriving Show runCommand :: CardanoConfiguration -> LoggingLayer -> ClientCommand -> ExceptT CliError IO () @@ -226,41 +214,94 @@ runCommand _ _(CheckDelegation magic cert issuerVF delegateVF) = do delegateVK <- readVerificationKey delegateVF liftIO $ checkByronGenesisDelegation cert magic issuerVK delegateVK -runCommand _ _(SubmitTx fp nCli) = do - nc <- liftIO . parseNodeConfiguration . unConfigPath $ configFp nCli - let topologyFp = unTopology . topFile $ mscFp nCli - tx <- liftIO $ readByronTx fp - liftIO $ nodeSubmitTx (TopologyInfo (ncNodeId nc) topologyFp) nc nCli tx - -runCommand _ _(SpendGenesisUTxO (NewTxFile ctTx) ctKey genRichAddr outs nCli) = do - nc <- liftIO . parseNodeConfiguration . unConfigPath $ configFp nCli - sk <- readSigningKey (ncProtocol nc) ctKey - tx <- liftIO $ issueGenesisUTxOExpenditure genRichAddr outs nc nCli sk - liftIO . ensureNewFileLBS ctTx $ serialise tx - -runCommand _ _ (SpendUTxO (NewTxFile ctTx) ctKey ins outs nCli) = do - nc <- liftIO . parseNodeConfiguration . unConfigPath $ configFp nCli - sk <- readSigningKey (ncProtocol nc) ctKey - gTx <- liftIO $ issueUTxOExpenditure ins outs nc nCli sk - liftIO . ensureNewFileLBS ctTx $ serialise gTx - -runCommand _ loggingLayer - (GenerateTxs targetNodeAddresses - numOfTxs - numOfInsPerTx - numOfOutsPerTx - feePerTx - tps - txAdditionalSize - sigKeysFiles - nCli) = do - nc <- liftIO . parseNodeConfiguration . unConfigPath $ configFp nCli - - liftIO $ withRealPBFT nc nCli $ +runCommand + (CardanoConfiguration{ccCore, ccProtocol, ccSocketDir, ccUpdate}) + _ + (SubmitTx fp topology nid) = do + tx <- liftIO $ readByronTx fp + liftIO $ nodeSubmitTx + topology + (coGenesisHash ccCore) + (nid) + (coNumCoreNodes ccCore) + (GenesisFile $ coGenesisFile ccCore) + (coRequiresNetworkMagic ccCore) + (coPBftSigThd ccCore) + (DelegationCertFile <$> (coStaticKeyDlgCertFile ccCore)) + (SigningKeyFile <$> (coStaticKeySigningKeyFile ccCore)) + (SocketFile ccSocketDir) + ccUpdate + ccProtocol + tx +runCommand + CardanoConfiguration{ccCore, ccProtocol, ccUpdate} + _ + (SpendGenesisUTxO (NewTxFile ctTx) ctKey genRichAddr outs) = do + sk <- readSigningKey ccProtocol ctKey + tx <- liftIO $ issueGenesisUTxOExpenditure + genRichAddr + outs + (coGenesisHash ccCore) + (CoreId $ fromMaybe (panic "Node Id not specified") (coNodeId ccCore)) + (coNumCoreNodes ccCore) + (GenesisFile $ coGenesisFile ccCore) + (coRequiresNetworkMagic ccCore) + (coPBftSigThd ccCore) + (DelegationCertFile <$> (coStaticKeyDlgCertFile ccCore)) + (SigningKeyFile <$> (coStaticKeySigningKeyFile ccCore)) + ccUpdate + ccProtocol + sk + liftIO . ensureNewFileLBS ctTx $ serialise tx + +runCommand + CardanoConfiguration{ccCore, ccProtocol, ccUpdate} + _ + (SpendUTxO (NewTxFile ctTx) ctKey ins outs) = do + sk <- readSigningKey ccProtocol ctKey + gTx <- liftIO $ issueUTxOExpenditure + ins + outs + (coGenesisHash ccCore) + (CoreId $ fromMaybe (panic "Node Id not specified") (coNodeId ccCore)) + (coNumCoreNodes ccCore) + (GenesisFile $ coGenesisFile ccCore) + (coRequiresNetworkMagic ccCore) + (coPBftSigThd ccCore) + (DelegationCertFile <$> (coStaticKeyDlgCertFile ccCore)) + (SigningKeyFile <$> (coStaticKeySigningKeyFile ccCore)) + ccUpdate + ccProtocol + sk + liftIO . ensureNewFileLBS ctTx $ serialise gTx + +runCommand + CardanoConfiguration{ccCore, ccProtocol, ccSocketDir, ccUpdate} + loggingLayer + (GenerateTxs targetNodeAddresses + numOfTxs + numOfInsPerTx + numOfOutsPerTx + feePerTx + tps + txAdditionalSize + sigKeysFiles + nodeId) = do + liftIO $ withRealPBFT + (coGenesisHash ccCore) + (Just nodeId) + (coNumCoreNodes ccCore) + (GenesisFile $coGenesisFile ccCore) + (coRequiresNetworkMagic ccCore) + (coPBftSigThd ccCore) + (DelegationCertFile <$> coStaticKeyDlgCertFile ccCore) + (SigningKeyFile <$> coStaticKeySigningKeyFile ccCore) + ccUpdate + ccProtocol $ \protocol@(Consensus.ProtocolRealPBFT _ _ _ _ _) -> do res <- runExceptT $ genesisBenchmarkRunner loggingLayer - nCli + (SocketFile ccSocketDir) protocol targetNodeAddresses numOfTxs diff --git a/cardano-node/src/Cardano/CLI/Tx.hs b/cardano-node/src/Cardano/CLI/Tx.hs index c951f35336d..f0cdd3ea070 100644 --- a/cardano-node/src/Cardano/CLI/Tx.hs +++ b/cardano-node/src/Cardano/CLI/Tx.hs @@ -38,7 +38,7 @@ import qualified Cardano.Chain.MempoolPayload as CC.Mempool import Cardano.Chain.UTxO ( mkTxAux, annotateTxAux , Tx(..), TxId, TxIn, TxOut) import qualified Cardano.Chain.UTxO as UTxO -import Cardano.Crypto (SigningKey(..), ProtocolMagicId) +import Cardano.Crypto (SigningKey(..), ProtocolMagicId, RequiresNetworkMagic) import qualified Cardano.Crypto.Hashing as Crypto import qualified Cardano.Crypto.Signing as Crypto @@ -46,11 +46,13 @@ import qualified Ouroboros.Consensus.Ledger.Byron as Byron import Ouroboros.Consensus.Ledger.Byron (GenTx(..), ByronBlock) import qualified Ouroboros.Consensus.Protocol as Consensus import Ouroboros.Consensus.Node.Run (RunNode) +import Ouroboros.Consensus.NodeId import Cardano.CLI.Ops import Cardano.CLI.Tx.Submission import Cardano.Config.Protocol -import Cardano.Config.Types (NodeCLI, NodeConfiguration(..)) +import Cardano.Config.Types (DelegationCertFile, GenesisFile, + SigningKeyFile, SocketFile, Update) import Cardano.Config.Topology import Cardano.Common.Orphans () @@ -132,17 +134,35 @@ genesisUTxOTxIn gc vk genAddr = -- | Perform an action that expects ProtocolInfo for Byron/PBFT, -- with attendant configuration. withRealPBFT - :: NodeConfiguration - -> NodeCLI + :: Text + -> Maybe NodeId + -> Maybe Int + -> GenesisFile + -> RequiresNetworkMagic + -> (Maybe Double) + -> Maybe DelegationCertFile + -> Maybe SigningKeyFile + -> Update + -> Protocol -> (RunNode ByronBlock - => Consensus.Protocol ByronBlock - -> IO a) + => Consensus.Protocol ByronBlock + -> IO a) -> IO a -withRealPBFT nc nCli action = do - SomeProtocol p <- fromProtocol nc nCli +withRealPBFT gHash nId mNumNodes genFile nMagic sigThresh delCertFp sKeyFp update ptcl action = do + SomeProtocol p <- fromProtocol + gHash + nId + mNumNodes + genFile + nMagic + sigThresh + delCertFp + sKeyFp + update + ptcl case p of proto@Consensus.ProtocolRealPBFT{} -> action proto - _ -> throwIO $ ProtocolNotSupported (ncProtocol nc) + _ -> throwIO $ ProtocolNotSupported ptcl -- | Generate a transaction spending genesis UTxO at a given address, -- to given outputs, signed by the given key. @@ -170,20 +190,42 @@ txSpendGenesisUTxOByronPBFT gc sk genAddr outs = issueGenesisUTxOExpenditure :: Address -> NonEmpty TxOut - -> NodeConfiguration - -> NodeCLI + -> Text + -> NodeId + -> Maybe Int + -- ^ Number of core nodes. + -> GenesisFile + -> RequiresNetworkMagic + -> Maybe Double + -> Maybe DelegationCertFile + -> Maybe SigningKeyFile + -> Update + -> Protocol -> Crypto.SigningKey -> IO (GenTx ByronBlock) -issueGenesisUTxOExpenditure genRichAddr outs nc nCli sk = do - withRealPBFT nc nCli $ - \(Consensus.ProtocolRealPBFT gc _ _ _ _)-> do - case txSpendGenesisUTxOByronPBFT gc sk genRichAddr outs of - tx@(ByronTx txid _) -> do - putStrLn $ sformat ("TxId: "%Crypto.hashHexF) txid - pure tx - x -> - throwIO $ InvariantViolation $ - "Invariant violation: a non-ByronTx GenTx out of 'txSpendUTxOByronPBFT': " <> show x +issueGenesisUTxOExpenditure + genRichAddr + outs + gHash + nId + mNumCoreNodes + genFile + nMagic + sigThresh + delCertFp + sKeyFp + update + ptcl + sk = + withRealPBFT gHash (Just nId) mNumCoreNodes genFile nMagic sigThresh delCertFp sKeyFp update ptcl + $ \(Consensus.ProtocolRealPBFT gc _ _ _ _)-> do + case txSpendGenesisUTxOByronPBFT gc sk genRichAddr outs of + tx@(ByronTx txid _) -> do + putStrLn $ sformat ("TxId: "%Crypto.hashHexF) txid + pure tx + x -> + throwIO $ InvariantViolation $ + "Invariant violation: a non-ByronTx GenTx out of 'txSpendUTxOByronPBFT': " <> show x -- | Generate a transaction from given Tx inputs to outputs, -- signed by the given key. @@ -208,32 +250,77 @@ txSpendUTxOByronPBFT gc sk ins outs = issueUTxOExpenditure :: NonEmpty TxIn -> NonEmpty TxOut - -> NodeConfiguration - -> NodeCLI + -> Text + -> NodeId + -> Maybe Int + -- ^ Number of core nodes. + -> GenesisFile + -> RequiresNetworkMagic + -> Maybe Double + -> Maybe DelegationCertFile + -> Maybe SigningKeyFile + -> Update + -> Protocol -> Crypto.SigningKey -> IO (GenTx ByronBlock) -issueUTxOExpenditure ins outs nc nCli key = do - withRealPBFT nc nCli $ - \(Consensus.ProtocolRealPBFT gc _ _ _ _)-> do - case txSpendUTxOByronPBFT gc key ins outs of - tx@(ByronTx txid _) -> do - putStrLn $ sformat ("TxId: "%Crypto.hashHexF) txid - pure tx - x -> - throwIO $ InvariantViolation $ - "Invariant violation: a non-ByronTx GenTx out of 'txSpendUTxOByronPBFT': " <> show x +issueUTxOExpenditure + ins + outs + gHash + nId + mNumCoreNodes + genFile + nMagic + sigThresh + delCertFp + sKeyFp + update + ptcl + key = do + withRealPBFT gHash (Just nId) mNumCoreNodes genFile nMagic sigThresh delCertFp sKeyFp update ptcl $ + \(Consensus.ProtocolRealPBFT gc _ _ _ _)-> do + case txSpendUTxOByronPBFT gc key ins outs of + tx@(ByronTx txid _) -> do + putStrLn $ sformat ("TxId: "%Crypto.hashHexF) txid + pure tx + x -> + throwIO $ InvariantViolation $ + "Invariant violation: a non-ByronTx GenTx out of 'txSpendUTxOByronPBFT': " <> show x -- | Submit a transaction to a node specified by topology info. nodeSubmitTx :: TopologyInfo - -> NodeConfiguration - -> NodeCLI + -> Text + -> NodeId + -> Maybe Int + -- ^ Number of core nodes + -> GenesisFile + -> RequiresNetworkMagic + -> Maybe Double + -> Maybe DelegationCertFile + -> Maybe SigningKeyFile + -> SocketFile + -> Update + -> Protocol -> GenTx ByronBlock -> IO () -nodeSubmitTx topology nc nCli gentx = - withRealPBFT nc nCli $ - \p@Consensus.ProtocolRealPBFT{} -> do - case gentx of - ByronTx txid _ -> putStrLn $ sformat ("TxId: "%Crypto.hashHexF) txid - _ -> pure () - handleTxSubmission nCli p topology gentx stdoutTracer +nodeSubmitTx + topology + gHash + nId + mNumCoreNodes + genFile + nMagic + sigThresh + delCertFp + sKeyFp + socketFp + update + ptcl + gentx = + withRealPBFT gHash (Just nId) mNumCoreNodes genFile nMagic sigThresh delCertFp sKeyFp update ptcl $ + \p@Consensus.ProtocolRealPBFT{} -> do + case gentx of + ByronTx txid _ -> putStrLn $ sformat ("TxId: "%Crypto.hashHexF) txid + _ -> pure () + handleTxSubmission socketFp p topology gentx stdoutTracer diff --git a/cardano-node/src/Cardano/CLI/Tx/Generation.hs b/cardano-node/src/Cardano/CLI/Tx/Generation.hs index c017a0792a6..ff8c746709d 100644 --- a/cardano-node/src/Cardano/CLI/Tx/Generation.hs +++ b/cardano-node/src/Cardano/CLI/Tx/Generation.hs @@ -62,10 +62,10 @@ import qualified Cardano.Chain.Genesis as CC.Genesis import qualified Cardano.Chain.MempoolPayload as CC.Mempool import qualified Cardano.Chain.UTxO as CC.UTxO import Cardano.Config.Logging (LoggingLayer (..), Trace) -import Cardano.Config.Types (NodeCLI(..)) +import Cardano.Config.Types (SocketFile) import qualified Cardano.Crypto as Crypto import Cardano.Config.Topology (NodeAddress (..), - NodeHostAddress(..)) + NodeHostAddress(..)) import Cardano.CLI.Tx (txSpendGenesisUTxOByronPBFT) import Cardano.CLI.Tx.BenchmarkingTxSubmission (ROEnv (..), TraceBenchTxSubmit (..), @@ -79,7 +79,7 @@ import Cardano.CLI.Tx.BenchmarkingTxSubClient import Control.Tracer (Tracer, contramap, traceWith) import Ouroboros.Consensus.Node.Run (RunNode) -import Ouroboros.Consensus.Block(BlockProtocol) +import Ouroboros.Consensus.Block(BlockProtocol) import Ouroboros.Consensus.Ledger.Byron.Config (pbftProtocolMagic) import Ouroboros.Consensus.Node.ProtocolInfo (ProtocolInfo (..), protocolInfo) @@ -142,7 +142,7 @@ data TxGenError = CurrentlyCannotSendTxToRelayNode FilePath ----------------------------------------------------------------------------------------- genesisBenchmarkRunner :: LoggingLayer - -> NodeCLI + -> SocketFile -> Consensus.Protocol ByronBlock -> NonEmpty NodeAddress -> NumberOfTxs @@ -154,7 +154,7 @@ genesisBenchmarkRunner -> [FilePath] -> ExceptT TxGenError IO () genesisBenchmarkRunner loggingLayer - nCli + socketFp protocol@(Consensus.ProtocolRealPBFT genesisConfig _ _ _ _) targetNodeAddresses numOfTxs@(NumberOfTxs rawNumOfTxs) @@ -197,7 +197,7 @@ genesisBenchmarkRunner loggingLayer -- 'sourceAddress'), this will be our very first transaction. liftIO $ prepareInitialFunds lowLevelSubmitTracer - nCli + socketFp genesisConfig pInfoConfig genesisUtxo @@ -214,7 +214,7 @@ genesisBenchmarkRunner loggingLayer connectTracer submitTracer lowLevelSubmitTracer - nCli + socketFp pInfoConfig sourceKey recipientAddress @@ -389,7 +389,7 @@ extractGenesisFunds genesisConfig signingKeys = -- (latter corresponds to 'targetAddress' here) and "remember" it in 'availableFunds'. prepareInitialFunds :: Tracer IO String - -> NodeCLI + -> SocketFile -> CC.Genesis.Config -> NodeConfig ByronConsensusProtocol -> Map Int ((CC.UTxO.TxIn, CC.UTxO.TxOut), Crypto.SigningKey) @@ -398,7 +398,7 @@ prepareInitialFunds -> FeePerTx -> IO () prepareInitialFunds llTracer - nCli + socketFp genesisConfig pInfoConfig genesisUtxo @@ -419,7 +419,7 @@ prepareInitialFunds llTracer genesisAddress (NE.fromList [outForBig]) - submitTx nCli pInfoConfig (CoreId 0) genesisTx llTracer + submitTx socketFp pInfoConfig (CoreId 0) genesisTx llTracer -- Done, the first transaction 'initGenTx' is submitted, now 'sourceAddress' has a lot of money. let txIn = CC.UTxO.TxInUtxo (getTxIdFromGenTx genesisTx) 0 @@ -642,7 +642,7 @@ runBenchmark -> Tracer IO SendRecvConnect -> Tracer IO (SendRecvTxSubmission ByronBlock) -> Tracer IO String - -> NodeCLI + -> SocketFile -> NodeConfig ByronConsensusProtocol -> Crypto.SigningKey -> CC.Common.Address @@ -658,7 +658,7 @@ runBenchmark benchTracer connectTracer submitTracer lowLevelSubmitTracer - nCli + socketFp pInfoConfig sourceKey recipientAddress @@ -673,7 +673,7 @@ runBenchmark benchTracer $ "******* Tx generator, phase 1: make enough available UTxO entries *******" createMoreFundCoins lowLevelSubmitTracer - nCli + socketFp pInfoConfig sourceKey txFee @@ -760,7 +760,7 @@ runBenchmark benchTracer -- Technically all splitting transactions will send money back to 'sourceAddress'. createMoreFundCoins :: Tracer IO String - -> NodeCLI + -> SocketFile -> NodeConfig ByronConsensusProtocol -> Crypto.SigningKey -> FeePerTx @@ -768,7 +768,7 @@ createMoreFundCoins -> NumberOfInputsPerTx -> ExceptT TxGenError IO () createMoreFundCoins llTracer - nCli + socketFp pInfoConfig sourceKey (FeePerTx txFee) @@ -809,7 +809,7 @@ createMoreFundCoins llTracer txOut [] liftIO $ forM_ splittingTxs $ \(tx, txDetailsList) -> do - submitTx nCli pInfoConfig (CoreId 0) tx llTracer + submitTx socketFp pInfoConfig (CoreId 0) tx llTracer -- Update available fundValueStatus to reuse the numSplittingTxOuts TxOuts. forM_ txDetailsList addToAvailableFunds where diff --git a/cardano-node/src/Cardano/CLI/Tx/Submission.hs b/cardano-node/src/Cardano/CLI/Tx/Submission.hs index 5f3c4383156..1fa4e6b7ee8 100644 --- a/cardano-node/src/Cardano/CLI/Tx/Submission.hs +++ b/cardano-node/src/Cardano/CLI/Tx/Submission.hs @@ -49,8 +49,7 @@ import qualified Ouroboros.Network.NodeToClient as NodeToClient import Cardano.Config.Topology import Cardano.Common.LocalSocket -import Cardano.Config.Types (MiscellaneousFilepaths(..), - NodeCLI(..), SocketFile(..)) +import Cardano.Config.Types (SocketFile(..)) @@ -65,30 +64,29 @@ handleTxSubmission :: forall blk. ( RunNode blk , Show (ApplyTxErr blk) ) - => NodeCLI + => SocketFile -> Consensus.Protocol blk -> TopologyInfo -> GenTx blk -> Tracer IO String -> IO () -handleTxSubmission nCli ptcl tinfo tx tracer = do +handleTxSubmission socketFp ptcl tinfo tx tracer = do let pinfo :: ProtocolInfo blk pinfo = protocolInfo ptcl - submitTx nCli (pInfoConfig pinfo) (node tinfo) tx tracer - + submitTx socketFp (pInfoConfig pinfo) (node tinfo) tx tracer submitTx :: ( RunNode blk , Show (ApplyTxErr blk) ) - => NodeCLI + => SocketFile -> NodeConfig (BlockProtocol blk) -> NodeId -> GenTx blk -> Tracer IO String -> IO () -submitTx nCli protoInfoConfig nId tx tracer = do - socketPath <- localSocketAddrInfo nId (unSocket . socketFile $ mscFp nCli) NoMkdirIfMissing +submitTx socketFp protoInfoConfig nId tx tracer = do + socketPath <- localSocketAddrInfo (Just nId) (unSocket $ socketFp) NoMkdirIfMissing NodeToClient.connectTo nullTracer nullTracer diff --git a/cardano-node/src/Cardano/Chairman.hs b/cardano-node/src/Cardano/Chairman.hs index 1ed547b03d7..67ea2ac2d65 100644 --- a/cardano-node/src/Cardano/Chairman.hs +++ b/cardano-node/src/Cardano/Chairman.hs @@ -133,7 +133,7 @@ createConnection tracer pInfoConfig socketDir = do - addr <- localSocketAddrInfo (fromCoreNodeId coreNodeId) socketDir NoMkdirIfMissing + addr <- localSocketAddrInfo (Just $ fromCoreNodeId coreNodeId) socketDir NoMkdirIfMissing connectTo nullTracer nullTracer diff --git a/cardano-node/src/Cardano/Common/LocalSocket.hs b/cardano-node/src/Cardano/Common/LocalSocket.hs index 6faab193c24..cb2f59df8ea 100644 --- a/cardano-node/src/Cardano/Common/LocalSocket.hs +++ b/cardano-node/src/Cardano/Common/LocalSocket.hs @@ -26,8 +26,17 @@ localSocketFilePath (RelayId n) = "node-relay-" ++ show n ++ ".socket" -- | Provide an AF_UNIX address for a socket situated in 'socketDir', with its name -- derived from the node ID. When 'mkdir' is 'MkdirIfMissing', the directory is created. -localSocketAddrInfo :: NodeId -> FilePath -> MkdirIfMissing -> IO Socket.AddrInfo -localSocketAddrInfo nodeId socketDir mkdir = do +localSocketAddrInfo :: Maybe NodeId -> FilePath -> MkdirIfMissing -> IO Socket.AddrInfo +localSocketAddrInfo Nothing socketPath _ = do + pure $ + Socket.AddrInfo + [] + Socket.AF_UNIX + Socket.Stream + Socket.defaultProtocol + (Socket.SockAddrUnix socketPath) + Nothing +localSocketAddrInfo (Just nodeId) socketDir mkdir = do dir <- canonicalizePath =<< makeAbsolute socketDir when (mkdir == MkdirIfMissing) $ createDirectoryIfMissing True dir @@ -41,8 +50,14 @@ localSocketAddrInfo nodeId socketDir mkdir = do Nothing -- | Remove the socket established with 'localSocketAddrInfo'. -removeStaleLocalSocket :: NodeId -> FilePath -> IO () -removeStaleLocalSocket nodeId socketDir = do +removeStaleLocalSocket :: Maybe NodeId -> FilePath -> IO () +removeStaleLocalSocket Nothing socketFp = do + removeFile socketFp + `catch` \e -> + if isDoesNotExistError e + then return () + else throwIO e +removeStaleLocalSocket (Just nodeId) socketDir = do dir <- canonicalizePath =<< makeAbsolute socketDir removeFile (dir localSocketFilePath nodeId) `catch` \e -> diff --git a/cardano-node/src/Cardano/Common/Parsers.hs b/cardano-node/src/Cardano/Common/Parsers.hs index 6ce3f468e14..141e5b2a4f5 100644 --- a/cardano-node/src/Cardano/Common/Parsers.hs +++ b/cardano-node/src/Cardano/Common/Parsers.hs @@ -13,6 +13,7 @@ module Cardano.Common.Parsers , parseLogConfigFileLast , parseLogMetricsLast , parseLogOutputFile + , parseNodeId , parseProtocol , parseProtocolBFT , parseProtocolByron diff --git a/cardano-node/src/Cardano/Node/Run.hs b/cardano-node/src/Cardano/Node/Run.hs index c4730e9137b..931f86047e2 100644 --- a/cardano-node/src/Cardano/Node/Run.hs +++ b/cardano-node/src/Cardano/Node/Run.hs @@ -105,7 +105,17 @@ runNode loggingLayer nc nCli = do NormalVerbosity -> "normal" MinimalVerbosity -> "minimal" MaximalVerbosity -> "maximal" - SomeProtocol p <- fromProtocol nc nCli + SomeProtocol p <- fromProtocol + (ncGenesisHash nc) + (ncNodeId nc) + (ncNumCoreNodes nc) + (genesisFile $ mscFp nCli) + (ncReqNetworkMagic nc) + (ncPbftSignatureThresh nc) + (delegCertFile $ mscFp nCli) + (signKeyFile $ mscFp nCli) + (ncUpdate nc) + (ncProtocol nc) let tracers = mkTracers (traceOpts nCli) trace @@ -123,7 +133,8 @@ runNode loggingLayer nc nCli = do be :: LiveViewBackend Text <- realize c let lvbe = MkBackend { bEffectuate = effectuate be, bUnrealize = unrealize be } llAddBackend loggingLayer lvbe (UserDefinedBK "LiveViewBackend") - setTopology be (ncNodeId nc) + let nId = fromMaybe (panic "LiveView not possible for real protocols as yet") (ncNodeId nc) + setTopology be nId setNodeThread be nodeThread captureCounters be trace @@ -240,5 +251,6 @@ handleSimpleNode p trace nodeTracers nCli nc = do where nid :: Int nid = case ncNodeId nc of - CoreId n -> n - RelayId _ -> error "Non-core nodes currently not supported" + Just (CoreId n) -> n + Just (RelayId _) -> error "Non-core nodes currently not supported" + Nothing -> 999 diff --git a/cardano-node/src/Cardano/Wallet/Client.hs b/cardano-node/src/Cardano/Wallet/Client.hs index c13e1ea8057..8592d322a8e 100644 --- a/cardano-node/src/Cardano/Wallet/Client.hs +++ b/cardano-node/src/Cardano/Wallet/Client.hs @@ -62,7 +62,7 @@ runWalletClient :: forall blk. -> IO () runWalletClient ptcl sockDir (CoreNodeId id) tracer = do - addr <- localSocketAddrInfo (CoreId id) sockDir NoMkdirIfMissing + addr <- localSocketAddrInfo (Just $ CoreId id) sockDir NoMkdirIfMissing let ProtocolInfo{pInfoConfig} = protocolInfo ptcl diff --git a/cardano-node/src/Cardano/Wallet/Run.hs b/cardano-node/src/Cardano/Wallet/Run.hs index e3b36f45d2b..8bc60bba99e 100644 --- a/cardano-node/src/Cardano/Wallet/Run.hs +++ b/cardano-node/src/Cardano/Wallet/Run.hs @@ -19,7 +19,8 @@ import Ouroboros.Consensus.NodeId (CoreNodeId (..)) import Cardano.Config.CommonCLI import Cardano.Config.Types (ConfigYamlFilePath(..), MiscellaneousFilepaths(..), - NodeCLI(..), SocketFile(..), parseNodeConfiguration) + NodeCLI(..), NodeConfiguration(..), SocketFile(..), + parseNodeConfiguration) import Cardano.Wallet.Client runClient :: WalletCLI -> Trace IO Text -> IO () @@ -28,8 +29,17 @@ runClient WalletCLI{..} tracer = do let tracer' = contramap pack . toLogObject $ appendName ("Wallet " <> pack (show nid)) tracer nc <- parseNodeConfiguration . unConfigPath $ configFp cliNodeCLI - -- TODO - SomeProtocol p <- fromProtocol nc cliNodeCLI + SomeProtocol p <- fromProtocol + (ncGenesisHash nc) + (ncNodeId nc) + (ncNumCoreNodes nc) + (genesisFile $ mscFp cliNodeCLI) + (ncReqNetworkMagic nc) + (ncPbftSignatureThresh nc) + (delegCertFile $ mscFp cliNodeCLI) + (signKeyFile $ mscFp cliNodeCLI) + (ncUpdate nc) + (ncProtocol nc) let socketDir = unSocket . socketFile $ mscFp cliNodeCLI runWalletClient p socketDir cliCoreNodeId tracer' diff --git a/scripts/chairman.sh b/scripts/chairman.sh index 9274f4182b0..99c20f7b7e0 100755 --- a/scripts/chairman.sh +++ b/scripts/chairman.sh @@ -18,15 +18,6 @@ exec cabal new-run exe:chairman -- \ --core-node-id 0 --core-node-id 1 --core-node-id 2 \ -k 10 -s 250 \ -t 1000 \ - --port 1234 \ --genesis-file "${genesis_file}" \ - --genesis-hash "${genesis_hash}" \ - --socket-dir "./socket/" \ - --pbft-signature-threshold 0.7 \ - --require-network-magic \ - --database-path "db" \ - --topology configuration/simple-topology.json \ - --database-path ./db/ \ - --genesis-file ${genesis_file} \ --socket-dir "./socket/" \ --config "configuration/log-config-0.yaml" diff --git a/scripts/generator.sh b/scripts/generator.sh index 6b8f90993ee..c6667fe416c 100755 --- a/scripts/generator.sh +++ b/scripts/generator.sh @@ -10,12 +10,6 @@ NETARGS=( --genesis-file "${genesis_file}" --genesis-hash "${genesis_hash}" generate-txs - --topology "configuration/simple-topology.json" - --genesis-file "${genesis_file}" - --database-path "./db/" - --socket-dir "./socket/" - --config "configuration/log-config-0.yaml" - --port 3003 ) TX_GEN_ARGS=( --num-of-txs 10000 diff --git a/scripts/issue-genesis-utxo-expenditure.sh b/scripts/issue-genesis-utxo-expenditure.sh index ad7be321690..f8121114e46 100755 --- a/scripts/issue-genesis-utxo-expenditure.sh +++ b/scripts/issue-genesis-utxo-expenditure.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/usr/bin/env bash RUNNER=${RUNNER:-cabal new-run -v0 --} @@ -33,10 +33,6 @@ args=" --real-pbft --wallet-key ${from_key} --rich-addr-from \"${from_addr}\" --txout (\"${addr}\",${lovelace}) - --topology configuration/simple-topology.json - --genesis-file \"${genesis_file}\" - --database-path ./db/ - --socket-dir ./socket/ -" + " set -x ${RUNNER} cardano-cli ${args} diff --git a/scripts/issue-utxo-expenditure.sh b/scripts/issue-utxo-expenditure.sh index fb21b73cde1..5fabdb04c21 100755 --- a/scripts/issue-utxo-expenditure.sh +++ b/scripts/issue-utxo-expenditure.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/usr/bin/env bash RUNNER=${RUNNER:-cabal new-run -v0 --} @@ -38,10 +38,6 @@ args=" --real-pbft --wallet-key ${from_key} --txin (\"${txid}\",${outindex}) --txout (\"${addr}\",${lovelace}) - --topology configuration/simple-topology.json - --genesis-file \"${genesis_file}\" - --database-path ./db/ - --socket-dir ./socket/ " set -x ${RUNNER} cardano-cli ${args} diff --git a/scripts/submit-tx.sh b/scripts/submit-tx.sh index 3d2c8bbee49..85f12d75d02 100755 --- a/scripts/submit-tx.sh +++ b/scripts/submit-tx.sh @@ -22,9 +22,6 @@ NETARGS=( --genesis-hash "${genesis_hash}" submit-tx --topology "configuration/simple-topology.json" - --genesis-file "${genesis_file}" - --database-path "./db/" - --socket-dir "./socket/" --node-id "0" --tx "$TX" )