diff --git a/benchmarking/chain-sync/configuration/log-config-ci.yaml b/benchmarking/chain-sync/configuration/log-config-ci.yaml index edd756d4ac2..0ae62836287 100644 --- a/benchmarking/chain-sync/configuration/log-config-ci.yaml +++ b/benchmarking/chain-sync/configuration/log-config-ci.yaml @@ -81,12 +81,14 @@ options: NodeId: Protocol: RealPBFT +GenesisFile: configuration/genesis/latest-genesis NumCoreNodes: 1 RequiresNetworkMagic: RequiresNoMagic PBftSignatureThreshold: 0.5 TurnOnLogging: True ViewMode: SimpleView TurnOnLogMetrics: True +SocketPath: ##### Update Parameters ##### diff --git a/benchmarking/chain-sync/configuration/log-configuration.yaml b/benchmarking/chain-sync/configuration/log-configuration.yaml index 84e46202bbe..d53c39d7964 100644 --- a/benchmarking/chain-sync/configuration/log-configuration.yaml +++ b/benchmarking/chain-sync/configuration/log-configuration.yaml @@ -85,12 +85,14 @@ options: NodeId: Protocol: RealPBFT +GenesisFile: configuration/genesis/latest-genesis NumCoreNodes: 1 RequiresNetworkMagic: RequiresNoMagic PBftSignatureThreshold: TurnOnLogging: True ViewMode: LiveView TurnOnLogMetrics: True +SocketPath: ##### Update Parameters ##### diff --git a/benchmarking/cluster3nodes/configuration/log-config-0.yaml b/benchmarking/cluster3nodes/configuration/log-config-0.yaml index 6217c794406..a6330d6bbe5 100644 --- a/benchmarking/cluster3nodes/configuration/log-config-0.yaml +++ b/benchmarking/cluster3nodes/configuration/log-config-0.yaml @@ -75,12 +75,14 @@ options: NodeId: Protocol: RealPBFT +GenesisFile: configuration/genesis/latest-genesis NumCoreNodes: 1 RequiresNetworkMagic: RequiresMagic PBftSignatureThreshold: TurnOnLogging: True ViewMode: LiveView TurnOnLogMetrics: False +SocketPath: diff --git a/benchmarking/cluster3nodes/configuration/log-config-1.yaml b/benchmarking/cluster3nodes/configuration/log-config-1.yaml index 5307beb4c20..7be89667487 100644 --- a/benchmarking/cluster3nodes/configuration/log-config-1.yaml +++ b/benchmarking/cluster3nodes/configuration/log-config-1.yaml @@ -79,12 +79,14 @@ options: NodeId: Protocol: RealPBFT +GenesisFile: configuration/genesis/latest-genesis NumCoreNodes: 1 RequiresNetworkMagic: RequiresMagic PBftSignatureThreshold: TurnOnLogging: True ViewMode: LiveView TurnOnLogMetrics: False +SocketPath: diff --git a/benchmarking/cluster3nodes/configuration/log-config-2.yaml b/benchmarking/cluster3nodes/configuration/log-config-2.yaml index d4816f20568..af89626a18b 100644 --- a/benchmarking/cluster3nodes/configuration/log-config-2.yaml +++ b/benchmarking/cluster3nodes/configuration/log-config-2.yaml @@ -81,12 +81,14 @@ options: NodeId: Protocol: RealPBFT +GenesisFile: configuration/genesis/latest-genesis NumCoreNodes: 1 RequiresNetworkMagic: RequiresMagic PBftSignatureThreshold: TurnOnLogging: True ViewMode: LiveView TurnOnLogMetrics: False +SocketPath: diff --git a/benchmarking/cluster3nodes/configuration/log-config-generator.yaml b/benchmarking/cluster3nodes/configuration/log-config-generator.yaml index 24e354e42f9..084097bb0e3 100644 --- a/benchmarking/cluster3nodes/configuration/log-config-generator.yaml +++ b/benchmarking/cluster3nodes/configuration/log-config-generator.yaml @@ -81,12 +81,14 @@ options: NodeId: Protocol: RealPBFT +GenesisFile: configuration/genesis/latest-genesis NumCoreNodes: 1 RequiresNetworkMagic: RequiresMagic PBftSignatureThreshold: TurnOnLogging: True ViewMode: SimpleView TurnOnLogMetrics: True +SocketPath: diff --git a/benchmarking/cluster3nodes/configuration/log-config-genesis.yaml b/benchmarking/cluster3nodes/configuration/log-config-genesis.yaml index d702d368637..a253d97adee 100644 --- a/benchmarking/cluster3nodes/configuration/log-config-genesis.yaml +++ b/benchmarking/cluster3nodes/configuration/log-config-genesis.yaml @@ -49,12 +49,14 @@ options: NodeId: Protocol: RealPBFT +GenesisFile: configuration/genesis/latest-genesis NumCoreNodes: 1 RequiresNetworkMagic: RequiresMagic PBftSignatureThreshold: TurnOnLogging: False ViewMode: SimpleView TurnOnLogMetrics: False +SocketPath: diff --git a/cardano-config/src/Cardano/Config/Types.hs b/cardano-config/src/Cardano/Config/Types.hs index 3a441c7eead..5f7bed0e24f 100644 --- a/cardano-config/src/Cardano/Config/Types.hs +++ b/cardano-config/src/Cardano/Config/Types.hs @@ -3,9 +3,10 @@ {-# LANGUAGE RecordWildCards #-} module Cardano.Config.Types - ( CBORObject (..) + ( CardanoEnvironment (..) + , CBORObject (..) + , CLISocketPath (..) , ConfigYamlFilePath (..) - , CardanoEnvironment (..) , DbFile (..) , DelegationCertFile (..) , GenesisFile (..) @@ -24,6 +25,7 @@ module Cardano.Config.Types , SocketPath (..) , Update (..) , ViewMode (..) + , YamlSocketPath (..) , parseNodeConfiguration , parseNodeConfigurationFP ) where @@ -68,20 +70,20 @@ data CardanoEnvironment = NoEnvironment -------------------------------------------------------------------------------- data NodeCLI = NodeCLI - { mscFp :: !MiscellaneousFilepaths - , genesisHash :: !Text - , nodeAddr :: !NodeAddress - , configFp :: !ConfigYamlFilePath - , validateDB :: !Bool - } + { mscFp :: !MiscellaneousFilepaths + , genesisHash :: !Text + , nodeAddr :: !NodeAddress + , configFp :: !ConfigYamlFilePath + , validateDB :: !Bool + } data NodeMockCLI = NodeMockCLI - { mockMscFp :: !MiscellaneousFilepaths - , mockGenesisHash :: !Text - , mockNodeAddr :: !NodeAddress - , mockConfigFp :: !ConfigYamlFilePath - , mockValidateDB :: !Bool - } deriving Show + { mockMscFp :: !MiscellaneousFilepaths + , mockGenesisHash :: !Text + , mockNodeAddr :: !NodeAddress + , mockConfigFp :: !ConfigYamlFilePath + , mockValidateDB :: !Bool + } deriving Show -- | Mock protocols requires different parameters to real protocols. -- Therefore we distinguish this at the top level on the command line. @@ -101,7 +103,7 @@ data MiscellaneousFilepaths = MiscellaneousFilepaths , genesisFile :: !(Maybe GenesisFile) , delegCertFile :: !(Maybe DelegationCertFile) , signKeyFile :: !(Maybe SigningKeyFile) - , socketFile :: !SocketPath + , socketFile :: !(Maybe CLISocketPath) } deriving Show newtype TopologyFile = TopologyFile @@ -116,94 +118,120 @@ newtype GenesisFile = GenesisFile { unGenesisFile :: FilePath } deriving (Eq, Ord, Show, IsString) +instance FromJSON GenesisFile where + parseJSON (String genFp) = pure . GenesisFile $ T.unpack genFp + parseJSON invalid = panic $ "Parsing of GenesisFile failed due to type mismatch. " + <> "Encountered: " <> (T.pack $ show invalid) + newtype DelegationCertFile = DelegationCertFile { unDelegationCert :: FilePath } deriving Show -data SocketPath = SocketFile +newtype SocketPath = SocketFile { unSocket :: FilePath } - deriving (Eq, Ord, Show) + deriving (Eq, Ord, Show, IsString) newtype SigningKeyFile = SigningKeyFile { unSigningKey :: FilePath } deriving (Eq, Ord, Show, IsString) data NodeConfiguration = - NodeConfiguration - { ncProtocol :: Protocol - , ncNodeId :: Maybe NodeId - , ncNumCoreNodes :: Maybe Word64 - , ncReqNetworkMagic :: RequiresNetworkMagic - , ncPbftSignatureThresh :: Maybe Double - , ncLoggingSwitch :: Bool - , ncLogMetrics :: Bool - , ncTraceOptions :: TraceOptions - , ncViewMode :: ViewMode - , ncUpdate :: Update - } deriving (Show) + NodeConfiguration + { ncProtocol :: Protocol + , ncGenesisFile :: GenesisFile + , ncNodeId :: Maybe NodeId + , ncNumCoreNodes :: Maybe Word64 + , ncReqNetworkMagic :: RequiresNetworkMagic + , ncPbftSignatureThresh :: Maybe Double + , ncLoggingSwitch :: Bool + , ncLogMetrics :: Bool + , ncSocketPath :: Maybe YamlSocketPath + , ncTraceOptions :: TraceOptions + , ncViewMode :: ViewMode + , ncUpdate :: Update + } deriving (Show) instance FromJSON NodeConfiguration where - parseJSON = withObject "NodeConfiguration" $ \v -> do - nId <- v .:? "NodeId" - ptcl <- v .: "Protocol" .!= RealPBFT - numCoreNode <- v .:? "NumCoreNodes" - rNetworkMagic <- v .:? "RequiresNetworkMagic" .!= RequiresNoMagic - pbftSignatureThresh <- v .:? "PBftSignatureThreshold" - loggingSwitch <- v .:? "TurnOnLogging" .!= True - vMode <- v .:? "ViewMode" .!= LiveView - logMetrics <- v .:? "TurnOnLogMetrics" .!= True - - -- Update Parameters - appName <- v .:? "ApplicationName" .!= Update.ApplicationName "cardano-sl" - appVersion <- v .:? "ApplicationVersion" .!= 1 - lkBlkVersionMajor <- v .:? "LastKnownBlockVersion-Major" .!= 0 - lkBlkVersionMinor <- v .:? "LastKnownBlockVersion-Minor" .!= 2 - lkBlkVersionAlt <- v .:? "LastKnownBlockVersion-Alt" .!= 0 - - -- Trace Options - tOptions <- TraceOptions - <$> v .:? "TracingVerbosity" .!= NormalVerbosity - <*> v .:? "TraceBlockFetchClient" .!= False - <*> v .:? "TraceBlockFetchDecisions" .!= True - <*> v .:? "TraceBlockFetchProtocol" .!= False - <*> v .:? "TraceBlockFetchProtocolSerialised" .!= False - <*> v .:? "TraceBlockFetchServer" .!= False - <*> v .:? "TraceChainDb" .!= True - <*> v .:? "TraceChainSyncClient" .!= True - <*> v .:? "TraceChainSyncBlockServer" .!= False - <*> v .:? "TraceChainSyncHeaderServer" .!= False - <*> v .:? "TraceChainSyncProtocol" .!= False - <*> v .:? "TraceDNSResolver" .!= False - <*> v .:? "TraceDNSSubscription" .!= True - <*> v .:? "TraceErrorPolicy" .!= True - <*> v .:? "TraceLocalErrorPolicy" .!= True - <*> v .:? "TraceForge" .!= True - <*> v .:? "TraceIpSubscription" .!= True - <*> v .:? "TraceLocalChainSyncProtocol" .!= False - <*> v .:? "TraceLocalTxSubmissionProtocol" .!= False - <*> v .:? "TraceLocalTxSubmissionServer" .!= False - <*> v .:? "TraceLocalStateQueryProtocol" .!= False - <*> v .:? "TraceMempool" .!= True - <*> v .:? "TraceMux" .!= True - <*> v .:? "TraceTxInbound" .!= False - <*> v .:? "TraceTxOutbound" .!= False - <*> v .:? "TraceTxSubmissionProtocol" .!= False - - pure $ NodeConfiguration - ptcl - nId - numCoreNode - rNetworkMagic - pbftSignatureThresh - loggingSwitch - logMetrics - tOptions - vMode - (Update appName appVersion (LastKnownBlockVersion - lkBlkVersionMajor - lkBlkVersionMinor - lkBlkVersionAlt)) + parseJSON = withObject "NodeConfiguration" $ \v -> do + nId <- v .:? "NodeId" + ptcl <- v .: "Protocol" .!= RealPBFT + genFile <- v .: "GenesisFile" + numCoreNode <- v .:? "NumCoreNodes" + rNetworkMagic <- v .:? "RequiresNetworkMagic" .!= RequiresNoMagic + pbftSignatureThresh <- v .:? "PBftSignatureThreshold" + loggingSwitch <- v .:? "TurnOnLogging" .!= True + vMode <- v .:? "ViewMode" .!= LiveView + logMetrics <- v .:? "TurnOnLogMetrics" .!= True + socketPath <- v .:? "SocketPath" + + -- Update Parameters + appName <- v .:? "ApplicationName" .!= Update.ApplicationName "cardano-sl" + appVersion <- v .:? "ApplicationVersion" .!= 1 + lkBlkVersionMajor <- v .:? "LastKnownBlockVersion-Major" .!= 0 + lkBlkVersionMinor <- v .:? "LastKnownBlockVersion-Minor" .!= 2 + lkBlkVersionAlt <- v .:? "LastKnownBlockVersion-Alt" .!= 0 + + -- Trace Options + tOptions <- TraceOptions + <$> v .:? "TracingVerbosity" .!= NormalVerbosity + <*> v .:? "TraceBlockFetchClient" .!= False + <*> v .:? "TraceBlockFetchDecisions" .!= True + <*> v .:? "TraceBlockFetchProtocol" .!= False + <*> v .:? "TraceBlockFetchProtocolSerialised" .!= False + <*> v .:? "TraceBlockFetchServer" .!= False + <*> v .:? "TraceChainDb" .!= True + <*> v .:? "TraceChainSyncClient" .!= True + <*> v .:? "TraceChainSyncBlockServer" .!= False + <*> v .:? "TraceChainSyncHeaderServer" .!= False + <*> v .:? "TraceChainSyncProtocol" .!= False + <*> v .:? "TraceDNSResolver" .!= False + <*> v .:? "TraceDNSSubscription" .!= True + <*> v .:? "TraceErrorPolicy" .!= True + <*> v .:? "TraceForge" .!= True + <*> v .:? "TraceIpSubscription" .!= True + <*> v .:? "TraceLocalChainSyncProtocol" .!= False + <*> v .:? "TraceLocalErrorPolicy" .!= True + <*> v .:? "TraceLocalTxSubmissionProtocol" .!= False + <*> v .:? "TraceLocalTxSubmissionServer" .!= False + <*> v .:? "TraceLocalStateQueryProtocol" .!= False + <*> v .:? "TraceMempool" .!= True + <*> v .:? "TraceMux" .!= True + <*> v .:? "TraceTxInbound" .!= False + <*> v .:? "TraceTxOutbound" .!= False + <*> v .:? "TraceTxSubmissionProtocol" .!= False + + pure $ NodeConfiguration + { ncProtocol = ptcl + , ncGenesisFile = genFile + , ncNodeId = nId + , ncNumCoreNodes = numCoreNode + , ncReqNetworkMagic = rNetworkMagic + , ncPbftSignatureThresh = pbftSignatureThresh + , ncLoggingSwitch = loggingSwitch + , ncLogMetrics = logMetrics + , ncSocketPath = socketPath + , ncTraceOptions = tOptions + , ncViewMode = vMode + , ncUpdate = (Update appName appVersion (LastKnownBlockVersion + lkBlkVersionMajor + lkBlkVersionMinor + lkBlkVersionAlt)) + } + +-- | Socket path read from the command line. +newtype CLISocketPath = CLISocketPath + { unCLISocketPath :: SocketPath} + deriving Show + +-- | Socket path defined in the node's configuration yaml file. +newtype YamlSocketPath = YamlSocketPath + { unYamlSocketPath :: SocketPath } + deriving Show +instance FromJSON YamlSocketPath where + parseJSON (String sPath) = pure . YamlSocketPath . SocketFile $ T.unpack sPath + parseJSON invalid = panic $ "Parsing of SocketPath failed due to type mismatch. " + <> "Encountered: " <> (T.pack $ show invalid) parseNodeConfigurationFP :: FilePath -> IO NodeConfiguration parseNodeConfigurationFP fp = decodeFileThrow fp @@ -268,8 +296,8 @@ instance FromJSON ViewMode where view -> panic $ "Parsing of ViewMode: " <> view <> " failed. " <> view <> " is not a valid view mode" - parseJSON invalid = panic $ "Parsing of ViewMode failed due to type mismatch. " - <> "Encountered: " <> (T.pack $ show invalid) + parseJSON invalid = panic $ "Parsing of ViewMode failed due to type mismatch. " + <> "Encountered: " <> (T.pack $ show invalid) -- | Detailed tracing options. Each option enables a tracer -- which verbosity to the log output. @@ -288,10 +316,10 @@ data TraceOptions = TraceOptions , traceDnsResolver :: !Bool , traceDnsSubscription :: !Bool , traceErrorPolicy :: !Bool - , traceLocalErrorPolicy :: !Bool , traceForge :: !Bool , traceIpSubscription :: !Bool , traceLocalChainSyncProtocol :: !Bool + , traceLocalErrorPolicy :: !Bool , traceLocalTxSubmissionProtocol :: !Bool , traceLocalTxSubmissionServer :: !Bool , traceLocalStateQueryProtocol :: !Bool diff --git a/cardano-node/README.md b/cardano-node/README.md index 1bc4e368aea..9b95ac78ded 100644 --- a/cardano-node/README.md +++ b/cardano-node/README.md @@ -101,7 +101,7 @@ A CLI utility to support a variety of key material operations (genesis, migratio The general synopsis is as follows: ``` - Usage: cardano-cli (Genesis Related CMDs | Key Related CMDs | Delegation related CMDs | Tx related CMDs | Benchmarking related CMDs) + Usage: cardano-cli (Genesis related CMDs | Key related CMDs | Delegation related CMDs | Transaction related CMDs | Local node related CMDs | Benchmarking related CMDs) ``` NOTE: the exact invocation command depends on the environment. If you have only @@ -228,7 +228,7 @@ VerKey address with root e5a3807d99a1807c3f161a1558bcbc45de8392e049682df01809c48 The `issue-delegation-certificate` subcommand enables generation of Byron genesis delegation certificates, given the following inputs: - - protocol magic + - node configuration yaml file - starting epoch of delegation - genesis delegator signing key - delegate verification key @@ -260,7 +260,7 @@ The `submit-tx` subcommand provides the option of submitting a pre-signed transaction, in its raw wire format (see GenTx for Byron transactions). The canned `scripts/submit-tx.sh` script will submit the supplied transaction to a testnet -launched by `scripts/shelley-testnet*.sh` family of scripts. +launched by `scripts/shelley-testnet-*.sh` family of scripts. ### Issuing UTxO expenditure (genesis and regular) @@ -289,7 +289,7 @@ You can query the tip of your local node via the `get-tip` command as follows 1. Open `tmux` 2. Run `cabal build cardano-node` 3. Run `./scripts/shelley-testnet-live.sh` -4. `cabal exec cardano-cli -- get-tip --config configuration/log-config-0.liveview.yaml --genesis-json configuration/genesis/genesis.json --socket-path socket/0` +4. `cabal exec cardano-cli -- get-tip --config configuration/log-config-0.liveview.yaml --socket-path socket/0` You will see output from stdout in this format: ``` diff --git a/cardano-node/src/Cardano/CLI/Ops.hs b/cardano-node/src/Cardano/CLI/Ops.hs index 8d0393315aa..e520a168720 100644 --- a/cardano-node/src/Cardano/CLI/Ops.hs +++ b/cardano-node/src/Cardano/CLI/Ops.hs @@ -18,6 +18,7 @@ module Cardano.CLI.Ops , pPrintCBOR , readCBOR , readGenesis + , readProtocolMagicId , serialiseDelegationCert , serialiseDelegateKey , serialiseGenesis @@ -44,6 +45,7 @@ import Control.Monad.Trans.Except.Extra import qualified Data.ByteString.Lazy as LB import qualified Data.Text as T import qualified Formatting as F +import System.Directory (canonicalizePath, makeAbsolute) import qualified Text.JSON.Canonical as CanonicalJSON import Cardano.Binary @@ -57,6 +59,7 @@ import qualified Cardano.Chain.Update as Update import qualified Cardano.Chain.UTxO as UTxO import Cardano.Crypto (RequiresNetworkMagic, SigningKey (..)) import qualified Cardano.Crypto.Hashing as Crypto +import Cardano.Crypto.ProtocolMagic as Crypto import Control.Monad.Class.MonadTimer import Control.Monad.Class.MonadThrow import Control.Tracer (nullTracer, stdoutTracer, traceWith) @@ -129,10 +132,17 @@ deserialiseDelegateKey RealPBFT fp delSkey = deserialiseDelegateKey ptcl _ _ = Left $ ProtocolNotSupported ptcl getGenesisHash :: GenesisFile -> ExceptT CliError IO Text -getGenesisHash genFile = do - (_, Genesis.GenesisHash gHash) <- readGenesis genFile +getGenesisHash (GenesisFile genFile) = do + canonGenFile <- liftIO $ canonicalizePath genFile + gFile <- liftIO $ makeAbsolute canonGenFile + (_, Genesis.GenesisHash gHash) <- readGenesis $ GenesisFile gFile return $ F.sformat Crypto.hashHexF gHash +readProtocolMagicId :: GenesisFile -> ExceptT CliError IO Crypto.ProtocolMagicId +readProtocolMagicId gFile = do + (genData, _) <- readGenesis gFile + pure $ Genesis.gdProtocolMagicId genData + -- | Read genesis from a file. readGenesis :: GenesisFile -> ExceptT CliError IO (Genesis.GenesisData, Genesis.GenesisHash) readGenesis (GenesisFile fp) = firstExceptT (GenesisReadError fp) $ Genesis.readGenesisData fp @@ -349,14 +359,13 @@ withRealPBFT gHash genFile nMagic sigThresh delCertFp sKeyFp update ptcl action getLocalTip :: ConfigYamlFilePath - -> GenesisFile + -> Maybe CLISocketPath -> AssociateWithIOCP - -> SocketPath -> IO () -getLocalTip configFp genFp iocp sockPath = do +getLocalTip configFp mSockPath iocp = do nc <- parseNodeConfigurationFP $ unConfigPath configFp - - eGenHash <- runExceptT $ getGenesisHash genFp + sockPath <- return $ chooseSocketPath (ncSocketPath nc) mSockPath + eGenHash <- runExceptT $ getGenesisHash (ncGenesisFile nc) genHash <- case eGenHash of Right gHash -> pure gHash @@ -368,7 +377,7 @@ getLocalTip configFp genFp iocp sockPath = do genHash (ncNodeId nc) (ncNumCoreNodes nc) - (Just genFp) + (Just $ ncGenesisFile nc) (ncReqNetworkMagic nc) (ncPbftSignatureThresh nc) Nothing diff --git a/cardano-node/src/Cardano/CLI/Parsers.hs b/cardano-node/src/Cardano/CLI/Parsers.hs index 1a5308aed3d..7e7d3794f92 100644 --- a/cardano-node/src/Cardano/CLI/Parsers.hs +++ b/cardano-node/src/Cardano/CLI/Parsers.hs @@ -166,8 +166,7 @@ parseDelegationRelatedValues = "Create a delegation certificate allowing the\ \ delegator to sign blocks on behalf of the issuer" $ IssueDelegationCertificate - <$> parseProtocol - <*> parseProtocolMagicId "protocol-magic" + <$> (ConfigYamlFilePath <$> parseConfigFile) <*> ( EpochNumber <$> parseIntegral "since-epoch" @@ -186,7 +185,7 @@ parseDelegationRelatedValues = "Verify that a given certificate constitutes a valid\ \ delegation relationship between keys." $ CheckDelegation - <$> parseProtocolMagicId "protocol-magic" + <$> (ConfigYamlFilePath <$> parseConfigFile) <*> parseCertificateFile "certificate" "The certificate embodying delegation to verify." @@ -315,8 +314,7 @@ parseLocalNodeQueryValues = , command' "get-tip" "Get the tip of your local node's blockchain" $ GetLocalNodeTip <$> (ConfigYamlFilePath <$> parseConfigFile) - <*> parseGenesisFile "genesis-json" - <*> parseSocketPath "Socket of target node" + <*> parseCLISocketPath "Socket of target node" ] parseLovelace :: String -> String -> Parser Lovelace @@ -509,15 +507,13 @@ parseTxRelatedValues = "Submit a raw, signed transaction, in its on-wire representation." $ SubmitTx <$> parseTxFile "tx" - <*> parseProtocol - <*> (GenesisFile <$> parseGenesisPath) - <*> parseSocketPath "Socket of target node" + <*> (ConfigYamlFilePath <$> parseConfigFile) + <*> parseCLISocketPath "Socket of target node" , command' "issue-genesis-utxo-expenditure" "Write a file with a signed transaction, spending genesis UTxO." $ SpendGenesisUTxO - <$> parseProtocol - <*> (GenesisFile <$> parseGenesisPath) + <$> (ConfigYamlFilePath <$> parseConfigFile) <*> parseNewTxFile "tx" <*> parseSigningKeyFile "wallet-key" @@ -531,8 +527,7 @@ parseTxRelatedValues = "issue-utxo-expenditure" "Write a file with a signed transaction, spending normal UTxO." $ SpendUTxO - <$> parseProtocol - <*> (GenesisFile <$> parseGenesisPath) + <$> (ConfigYamlFilePath <$> parseConfigFile) <*> parseNewTxFile "tx" <*> parseSigningKeyFile "wallet-key" diff --git a/cardano-node/src/Cardano/CLI/Run.hs b/cardano-node/src/Cardano/CLI/Run.hs index 297fd4e5c9a..1805051619e 100644 --- a/cardano-node/src/Cardano/CLI/Run.hs +++ b/cardano-node/src/Cardano/CLI/Run.hs @@ -53,7 +53,7 @@ import Cardano.Chain.Slotting (EpochNumber(..)) import qualified Cardano.Chain.UTxO as UTxO import Cardano.Chain.Update (ApplicationName(..)) -import Cardano.Crypto (ProtocolMagicId, RequiresNetworkMagic(..)) +import Cardano.Crypto (RequiresNetworkMagic(..)) import qualified Cardano.Crypto.Hashing as Crypto import qualified Cardano.Crypto.Signing as Crypto @@ -73,6 +73,7 @@ import Cardano.CLI.Benchmarking.Tx.Generation , NumberOfInputsPerTx (..), NumberOfOutputsPerTx (..) , FeePerTx (..), TPSRate (..), TxAdditionalSize (..) , genesisBenchmarkRunner) +import Cardano.Common.LocalSocket import Cardano.Config.Protocol import Cardano.Config.Logging (createLoggingFeatureCLI) import Cardano.Config.Types @@ -121,8 +122,7 @@ data ClientCommand --- Delegation Related Commands --- | IssueDelegationCertificate - Protocol - ProtocolMagicId + ConfigYamlFilePath EpochNumber -- ^ The epoch from which the delegation is valid. SigningKeyFile @@ -132,28 +132,25 @@ data ClientCommand NewCertificateFile -- ^ Filepath of the newly created delegation certificate. | CheckDelegation - ProtocolMagicId + ConfigYamlFilePath CertificateFile VerificationKeyFile VerificationKeyFile | GetLocalNodeTip ConfigYamlFilePath - GenesisFile - SocketPath + (Maybe CLISocketPath) ----------------------------------- | SubmitTx TxFile -- ^ Filepath of transaction to submit. - Protocol - GenesisFile - SocketPath - -- ^ Socket path of target node. + ConfigYamlFilePath + (Maybe CLISocketPath) + | SpendGenesisUTxO - Protocol - GenesisFile + ConfigYamlFilePath NewTxFile -- ^ Filepath of the newly created transaction. SigningKeyFile @@ -163,8 +160,7 @@ data ClientCommand (NonEmpty UTxO.TxOut) -- ^ Tx output. | SpendUTxO - Protocol - GenesisFile + ConfigYamlFilePath NewTxFile -- ^ Filepath of the newly created transaction. SigningKeyFile @@ -208,8 +204,8 @@ runCommand (Genesis outDir params ptcl) = do gen <- mkGenesis params dumpGenesis ptcl outDir `uncurry` gen -runCommand (GetLocalNodeTip configFp gFile sockPath) = withIOManagerE $ \iocp -> - liftIO $ getLocalTip configFp gFile iocp sockPath +runCommand (GetLocalNodeTip configFp mSockPath) = + withIOManagerE $ \iocp -> liftIO $ getLocalTip configFp mSockPath iocp runCommand (ValidateCBOR cborObject fp) = do bs <- readCBOR fp @@ -251,24 +247,29 @@ runCommand (ToVerification ptcl skFp (NewVerificationKeyFile vkFp)) = do let vKey = Builder.toLazyText . Crypto.formatFullVerificationKey $ Crypto.toVerification sk ensureNewFile TL.writeFile vkFp vKey -runCommand (IssueDelegationCertificate ptcl magic epoch issuerSK delegateVK cert) = do +runCommand (IssueDelegationCertificate configFp epoch issuerSK delegateVK cert) = do + nc <- liftIO . parseNodeConfigurationFP $ unConfigPath configFp vk <- readVerificationKey delegateVK - sk <- readSigningKey ptcl issuerSK + sk <- readSigningKey (ncProtocol nc) issuerSK + pmId <- readProtocolMagicId $ ncGenesisFile nc let byGenDelCert :: Delegation.Certificate - byGenDelCert = issueByronGenesisDelegation magic epoch sk vk - sCert <- hoistEither $ serialiseDelegationCert ptcl byGenDelCert + byGenDelCert = issueByronGenesisDelegation pmId epoch sk vk + sCert <- hoistEither $ serialiseDelegationCert (ncProtocol nc) byGenDelCert ensureNewFileLBS (nFp cert) sCert -runCommand (CheckDelegation magic cert issuerVF delegateVF) = do +runCommand (CheckDelegation configFp cert issuerVF delegateVF) = do + nc <- liftIO . parseNodeConfigurationFP $ unConfigPath configFp issuerVK <- readVerificationKey issuerVF delegateVK <- readVerificationKey delegateVF - liftIO $ checkByronGenesisDelegation cert magic issuerVK delegateVK + pmId <- readProtocolMagicId $ ncGenesisFile nc + liftIO $ checkByronGenesisDelegation cert pmId issuerVK delegateVK -runCommand (SubmitTx fp ptcl genFile socketPath) = withIOManagerE $ \iocp -> do +runCommand (SubmitTx fp configFp mCliSockPath) = withIOManagerE $ \iocp -> do + nc <- liftIO . parseNodeConfigurationFP $ unConfigPath configFp -- Default update value let update = Update (ApplicationName "cardano-sl") 1 $ LastKnownBlockVersion 0 2 0 tx <- liftIO $ readByronTx fp - genHash <- getGenesisHash genFile + genHash <- getGenesisHash (ncGenesisFile nc) firstExceptT NodeSubmitTxError @@ -276,43 +277,45 @@ runCommand (SubmitTx fp ptcl genFile socketPath) = withIOManagerE $ \iocp -> do iocp genHash Nothing - genFile + (ncGenesisFile nc) RequiresNoMagic Nothing Nothing Nothing - socketPath + (chooseSocketPath (ncSocketPath nc) mCliSockPath) update - ptcl + (ncProtocol nc) tx -runCommand (SpendGenesisUTxO ptcl genFile (NewTxFile ctTx) ctKey genRichAddr outs) = do - sk <- readSigningKey ptcl ctKey - -- Default update value - let update = Update (ApplicationName "cardano-sl") 1 $ LastKnownBlockVersion 0 2 0 - - genHash <- getGenesisHash genFile - - tx <- firstExceptT SpendGenesisUTxOError - $ issueGenesisUTxOExpenditure - genRichAddr - outs - genHash - genFile - RequiresNoMagic - Nothing - Nothing - Nothing - update - ptcl - sk - ensureNewFileLBS ctTx $ toCborTxAux tx - -runCommand (SpendUTxO ptcl genFile (NewTxFile ctTx) ctKey ins outs) = do - sk <- readSigningKey ptcl ctKey +runCommand (SpendGenesisUTxO configFp (NewTxFile ctTx) ctKey genRichAddr outs) = do + nc <- liftIO . parseNodeConfigurationFP $ unConfigPath configFp + sk <- readSigningKey (ncProtocol nc) ctKey + -- Default update value + let update = Update (ApplicationName "cardano-sl") 1 $ LastKnownBlockVersion 0 2 0 + + genHash <- getGenesisHash $ ncGenesisFile nc + + tx <- firstExceptT SpendGenesisUTxOError + $ issueGenesisUTxOExpenditure + genRichAddr + outs + genHash + (ncGenesisFile nc) + RequiresNoMagic + Nothing + Nothing + Nothing + update + (ncProtocol nc) + sk + ensureNewFileLBS ctTx $ toCborTxAux tx + +runCommand (SpendUTxO configFp (NewTxFile ctTx) ctKey ins outs) = do + nc <- liftIO . parseNodeConfigurationFP $ unConfigPath configFp + sk <- readSigningKey (ncProtocol nc) ctKey -- Default update value let update = Update (ApplicationName "cardano-sl") 1 $ LastKnownBlockVersion 0 2 0 - genHash <- getGenesisHash genFile + genHash <- getGenesisHash $ ncGenesisFile nc gTx <- firstExceptT IssueUtxoError @@ -320,13 +323,13 @@ runCommand (SpendUTxO ptcl genFile (NewTxFile ctTx) ctKey ins outs) = do ins outs genHash - genFile + (ncGenesisFile nc) RequiresNoMagic Nothing Nothing Nothing update - ptcl + (ncProtocol nc) sk ensureNewFileLBS ctTx $ toCborTxAux gTx diff --git a/cardano-node/src/Cardano/Common/LocalSocket.hs b/cardano-node/src/Cardano/Common/LocalSocket.hs index cab63dce392..7b38aca8daf 100644 --- a/cardano-node/src/Cardano/Common/LocalSocket.hs +++ b/cardano-node/src/Cardano/Common/LocalSocket.hs @@ -1,5 +1,8 @@ +{-# LANGUAGE NamedFieldPuns #-} + module Cardano.Common.LocalSocket - ( localSocketPath + ( chooseSocketPath + , localSocketPath , nodeLocalSocketAddrInfo , removeStaleLocalSocket ) @@ -11,16 +14,25 @@ import System.Directory (createDirectoryIfMissing, removeFile) import System.FilePath (takeDirectory) import System.IO.Error (isDoesNotExistError) -import Cardano.Config.Types ( MiscellaneousFilepaths(..), NodeCLI(..) - , NodeMockCLI(..), NodeProtocolMode(..) - , SocketPath(..)) +import Cardano.Config.Types + +-- | This lets us override the socket path specified in the node configuration yaml file +-- if required. +chooseSocketPath :: Maybe YamlSocketPath -> Maybe CLISocketPath -> SocketPath +chooseSocketPath Nothing Nothing = panic $ "Cardano.Common.LocalSocket.chooseSocketPath: " + <> "Please specify a socket path either in the config yaml " + <> "file or on the command line." +chooseSocketPath (Just yamlSockPath) Nothing = unYamlSocketPath yamlSockPath +chooseSocketPath Nothing (Just cliSockPath) = unCLISocketPath cliSockPath +chooseSocketPath _ (Just cliSockPath) = unCLISocketPath cliSockPath +nodeLocalSocketAddrInfo :: NodeConfiguration -> NodeProtocolMode -> IO FilePath +nodeLocalSocketAddrInfo nc npm = do + mCliSockPath <- case npm of + MockProtocolMode (NodeMockCLI {mockMscFp}) -> pure $ socketFile mockMscFp + RealProtocolMode (NodeCLI {mscFp}) -> pure $ socketFile mscFp -nodeLocalSocketAddrInfo :: NodeProtocolMode -> IO FilePath -nodeLocalSocketAddrInfo npm = - case npm of - MockProtocolMode (NodeMockCLI mscFp' _ _ _ _) -> localSocketPath $ socketFile mscFp' - RealProtocolMode (NodeCLI mscFp' _ _ _ _) -> localSocketPath $ socketFile mscFp' + localSocketPath $ chooseSocketPath (ncSocketPath nc) mCliSockPath -- | Provide an filepath intended for a socket situated in 'socketDir'. -- When 'mkdir' is 'MkdirIfMissing', the directory is created. @@ -31,12 +43,13 @@ localSocketPath (SocketFile fp) = do -- TODO: Convert to ExceptT -- | Remove the socket established with 'localSocketAddrInfo'. -removeStaleLocalSocket :: NodeProtocolMode -> IO () -removeStaleLocalSocket npm = do - SocketFile socketFp <- - case npm of - MockProtocolMode (NodeMockCLI mscFp' _ _ _ _) -> pure $ socketFile mscFp' - RealProtocolMode (NodeCLI mscFp' _ _ _ _) -> pure $ socketFile mscFp' +removeStaleLocalSocket :: NodeConfiguration -> NodeProtocolMode -> IO () +removeStaleLocalSocket nc npm = do + mCliSockPath <- case npm of + MockProtocolMode (NodeMockCLI {mockMscFp}) -> pure $ socketFile mockMscFp + RealProtocolMode (NodeCLI {mscFp}) -> pure $ socketFile mscFp + + (SocketFile socketFp) <- pure $ chooseSocketPath (ncSocketPath nc) mCliSockPath removeFile socketFp `catch` \e -> diff --git a/cardano-node/src/Cardano/Common/Parsers.hs b/cardano-node/src/Cardano/Common/Parsers.hs index bbf10f1da03..89635a88b90 100644 --- a/cardano-node/src/Cardano/Common/Parsers.hs +++ b/cardano-node/src/Cardano/Common/Parsers.hs @@ -9,6 +9,7 @@ module Cardano.Common.Parsers , nodeMockProtocolModeParser , nodeProtocolModeParser , nodeRealParser + , parseCLISocketPath , parseConfigFile , parseCoreNodeId , parseDbPath @@ -72,7 +73,7 @@ nodeMockParser = do -- Filepaths topFp <- parseTopologyFile dbFp <- parseDbPath - socketFp <- parseSocketPath "Path to a cardano-node socket" + socketFp <- parseCLISocketPath "Path to a cardano-node socket" genHash <- parseGenesisHash @@ -108,7 +109,7 @@ nodeRealParser = do genFp <- optional parseGenesisPath delCertFp <- optional parseDelegationCert sKeyFp <- optional parseSigningKey - socketFp <- parseSocketPath "Path to a cardano-node socket" + socketFp <- parseCLISocketPath "Path to a cardano-node socket" genHash <- parseGenesisHash @@ -135,7 +136,14 @@ nodeRealParser = do , validateDB = validate } - +parseCLISocketPath :: Text -> Parser (Maybe CLISocketPath) +parseCLISocketPath helpMessage = + optional $ CLISocketPath <$> strOption + ( long "socket-path" + <> (help $ toS helpMessage) + <> completer (bashCompleter "file") + <> metavar "FILEPATH" + ) parseConfigFile :: Parser FilePath parseConfigFile = diff --git a/cardano-node/src/Cardano/Node/Run.hs b/cardano-node/src/Cardano/Node/Run.hs index 0a6d5698407..933a9f0d285 100644 --- a/cardano-node/src/Cardano/Node/Run.hs +++ b/cardano-node/src/Cardano/Node/Run.hs @@ -186,7 +186,7 @@ handleSimpleNode p trace nodeTracers npm onKernel = do nt <- either (\err -> panic $ "Cardano.Node.Run.readTopologyFile: " <> err) pure eitherTopology - myLocalAddr <- nodeLocalSocketAddrInfo npm + myLocalAddr <- nodeLocalSocketAddrInfo nc npm let diffusionArguments :: DiffusionArguments diffusionArguments = createDiffusionArguments addrs myLocalAddr ipProducers dnsProducers @@ -198,7 +198,7 @@ handleSimpleNode p trace nodeTracers npm onKernel = do ipProducers = ipSubscriptionTargets ipProducerAddrs (dnsProducerAddrs, ipProducerAddrs) = producerAddresses nt - removeStaleLocalSocket npm + removeStaleLocalSocket nc npm varTip <- atomically $ newTVar GenesisPoint diff --git a/configuration/configuration-mainnet.yaml b/configuration/configuration-mainnet.yaml index 9d2f92a76f6..df5d3446a54 100644 --- a/configuration/configuration-mainnet.yaml +++ b/configuration/configuration-mainnet.yaml @@ -78,12 +78,14 @@ options: NodeId: Protocol: RealPBFT +GenesisFile: configuration/genesis/genesis.json NumCoreNodes: 1 RequiresNetworkMagic: RequiresNoMagic PBftSignatureThreshold: TurnOnLogging: True ViewMode: LiveView TurnOnLogMetrics: True +SocketPath: ##### Update Parameters ##### diff --git a/configuration/configuration-silent.yaml b/configuration/configuration-silent.yaml index 99a28f86e9f..74d37046692 100644 --- a/configuration/configuration-silent.yaml +++ b/configuration/configuration-silent.yaml @@ -56,12 +56,14 @@ options: NodeId: Protocol: RealPBFT +GenesisFile: configuration/genesis/genesis.json NumCoreNodes: 1 RequiresNetworkMagic: RequiresNoMagic PBftSignatureThreshold: TurnOnLogging: True ViewMode: SimpleView TurnOnLogMetrics: False +SocketPath: ##### Update Parameters ##### diff --git a/configuration/log-config-0.liveview.yaml b/configuration/log-config-0.liveview.yaml index e132bee42c3..9c25e481fa7 100644 --- a/configuration/log-config-0.liveview.yaml +++ b/configuration/log-config-0.liveview.yaml @@ -91,12 +91,14 @@ options: NodeId: Protocol: RealPBFT +GenesisFile: configuration/genesis/genesis.json NumCoreNodes: 1 RequiresNetworkMagic: RequiresMagic PBftSignatureThreshold: TurnOnLogging: True ViewMode: LiveView TurnOnLogMetrics: True +SocketPath: diff --git a/configuration/log-config-0.yaml b/configuration/log-config-0.yaml index 603a6f515d8..19a3542c85e 100644 --- a/configuration/log-config-0.yaml +++ b/configuration/log-config-0.yaml @@ -92,12 +92,14 @@ options: NodeId: Protocol: RealPBFT +GenesisFile: configuration/genesis/genesis.json NumCoreNodes: 1 RequiresNetworkMagic: RequiresMagic PBftSignatureThreshold: TurnOnLogging: True ViewMode: SimpleView TurnOnLogMetrics: True +SocketPath: diff --git a/configuration/log-config-1.liveview.yaml b/configuration/log-config-1.liveview.yaml index 7ef515f39da..e1219ed98f1 100644 --- a/configuration/log-config-1.liveview.yaml +++ b/configuration/log-config-1.liveview.yaml @@ -85,12 +85,14 @@ options: NodeId: Protocol: RealPBFT +GenesisFile: configuration/genesis/genesis.json NumCoreNodes: 1 RequiresNetworkMagic: RequiresMagic PBftSignatureThreshold: TurnOnLogging: True ViewMode: LiveView TurnOnLogMetrics: True +SocketPath: diff --git a/configuration/log-config-1.yaml b/configuration/log-config-1.yaml index 092fff45aa7..34617f585ba 100644 --- a/configuration/log-config-1.yaml +++ b/configuration/log-config-1.yaml @@ -91,12 +91,14 @@ options: NodeId: Protocol: RealPBFT +GenesisFile: configuration/genesis/genesis.json NumCoreNodes: 1 RequiresNetworkMagic: RequiresMagic PBftSignatureThreshold: TurnOnLogging: True ViewMode: SimpleView TurnOnLogMetrics: True +SocketPath: diff --git a/configuration/log-config-2.liveview.yaml b/configuration/log-config-2.liveview.yaml index 38f096855c4..5c24b29bcbf 100644 --- a/configuration/log-config-2.liveview.yaml +++ b/configuration/log-config-2.liveview.yaml @@ -91,12 +91,14 @@ options: NodeId: Protocol: RealPBFT +GenesisFile: configuration/genesis/genesis.json NumCoreNodes: 1 RequiresNetworkMagic: RequiresMagic PBftSignatureThreshold: TurnOnLogging: True ViewMode: LiveView TurnOnLogMetrics: True +SocketPath: diff --git a/configuration/log-config-2.yaml b/configuration/log-config-2.yaml index 440f55924a9..d6e0f25dc07 100644 --- a/configuration/log-config-2.yaml +++ b/configuration/log-config-2.yaml @@ -97,12 +97,14 @@ options: NodeId: Protocol: RealPBFT +GenesisFile: configuration/genesis/genesis.json NumCoreNodes: 1 RequiresNetworkMagic: RequiresMagic PBftSignatureThreshold: TurnOnLogging: True ViewMode: SimpleView TurnOnLogMetrics: True +SocketPath: diff --git a/configuration/log-configuration.yaml b/configuration/log-configuration.yaml index 5a72c5d8a22..021a00d49c2 100644 --- a/configuration/log-configuration.yaml +++ b/configuration/log-configuration.yaml @@ -89,13 +89,14 @@ options: NodeId: Protocol: RealPBFT +GenesisFile: configuration/genesis/genesis.json NumCoreNodes: 1 RequiresNetworkMagic: RequiresNoMagic PBftSignatureThreshold: TurnOnLogging: True ViewMode: SimpleView TurnOnLogMetrics: True - +SocketPath: ##### Update Parameters ##### diff --git a/nix/svclib.nix b/nix/svclib.nix index 5365930d375..63e86a8e8c2 100644 --- a/nix/svclib.nix +++ b/nix/svclib.nix @@ -12,6 +12,7 @@ let (optionalAttrs (cfg.protover-major or null != null) { LastKnownBlockVersion-Major = cfg.protover-major; }) // (optionalAttrs (cfg.protover-minor or null != null) { LastKnownBlockVersion-Minor = cfg.protover-minor; }) // (optionalAttrs (cfg.protover-alt or null != null) { LastKnownBlockVersion-Alt = cfg.protover-alt; }) // + (optionalAttrs (cfg.genesisFile != null) { GenesisFile = cfg.genesisFile; }) // (optionalAttrs (cfg.genesisHash != null) { GenesisHash = cfg.genesisHash; }); ## mkFullyConnectedLocalClusterTopology diff --git a/scripts/issue-genesis-utxo-expenditure.sh b/scripts/issue-genesis-utxo-expenditure.sh index 0b891bf692a..6d055b3ae27 100755 --- a/scripts/issue-genesis-utxo-expenditure.sh +++ b/scripts/issue-genesis-utxo-expenditure.sh @@ -3,7 +3,7 @@ . $(dirname $0)/lib-node.sh CLI="$(executable_quiet_runner cardano-cli)" - +CONFIG="configuration/log-config-0.liveview.yaml" from_addr="2cWKMJemoBain3UWCzSY5wZvcf8uQ2MAaSy8hedrwpqsbYCm4QnBgPn3cEH7KF3X7DKoZ" from_key="${genesis_root}/delegate-keys.000.key" default_to_key="${genesis_root}/delegate-keys.001.key" @@ -25,8 +25,7 @@ EOF exit 1;; esac args=" issue-genesis-utxo-expenditure - --real-pbft - --genesis-file ${genesis_file} + --config "$CONFIG" --tx ${tx} --wallet-key ${from_key} --rich-addr-from \"${from_addr}\" diff --git a/scripts/issue-utxo-expenditure.sh b/scripts/issue-utxo-expenditure.sh index c76cdb8fa1c..c8a9438c213 100755 --- a/scripts/issue-utxo-expenditure.sh +++ b/scripts/issue-utxo-expenditure.sh @@ -2,7 +2,7 @@ . $(dirname $0)/lib-node.sh CLI="$(executable_quiet_runner cardano-cli)" - +CONFIG="configuration/log-config-0.liveview.yaml" default_from_key="${genesis_root}/delegate-keys.001.key" default_to_key="${genesis_root}/delegate-keys.002.key" @@ -30,8 +30,7 @@ EOF addr=$(${scripts}/get-default-key-address.sh ${to_key}) args=" issue-utxo-expenditure - --real-pbft - --genesis-file ${genesis_file} + --config $CONFIG --tx ${tx} --wallet-key ${from_key} --txin (\"${txid}\",${outindex}) diff --git a/scripts/submit-tx.sh b/scripts/submit-tx.sh index c47c1fd0013..651d8c7b5f9 100755 --- a/scripts/submit-tx.sh +++ b/scripts/submit-tx.sh @@ -12,13 +12,14 @@ shift . $(dirname $0)/lib-node.sh CLI="$(executable_runner cardano-cli)" -ALGO="real-pbft" +CONFIG="configuration/log-config-0.liveview.yaml" NOW=`date "+%Y-%m-%d 00:00:00"` +SOCKET="socket/0" NETARGS=( submit-tx --tx "$TX" - --${ALGO} - --genesis-file "${genesis_file}" + --config "$CONFIG" + --socket-path "$SOCKET" )