From 4fe75fdcfedde28d62ad71630c4385b615879046 Mon Sep 17 00:00:00 2001 From: Thomas Winant Date: Wed, 19 Feb 2020 13:17:28 +0100 Subject: [PATCH 1/6] Update ouroboros-network dependency After https://github.com/input-output-hk/ouroboros-network/pull/1657 Co-authored-by: Karl Knutsson --- cabal.project | 63 +++++++++++++------ cardano-config/cardano-config.cabal | 2 + cardano-config/src/Cardano/Config/Protocol.hs | 59 ++++++++--------- cardano-config/src/Cardano/Config/Types.hs | 2 + cardano-node/cardano-node.cabal | 3 +- .../Cardano/CLI/Benchmarking/Tx/Generation.hs | 16 +++-- .../Cardano/CLI/Benchmarking/Tx/NodeToNode.hs | 17 ++--- .../CLI/Benchmarking/Tx/TxSubmission.hs | 2 +- cardano-node/src/Cardano/CLI/Ops.hs | 4 +- cardano-node/src/Cardano/CLI/Run.hs | 4 +- cardano-node/src/Cardano/CLI/Tx.hs | 11 ++-- cardano-node/src/Cardano/Chairman.hs | 41 ++++++------ .../src/Cardano/Common/LocalSocket.hs | 26 +++----- cardano-node/src/Cardano/Common/Orphans.hs | 19 ------ cardano-node/src/Cardano/Node/Run.hs | 27 ++++---- cardano-node/src/Cardano/Node/Submission.hs | 9 +-- cardano-node/src/Cardano/Node/TUI/LiveView.hs | 12 ++-- .../src/Cardano/Tracing/ToObjectOrphans.hs | 22 ++++--- cardano-node/src/Cardano/Tracing/Tracers.hs | 57 +++++++++++------ cardano-node/src/Cardano/Wallet/Client.hs | 11 ++-- configuration/configuration-mainnet.yaml | 3 + stack.yaml | 5 +- 22 files changed, 227 insertions(+), 188 deletions(-) delete mode 100644 cardano-node/src/Cardano/Common/Orphans.hs diff --git a/cabal.project b/cabal.project index d46ed1b5114..fbd256df921 100644 --- a/cabal.project +++ b/cabal.project @@ -10,6 +10,12 @@ package cardano-config package cardano-node ghc-options: -Wall -fwarn-redundant-constraints +package ouroboros-consensus-byron + tests: False + +package ouroboros-consensus-mock + tests: False + source-repository-package type: git location: https://github.com/input-output-hk/cardano-base @@ -184,64 +190,85 @@ source-repository-package source-repository-package type: git location: https://github.com/input-output-hk/ouroboros-network - tag: 5f77e24c2263560ad58b9ba092c8cfed174675ae - --sha256: 00bm1fa83lc6jgh36mwr4zymzg9hvmq68y2hm4klk8c8gn7vwqqb + tag: 68ebc7b8c53078629dd57fd579eece12c66576c8 + --sha256: 11hsa5b218cbkq0wb7hc9x7m5mp56dlfw4zx4q9i4ymyq82ra69c subdir: ouroboros-network source-repository-package type: git location: https://github.com/input-output-hk/ouroboros-network - tag: 5f77e24c2263560ad58b9ba092c8cfed174675ae - --sha256: 00bm1fa83lc6jgh36mwr4zymzg9hvmq68y2hm4klk8c8gn7vwqqb + tag: 68ebc7b8c53078629dd57fd579eece12c66576c8 + --sha256: 11hsa5b218cbkq0wb7hc9x7m5mp56dlfw4zx4q9i4ymyq82ra69c subdir: io-sim source-repository-package type: git location: https://github.com/input-output-hk/ouroboros-network - tag: 5f77e24c2263560ad58b9ba092c8cfed174675ae - --sha256: 00bm1fa83lc6jgh36mwr4zymzg9hvmq68y2hm4klk8c8gn7vwqqb + tag: 68ebc7b8c53078629dd57fd579eece12c66576c8 + --sha256: 11hsa5b218cbkq0wb7hc9x7m5mp56dlfw4zx4q9i4ymyq82ra69c subdir: ouroboros-network-testing source-repository-package type: git location: https://github.com/input-output-hk/ouroboros-network - tag: 5f77e24c2263560ad58b9ba092c8cfed174675ae - --sha256: 00bm1fa83lc6jgh36mwr4zymzg9hvmq68y2hm4klk8c8gn7vwqqb + tag: 68ebc7b8c53078629dd57fd579eece12c66576c8 + --sha256: 11hsa5b218cbkq0wb7hc9x7m5mp56dlfw4zx4q9i4ymyq82ra69c subdir: ouroboros-consensus source-repository-package type: git location: https://github.com/input-output-hk/ouroboros-network - tag: 5f77e24c2263560ad58b9ba092c8cfed174675ae - --sha256: 00bm1fa83lc6jgh36mwr4zymzg9hvmq68y2hm4klk8c8gn7vwqqb + tag: 68ebc7b8c53078629dd57fd579eece12c66576c8 + --sha256: 11hsa5b218cbkq0wb7hc9x7m5mp56dlfw4zx4q9i4ymyq82ra69c + subdir: ouroboros-consensus/ouroboros-consensus-mock + +source-repository-package + type: git + location: https://github.com/input-output-hk/ouroboros-network + tag: 68ebc7b8c53078629dd57fd579eece12c66576c8 + --sha256: 11hsa5b218cbkq0wb7hc9x7m5mp56dlfw4zx4q9i4ymyq82ra69c + subdir: ouroboros-consensus-byron + +source-repository-package + type: git + location: https://github.com/input-output-hk/ouroboros-network + tag: 68ebc7b8c53078629dd57fd579eece12c66576c8 + --sha256: 11hsa5b218cbkq0wb7hc9x7m5mp56dlfw4zx4q9i4ymyq82ra69c + subdir: ouroboros-consensus-cardano + +source-repository-package + type: git + location: https://github.com/input-output-hk/ouroboros-network + tag: 68ebc7b8c53078629dd57fd579eece12c66576c8 + --sha256: 11hsa5b218cbkq0wb7hc9x7m5mp56dlfw4zx4q9i4ymyq82ra69c subdir: typed-protocols source-repository-package type: git location: https://github.com/input-output-hk/ouroboros-network - tag: 5f77e24c2263560ad58b9ba092c8cfed174675ae - --sha256: 00bm1fa83lc6jgh36mwr4zymzg9hvmq68y2hm4klk8c8gn7vwqqb + tag: 68ebc7b8c53078629dd57fd579eece12c66576c8 + --sha256: 11hsa5b218cbkq0wb7hc9x7m5mp56dlfw4zx4q9i4ymyq82ra69c subdir: typed-protocols-examples source-repository-package type: git location: https://github.com/input-output-hk/ouroboros-network - tag: 5f77e24c2263560ad58b9ba092c8cfed174675ae - --sha256: 00bm1fa83lc6jgh36mwr4zymzg9hvmq68y2hm4klk8c8gn7vwqqb + tag: 68ebc7b8c53078629dd57fd579eece12c66576c8 + --sha256: 11hsa5b218cbkq0wb7hc9x7m5mp56dlfw4zx4q9i4ymyq82ra69c subdir: ouroboros-network-framework source-repository-package type: git location: https://github.com/input-output-hk/ouroboros-network - tag: 5f77e24c2263560ad58b9ba092c8cfed174675ae - --sha256: 00bm1fa83lc6jgh36mwr4zymzg9hvmq68y2hm4klk8c8gn7vwqqb + tag: 68ebc7b8c53078629dd57fd579eece12c66576c8 + --sha256: 11hsa5b218cbkq0wb7hc9x7m5mp56dlfw4zx4q9i4ymyq82ra69c subdir: network-mux source-repository-package type: git location: https://github.com/input-output-hk/ouroboros-network - tag: 5f77e24c2263560ad58b9ba092c8cfed174675ae - --sha256: 00bm1fa83lc6jgh36mwr4zymzg9hvmq68y2hm4klk8c8gn7vwqqb + tag: 68ebc7b8c53078629dd57fd579eece12c66576c8 + --sha256: 11hsa5b218cbkq0wb7hc9x7m5mp56dlfw4zx4q9i4ymyq82ra69c subdir: io-sim-classes source-repository-package diff --git a/cardano-config/cardano-config.cabal b/cardano-config/cardano-config.cabal index f87c2300f77..70ffd17d488 100644 --- a/cardano-config/cardano-config.cabal +++ b/cardano-config/cardano-config.cabal @@ -44,6 +44,8 @@ library , network , optparse-applicative , ouroboros-consensus + , ouroboros-consensus-byron + , ouroboros-consensus-cardano , ouroboros-network , process , iproute diff --git a/cardano-config/src/Cardano/Config/Protocol.hs b/cardano-config/src/Cardano/Config/Protocol.hs index 1122d8ed5b8..863a05ed21c 100644 --- a/cardano-config/src/Cardano/Config/Protocol.hs +++ b/cardano-config/src/Cardano/Config/Protocol.hs @@ -1,8 +1,8 @@ -{-# LANGUAGE ConstraintKinds #-} -{-# LANGUAGE DeriveAnyClass #-} -{-# LANGUAGE FlexibleContexts #-} -{-# LANGUAGE GADTs #-} -{-# LANGUAGE NamedFieldPuns #-} +{-# LANGUAGE ConstraintKinds #-} +{-# LANGUAGE DeriveAnyClass #-} +{-# LANGUAGE FlexibleContexts #-} +{-# LANGUAGE GADTs #-} +{-# LANGUAGE NamedFieldPuns #-} {-# LANGUAGE OverloadedStrings #-} {-# OPTIONS_GHC -Wno-all-missed-specialisations #-} @@ -16,15 +16,13 @@ module Cardano.Config.Protocol , TraceConstraints ) where - - import Cardano.Prelude import Test.Cardano.Prelude (canonicalDecodePretty) -import Codec.CBOR.Read (deserialiseFromBytes, DeserialiseFailure) +import Codec.CBOR.Read (DeserialiseFailure, deserialiseFromBytes) import Control.Monad.Trans.Except (ExceptT) -import Control.Monad.Trans.Except.Extra ( bimapExceptT, firstExceptT - , hoistEither, left) +import Control.Monad.Trans.Except.Extra (bimapExceptT, firstExceptT, + hoistEither, left) import qualified Data.ByteString.Lazy as LB import qualified Cardano.Chain.Genesis as Genesis @@ -33,31 +31,28 @@ import Cardano.Crypto (RequiresNetworkMagic, decodeHash) import qualified Cardano.Crypto.Signing as Signing import Ouroboros.Consensus.Block (Header) -import Ouroboros.Consensus.BlockchainTime - (SlotLength, slotLengthFromSec, - SlotLengths, singletonSlotLengths) +import Ouroboros.Consensus.BlockchainTime (SlotLength, SlotLengths, + singletonSlotLengths, + slotLengthFromSec) +import Ouroboros.Consensus.Cardano hiding (Protocol) +import qualified Ouroboros.Consensus.Cardano as Consensus import Ouroboros.Consensus.Mempool.API (ApplyTxErr, GenTx, GenTxId, HasTxId, TxId) -import Ouroboros.Consensus.Node.ProtocolInfo (NumCoreNodes (..), - PBftLeaderCredentials, - PBftLeaderCredentialsError, - PBftSignatureThreshold(..), - mkPBftLeaderCredentials) -import Ouroboros.Consensus.NodeId (CoreNodeId (..), NodeId (..)) +import Ouroboros.Consensus.Node.ProtocolInfo (NumCoreNodes (..)) + +import Ouroboros.Consensus.Byron.Ledger (ByronBlock) import Ouroboros.Consensus.Node.Run (RunNode) -import Ouroboros.Consensus.Protocol (SecurityParam (..), - PraosParams (..), - PBftParams (..)) -import qualified Ouroboros.Consensus.Protocol as Consensus -import qualified Ouroboros.Consensus.Ledger.Byron as Consensus -import Ouroboros.Consensus.Util (Dict(..)) +import Ouroboros.Consensus.NodeId (CoreNodeId (..), NodeId (..)) +import Ouroboros.Consensus.Protocol.Abstract (SecurityParam (..)) +import Ouroboros.Consensus.Util (Dict (..)) import Ouroboros.Consensus.Util.Condense -import Ouroboros.Network.Block +import Ouroboros.Network.Block (HeaderHash) -import Cardano.Config.Types - (DelegationCertFile (..), GenesisFile (..), - LastKnownBlockVersion (..), Update (..), - Protocol (..), SigningKeyFile (..)) +import Cardano.Config.Types (DelegationCertFile (..), + GenesisFile (..), + LastKnownBlockVersion (..), + Protocol (..), SigningKeyFile (..), + Update (..)) -- TODO: consider not throwing this, or wrap it in a local error type here -- that has proper error messages. @@ -194,7 +189,7 @@ protocolConfigRealPbft :: Update -> Maybe Double -> Genesis.Config -> Maybe PBftLeaderCredentials - -> Consensus.Protocol Consensus.ByronBlock + -> Consensus.Protocol ByronBlock protocolConfigRealPbft (Update appName appVer lastKnownBlockVersion) pbftSignatureThresh genesis leaderCredentials = @@ -247,6 +242,6 @@ extractNodeInfo mNodeId ncNumCoreNodes = do coreNodeId <- case mNodeId of Just (CoreId coreNodeId) -> pure coreNodeId - _ -> Left MissingCoreNodeId + _ -> Left MissingCoreNodeId numCoreNodes <- maybe (Left MissingNumCoreNodes) Right ncNumCoreNodes return (coreNodeId , NumCoreNodes numCoreNodes) diff --git a/cardano-config/src/Cardano/Config/Types.hs b/cardano-config/src/Cardano/Config/Types.hs index 5ab9f571f96..a193dfafc73 100644 --- a/cardano-config/src/Cardano/Config/Types.hs +++ b/cardano-config/src/Cardano/Config/Types.hs @@ -166,6 +166,7 @@ instance FromJSON NodeConfiguration where <*> v .:? "TraceDNSResolver" .!= False <*> v .:? "TraceDNSSubscription" .!= True <*> v .:? "TraceErrorPolicy" .!= True + <*> v .:? "TraceLocalErrorPolicy" .!= True <*> v .:? "TraceForge" .!= True <*> v .:? "TraceIpSubscription" .!= True <*> v .:? "TraceLocalChainSyncProtocol" .!= False @@ -277,6 +278,7 @@ data TraceOptions = TraceOptions , traceDnsResolver :: !Bool , traceDnsSubscription :: !Bool , traceErrorPolicy :: !Bool + , traceLocalErrorPolicy :: !Bool , traceForge :: !Bool , traceIpSubscription :: !Bool , traceLocalChainSyncProtocol :: !Bool diff --git a/cardano-node/cardano-node.cabal b/cardano-node/cardano-node.cabal index 3ce86867e13..f9776a40569 100644 --- a/cardano-node/cardano-node.cabal +++ b/cardano-node/cardano-node.cabal @@ -36,7 +36,6 @@ library Cardano.CLI.Tx Cardano.Common.Help Cardano.Common.LocalSocket - Cardano.Common.Orphans Cardano.Common.Parsers Cardano.Common.TopHandler Cardano.Node.Features.Node @@ -90,6 +89,8 @@ library , network-mux , optparse-applicative , ouroboros-consensus + , ouroboros-consensus-byron + , ouroboros-consensus-cardano , ouroboros-network , safe-exceptions , serialise diff --git a/cardano-node/src/Cardano/CLI/Benchmarking/Tx/Generation.hs b/cardano-node/src/Cardano/CLI/Benchmarking/Tx/Generation.hs index d5b73a6d0d2..c17cd744790 100644 --- a/cardano-node/src/Cardano/CLI/Benchmarking/Tx/Generation.hs +++ b/cardano-node/src/Cardano/CLI/Benchmarking/Tx/Generation.hs @@ -85,16 +85,14 @@ import Control.Tracer (Tracer, traceWith) import Ouroboros.Consensus.Node.Run (RunNode) import Ouroboros.Consensus.Block(BlockProtocol) -import Ouroboros.Consensus.Ledger.Byron.Config (pbftProtocolMagic) -import Ouroboros.Consensus.Node.ProtocolInfo (ProtocolInfo (..), - protocolInfo) -import qualified Ouroboros.Consensus.Protocol as Consensus +import Ouroboros.Consensus.Node.ProtocolInfo (ProtocolInfo (..)) +import qualified Ouroboros.Consensus.Cardano as Consensus import qualified Ouroboros.Consensus.Mempool as Mempool -import Ouroboros.Consensus.Ledger.Byron (ByronBlock (..), +import Ouroboros.Consensus.Byron.Ledger (ByronBlock (..), GenTx (..), - ByronConsensusProtocol) + ByronConsensusProtocol, + getGenesisConfig) import Ouroboros.Consensus.Protocol.Abstract (NodeConfig) -import Ouroboros.Consensus.Protocol.ExtConfig (extNodeConfig) newtype NumberOfTxs = NumberOfTxs Word64 @@ -190,7 +188,7 @@ genesisBenchmarkRunner loggingLayer liftIO . traceWith benchTracer . TraceBenchTxSubDebug $ "******* Tx generator, genesis UTxO is ready *******" - let ProtocolInfo{pInfoConfig} = protocolInfo protocol + let ProtocolInfo{pInfoConfig} = Consensus.protocolInfo protocol genesisAddress = mkAddressForKey pInfoConfig genesisKey sourceAddress = mkAddressForKey pInfoConfig sourceKey recipientAddress = mkAddressForKey pInfoConfig recepientKey @@ -599,7 +597,7 @@ createTxAux config tx signingKey = CC.UTxO.annotateTxAux $ CC.UTxO.mkTxAux tx wi CC.UTxO.VKWitness (Crypto.toVerification signingKey) (Crypto.sign - (Crypto.getProtocolMagicId . pbftProtocolMagic . extNodeConfig $ config) + (CC.Genesis.configProtocolMagicId (getGenesisConfig config)) -- provide ProtocolMagicId so as not to calculate it every time Crypto.SignTx signingKey diff --git a/cardano-node/src/Cardano/CLI/Benchmarking/Tx/NodeToNode.hs b/cardano-node/src/Cardano/CLI/Benchmarking/Tx/NodeToNode.hs index 94845e27c73..3b933eac670 100644 --- a/cardano-node/src/Cardano/CLI/Benchmarking/Tx/NodeToNode.hs +++ b/cardano-node/src/Cardano/CLI/Benchmarking/Tx/NodeToNode.hs @@ -31,7 +31,7 @@ import Data.Proxy (Proxy (..)) import qualified Data.Text as T import Data.Time.Clock (getCurrentTime) import Network.Mux (AppType(InitiatorApp), WithMuxBearer (..)) -import Network.Socket (AddrInfo) +import Network.Socket (AddrInfo (..)) import Network.TypedProtocol.Codec (AnyMessage (..)) import Network.TypedProtocol.Driver (TraceSendRecv (..), runPeer) @@ -42,7 +42,7 @@ import Cardano.BM.Data.Tracer (DefinePrivacyAnnotation (..), TracingVerbosity (..), Transformable (..), emptyObject, mkObject, trStructured) import Ouroboros.Consensus.Block (BlockProtocol) -import Ouroboros.Consensus.Ledger.Byron (ByronBlock (..)) +import Ouroboros.Consensus.Byron.Ledger (ByronBlock (..)) import Ouroboros.Consensus.Mempool.API (GenTxId, GenTx) import Ouroboros.Consensus.Node.NetworkProtocolVersion import Ouroboros.Consensus.Node.Run (RunNode, nodeNetworkMagic) @@ -57,9 +57,11 @@ import Ouroboros.Network.Protocol.Handshake.Type (Handshake) import Ouroboros.Network.Protocol.Handshake.Version (Versions, simpleSingletonVersions) import Ouroboros.Network.Protocol.TxSubmission.Client (TxSubmissionClient, txSubmissionClientPeer) import qualified Ouroboros.Network.Protocol.TxSubmission.Type as TS +import Ouroboros.Network.Snocket (socketSnocket) +import Ouroboros.Network.IOManager (withIOManager) type SendRecvConnect = WithMuxBearer - NtN.ConnectionId + NtN.RemoteConnectionId (TraceSendRecv (Handshake NtN.NodeToNodeVersion CBOR.Term)) @@ -201,15 +203,16 @@ benchmarkConnectTxSubmit -> TxSubmissionClient (GenTxId blk) (GenTx blk) m () -- ^ the particular txSubmission peer -> m () -benchmarkConnectTxSubmit trs nc localAddr remoteAddr myTxSubClient = do +benchmarkConnectTxSubmit trs nc localAddr remoteAddr myTxSubClient = withIOManager $ \iocp -> do NtN.connectTo + (socketSnocket iocp) NetworkConnectTracers { nctMuxTracer = nullTracer, nctHandshakeTracer = trSendRecvConnect trs } peerMultiplex - localAddr - remoteAddr + (addrAddress <$> localAddr) + (addrAddress remoteAddr) where myCodecs :: ProtocolCodecs blk DeserialiseFailure m ByteString ByteString ByteString ByteString ByteString @@ -219,7 +222,7 @@ benchmarkConnectTxSubmit trs nc localAddr remoteAddr myTxSubClient = do peerMultiplex :: Versions NtN.NodeToNodeVersion NtN.DictVersion (OuroborosApplication 'InitiatorApp - NtN.ConnectionId + NtN.RemoteConnectionId NtN.NodeToNodeProtocols m ByteString diff --git a/cardano-node/src/Cardano/CLI/Benchmarking/Tx/TxSubmission.hs b/cardano-node/src/Cardano/CLI/Benchmarking/Tx/TxSubmission.hs index 7b6bfe107fa..f3751b662f7 100644 --- a/cardano-node/src/Cardano/CLI/Benchmarking/Tx/TxSubmission.hs +++ b/cardano-node/src/Cardano/CLI/Benchmarking/Tx/TxSubmission.hs @@ -40,7 +40,7 @@ import Cardano.BM.Data.Tracer (DefinePrivacyAnnotation (..), emptyObject, mkObject, nullTracer, trStructured) import Control.Tracer (Tracer, traceWith) -import Ouroboros.Consensus.Ledger.Byron (ByronBlock (..)) +import Ouroboros.Consensus.Byron.Ledger (ByronBlock (..)) import qualified Ouroboros.Consensus.Mempool as Mempool import qualified Ouroboros.Network.Protocol.TxSubmission.Type as TxSubmit diff --git a/cardano-node/src/Cardano/CLI/Ops.hs b/cardano-node/src/Cardano/CLI/Ops.hs index 89ddb00c619..260eec9a69e 100644 --- a/cardano-node/src/Cardano/CLI/Ops.hs +++ b/cardano-node/src/Cardano/CLI/Ops.hs @@ -48,7 +48,8 @@ import Control.Tracer (nullTracer, stdoutTracer, traceWith) import Network.Mux (MuxError) import Network.TypedProtocol.Driver (runPeer) import Ouroboros.Consensus.Block (BlockProtocol) -import Ouroboros.Consensus.Ledger.Byron (ByronBlock, GenTx) +import Ouroboros.Consensus.Byron.Ledger (ByronBlock, GenTx) +import qualified Ouroboros.Consensus.Cardano as Consensus import Ouroboros.Consensus.Mempool.API (ApplyTxErr) import Ouroboros.Consensus.NodeNetwork (ProtocolCodecs(..), protocolCodecs) import Ouroboros.Consensus.Node.NetworkProtocolVersion @@ -56,7 +57,6 @@ import Ouroboros.Consensus.Node.NetworkProtocolVersion import Ouroboros.Consensus.Node.ProtocolInfo (ProtocolInfo(..), protocolInfo) import Ouroboros.Consensus.Node.Run (RunNode(..)) -import qualified Ouroboros.Consensus.Protocol as Consensus import Ouroboros.Consensus.Util.Condense (Condense(..)) import Ouroboros.Consensus.Util.IOLike (IOLike) import Ouroboros.Network.Block diff --git a/cardano-node/src/Cardano/CLI/Run.hs b/cardano-node/src/Cardano/CLI/Run.hs index 03ec036d54f..d30f817c30c 100644 --- a/cardano-node/src/Cardano/CLI/Run.hs +++ b/cardano-node/src/Cardano/CLI/Run.hs @@ -53,7 +53,7 @@ import Cardano.Crypto (ProtocolMagicId, RequiresNetworkMagic(..)) import qualified Cardano.Crypto.Hashing as Crypto import qualified Cardano.Crypto.Signing as Crypto -import qualified Ouroboros.Consensus.Protocol as Consensus +import qualified Ouroboros.Consensus.Cardano as Consensus import Cardano.CLI.Delegation import Cardano.CLI.Genesis @@ -65,7 +65,6 @@ import Cardano.CLI.Benchmarking.Tx.Generation , NumberOfInputsPerTx (..), NumberOfOutputsPerTx (..) , FeePerTx (..), TPSRate (..), TxAdditionalSize (..) , genesisBenchmarkRunner) -import Cardano.Common.Orphans () import Cardano.Config.Protocol import Cardano.Config.Logging (createLoggingFeatureCLI) import Cardano.Config.Types @@ -204,7 +203,6 @@ runCommand (GetLocalNodeTip configFp gFile sockPath) = do runCommand (PrettySigningKeyPublic ptcl skF) = do sK <- readSigningKey ptcl skF liftIO . putTextLn . prettyPublicKey $ Crypto.toVerification sK - runCommand (MigrateDelegateKeyFrom oldPtcl oldKey newPtcl (NewSigningKeyFile newKey)) = do sk <- readSigningKey oldPtcl oldKey sDk <- hoistEither $ serialiseDelegateKey newPtcl sk diff --git a/cardano-node/src/Cardano/CLI/Tx.hs b/cardano-node/src/Cardano/CLI/Tx.hs index 798850df8a1..8bd502a0038 100644 --- a/cardano-node/src/Cardano/CLI/Tx.hs +++ b/cardano-node/src/Cardano/CLI/Tx.hs @@ -48,10 +48,10 @@ import Cardano.Crypto (SigningKey(..), ProtocolMagicId, RequiresNetwor import qualified Cardano.Crypto.Hashing as Crypto import qualified Cardano.Crypto.Signing as Crypto -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.ProtocolInfo (protocolInfo, pInfoConfig) +import qualified Ouroboros.Consensus.Byron.Ledger as Byron +import Ouroboros.Consensus.Byron.Ledger (GenTx(..), ByronBlock) +import qualified Ouroboros.Consensus.Cardano as Consensus +import Ouroboros.Consensus.Node.ProtocolInfo (pInfoConfig) import qualified Ouroboros.Consensus.Mempool as Consensus import Ouroboros.Consensus.Util.Condense (condense) @@ -60,7 +60,6 @@ import Cardano.Node.Submission import Cardano.Config.Protocol import Cardano.Config.Types (DelegationCertFile, GenesisFile, SigningKeyFile, SocketPath, Update) -import Cardano.Common.Orphans () newtype TxFile = @@ -278,7 +277,7 @@ nodeSubmitTx -- TODO: Update submitGenTx to use `ExceptT` traceWith stdoutTracer ("TxId: " ++ condense (Consensus.txId gentx)) submitTx targetSocketFp - (pInfoConfig (protocolInfo p)) + (pInfoConfig (Consensus.protocolInfo p)) gentx nullTracer -- stdoutTracer diff --git a/cardano-node/src/Cardano/Chairman.hs b/cardano-node/src/Cardano/Chairman.hs index 1437751c239..363d390a1b4 100644 --- a/cardano-node/src/Cardano/Chairman.hs +++ b/cardano-node/src/Cardano/Chairman.hs @@ -40,7 +40,7 @@ import Ouroboros.Consensus.Block (BlockProtocol, GetHeader (..)) import Ouroboros.Consensus.Mempool import Ouroboros.Consensus.Node.ProtocolInfo import Ouroboros.Consensus.Node.Run -import Ouroboros.Consensus.Protocol +import Ouroboros.Consensus.Cardano import Ouroboros.Consensus.Util.Condense import Network.TypedProtocol.Driver @@ -58,6 +58,7 @@ import Ouroboros.Network.Protocol.ChainSync.Client import Ouroboros.Network.Protocol.ChainSync.Codec import Ouroboros.Network.Protocol.Handshake.Version import Ouroboros.Network.NodeToClient +import Ouroboros.Network.Snocket (socketSnocket) import Cardano.Common.LocalSocket import Cardano.Config.Types (SocketPath) @@ -131,25 +132,25 @@ createConnection maxBlockNo tracer pInfoConfig - socketPath = do - addr <- localSocketAddrInfo socketPath - connectTo - NetworkConnectTracers { - nctMuxTracer = nullTracer, - nctHandshakeTracer = nullTracer - } - (localInitiatorNetworkApplication - socketPath - chainsVar - securityParam - maxBlockNo - (showTracing tracer) - nullTracer - nullTracer - pInfoConfig) - Nothing - addr - `catch` handleMuxError tracer chainsVar socketPath + socketPath = withIOManager $ \iocp -> do + path <- localSocketPath socketPath + connectTo + (socketSnocket iocp) + NetworkConnectTracers { + nctMuxTracer = nullTracer, + nctHandshakeTracer = nullTracer + } + (localInitiatorNetworkApplication + socketPath + chainsVar + securityParam + maxBlockNo + (showTracing tracer) + nullTracer + nullTracer + pInfoConfig) + path + `catch` handleMuxError tracer chainsVar socketPath data ChairmanTrace blk = WitnessedConsensus [Point (Header blk)] diff --git a/cardano-node/src/Cardano/Common/LocalSocket.hs b/cardano-node/src/Cardano/Common/LocalSocket.hs index 5c56b83edd8..cab63dce392 100644 --- a/cardano-node/src/Cardano/Common/LocalSocket.hs +++ b/cardano-node/src/Cardano/Common/LocalSocket.hs @@ -1,5 +1,5 @@ module Cardano.Common.LocalSocket - ( localSocketAddrInfo + ( localSocketPath , nodeLocalSocketAddrInfo , removeStaleLocalSocket ) @@ -10,32 +10,24 @@ import Cardano.Prelude import System.Directory (createDirectoryIfMissing, removeFile) import System.FilePath (takeDirectory) import System.IO.Error (isDoesNotExistError) -import Network.Socket as Socket import Cardano.Config.Types ( MiscellaneousFilepaths(..), NodeCLI(..) , NodeMockCLI(..), NodeProtocolMode(..) , SocketPath(..)) -nodeLocalSocketAddrInfo :: NodeProtocolMode -> IO Socket.AddrInfo +nodeLocalSocketAddrInfo :: NodeProtocolMode -> IO FilePath nodeLocalSocketAddrInfo npm = case npm of - MockProtocolMode (NodeMockCLI mscFp' _ _ _ _) -> localSocketAddrInfo $ socketFile mscFp' - RealProtocolMode (NodeCLI mscFp' _ _ _ _) -> localSocketAddrInfo $ socketFile mscFp' + MockProtocolMode (NodeMockCLI mscFp' _ _ _ _) -> localSocketPath $ socketFile mscFp' + RealProtocolMode (NodeCLI mscFp' _ _ _ _) -> localSocketPath $ socketFile mscFp' --- | 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 :: SocketPath -> IO Socket.AddrInfo -localSocketAddrInfo (SocketFile fp) = do +-- | Provide an filepath intended for a socket situated in 'socketDir'. +-- When 'mkdir' is 'MkdirIfMissing', the directory is created. +localSocketPath :: SocketPath -> IO FilePath +localSocketPath (SocketFile fp) = do createDirectoryIfMissing True $ takeDirectory fp - pure $ - Socket.AddrInfo - [] - Socket.AF_UNIX - Socket.Stream - Socket.defaultProtocol - (Socket.SockAddrUnix fp) - Nothing + return fp -- TODO: Convert to ExceptT -- | Remove the socket established with 'localSocketAddrInfo'. diff --git a/cardano-node/src/Cardano/Common/Orphans.hs b/cardano-node/src/Cardano/Common/Orphans.hs deleted file mode 100644 index ac9c9dc77c2..00000000000 --- a/cardano-node/src/Cardano/Common/Orphans.hs +++ /dev/null @@ -1,19 +0,0 @@ -{-# LANGUAGE DeriveGeneric #-} -{-# LANGUAGE FlexibleInstances #-} -{-# LANGUAGE StandaloneDeriving #-} -{-# OPTIONS_GHC -Wno-all-missed-specialisations #-} -{-# OPTIONS_GHC -Wno-orphans #-} - -module Cardano.Common.Orphans - () -where - -import Codec.Serialise (Serialise(..)) - -import Ouroboros.Consensus.Ledger.Byron - ( ByronBlock, GenTx(..) - , decodeByronGenTx, encodeByronGenTx) - -instance Serialise (GenTx ByronBlock) where - decode = decodeByronGenTx - encode = encodeByronGenTx diff --git a/cardano-node/src/Cardano/Node/Run.hs b/cardano-node/src/Cardano/Node/Run.hs index ca77adffdcf..9d09a1fbfb7 100644 --- a/cardano-node/src/Cardano/Node/Run.hs +++ b/cardano-node/src/Cardano/Node/Run.hs @@ -54,22 +54,25 @@ import Cardano.Config.Logging (LoggingLayer (..)) import Cardano.Config.Types (MiscellaneousFilepaths(..), NodeConfiguration (..), ViewMode (..)) + import Ouroboros.Network.Block +import Ouroboros.Network.NodeToClient (LocalConnectionId) import Ouroboros.Consensus.Block (BlockProtocol) import Ouroboros.Consensus.Node (NodeKernel (getChainDB), - ConnectionId (..), DiffusionTracers (..), DiffusionArguments (..), + DiffusionTracers (..), DiffusionArguments (..), DnsSubscriptionTarget (..), IPSubscriptionTarget (..), - RunNode (nodeNetworkMagic, nodeStartTime), IsProducer (..)) + RunNode (nodeNetworkMagic, nodeStartTime), IsProducer (..), + RemoteConnectionId) import qualified Ouroboros.Consensus.Node as Node (run) import Ouroboros.Consensus.Node.ProtocolInfo import Ouroboros.Consensus.NodeId -import qualified Ouroboros.Consensus.Protocol as Consensus +import qualified Ouroboros.Consensus.Cardano as Consensus import Ouroboros.Consensus.Util.Orphans () import Ouroboros.Consensus.Util.STM (onEachChange) -import qualified Ouroboros.Storage.ChainDB as ChainDB -import Ouroboros.Storage.ImmutableDB (ValidationPolicy (..)) -import Ouroboros.Storage.VolatileDB (BlockValidationPolicy (..)) +import qualified Ouroboros.Consensus.Storage.ChainDB as ChainDB +import Ouroboros.Consensus.Storage.ImmutableDB (ValidationPolicy (..)) +import Ouroboros.Consensus.Storage.VolatileDB (BlockValidationPolicy (..)) import Cardano.Common.LocalSocket import Cardano.Config.Protocol (SomeProtocol(..), fromProtocol) @@ -157,16 +160,16 @@ handleSimpleNode :: forall blk. RunNode blk => Consensus.Protocol blk -> Trace IO Text - -> Tracers ConnectionId blk + -> Tracers RemoteConnectionId LocalConnectionId blk -> NodeProtocolMode - -> (NodeKernel IO ConnectionId blk -> IO ()) + -> (NodeKernel IO RemoteConnectionId blk -> IO ()) -- ^ Called on the 'NodeKernel' after creating it, but before the network -- layer is initialised. This implies this function must not block, -- otherwise the node won't actually start. -> IO () handleSimpleNode p trace nodeTracers npm onKernel = do - let pInfo@ProtocolInfo{ pInfoConfig = cfg } = protocolInfo p + let pInfo@ProtocolInfo{ pInfoConfig = cfg } = Consensus.protocolInfo p tracer = contramap pack $ toLogObject trace -- Node configuration @@ -241,12 +244,14 @@ handleSimpleNode p trace nodeTracers npm onKernel = do Just (CoreId _) -> IsProducer _ -> IsNotProducer - createDiffusionTracers :: Tracers ConnectionId blk -> DiffusionTracers + createDiffusionTracers :: Tracers RemoteConnectionId LocalConnectionId blk + -> DiffusionTracers createDiffusionTracers nodeTracers' = DiffusionTracers { dtIpSubscriptionTracer = ipSubscriptionTracer nodeTracers' , dtDnsSubscriptionTracer = dnsSubscriptionTracer nodeTracers' , dtDnsResolverTracer = dnsResolverTracer nodeTracers' , dtErrorPolicyTracer = errorPolicyTracer nodeTracers' + , dtLocalErrorPolicyTracer = localErrorPolicyTracer nodeTracers' , dtMuxTracer = muxTracer nodeTracers' , dtMuxLocalTracer = nullTracer , dtHandshakeTracer = nullTracer @@ -333,7 +338,7 @@ dbValidation (RealProtocolMode (NodeCLI _ _ _ _ dbval)) = dbval createDiffusionArguments :: [AddrInfo] - -> AddrInfo + -> FilePath -> IPSubscriptionTarget -> [DnsSubscriptionTarget] -> DiffusionArguments diff --git a/cardano-node/src/Cardano/Node/Submission.hs b/cardano-node/src/Cardano/Node/Submission.hs index 5e2b8dad5b1..6a9cbe28d53 100644 --- a/cardano-node/src/Cardano/Node/Submission.hs +++ b/cardano-node/src/Cardano/Node/Submission.hs @@ -30,7 +30,7 @@ import Ouroboros.Consensus.Block (BlockProtocol) import Ouroboros.Consensus.Mempool (ApplyTxErr, GenTx) import Ouroboros.Consensus.Node.Run (RunNode) import qualified Ouroboros.Consensus.Node.Run as Node -import Ouroboros.Consensus.Protocol (NodeConfig) +import Ouroboros.Consensus.Protocol.Abstract (NodeConfig) import Network.TypedProtocol.Driver (runPeer) import Ouroboros.Network.Codec (Codec, DeserialiseFailure) @@ -47,6 +47,7 @@ import Ouroboros.Network.Protocol.Handshake.Version ( Versions , simpleSingletonVersions) import Ouroboros.Network.NodeToClient (NetworkConnectTracers (..)) import qualified Ouroboros.Network.NodeToClient as NodeToClient +import Ouroboros.Network.Snocket (socketSnocket) import Cardano.BM.Data.Tracer (DefinePrivacyAnnotation (..), DefineSeverity (..), ToObject (..), TracingFormatting (..), @@ -106,15 +107,15 @@ submitTx :: ( RunNode blk -> GenTx blk -> Tracer IO TraceLowLevelSubmit -> IO () -submitTx targetSocketFp protoInfoConfig tx tracer = do - targetSocketFp' <- localSocketAddrInfo targetSocketFp +submitTx targetSocketFp protoInfoConfig tx tracer = NodeToClient.withIOManager $ \iocp -> do + targetSocketFp' <- localSocketPath targetSocketFp NodeToClient.connectTo + (socketSnocket iocp) NetworkConnectTracers { nctMuxTracer = nullTracer, nctHandshakeTracer = nullTracer } (localInitiatorNetworkApplication tracer protoInfoConfig tx) - Nothing targetSocketFp' localInitiatorNetworkApplication diff --git a/cardano-node/src/Cardano/Node/TUI/LiveView.hs b/cardano-node/src/Cardano/Node/TUI/LiveView.hs index 219f727bb8c..382de7643d3 100644 --- a/cardano-node/src/Cardano/Node/TUI/LiveView.hs +++ b/cardano-node/src/Cardano/Node/TUI/LiveView.hs @@ -82,7 +82,7 @@ import Cardano.Slotting.Slot (unSlotNo) import qualified Ouroboros.Network.AnchoredFragment as Net import qualified Ouroboros.Network.Block as Net import Ouroboros.Consensus.Block (GetHeader(..)) -import Ouroboros.Consensus.Node (NodeKernel(..), ConnectionId(..)) +import Ouroboros.Consensus.Node (NodeKernel(..), RemoteConnectionId, remoteAddress) import Ouroboros.Consensus.NodeId import qualified Ouroboros.Network.BlockFetch.ClientState as Net import qualified Ouroboros.Network.BlockFetch.ClientRegistry as Net @@ -190,7 +190,7 @@ fromSMaybe x SNothing = x fromSMaybe _ (SJust x) = x data LVNodeKernel blk = LVNodeKernel - { getNodeKernel :: !(NodeKernel IO ConnectionId blk) } + { getNodeKernel :: !(NodeKernel IO RemoteConnectionId blk) } deriving (Generic) instance NoUnexpectedThunks (LVNodeKernel blk) where @@ -373,7 +373,7 @@ instance IsEffectuator (LiveViewBackend blk) Text where -> STM.STM IO (Map peer (Net.AnchoredFragment (Header blk))) getCandidates var = STM.readTVar var >>= traverse STM.readTVar - extractPeers :: NodeKernel IO ConnectionId blk -> IO [LVPeer blk] + extractPeers :: NodeKernel IO RemoteConnectionId blk -> IO [LVPeer blk] extractPeers kernel = do peerStates <- fmap tuple3pop <$> (atomically . (>>= traverse Net.readFetchClientState) . Net.readFetchClientsStateVars . getFetchClientRegistry $ kernel) candidates <- atomically . getCandidates . getNodeCandidates $ kernel @@ -562,7 +562,7 @@ setNodeThread lvbe nodeThr = modifyMVar_ (getbe lvbe) $ \lvs -> return $ lvs { lvsNodeThread = LiveViewThread $ Just nodeThr } -setNodeKernel :: NFData a => LiveViewBackend blk a -> NodeKernel IO ConnectionId blk -> IO () +setNodeKernel :: NFData a => LiveViewBackend blk a -> NodeKernel IO RemoteConnectionId blk -> IO () setNodeKernel lvbe nodeKern = modifyMVar_ (getbe lvbe) $ \lvs -> return $ lvs { lvsNodeKernel = SJust (LVNodeKernel nodeKern) } @@ -710,7 +710,7 @@ darkTheme = newTheme (V.white `on` darkMainBG) data LVPeer blk = LVPeer - !ConnectionId + !RemoteConnectionId !(Net.AnchoredFragment (Header blk)) !(Net.PeerFetchStatus (Header blk)) !(Net.PeerFetchInFlight (Header blk)) @@ -726,7 +726,7 @@ ppPeer :: LVPeer blk -> Text ppPeer (LVPeer cid _af status inflight) = pack $ printf "%-15s %-8s %s" (ppCid cid) (ppStatus status) (ppInFlight inflight) where - ppCid :: ConnectionId -> String + ppCid :: RemoteConnectionId -> String ppCid = takeWhile (/= ':') . show . remoteAddress ppInFlight :: Net.PeerFetchInFlight header -> String diff --git a/cardano-node/src/Cardano/Tracing/ToObjectOrphans.hs b/cardano-node/src/Cardano/Tracing/ToObjectOrphans.hs index e9fe1a0e0b5..82fec7be42d 100644 --- a/cardano-node/src/Cardano/Tracing/ToObjectOrphans.hs +++ b/cardano-node/src/Cardano/Tracing/ToObjectOrphans.hs @@ -64,9 +64,9 @@ import Ouroboros.Network.TxSubmission.Inbound import Ouroboros.Network.TxSubmission.Outbound (TraceTxSubmissionOutbound) -import qualified Ouroboros.Storage.ChainDB as ChainDB -import Ouroboros.Storage.Common (EpochNo (..)) -import qualified Ouroboros.Storage.LedgerDB.OnDisk as LedgerDB +import qualified Ouroboros.Consensus.Storage.ChainDB as ChainDB +import Ouroboros.Consensus.Storage.Common (EpochNo (..)) +import qualified Ouroboros.Consensus.Storage.LedgerDB.OnDisk as LedgerDB -- | Tracing wrapper which includes current tip in the logs (thus it requires -- it from the context). @@ -252,7 +252,8 @@ instance DefineSeverity (ChainDB.TraceEvent blk) where ChainDB.StoreButDontChange {} -> Debug ChainDB.TryAddToCurrentChain {} -> Debug ChainDB.TrySwitchToAFork {} -> Info - ChainDB.SwitchedToChain {} -> Notice + ChainDB.AddedToCurrentChain {} -> Notice + ChainDB.SwitchedToAFork {} -> Notice ChainDB.AddBlockValidation ev' -> case ev' of ChainDB.InvalidBlock {} -> Error ChainDB.InvalidCandidate {} -> Error @@ -477,8 +478,10 @@ readableChainDBTracer tracer = Tracer $ \case "Block fits onto the current chain: " <> condense pt ChainDB.TrySwitchToAFork pt _ -> tr $ WithTip tip $ "Block fits onto some fork: " <> condense pt - ChainDB.SwitchedToChain _ c -> tr $ WithTip tip $ - "Chain changed, new tip: " <> condense (AF.headPoint c) + ChainDB.AddedToCurrentChain _ _ c -> tr $ WithTip tip $ + "Chain extended, new tip: " <> condense (AF.headPoint c) + ChainDB.SwitchedToAFork _ _ c -> tr $ WithTip tip $ + "Switched to a fork, new tip: " <> condense (AF.headPoint c) ChainDB.AddBlockValidation ev' -> case ev' of ChainDB.InvalidBlock err pt -> tr $ WithTip tip $ "Invalid block " <> condense pt <> ": " <> show err @@ -642,8 +645,11 @@ instance (Condense (HeaderHash blk), ProtocolLedgerView blk) ChainDB.TrySwitchToAFork pt _ -> mkObject [ "kind" .= String "TraceAddBlockEvent.TrySwitchToAFork" , "block" .= toObject verb pt ] - ChainDB.SwitchedToChain _ c -> - mkObject [ "kind" .= String "TraceAddBlockEvent.SwitchedToChain" + ChainDB.AddedToCurrentChain _ _ c -> + mkObject [ "kind" .= String "TraceAddBlockEvent.AddedToCurrentChain" + , "newtip" .= showPoint verb (AF.headPoint c) ] + ChainDB.SwitchedToAFork _ _ c -> + mkObject [ "kind" .= String "TraceAddBlockEvent.SwitchedToAFork" , "newtip" .= showPoint verb (AF.headPoint c) ] ChainDB.AddBlockValidation ev' -> case ev' of ChainDB.InvalidBlock err pt -> diff --git a/cardano-node/src/Cardano/Tracing/Tracers.hs b/cardano-node/src/Cardano/Tracing/Tracers.hs index 77874c150b3..034ca061c87 100644 --- a/cardano-node/src/Cardano/Tracing/Tracers.hs +++ b/cardano-node/src/Cardano/Tracing/Tracers.hs @@ -63,8 +63,8 @@ import Ouroboros.Network.NodeToNode (WithAddr, ErrorPolicyTrace) import Ouroboros.Network.Point (fromWithOrigin) import Ouroboros.Network.Subscription -import qualified Ouroboros.Storage.ChainDB as ChainDB -import qualified Ouroboros.Storage.LedgerDB.OnDisk as LedgerDB +import qualified Ouroboros.Consensus.Storage.ChainDB as ChainDB +import qualified Ouroboros.Consensus.Storage.LedgerDB.OnDisk as LedgerDB import Cardano.Config.Protocol (TraceConstraints) import Cardano.Config.Types @@ -73,13 +73,13 @@ import Cardano.Tracing.ToObjectOrphans import Control.Tracer.Transformers -data Tracers peer blk = Tracers +data Tracers peer localPeer blk = Tracers { -- | Trace the ChainDB chainDBTracer :: Tracer IO (WithTip blk (ChainDB.TraceEvent blk)) -- | Consensus-specific tracers. , consensusTracers :: Consensus.Tracers IO peer blk -- | Tracers for the protocol messages. - , protocolTracers :: ProtocolTracers IO peer blk DeserialiseFailure + , protocolTracers :: ProtocolTracers IO peer localPeer blk DeserialiseFailure -- | Trace the IP subscription manager , ipSubscriptionTracer :: Tracer IO (WithIPList (SubscriptionTrace Socket.SockAddr)) -- | Trace the DNS subscription manager @@ -88,6 +88,8 @@ data Tracers peer blk = Tracers , dnsResolverTracer :: Tracer IO (WithDomainName DnsTrace) -- | Trace error policy resolution , errorPolicyTracer :: Tracer IO (WithAddr Socket.SockAddr ErrorPolicyTrace) + -- | Trace local error policy resolution + , localErrorPolicyTracer :: Tracer IO (WithAddr Socket.SockAddr ErrorPolicyTrace) -- | Trace the Mux , muxTracer :: Tracer IO (WithMuxBearer peer MuxTrace) } @@ -105,7 +107,7 @@ data ForgeTracers = ForgeTracers , ftTraceNodeIsLeader :: Trace IO Text } -nullTracers :: Tracers peer blk +nullTracers :: Tracers peer localPeer blk nullTracers = Tracers { chainDBTracer = nullTracer , consensusTracers = Consensus.nullTracers @@ -114,6 +116,7 @@ nullTracers = Tracers , dnsSubscriptionTracer = nullTracer , dnsResolverTracer = nullTracer , errorPolicyTracer = nullTracer + , localErrorPolicyTracer = nullTracer , muxTracer = nullTracer } @@ -151,15 +154,16 @@ instance ElidingTracer -- | Smart constructor of 'NodeTraces'. -- mkTracers - :: forall peer blk. + :: forall peer localPeer blk. ( ProtocolLedgerView blk , TraceConstraints blk , ShowQuery (Query blk) , Show peer + , Show localPeer ) => TraceOptions -> Trace IO Text - -> IO (Tracers peer blk) + -> IO (Tracers peer localPeer blk) mkTracers traceOptions tracer = do -- We probably don't want to pay the extra IO cost per-counter-increment. -- sk staticMetaCC <- mkLOMeta Critical Confidential @@ -216,6 +220,11 @@ mkTracers traceOptions tracer = do $ annotateSeverity $ toLogObject' StructuredLogging tracingVerbosity $ appendName "ErrorPolicy" tracer + , localErrorPolicyTracer + = tracerOnOff (traceLocalErrorPolicy traceOptions) + $ annotateSeverity + $ toLogObject' StructuredLogging tracingVerbosity + $ appendName "LocalErrorPolicy" tracer , muxTracer = tracerOnOff (traceMux traceOptions) $ annotateSeverity @@ -245,22 +254,34 @@ mkTracers traceOptions tracer = do -> Tracer IO (WithSeverity (WithTip blk (ChainDB.TraceEvent blk))) teeTraceChainTipElide = elideToLogObject + traceChainInformation :: Trace IO Text + -> ChainInformation + -> IO () + traceChainInformation tr ChainInformation { slots, blocks, density } = do + -- TODO this is executed each time the chain changes. How cheap is it? + meta <- mkLOMeta Critical Confidential + let tr' = appendName "metrics" tr + traceD :: Text -> Double -> IO () + traceD msg d = traceNamedObject tr' (meta, LogValue msg (PureD d)) + traceI :: Integral a => Text -> a -> IO () + traceI msg i = traceNamedObject tr' (meta, LogValue msg (PureI (fromIntegral i))) + + traceD "density" (fromRational density) + traceI "slotNum" slots + traceI "blockNum" blocks + traceI "slotInEpoch" (slots `rem` epochSlots) + traceI "epoch" (slots `div` epochSlots) + where + epochSlots :: Word64 = 21600 -- TODO + teeTraceChainTip' :: Trace IO Text -> Tracer IO (WithSeverity (WithTip blk (ChainDB.TraceEvent blk))) teeTraceChainTip' tr = Tracer $ \(WithSeverity _ (WithTip _tip ev')) -> case ev' of (ChainDB.TraceAddBlockEvent ev) -> case ev of - ChainDB.SwitchedToChain _ c -> do - meta <- mkLOMeta Critical Confidential - let tr' = appendName "metrics" tr - ChainInformation { slots, blocks, density } = chainInformation c - epochSlots :: Word64 = 21600 -- TODO - traceNamedObject tr' (meta, LogValue "density" . PureD $ fromRational density) - traceNamedObject tr' (meta, LogValue "slotNum" . PureI $ fromIntegral slots) - traceNamedObject tr' (meta, LogValue "blockNum" . PureI $ fromIntegral blocks) - traceNamedObject tr' (meta, LogValue "slotInEpoch" . PureI $ fromIntegral (slots `rem` epochSlots)) - traceNamedObject tr' (meta, LogValue "epoch" . PureI $ fromIntegral (slots `div` epochSlots)) + ChainDB.SwitchedToAFork _ _ c -> traceChainInformation tr (chainInformation c) + ChainDB.AddedToCurrentChain _ _ c -> traceChainInformation tr (chainInformation c) _ -> pure () _ -> pure () teeTraceBlockFetchDecision :: TracingFormatting @@ -446,7 +467,7 @@ mkTracers traceOptions tracer = do TraceStartTimeInTheFuture (SystemStart start) toWait -> "Waiting " <> show toWait <> " until genesis start time at " <> show start - mkProtocolTracers :: TraceOptions -> ProtocolTracers' peer blk DeserialiseFailure (Tracer IO) + mkProtocolTracers :: TraceOptions -> ProtocolTracers' peer localPeer blk DeserialiseFailure (Tracer IO) mkProtocolTracers traceOpts = ProtocolTracers { ptChainSyncTracer = tracerOnOff (traceChainSyncProtocol traceOpts) diff --git a/cardano-node/src/Cardano/Wallet/Client.hs b/cardano-node/src/Cardano/Wallet/Client.hs index dba0d33ab7f..1300d244f03 100644 --- a/cardano-node/src/Cardano/Wallet/Client.hs +++ b/cardano-node/src/Cardano/Wallet/Client.hs @@ -30,7 +30,7 @@ import Ouroboros.Consensus.Block (BlockProtocol) import Ouroboros.Consensus.Mempool import Ouroboros.Consensus.Node.ProtocolInfo import Ouroboros.Consensus.Node.Run -import Ouroboros.Consensus.Protocol +import Ouroboros.Consensus.Cardano import Network.TypedProtocol.Driver import Ouroboros.Network.Codec @@ -45,6 +45,7 @@ import Ouroboros.Network.Protocol.ChainSync.Client import Ouroboros.Network.Protocol.ChainSync.Codec import Ouroboros.Network.Protocol.Handshake.Version import Ouroboros.Network.NodeToClient +import Ouroboros.Network.Snocket (socketSnocket) import Cardano.Common.LocalSocket import Cardano.Config.Types (SocketPath) @@ -58,9 +59,9 @@ runWalletClient :: forall blk. -> SocketPath -> Tracer IO String -> IO () -runWalletClient ptcl sockFp tracer = do +runWalletClient ptcl sockFp tracer = withIOManager $ \iocp -> do - addr <- localSocketAddrInfo sockFp + path <- localSocketPath sockFp let ProtocolInfo{pInfoConfig} = protocolInfo ptcl @@ -68,6 +69,7 @@ runWalletClient ptcl sockFp tracer = do localTxSubmissionTracer = contramap show tracer connectTo + (socketSnocket iocp) NetworkConnectTracers { nctMuxTracer = nullTracer, nctHandshakeTracer = nullTracer @@ -77,8 +79,7 @@ runWalletClient ptcl sockFp tracer = do chainSyncTracer localTxSubmissionTracer pInfoConfig) - Nothing - addr + path localInitiatorNetworkApplication :: forall blk m peer. diff --git a/configuration/configuration-mainnet.yaml b/configuration/configuration-mainnet.yaml index ab599f6b2db..a7cccd190e9 100644 --- a/configuration/configuration-mainnet.yaml +++ b/configuration/configuration-mainnet.yaml @@ -143,6 +143,9 @@ TraceDNSSubscription: False # Trace error policy resolution. TraceErrorPolicy: False +# Trace local error policy resolution. +TraceLocalErrorPolicy: False + # Trace block forging. TraceForge: True diff --git a/stack.yaml b/stack.yaml index df2f5ca5ae4..ea798d074e1 100644 --- a/stack.yaml +++ b/stack.yaml @@ -121,13 +121,16 @@ extra-deps: #Ouroboros-network dependencies - git: https://github.com/input-output-hk/ouroboros-network - commit: 5f77e24c2263560ad58b9ba092c8cfed174675ae + commit: 68ebc7b8c53078629dd57fd579eece12c66576c8 subdirs: - io-sim - io-sim-classes - network-mux - ouroboros-network - ouroboros-consensus + - ouroboros-consensus-byron + - ouroboros-consensus/ouroboros-consensus-mock + - ouroboros-consensus-cardano - typed-protocols - typed-protocols-examples - ouroboros-network-framework From 56c3e87aeccbde995a1b9c683b782db5d67e29bf Mon Sep 17 00:00:00 2001 From: Marcin Szamotulski Date: Mon, 24 Feb 2020 11:31:03 +0100 Subject: [PATCH 2/6] Proper use of io manager Behaviour of IO manager depends on platform. On Unix its noop, as RTS has an io manager already; on Windows: it starts a thread which fulfills aysynchronous IO request (throuh IO completion port). `withIOManager` is used when an application starts and it must be called only once, so the best place to start is at the very begining of `main`. --- cardano-node/app/cardano-cli.hs | 5 +- cardano-node/app/chairman.hs | 6 +- .../Cardano/CLI/Benchmarking/Tx/Generation.hs | 28 ++++++-- .../Cardano/CLI/Benchmarking/Tx/NodeToNode.hs | 9 ++- cardano-node/src/Cardano/CLI/Run.hs | 68 +++++++++++-------- cardano-node/src/Cardano/CLI/Tx.hs | 8 ++- cardano-node/src/Cardano/Chairman.hs | 10 ++- cardano-node/src/Cardano/Node/Submission.hs | 8 ++- 8 files changed, 93 insertions(+), 49 deletions(-) diff --git a/cardano-node/app/cardano-cli.hs b/cardano-node/app/cardano-cli.hs index 7d6b517d621..503ab5c09ca 100644 --- a/cardano-node/app/cardano-cli.hs +++ b/cardano-node/app/cardano-cli.hs @@ -13,12 +13,13 @@ import Cardano.CLI.Parsers import Cardano.CLI.Run import Cardano.Common.TopHandler + main :: IO () -main = toplevelExceptionHandler $ do +main = toplevelExceptionHandler $ withIOManager $ \iocp -> do co <- Opt.customExecParser pref opts - cmdRes <- runExceptT . runCommand $ mainCommand co + cmdRes <- runExceptT . runCommand iocp $ mainCommand co case cmdRes of Right _ -> pure () diff --git a/cardano-node/app/chairman.hs b/cardano-node/app/chairman.hs index 4271bf560a8..89a0e0c3334 100644 --- a/cardano-node/app/chairman.hs +++ b/cardano-node/app/chairman.hs @@ -15,6 +15,7 @@ import Control.Monad.Trans.Except.Extra (runExceptT) import Control.Tracer (stdoutTracer) import Ouroboros.Network.Block (BlockNo) +import Ouroboros.Network.NodeToClient (withIOManager) import Ouroboros.Consensus.Protocol.Abstract (SecurityParam (..)) import Cardano.Config.CommonCLI @@ -27,7 +28,7 @@ import Cardano.Common.Parsers import Cardano.Chairman (runChairman) main :: IO () -main = do +main = withIOManager $ \iocp -> do ChairmanArgs { caSecurityParam , caMaxBlockNo , caTimeout @@ -58,7 +59,8 @@ main = do Left err -> do putTextLn $ renderPtclInstantiationErr err exitFailure - let run = runChairman p + let run = runChairman iocp + p caSecurityParam caMaxBlockNo caSocketPaths diff --git a/cardano-node/src/Cardano/CLI/Benchmarking/Tx/Generation.hs b/cardano-node/src/Cardano/CLI/Benchmarking/Tx/Generation.hs index c17cd744790..85de212f925 100644 --- a/cardano-node/src/Cardano/CLI/Benchmarking/Tx/Generation.hs +++ b/cardano-node/src/Cardano/CLI/Benchmarking/Tx/Generation.hs @@ -83,6 +83,8 @@ import Cardano.CLI.Benchmarking.Tx.NodeToNode (BenchmarkTxSubmitTracer import Cardano.Node.TxSubClient import Control.Tracer (Tracer, traceWith) +import Ouroboros.Network.NodeToClient (AssociateWithIOCP) + import Ouroboros.Consensus.Node.Run (RunNode) import Ouroboros.Consensus.Block(BlockProtocol) import Ouroboros.Consensus.Node.ProtocolInfo (ProtocolInfo (..)) @@ -143,6 +145,7 @@ newtype ExplorerAPIEnpoint = ----------------------------------------------------------------------------------------- genesisBenchmarkRunner :: LoggingLayer + -> AssociateWithIOCP -> SocketPath -> Consensus.Protocol ByronBlock -> NonEmpty NodeAddress @@ -156,6 +159,7 @@ genesisBenchmarkRunner -> [FilePath] -> ExceptT TxGenError IO () genesisBenchmarkRunner loggingLayer + iocp socketFp protocol@(Consensus.ProtocolRealPBFT genesisConfig _ _ _ _) targetNodeAddresses @@ -201,6 +205,7 @@ genesisBenchmarkRunner loggingLayer fundsWithGenesisMoney <- liftIO $ prepareInitialFunds benchTracer lowLevelSubmitTracer + iocp socketFp genesisConfig pInfoConfig @@ -219,6 +224,7 @@ genesisBenchmarkRunner loggingLayer connectTracer submitTracer lowLevelSubmitTracer + iocp socketFp pInfoConfig sourceKey @@ -389,6 +395,7 @@ extractGenesisFunds genesisConfig signingKeys = prepareInitialFunds :: Tracer IO (TraceBenchTxSubmit (Mempool.GenTxId ByronBlock)) -> Tracer IO TraceLowLevelSubmit + -> AssociateWithIOCP -> SocketPath -> CC.Genesis.Config -> NodeConfig ByronConsensusProtocol @@ -400,6 +407,7 @@ prepareInitialFunds -> IO AvailableFunds prepareInitialFunds benchTracer llTracer + iocp socketFp genesisConfig pInfoConfig @@ -428,7 +436,7 @@ prepareInitialFunds benchTracer Nothing -> do -- There's no Explorer's API endpoint specified, submit genesis -- transaction to the target nodes via 'ouroboros-network'. - submitTx socketFp pInfoConfig genesisTxGeneral llTracer + submitTx iocp socketFp pInfoConfig genesisTxGeneral llTracer Just (ExplorerAPIEnpoint endpoint) -> do -- Explorer's API endpoint is specified, submit genesis -- transaction to that endpoint using POST-request. @@ -633,6 +641,7 @@ runBenchmark -> Tracer IO SendRecvConnect -> Tracer IO (SendRecvTxSubmission ByronBlock) -> Tracer IO TraceLowLevelSubmit + -> AssociateWithIOCP -> SocketPath -> NodeConfig ByronConsensusProtocol -> Crypto.SigningKey @@ -651,6 +660,7 @@ runBenchmark benchTracer connectTracer submitTracer lowLevelSubmitTracer + iocp socketFp pInfoConfig sourceKey @@ -669,6 +679,7 @@ runBenchmark benchTracer fundsWithSufficientCoins <- createMoreFundCoins benchTracer lowLevelSubmitTracer + iocp socketFp pInfoConfig sourceKey @@ -766,6 +777,7 @@ runBenchmark benchTracer launchTxPeer benchTracer benchmarkTracers + iocp txSubmissionTerm pInfoConfig localAddr @@ -824,6 +836,7 @@ postTx benchTracer initialRequest serializedTx = do createMoreFundCoins :: Tracer IO (TraceBenchTxSubmit (Mempool.GenTxId ByronBlock)) -> Tracer IO TraceLowLevelSubmit + -> AssociateWithIOCP -> SocketPath -> NodeConfig ByronConsensusProtocol -> Crypto.SigningKey @@ -835,6 +848,7 @@ createMoreFundCoins -> ExceptT TxGenError IO AvailableFunds createMoreFundCoins benchTracer llTracer + iocp socketFp pInfoConfig sourceKey @@ -884,7 +898,7 @@ createMoreFundCoins benchTracer liftIO $ forM_ splittingTxs $ \(txAux, _) -> do let splittingTxGeneral :: GenTx ByronBlock splittingTxGeneral = normalByronTxToGenTx txAux - submitTx socketFp pInfoConfig splittingTxGeneral llTracer + submitTx iocp socketFp pInfoConfig splittingTxGeneral llTracer Just (ExplorerAPIEnpoint endpoint) -> do -- Explorer's API endpoint is specified, submit splitting -- transactions to that endpoint using POST-request. @@ -1145,7 +1159,9 @@ writeTxsInListForTargetNode txsListsForTargetNodes txs listIndex = STM.atomicall -- | To get higher performance we need to hide latency of getting and -- forwarding (in sufficient numbers) transactions. - +-- +-- TODO: transform comments into haddocks. +-- launchTxPeer :: forall m block txid tx. ( RunNode block @@ -1159,6 +1175,8 @@ launchTxPeer -- tracer for lower level connection and details of -- protocol interactisn, intended for debugging -- associated issues. + -> AssociateWithIOCP + -- ^ associate a file descriptor with IO completion port -> MSTM.TVar m Bool -- a "global" stop variable, set to True to force shutdown -> NodeConfig (Ouroboros.Consensus.Block.BlockProtocol block) @@ -1174,7 +1192,7 @@ launchTxPeer -- give this peer 1 or more transactions, empty list -- signifies stop this peer -> m (Async (), Async ()) -launchTxPeer tr1 tr2 termTM nc localAddr remoteAddr updROEnv txInChan = do +launchTxPeer tr1 tr2 iocp termTM nc localAddr remoteAddr updROEnv txInChan = do tmv <- MSTM.newEmptyTMVarM - (,) <$> (async $ benchmarkConnectTxSubmit tr2 nc localAddr remoteAddr (txSubmissionClient tmv)) + (,) <$> (async $ benchmarkConnectTxSubmit iocp tr2 nc localAddr remoteAddr (txSubmissionClient tmv)) <*> (async $ bulkSubmission updROEnv tr1 termTM txInChan tmv) diff --git a/cardano-node/src/Cardano/CLI/Benchmarking/Tx/NodeToNode.hs b/cardano-node/src/Cardano/CLI/Benchmarking/Tx/NodeToNode.hs index 3b933eac670..b698440e3a9 100644 --- a/cardano-node/src/Cardano/CLI/Benchmarking/Tx/NodeToNode.hs +++ b/cardano-node/src/Cardano/CLI/Benchmarking/Tx/NodeToNode.hs @@ -51,6 +51,9 @@ import Ouroboros.Consensus.Protocol.Abstract (NodeConfig) import Ouroboros.Network.Mux (OuroborosApplication(..)) import Ouroboros.Network.NodeToNode (NetworkConnectTracers (..)) import qualified Ouroboros.Network.NodeToNode as NtN +-- TODO: #1685 (ouroboros-network) IO manager terms and types should be exported +-- from NodeToNode module as well. +import Ouroboros.Network.NodeToClient (AssociateWithIOCP) import Ouroboros.Network.Protocol.BlockFetch.Client (BlockFetchClient(..), blockFetchClientPeer) import Ouroboros.Network.Protocol.ChainSync.Client (chainSyncClientNull, chainSyncClientPeer) import Ouroboros.Network.Protocol.Handshake.Type (Handshake) @@ -58,7 +61,6 @@ import Ouroboros.Network.Protocol.Handshake.Version (Versions, simpleS import Ouroboros.Network.Protocol.TxSubmission.Client (TxSubmissionClient, txSubmissionClientPeer) import qualified Ouroboros.Network.Protocol.TxSubmission.Type as TS import Ouroboros.Network.Snocket (socketSnocket) -import Ouroboros.Network.IOManager (withIOManager) type SendRecvConnect = WithMuxBearer NtN.RemoteConnectionId @@ -192,7 +194,8 @@ data BenchmarkTxSubmitTracers m blk = BenchmarkTracers benchmarkConnectTxSubmit :: forall m blk . (RunNode blk, m ~ IO) - => BenchmarkTxSubmitTracers m blk + => AssociateWithIOCP + -> BenchmarkTxSubmitTracers m blk -- ^ For tracing the send/receive actions -> NodeConfig (BlockProtocol blk) -- ^ The particular block protocol @@ -203,7 +206,7 @@ benchmarkConnectTxSubmit -> TxSubmissionClient (GenTxId blk) (GenTx blk) m () -- ^ the particular txSubmission peer -> m () -benchmarkConnectTxSubmit trs nc localAddr remoteAddr myTxSubClient = withIOManager $ \iocp -> do +benchmarkConnectTxSubmit iocp trs nc localAddr remoteAddr myTxSubClient = do NtN.connectTo (socketSnocket iocp) NetworkConnectTracers { diff --git a/cardano-node/src/Cardano/CLI/Run.hs b/cardano-node/src/Cardano/CLI/Run.hs index d30f817c30c..0e2503257fe 100644 --- a/cardano-node/src/Cardano/CLI/Run.hs +++ b/cardano-node/src/Cardano/CLI/Run.hs @@ -26,6 +26,10 @@ module Cardano.CLI.Run ( , TPSRate(..) , TxAdditionalSize(..) , ExplorerAPIEnpoint(..) + + -- * re-exports from Ouroboros-Network + , AssociateWithIOCP + , withIOManager ) where import Cardano.Prelude hiding (option, trace) @@ -53,6 +57,10 @@ import Cardano.Crypto (ProtocolMagicId, RequiresNetworkMagic(..)) import qualified Cardano.Crypto.Hashing as Crypto import qualified Cardano.Crypto.Signing as Crypto +import Ouroboros.Network.NodeToClient ( AssociateWithIOCP + , withIOManager + ) + import qualified Ouroboros.Consensus.Cardano as Consensus import Cardano.CLI.Delegation @@ -192,23 +200,23 @@ data ClientCommand [SigningKeyFile] deriving Show -runCommand :: ClientCommand -> ExceptT CliError IO () -runCommand (Genesis outDir params ptcl) = do +runCommand :: AssociateWithIOCP -> ClientCommand -> ExceptT CliError IO () +runCommand _iocp (Genesis outDir params ptcl) = do gen <- mkGenesis params dumpGenesis ptcl outDir `uncurry` gen -runCommand (GetLocalNodeTip configFp gFile sockPath) = do +runCommand _iocp (GetLocalNodeTip configFp gFile sockPath) = do liftIO $ getLocalTip configFp gFile sockPath -runCommand (PrettySigningKeyPublic ptcl skF) = do +runCommand _iocp (PrettySigningKeyPublic ptcl skF) = do sK <- readSigningKey ptcl skF liftIO . putTextLn . prettyPublicKey $ Crypto.toVerification sK -runCommand (MigrateDelegateKeyFrom oldPtcl oldKey newPtcl (NewSigningKeyFile newKey)) = do +runCommand _iocp (MigrateDelegateKeyFrom oldPtcl oldKey newPtcl (NewSigningKeyFile newKey)) = do sk <- readSigningKey oldPtcl oldKey sDk <- hoistEither $ serialiseDelegateKey newPtcl sk liftIO $ ensureNewFileLBS newKey sDk -runCommand (PrintGenesisHash genFp) = do +runCommand _iocp (PrintGenesisHash genFp) = do eGen <- readGenesis genFp let formatter :: (a, Genesis.GenesisHash)-> Text @@ -216,23 +224,23 @@ runCommand (PrintGenesisHash genFp) = do liftIO . putTextLn $ formatter eGen -runCommand (PrintSigningKeyAddress ptcl netMagic skF) = do +runCommand _iocp (PrintSigningKeyAddress ptcl netMagic skF) = do sK <- readSigningKey ptcl skF let sKeyAddress = prettyAddress . Common.makeVerKeyAddress netMagic $ Crypto.toVerification sK liftIO $ putTextLn sKeyAddress -runCommand (Keygen ptcl (NewSigningKeyFile skF) passReq) = do +runCommand _iocp (Keygen ptcl (NewSigningKeyFile skF) passReq) = do pPhrase <- liftIO $ getPassphrase ("Enter password to encrypt '" <> skF <> "': ") passReq sK <- liftIO $ keygen pPhrase serDk <- hoistEither $ serialiseDelegateKey ptcl sK liftIO $ ensureNewFileLBS skF serDk -runCommand (ToVerification ptcl skFp (NewVerificationKeyFile vkFp)) = do +runCommand _iocp (ToVerification ptcl skFp (NewVerificationKeyFile vkFp)) = do sk <- readSigningKey ptcl skFp let vKey = Builder.toLazyText . Crypto.formatFullVerificationKey $ Crypto.toVerification sk liftIO $ ensureNewFile TL.writeFile vkFp vKey -runCommand (IssueDelegationCertificate ptcl magic epoch issuerSK delegateVK cert) = do +runCommand _iocp (IssueDelegationCertificate ptcl magic epoch issuerSK delegateVK cert) = do vk <- readVerificationKey delegateVK sk <- readSigningKey ptcl issuerSK let byGenDelCert :: Delegation.Certificate @@ -240,12 +248,12 @@ runCommand (IssueDelegationCertificate ptcl magic epoch issuerSK delegateVK cert sCert <- hoistEither $ serialiseDelegationCert ptcl byGenDelCert liftIO $ ensureNewFileLBS (nFp cert) sCert -runCommand (CheckDelegation magic cert issuerVF delegateVF) = do +runCommand _iocp (CheckDelegation magic cert issuerVF delegateVF) = do issuerVK <- readVerificationKey issuerVF delegateVK <- readVerificationKey delegateVF liftIO $ checkByronGenesisDelegation cert magic issuerVK delegateVK -runCommand (SubmitTx fp ptcl genFile socketPath) = do +runCommand iocp (SubmitTx fp ptcl genFile socketPath) = do -- Default update value let update = Update (ApplicationName "cardano-sl") 1 $ LastKnownBlockVersion 0 2 0 tx <- liftIO $ readByronTx fp @@ -254,6 +262,7 @@ runCommand (SubmitTx fp ptcl genFile socketPath) = do firstExceptT NodeSubmitTxError $ nodeSubmitTx + iocp genHash Nothing genFile @@ -265,7 +274,7 @@ runCommand (SubmitTx fp ptcl genFile socketPath) = do update ptcl tx -runCommand (SpendGenesisUTxO ptcl genFile (NewTxFile ctTx) ctKey genRichAddr outs) = do +runCommand _iocp (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 @@ -287,7 +296,7 @@ runCommand (SpendGenesisUTxO ptcl genFile (NewTxFile ctTx) ctKey genRichAddr out sk liftIO . ensureNewFileLBS ctTx $ toCborTxAux tx -runCommand (SpendUTxO ptcl genFile (NewTxFile ctTx) ctKey ins outs) = do +runCommand _iocp (SpendUTxO ptcl genFile (NewTxFile ctTx) ctKey ins outs) = do sk <- readSigningKey ptcl ctKey -- Default update value let update = Update (ApplicationName "cardano-sl") 1 $ LastKnownBlockVersion 0 2 0 @@ -310,21 +319,21 @@ runCommand (SpendUTxO ptcl genFile (NewTxFile ctTx) ctKey ins outs) = do sk liftIO . ensureNewFileLBS ctTx $ toCborTxAux gTx -runCommand (GenerateTxs - logConfigFp - signingKey - delegCert - genFile - socketFp - targetNodeAddresses - numOfTxs - numOfInsPerTx - numOfOutsPerTx - feePerTx - tps - txAdditionalSize - explorerAPIEndpoint - sigKeysFiles) = do +runCommand iocp (GenerateTxs + logConfigFp + signingKey + delegCert + genFile + socketFp + targetNodeAddresses + numOfTxs + numOfInsPerTx + numOfOutsPerTx + feePerTx + tps + txAdditionalSize + explorerAPIEndpoint + sigKeysFiles) = do -- Default update value let update = Update (ApplicationName "cardano-sl") 1 $ LastKnownBlockVersion 0 2 0 nc <- liftIO $ parseNodeConfigurationFP logConfigFp @@ -352,6 +361,7 @@ runCommand (GenerateTxs firstExceptT GenesisBenchmarkRunnerError $ genesisBenchmarkRunner loggingLayer + iocp socketFp protocol targetNodeAddresses diff --git a/cardano-node/src/Cardano/CLI/Tx.hs b/cardano-node/src/Cardano/CLI/Tx.hs index 8bd502a0038..70bb4dd78b0 100644 --- a/cardano-node/src/Cardano/CLI/Tx.hs +++ b/cardano-node/src/Cardano/CLI/Tx.hs @@ -48,6 +48,8 @@ import Cardano.Crypto (SigningKey(..), ProtocolMagicId, RequiresNetwor import qualified Cardano.Crypto.Hashing as Crypto import qualified Cardano.Crypto.Signing as Crypto +import Ouroboros.Network.NodeToClient (AssociateWithIOCP) + import qualified Ouroboros.Consensus.Byron.Ledger as Byron import Ouroboros.Consensus.Byron.Ledger (GenTx(..), ByronBlock) import qualified Ouroboros.Consensus.Cardano as Consensus @@ -246,7 +248,8 @@ issueUTxOExpenditure -- | Submit a transaction to a node specified by topology info. nodeSubmitTx - :: Text + :: AssociateWithIOCP + -> Text -- ^ Genesis hash. -> Maybe Int -- ^ Number of core nodes. @@ -261,6 +264,7 @@ nodeSubmitTx -> GenTx ByronBlock -> ExceptT RealPBFTError IO () nodeSubmitTx + iocp gHash _mNumCoreNodes genFile @@ -276,7 +280,7 @@ nodeSubmitTx \p@Consensus.ProtocolRealPBFT{} -> liftIO $ do -- TODO: Update submitGenTx to use `ExceptT` traceWith stdoutTracer ("TxId: " ++ condense (Consensus.txId gentx)) - submitTx targetSocketFp + submitTx iocp targetSocketFp (pInfoConfig (Consensus.protocolInfo p)) gentx nullTracer -- stdoutTracer diff --git a/cardano-node/src/Cardano/Chairman.hs b/cardano-node/src/Cardano/Chairman.hs index 363d390a1b4..0c6543a4dfe 100644 --- a/cardano-node/src/Cardano/Chairman.hs +++ b/cardano-node/src/Cardano/Chairman.hs @@ -74,7 +74,8 @@ runChairman :: forall blk. ( RunNode blk , TraceConstraints blk ) - => Protocol blk + => AssociateWithIOCP + -> Protocol blk -> SecurityParam -- ^ security parameter, if a fork is deeper than it 'runChairman' -- will throw an exception. @@ -84,7 +85,7 @@ runChairman :: forall blk. -- ^ local socket dir -> Tracer IO String -> IO () -runChairman ptcl securityParam maxBlockNo socketPaths tracer = do +runChairman iocp ptcl securityParam maxBlockNo socketPaths tracer = do (chainsVar :: ChainsVar IO blk) <- newTVarM (Map.fromList $ map (\socketPath -> (socketPath, AF.Empty AF.AnchorGenesis)) socketPaths) @@ -98,6 +99,7 @@ runChairman ptcl securityParam maxBlockNo socketPaths tracer = do maxBlockNo tracer pInfoConfig + iocp sockPath -- catch 'MuxError'; it will be thrown if a node shuts down closing the @@ -124,6 +126,7 @@ createConnection -> Maybe BlockNo -> Tracer IO String -> NodeConfig (BlockProtocol blk) + -> AssociateWithIOCP -> SocketPath -> IO () createConnection @@ -132,7 +135,8 @@ createConnection maxBlockNo tracer pInfoConfig - socketPath = withIOManager $ \iocp -> do + iocp + socketPath = do path <- localSocketPath socketPath connectTo (socketSnocket iocp) diff --git a/cardano-node/src/Cardano/Node/Submission.hs b/cardano-node/src/Cardano/Node/Submission.hs index 6a9cbe28d53..39dbcbe1a89 100644 --- a/cardano-node/src/Cardano/Node/Submission.hs +++ b/cardano-node/src/Cardano/Node/Submission.hs @@ -45,7 +45,8 @@ import Ouroboros.Network.Protocol.ChainSync.Client (chainSyncClientPee import Ouroboros.Network.Protocol.ChainSync.Codec (codecChainSync) import Ouroboros.Network.Protocol.Handshake.Version ( Versions , simpleSingletonVersions) -import Ouroboros.Network.NodeToClient (NetworkConnectTracers (..)) +import Ouroboros.Network.NodeToClient ( AssociateWithIOCP + , NetworkConnectTracers (..)) import qualified Ouroboros.Network.NodeToClient as NodeToClient import Ouroboros.Network.Snocket (socketSnocket) @@ -102,12 +103,13 @@ instance (MonadIO m) => Transformable Text m TraceLowLevelSubmit where submitTx :: ( RunNode blk , Show (ApplyTxErr blk) ) - => SocketPath + => AssociateWithIOCP + -> SocketPath -> NodeConfig (BlockProtocol blk) -> GenTx blk -> Tracer IO TraceLowLevelSubmit -> IO () -submitTx targetSocketFp protoInfoConfig tx tracer = NodeToClient.withIOManager $ \iocp -> do +submitTx iocp targetSocketFp protoInfoConfig tx tracer = do targetSocketFp' <- localSocketPath targetSocketFp NodeToClient.connectTo (socketSnocket iocp) From 7501e84ca4ad445858b22e01173189fd0c83dce1 Mon Sep 17 00:00:00 2001 From: Thomas Winant Date: Tue, 25 Feb 2020 12:16:44 +0100 Subject: [PATCH 3/6] Add Win32-network dependency --- cabal.project | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/cabal.project b/cabal.project index fbd256df921..0bf819384ee 100644 --- a/cabal.project +++ b/cabal.project @@ -271,6 +271,13 @@ source-repository-package --sha256: 11hsa5b218cbkq0wb7hc9x7m5mp56dlfw4zx4q9i4ymyq82ra69c subdir: io-sim-classes +source-repository-package + type: git + location: https://github.com/input-output-hk/ouroboros-network + tag: 68ebc7b8c53078629dd57fd579eece12c66576c8 + --sha256: 11hsa5b218cbkq0wb7hc9x7m5mp56dlfw4zx4q9i4ymyq82ra69c + subdir: Win32-network + source-repository-package type: git location: http://github.com/well-typed/canonical-json From 751296f9910c55deff709cca9be54f138f868de6 Mon Sep 17 00:00:00 2001 From: Marcin Szamotulski Date: Wed, 26 Feb 2020 11:31:55 +0100 Subject: [PATCH 4/6] call withIOManager within runCommnad --- cardano-node/app/cardano-cli.hs | 4 +- cardano-node/src/Cardano/CLI/Run.hs | 105 +++++++++++++++------------- 2 files changed, 57 insertions(+), 52 deletions(-) diff --git a/cardano-node/app/cardano-cli.hs b/cardano-node/app/cardano-cli.hs index 503ab5c09ca..c01c4c2e398 100644 --- a/cardano-node/app/cardano-cli.hs +++ b/cardano-node/app/cardano-cli.hs @@ -15,11 +15,11 @@ import Cardano.Common.TopHandler main :: IO () -main = toplevelExceptionHandler $ withIOManager $ \iocp -> do +main = toplevelExceptionHandler $ do co <- Opt.customExecParser pref opts - cmdRes <- runExceptT . runCommand iocp $ mainCommand co + cmdRes <- runExceptT . runCommand $ mainCommand co case cmdRes of Right _ -> pure () diff --git a/cardano-node/src/Cardano/CLI/Run.hs b/cardano-node/src/Cardano/CLI/Run.hs index 0e2503257fe..2dd4efeecf9 100644 --- a/cardano-node/src/Cardano/CLI/Run.hs +++ b/cardano-node/src/Cardano/CLI/Run.hs @@ -200,23 +200,25 @@ data ClientCommand [SigningKeyFile] deriving Show -runCommand :: AssociateWithIOCP -> ClientCommand -> ExceptT CliError IO () -runCommand _iocp (Genesis outDir params ptcl) = do + + +runCommand :: ClientCommand -> ExceptT CliError IO () +runCommand (Genesis outDir params ptcl) = do gen <- mkGenesis params dumpGenesis ptcl outDir `uncurry` gen -runCommand _iocp (GetLocalNodeTip configFp gFile sockPath) = do +runCommand (GetLocalNodeTip configFp gFile sockPath) = do liftIO $ getLocalTip configFp gFile sockPath -runCommand _iocp (PrettySigningKeyPublic ptcl skF) = do +runCommand (PrettySigningKeyPublic ptcl skF) = do sK <- readSigningKey ptcl skF liftIO . putTextLn . prettyPublicKey $ Crypto.toVerification sK -runCommand _iocp (MigrateDelegateKeyFrom oldPtcl oldKey newPtcl (NewSigningKeyFile newKey)) = do +runCommand (MigrateDelegateKeyFrom oldPtcl oldKey newPtcl (NewSigningKeyFile newKey)) = do sk <- readSigningKey oldPtcl oldKey sDk <- hoistEither $ serialiseDelegateKey newPtcl sk liftIO $ ensureNewFileLBS newKey sDk -runCommand _iocp (PrintGenesisHash genFp) = do +runCommand (PrintGenesisHash genFp) = do eGen <- readGenesis genFp let formatter :: (a, Genesis.GenesisHash)-> Text @@ -224,23 +226,23 @@ runCommand _iocp (PrintGenesisHash genFp) = do liftIO . putTextLn $ formatter eGen -runCommand _iocp (PrintSigningKeyAddress ptcl netMagic skF) = do +runCommand (PrintSigningKeyAddress ptcl netMagic skF) = do sK <- readSigningKey ptcl skF let sKeyAddress = prettyAddress . Common.makeVerKeyAddress netMagic $ Crypto.toVerification sK liftIO $ putTextLn sKeyAddress -runCommand _iocp (Keygen ptcl (NewSigningKeyFile skF) passReq) = do +runCommand (Keygen ptcl (NewSigningKeyFile skF) passReq) = do pPhrase <- liftIO $ getPassphrase ("Enter password to encrypt '" <> skF <> "': ") passReq sK <- liftIO $ keygen pPhrase serDk <- hoistEither $ serialiseDelegateKey ptcl sK liftIO $ ensureNewFileLBS skF serDk -runCommand _iocp (ToVerification ptcl skFp (NewVerificationKeyFile vkFp)) = do +runCommand (ToVerification ptcl skFp (NewVerificationKeyFile vkFp)) = do sk <- readSigningKey ptcl skFp let vKey = Builder.toLazyText . Crypto.formatFullVerificationKey $ Crypto.toVerification sk liftIO $ ensureNewFile TL.writeFile vkFp vKey -runCommand _iocp (IssueDelegationCertificate ptcl magic epoch issuerSK delegateVK cert) = do +runCommand (IssueDelegationCertificate ptcl magic epoch issuerSK delegateVK cert) = do vk <- readVerificationKey delegateVK sk <- readSigningKey ptcl issuerSK let byGenDelCert :: Delegation.Certificate @@ -248,12 +250,12 @@ runCommand _iocp (IssueDelegationCertificate ptcl magic epoch issuerSK delegateV sCert <- hoistEither $ serialiseDelegationCert ptcl byGenDelCert liftIO $ ensureNewFileLBS (nFp cert) sCert -runCommand _iocp (CheckDelegation magic cert issuerVF delegateVF) = do +runCommand (CheckDelegation magic cert issuerVF delegateVF) = do issuerVK <- readVerificationKey issuerVF delegateVK <- readVerificationKey delegateVF liftIO $ checkByronGenesisDelegation cert magic issuerVK delegateVK -runCommand iocp (SubmitTx fp ptcl genFile socketPath) = do +runCommand (SubmitTx fp ptcl genFile socketPath) = withIOManagerE $ \iocp -> do -- Default update value let update = Update (ApplicationName "cardano-sl") 1 $ LastKnownBlockVersion 0 2 0 tx <- liftIO $ readByronTx fp @@ -274,29 +276,29 @@ runCommand iocp (SubmitTx fp ptcl genFile socketPath) = do update ptcl tx -runCommand _iocp (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 - liftIO . ensureNewFileLBS ctTx $ toCborTxAux tx - -runCommand _iocp (SpendUTxO ptcl genFile (NewTxFile ctTx) ctKey ins outs) = do +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 + liftIO . ensureNewFileLBS ctTx $ toCborTxAux tx + +runCommand (SpendUTxO ptcl genFile (NewTxFile ctTx) ctKey ins outs) = do sk <- readSigningKey ptcl ctKey -- Default update value let update = Update (ApplicationName "cardano-sl") 1 $ LastKnownBlockVersion 0 2 0 @@ -319,21 +321,21 @@ runCommand _iocp (SpendUTxO ptcl genFile (NewTxFile ctTx) ctKey ins outs) = do sk liftIO . ensureNewFileLBS ctTx $ toCborTxAux gTx -runCommand iocp (GenerateTxs - logConfigFp - signingKey - delegCert - genFile - socketFp - targetNodeAddresses - numOfTxs - numOfInsPerTx - numOfOutsPerTx - feePerTx - tps - txAdditionalSize - explorerAPIEndpoint - sigKeysFiles) = do +runCommand (GenerateTxs + logConfigFp + signingKey + delegCert + genFile + socketFp + targetNodeAddresses + numOfTxs + numOfInsPerTx + numOfOutsPerTx + feePerTx + tps + txAdditionalSize + explorerAPIEndpoint + sigKeysFiles) = withIOManagerE $ \iocp -> do -- Default update value let update = Update (ApplicationName "cardano-sl") 1 $ LastKnownBlockVersion 0 2 0 nc <- liftIO $ parseNodeConfigurationFP logConfigFp @@ -390,3 +392,6 @@ ensureNewFile writer outFile blob = do ensureNewFileLBS :: FilePath -> LB.ByteString -> IO () ensureNewFileLBS = ensureNewFile LB.writeFile + +withIOManagerE :: (AssociateWithIOCP -> ExceptT e IO a) -> ExceptT e IO a +withIOManagerE k = ExceptT $ withIOManager (runExceptT . k) From 91cd6ac28411ae0f094fe86fc4a40bdbd39a94f9 Mon Sep 17 00:00:00 2001 From: Luke Nadur <19835357+intricate@users.noreply.github.com> Date: Wed, 26 Feb 2020 11:10:17 -0600 Subject: [PATCH 5/6] Make changes required after rebase --- cardano-node/src/Cardano/CLI/Ops.hs | 23 +++++++++++++---------- cardano-node/src/Cardano/CLI/Run.hs | 5 ++--- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/cardano-node/src/Cardano/CLI/Ops.hs b/cardano-node/src/Cardano/CLI/Ops.hs index 260eec9a69e..088225dc460 100644 --- a/cardano-node/src/Cardano/CLI/Ops.hs +++ b/cardano-node/src/Cardano/CLI/Ops.hs @@ -54,7 +54,7 @@ import Ouroboros.Consensus.Mempool.API (ApplyTxErr) import Ouroboros.Consensus.NodeNetwork (ProtocolCodecs(..), protocolCodecs) import Ouroboros.Consensus.Node.NetworkProtocolVersion (NodeToClientVersion, mostRecentNetworkProtocolVersion) -import Ouroboros.Consensus.Node.ProtocolInfo (ProtocolInfo(..), protocolInfo) +import Ouroboros.Consensus.Node.ProtocolInfo (ProtocolInfo(..)) import Ouroboros.Consensus.Node.Run (RunNode(..)) import Ouroboros.Consensus.Util.Condense (Condense(..)) @@ -64,9 +64,9 @@ import Ouroboros.Network.Codec (Codec) import Ouroboros.Network.Mux (AppType(InitiatorApp), OuroborosApplication(..)) import Ouroboros.Network.NodeToClient - (NetworkConnectTracers(..), NodeToClientProtocols(..), NodeToClientVersionData(..) - , NodeToClientVersion(NodeToClientV_1), connectTo, localTxSubmissionClientNull - , nodeToClientCodecCBORTerm) + (AssociateWithIOCP, NetworkConnectTracers(..), NodeToClientProtocols(..) + , NodeToClientVersionData(..), NodeToClientVersion(NodeToClientV_1), connectTo + , localTxSubmissionClientNull, nodeToClientCodecCBORTerm) import Ouroboros.Network.Protocol.ChainSync.Client (ChainSyncClient(..), ClientStIdle(..), ClientStNext(..) , chainSyncClientPeer, recvMsgRollForward) @@ -77,6 +77,7 @@ import Ouroboros.Network.Protocol.LocalTxSubmission.Type (LocalTxSubmission) import Ouroboros.Network.Protocol.LocalTxSubmission.Client (localTxSubmissionClientPeer) +import Ouroboros.Network.Snocket (socketSnocket) import Cardano.Common.LocalSocket import Cardano.Config.Protocol @@ -274,9 +275,10 @@ withRealPBFT gHash genFile nMagic sigThresh delCertFp sKeyFp update ptcl action getLocalTip :: ConfigYamlFilePath -> GenesisFile + -> AssociateWithIOCP -> SocketPath -> IO () -getLocalTip configFp genFp sockPath = do +getLocalTip configFp genFp iocp sockPath = do nc <- parseNodeConfigurationFP $ unConfigPath configFp eGenHash <- runExceptT $ getGenesisHash genFp @@ -304,22 +306,23 @@ getLocalTip configFp genFp sockPath = do Left err -> do putTextLn . toS $ show err exitFailure - createNodeConnection (Proxy) p sockPath + createNodeConnection (Proxy) p iocp sockPath createNodeConnection :: forall blk . (Condense (HeaderHash blk), RunNode blk) => Proxy blk -> Consensus.Protocol blk + -> AssociateWithIOCP -> SocketPath -> IO () -createNodeConnection proxy ptcl socketPath = do - addr <- localSocketAddrInfo socketPath - let ProtocolInfo{pInfoConfig} = protocolInfo ptcl +createNodeConnection proxy ptcl iocp socketPath = do + addr <- localSocketPath socketPath + let ProtocolInfo{pInfoConfig} = Consensus.protocolInfo ptcl connectTo + (socketSnocket iocp) (NetworkConnectTracers nullTracer nullTracer) (localInitiatorNetworkApplication proxy pInfoConfig) - Nothing addr `catch` handleMuxError diff --git a/cardano-node/src/Cardano/CLI/Run.hs b/cardano-node/src/Cardano/CLI/Run.hs index 2dd4efeecf9..63d4f9e8468 100644 --- a/cardano-node/src/Cardano/CLI/Run.hs +++ b/cardano-node/src/Cardano/CLI/Run.hs @@ -201,14 +201,13 @@ data ClientCommand deriving Show - runCommand :: ClientCommand -> ExceptT CliError IO () runCommand (Genesis outDir params ptcl) = do gen <- mkGenesis params dumpGenesis ptcl outDir `uncurry` gen -runCommand (GetLocalNodeTip configFp gFile sockPath) = do - liftIO $ getLocalTip configFp gFile sockPath +runCommand (GetLocalNodeTip configFp gFile sockPath) = withIOManagerE $ \iocp -> + liftIO $ getLocalTip configFp gFile iocp sockPath runCommand (PrettySigningKeyPublic ptcl skF) = do sK <- readSigningKey ptcl skF From 94b440bb3c1cad246febf37c091784558ab423a5 Mon Sep 17 00:00:00 2001 From: Thomas Winant Date: Thu, 27 Feb 2020 08:41:45 +0100 Subject: [PATCH 6/6] Update the dependency on ouroboros-network again --- cabal.project | 52 +++++++++---------- cardano-config/src/Cardano/Config/Protocol.hs | 28 +++++----- .../Cardano/CLI/Benchmarking/Tx/Generation.hs | 28 +++++----- .../Cardano/CLI/Benchmarking/Tx/NodeToNode.hs | 11 ++-- cardano-node/src/Cardano/CLI/Ops.hs | 15 +++--- cardano-node/src/Cardano/Chairman.hs | 29 ++++++----- cardano-node/src/Cardano/Node/Run.hs | 7 +-- cardano-node/src/Cardano/Node/Submission.hs | 25 +++++---- cardano-node/src/Cardano/Node/TUI/LiveView.hs | 2 +- .../src/Cardano/Tracing/MicroBenchmarking.hs | 9 ++-- .../src/Cardano/Tracing/ToObjectOrphans.hs | 28 +++++----- cardano-node/src/Cardano/Tracing/Tracers.hs | 3 +- cardano-node/src/Cardano/Wallet/Client.hs | 23 ++++---- stack.yaml | 2 +- 14 files changed, 134 insertions(+), 128 deletions(-) diff --git a/cabal.project b/cabal.project index 0bf819384ee..2ac670b9e49 100644 --- a/cabal.project +++ b/cabal.project @@ -190,92 +190,92 @@ source-repository-package source-repository-package type: git location: https://github.com/input-output-hk/ouroboros-network - tag: 68ebc7b8c53078629dd57fd579eece12c66576c8 - --sha256: 11hsa5b218cbkq0wb7hc9x7m5mp56dlfw4zx4q9i4ymyq82ra69c + tag: 36861a97272de1e4de448925dd9bb9c0fddd80f6 + --sha256: 08jb0qj60i5dfsq17dyix3pdv05kg505n9kd7ps9j7dzl1p9pb2y subdir: ouroboros-network source-repository-package type: git location: https://github.com/input-output-hk/ouroboros-network - tag: 68ebc7b8c53078629dd57fd579eece12c66576c8 - --sha256: 11hsa5b218cbkq0wb7hc9x7m5mp56dlfw4zx4q9i4ymyq82ra69c + tag: 36861a97272de1e4de448925dd9bb9c0fddd80f6 + --sha256: 08jb0qj60i5dfsq17dyix3pdv05kg505n9kd7ps9j7dzl1p9pb2y subdir: io-sim source-repository-package type: git location: https://github.com/input-output-hk/ouroboros-network - tag: 68ebc7b8c53078629dd57fd579eece12c66576c8 - --sha256: 11hsa5b218cbkq0wb7hc9x7m5mp56dlfw4zx4q9i4ymyq82ra69c + tag: 36861a97272de1e4de448925dd9bb9c0fddd80f6 + --sha256: 08jb0qj60i5dfsq17dyix3pdv05kg505n9kd7ps9j7dzl1p9pb2y subdir: ouroboros-network-testing source-repository-package type: git location: https://github.com/input-output-hk/ouroboros-network - tag: 68ebc7b8c53078629dd57fd579eece12c66576c8 - --sha256: 11hsa5b218cbkq0wb7hc9x7m5mp56dlfw4zx4q9i4ymyq82ra69c + tag: 36861a97272de1e4de448925dd9bb9c0fddd80f6 + --sha256: 08jb0qj60i5dfsq17dyix3pdv05kg505n9kd7ps9j7dzl1p9pb2y subdir: ouroboros-consensus source-repository-package type: git location: https://github.com/input-output-hk/ouroboros-network - tag: 68ebc7b8c53078629dd57fd579eece12c66576c8 - --sha256: 11hsa5b218cbkq0wb7hc9x7m5mp56dlfw4zx4q9i4ymyq82ra69c + tag: 36861a97272de1e4de448925dd9bb9c0fddd80f6 + --sha256: 08jb0qj60i5dfsq17dyix3pdv05kg505n9kd7ps9j7dzl1p9pb2y subdir: ouroboros-consensus/ouroboros-consensus-mock source-repository-package type: git location: https://github.com/input-output-hk/ouroboros-network - tag: 68ebc7b8c53078629dd57fd579eece12c66576c8 - --sha256: 11hsa5b218cbkq0wb7hc9x7m5mp56dlfw4zx4q9i4ymyq82ra69c + tag: 36861a97272de1e4de448925dd9bb9c0fddd80f6 + --sha256: 08jb0qj60i5dfsq17dyix3pdv05kg505n9kd7ps9j7dzl1p9pb2y subdir: ouroboros-consensus-byron source-repository-package type: git location: https://github.com/input-output-hk/ouroboros-network - tag: 68ebc7b8c53078629dd57fd579eece12c66576c8 - --sha256: 11hsa5b218cbkq0wb7hc9x7m5mp56dlfw4zx4q9i4ymyq82ra69c + tag: 36861a97272de1e4de448925dd9bb9c0fddd80f6 + --sha256: 08jb0qj60i5dfsq17dyix3pdv05kg505n9kd7ps9j7dzl1p9pb2y subdir: ouroboros-consensus-cardano source-repository-package type: git location: https://github.com/input-output-hk/ouroboros-network - tag: 68ebc7b8c53078629dd57fd579eece12c66576c8 - --sha256: 11hsa5b218cbkq0wb7hc9x7m5mp56dlfw4zx4q9i4ymyq82ra69c + tag: 36861a97272de1e4de448925dd9bb9c0fddd80f6 + --sha256: 08jb0qj60i5dfsq17dyix3pdv05kg505n9kd7ps9j7dzl1p9pb2y subdir: typed-protocols source-repository-package type: git location: https://github.com/input-output-hk/ouroboros-network - tag: 68ebc7b8c53078629dd57fd579eece12c66576c8 - --sha256: 11hsa5b218cbkq0wb7hc9x7m5mp56dlfw4zx4q9i4ymyq82ra69c + tag: 36861a97272de1e4de448925dd9bb9c0fddd80f6 + --sha256: 08jb0qj60i5dfsq17dyix3pdv05kg505n9kd7ps9j7dzl1p9pb2y subdir: typed-protocols-examples source-repository-package type: git location: https://github.com/input-output-hk/ouroboros-network - tag: 68ebc7b8c53078629dd57fd579eece12c66576c8 - --sha256: 11hsa5b218cbkq0wb7hc9x7m5mp56dlfw4zx4q9i4ymyq82ra69c + tag: 36861a97272de1e4de448925dd9bb9c0fddd80f6 + --sha256: 08jb0qj60i5dfsq17dyix3pdv05kg505n9kd7ps9j7dzl1p9pb2y subdir: ouroboros-network-framework source-repository-package type: git location: https://github.com/input-output-hk/ouroboros-network - tag: 68ebc7b8c53078629dd57fd579eece12c66576c8 - --sha256: 11hsa5b218cbkq0wb7hc9x7m5mp56dlfw4zx4q9i4ymyq82ra69c + tag: 36861a97272de1e4de448925dd9bb9c0fddd80f6 + --sha256: 08jb0qj60i5dfsq17dyix3pdv05kg505n9kd7ps9j7dzl1p9pb2y subdir: network-mux source-repository-package type: git location: https://github.com/input-output-hk/ouroboros-network - tag: 68ebc7b8c53078629dd57fd579eece12c66576c8 - --sha256: 11hsa5b218cbkq0wb7hc9x7m5mp56dlfw4zx4q9i4ymyq82ra69c + tag: 36861a97272de1e4de448925dd9bb9c0fddd80f6 + --sha256: 08jb0qj60i5dfsq17dyix3pdv05kg505n9kd7ps9j7dzl1p9pb2y subdir: io-sim-classes source-repository-package type: git location: https://github.com/input-output-hk/ouroboros-network - tag: 68ebc7b8c53078629dd57fd579eece12c66576c8 - --sha256: 11hsa5b218cbkq0wb7hc9x7m5mp56dlfw4zx4q9i4ymyq82ra69c + tag: 36861a97272de1e4de448925dd9bb9c0fddd80f6 + --sha256: 08jb0qj60i5dfsq17dyix3pdv05kg505n9kd7ps9j7dzl1p9pb2y subdir: Win32-network source-repository-package diff --git a/cardano-config/src/Cardano/Config/Protocol.hs b/cardano-config/src/Cardano/Config/Protocol.hs index 863a05ed21c..68c4f25a38d 100644 --- a/cardano-config/src/Cardano/Config/Protocol.hs +++ b/cardano-config/src/Cardano/Config/Protocol.hs @@ -30,7 +30,7 @@ import qualified Cardano.Chain.Update as Update import Cardano.Crypto (RequiresNetworkMagic, decodeHash) import qualified Cardano.Crypto.Signing as Signing -import Ouroboros.Consensus.Block (Header) +import Ouroboros.Consensus.Block (Header, BlockProtocol) import Ouroboros.Consensus.BlockchainTime (SlotLength, SlotLengths, singletonSlotLengths, slotLengthFromSec) @@ -100,7 +100,7 @@ mockSomeProtocol => Maybe NodeId -> Maybe Word64 -- ^ Number of core nodes - -> (CoreNodeId -> NumCoreNodes -> Consensus.Protocol blk) + -> (CoreNodeId -> NumCoreNodes -> Consensus.Protocol blk (BlockProtocol blk)) -> Either ProtocolInstantiationError SomeProtocol mockSomeProtocol nId mNumCoreNodes mkConsensusProtocol = do (cid, numCoreNodes) <- extractNodeInfo nId mNumCoreNodes @@ -110,7 +110,7 @@ mockSomeProtocol nId mNumCoreNodes mkConsensusProtocol = do data SomeProtocol where SomeProtocol :: (RunNode blk, TraceConstraints blk) - => Consensus.Protocol blk -> SomeProtocol + => Consensus.Protocol blk (BlockProtocol blk) -> SomeProtocol data ProtocolInstantiationError = ByronLegacyProtocolNotImplemented @@ -144,21 +144,25 @@ fromProtocol _ nId mNumCoreNodes _ _ _ _ _ _ BFT = Consensus.ProtocolMockBFT numCoreNodes cid mockSecurityParam mockSlotLengths fromProtocol _ nId mNumCoreNodes _ _ _ _ _ _ Praos = hoistEither $ mockSomeProtocol nId mNumCoreNodes $ \cid numCoreNodes -> - Consensus.ProtocolMockPraos numCoreNodes cid PraosParams { - praosSecurityParam = mockSecurityParam - , praosSlotsPerEpoch = 3 - , praosLeaderF = 0.5 - , praosLifetimeKES = 1000000 - , praosSlotLength = slotLengthFromSec 2 - } + Consensus.ProtocolMockPraos + numCoreNodes + cid + PraosParams { + praosSecurityParam = mockSecurityParam + , praosSlotsPerEpoch = 3 + , praosLeaderF = 0.5 + , praosLifetimeKES = 1000000 + } + (singletonSlotLengths (slotLengthFromSec 2)) fromProtocol _ nId mNumCoreNodes _ _ _ _ _ _ MockPBFT = hoistEither $ mockSomeProtocol nId mNumCoreNodes $ \cid numCoreNodes@(NumCoreNodes numNodes) -> Consensus.ProtocolMockPBFT PBftParams { pbftSecurityParam = mockSecurityParam , pbftNumNodes = numCoreNodes , pbftSignatureThreshold = (1.0 / fromIntegral numNodes) + 0.1 - , pbftSlotLength = mockSlotLength + } + (singletonSlotLengths mockSlotLength) cid fromProtocol gHash _ _ mGenFile nMagic sigThresh delCertFp sKeyFp update RealPBFT = do let genHash = either panic identity $ decodeHash gHash @@ -189,7 +193,7 @@ protocolConfigRealPbft :: Update -> Maybe Double -> Genesis.Config -> Maybe PBftLeaderCredentials - -> Consensus.Protocol ByronBlock + -> Consensus.Protocol ByronBlock ProtocolRealPBFT protocolConfigRealPbft (Update appName appVer lastKnownBlockVersion) pbftSignatureThresh genesis leaderCredentials = diff --git a/cardano-node/src/Cardano/CLI/Benchmarking/Tx/Generation.hs b/cardano-node/src/Cardano/CLI/Benchmarking/Tx/Generation.hs index 85de212f925..47ed442363d 100644 --- a/cardano-node/src/Cardano/CLI/Benchmarking/Tx/Generation.hs +++ b/cardano-node/src/Cardano/CLI/Benchmarking/Tx/Generation.hs @@ -86,15 +86,13 @@ import Control.Tracer (Tracer, traceWith) import Ouroboros.Network.NodeToClient (AssociateWithIOCP) import Ouroboros.Consensus.Node.Run (RunNode) -import Ouroboros.Consensus.Block(BlockProtocol) import Ouroboros.Consensus.Node.ProtocolInfo (ProtocolInfo (..)) import qualified Ouroboros.Consensus.Cardano as Consensus +import Ouroboros.Consensus.Config (TopLevelConfig (configBlock)) import qualified Ouroboros.Consensus.Mempool as Mempool import Ouroboros.Consensus.Byron.Ledger (ByronBlock (..), GenTx (..), - ByronConsensusProtocol, - getGenesisConfig) -import Ouroboros.Consensus.Protocol.Abstract (NodeConfig) + byronProtocolMagicId) newtype NumberOfTxs = NumberOfTxs Word64 @@ -147,7 +145,7 @@ genesisBenchmarkRunner :: LoggingLayer -> AssociateWithIOCP -> SocketPath - -> Consensus.Protocol ByronBlock + -> Consensus.Protocol ByronBlock Consensus.ProtocolRealPBFT -> NonEmpty NodeAddress -> NumberOfTxs -> NumberOfInputsPerTx @@ -326,7 +324,7 @@ prepareSigningKeys skeys = do pure . map (Crypto.SigningKey . snd) $ rights desKeys mkAddressForKey - :: NodeConfig ByronConsensusProtocol + :: TopLevelConfig ByronBlock -> Crypto.SigningKey -> CC.Common.Address mkAddressForKey _pInfoConfig = @@ -398,7 +396,7 @@ prepareInitialFunds -> AssociateWithIOCP -> SocketPath -> CC.Genesis.Config - -> NodeConfig ByronConsensusProtocol + -> TopLevelConfig ByronBlock -> Map Int ((CC.UTxO.TxIn, CC.UTxO.TxOut), Crypto.SigningKey) -> CC.Common.Address -> CC.Common.Address @@ -466,7 +464,7 @@ getTxIdFromGenTx _ = panic "Impossible happened: generated transaction is not a -- | One or more inputs -> one or more outputs. mkTransaction :: (FiscalRecipient r) - => NodeConfig ByronConsensusProtocol + => TopLevelConfig ByronBlock -> NonEmpty (TxDetails, Crypto.SigningKey) -- ^ Non-empty list of (TxIn, TxOut) that will be used as -- inputs and the key to spend the associated value @@ -595,7 +593,7 @@ appendr l nel = foldr NE.cons nel l -- | ... createTxAux - :: NodeConfig ByronConsensusProtocol + :: TopLevelConfig ByronBlock -> CC.UTxO.Tx -> Crypto.SigningKey -> CC.UTxO.ATxAux ByteString @@ -605,7 +603,7 @@ createTxAux config tx signingKey = CC.UTxO.annotateTxAux $ CC.UTxO.mkTxAux tx wi CC.UTxO.VKWitness (Crypto.toVerification signingKey) (Crypto.sign - (CC.Genesis.configProtocolMagicId (getGenesisConfig config)) + (byronProtocolMagicId (configBlock config)) -- provide ProtocolMagicId so as not to calculate it every time Crypto.SignTx signingKey @@ -643,7 +641,7 @@ runBenchmark -> Tracer IO TraceLowLevelSubmit -> AssociateWithIOCP -> SocketPath - -> NodeConfig ByronConsensusProtocol + -> TopLevelConfig ByronBlock -> Crypto.SigningKey -> CC.Common.Address -> NonEmpty NodeAddress @@ -838,7 +836,7 @@ createMoreFundCoins -> Tracer IO TraceLowLevelSubmit -> AssociateWithIOCP -> SocketPath - -> NodeConfig ByronConsensusProtocol + -> TopLevelConfig ByronBlock -> Crypto.SigningKey -> FeePerTx -> NumberOfTxs @@ -912,7 +910,7 @@ createMoreFundCoins benchTracer where -- create txs which split the funds to numTxOuts equal parts createSplittingTxs - :: NodeConfig ByronConsensusProtocol + :: TopLevelConfig ByronBlock -> (TxDetails, Crypto.SigningKey) -> Word64 -> Word64 @@ -985,7 +983,7 @@ minimalTPSRate (TPSRate tps) = picosecondsToDiffTime timeInPicoSecs txGenerator :: Tracer IO (TraceBenchTxSubmit (Mempool.GenTxId ByronBlock)) - -> NodeConfig ByronConsensusProtocol + -> TopLevelConfig ByronBlock -> CC.Common.Address -> Crypto.SigningKey -> FeePerTx @@ -1179,7 +1177,7 @@ launchTxPeer -- ^ associate a file descriptor with IO completion port -> MSTM.TVar m Bool -- a "global" stop variable, set to True to force shutdown - -> NodeConfig (Ouroboros.Consensus.Block.BlockProtocol block) + -> TopLevelConfig block -- the configuration -> Maybe Network.Socket.AddrInfo -- local address binding (if wanted) diff --git a/cardano-node/src/Cardano/CLI/Benchmarking/Tx/NodeToNode.hs b/cardano-node/src/Cardano/CLI/Benchmarking/Tx/NodeToNode.hs index b698440e3a9..a3d1a9ff889 100644 --- a/cardano-node/src/Cardano/CLI/Benchmarking/Tx/NodeToNode.hs +++ b/cardano-node/src/Cardano/CLI/Benchmarking/Tx/NodeToNode.hs @@ -41,13 +41,12 @@ import Cardano.BM.Data.Tracer (DefinePrivacyAnnotation (..), DefineSeverity (..), ToObject (..), TracingFormatting (..), TracingVerbosity (..), Transformable (..), emptyObject, mkObject, trStructured) -import Ouroboros.Consensus.Block (BlockProtocol) import Ouroboros.Consensus.Byron.Ledger (ByronBlock (..)) import Ouroboros.Consensus.Mempool.API (GenTxId, GenTx) import Ouroboros.Consensus.Node.NetworkProtocolVersion import Ouroboros.Consensus.Node.Run (RunNode, nodeNetworkMagic) import Ouroboros.Consensus.NodeNetwork (ProtocolCodecs(..), protocolCodecs) -import Ouroboros.Consensus.Protocol.Abstract (NodeConfig) +import Ouroboros.Consensus.Config (TopLevelConfig) import Ouroboros.Network.Mux (OuroborosApplication(..)) import Ouroboros.Network.NodeToNode (NetworkConnectTracers (..)) import qualified Ouroboros.Network.NodeToNode as NtN @@ -197,7 +196,7 @@ benchmarkConnectTxSubmit => AssociateWithIOCP -> BenchmarkTxSubmitTracers m blk -- ^ For tracing the send/receive actions - -> NodeConfig (BlockProtocol blk) + -> TopLevelConfig blk -- ^ The particular block protocol -> Maybe AddrInfo -- ^ local address information (typically local interface/port to use) @@ -206,7 +205,7 @@ benchmarkConnectTxSubmit -> TxSubmissionClient (GenTxId blk) (GenTx blk) m () -- ^ the particular txSubmission peer -> m () -benchmarkConnectTxSubmit iocp trs nc localAddr remoteAddr myTxSubClient = do +benchmarkConnectTxSubmit iocp trs cfg localAddr remoteAddr myTxSubClient = do NtN.connectTo (socketSnocket iocp) NetworkConnectTracers { @@ -220,7 +219,7 @@ benchmarkConnectTxSubmit iocp trs nc localAddr remoteAddr myTxSubClient = do myCodecs :: ProtocolCodecs blk DeserialiseFailure m ByteString ByteString ByteString ByteString ByteString ByteString ByteString ByteString - myCodecs = protocolCodecs nc (mostRecentNetworkProtocolVersion (Proxy @blk)) + myCodecs = protocolCodecs cfg (mostRecentNetworkProtocolVersion (Proxy @blk)) peerMultiplex :: Versions NtN.NodeToNodeVersion NtN.DictVersion (OuroborosApplication @@ -234,7 +233,7 @@ benchmarkConnectTxSubmit iocp trs nc localAddr remoteAddr myTxSubClient = do peerMultiplex = simpleSingletonVersions NtN.NodeToNodeV_1 - (NtN.NodeToNodeVersionData { NtN.networkMagic = nodeNetworkMagic (Proxy @blk) nc}) + (NtN.NodeToNodeVersionData { NtN.networkMagic = nodeNetworkMagic (Proxy @blk) cfg}) (NtN.DictVersion NtN.nodeToNodeCodecCBORTerm) $ OuroborosInitiatorApplication $ \_peer ptcl -> case ptcl of diff --git a/cardano-node/src/Cardano/CLI/Ops.hs b/cardano-node/src/Cardano/CLI/Ops.hs index 088225dc460..b74c312aeb6 100644 --- a/cardano-node/src/Cardano/CLI/Ops.hs +++ b/cardano-node/src/Cardano/CLI/Ops.hs @@ -54,6 +54,7 @@ import Ouroboros.Consensus.Mempool.API (ApplyTxErr) import Ouroboros.Consensus.NodeNetwork (ProtocolCodecs(..), protocolCodecs) import Ouroboros.Consensus.Node.NetworkProtocolVersion (NodeToClientVersion, mostRecentNetworkProtocolVersion) +import Ouroboros.Consensus.Config (TopLevelConfig) import Ouroboros.Consensus.Node.ProtocolInfo (ProtocolInfo(..)) import Ouroboros.Consensus.Node.Run (RunNode(..)) @@ -247,7 +248,7 @@ withRealPBFT -> Update -> Protocol -> (RunNode ByronBlock - => Consensus.Protocol ByronBlock + => Consensus.Protocol ByronBlock Consensus.ProtocolRealPBFT -> ExceptT RealPBFTError IO a) -> ExceptT RealPBFTError IO a withRealPBFT gHash genFile nMagic sigThresh delCertFp sKeyFp update ptcl action = do @@ -312,7 +313,7 @@ getLocalTip configFp genFp iocp sockPath = do createNodeConnection :: forall blk . (Condense (HeaderHash blk), RunNode blk) => Proxy blk - -> Consensus.Protocol blk + -> Consensus.Protocol blk (BlockProtocol blk) -> AssociateWithIOCP -> SocketPath -> IO () @@ -338,14 +339,14 @@ localInitiatorNetworkApplication , MonadTimer m ) => Proxy blk - -> Consensus.NodeConfig (BlockProtocol blk) + -> TopLevelConfig blk -> Versions NodeToClientVersion DictVersion (OuroborosApplication 'InitiatorApp peer NodeToClientProtocols m LB.ByteString () Void) -localInitiatorNetworkApplication proxy pInfoConfig = +localInitiatorNetworkApplication proxy cfg = simpleSingletonVersions NodeToClientV_1 - (NodeToClientVersionData { networkMagic = nodeNetworkMagic proxy pInfoConfig }) + (NodeToClientVersionData { networkMagic = nodeNetworkMagic proxy cfg }) (DictVersion nodeToClientCodecCBORTerm) $ OuroborosInitiatorApplication $ \_peer ptcl -> case ptcl of @@ -364,10 +365,10 @@ localInitiatorNetworkApplication proxy pInfoConfig = (chainSyncClientPeer chainSyncClient) where localChainSyncCodec :: Codec (ChainSync (Serialised blk) (Tip blk)) DeserialiseFailure m LB.ByteString - localChainSyncCodec = pcLocalChainSyncCodec . protocolCodecs pInfoConfig $ mostRecentNetworkProtocolVersion proxy + localChainSyncCodec = pcLocalChainSyncCodec . protocolCodecs cfg $ mostRecentNetworkProtocolVersion proxy localTxSubmissionCodec :: Codec (LocalTxSubmission (GenTx blk) (ApplyTxErr blk)) DeserialiseFailure m LB.ByteString - localTxSubmissionCodec = pcLocalTxSubmissionCodec . protocolCodecs pInfoConfig $ mostRecentNetworkProtocolVersion proxy + localTxSubmissionCodec = pcLocalTxSubmissionCodec . protocolCodecs cfg $ mostRecentNetworkProtocolVersion proxy chainSyncClient :: forall blk m . (Condense (HeaderHash blk), MonadIO m) diff --git a/cardano-node/src/Cardano/Chairman.hs b/cardano-node/src/Cardano/Chairman.hs index 0c6543a4dfe..a9b2d70b894 100644 --- a/cardano-node/src/Cardano/Chairman.hs +++ b/cardano-node/src/Cardano/Chairman.hs @@ -37,6 +37,7 @@ import Control.Tracer import Network.Mux (MuxError) import Ouroboros.Consensus.Block (BlockProtocol, GetHeader (..)) +import Ouroboros.Consensus.Config (TopLevelConfig) import Ouroboros.Consensus.Mempool import Ouroboros.Consensus.Node.ProtocolInfo import Ouroboros.Consensus.Node.Run @@ -75,7 +76,7 @@ runChairman :: forall blk. , TraceConstraints blk ) => AssociateWithIOCP - -> Protocol blk + -> Protocol blk (BlockProtocol blk) -> SecurityParam -- ^ security parameter, if a fork is deeper than it 'runChairman' -- will throw an exception. @@ -91,14 +92,14 @@ runChairman iocp ptcl securityParam maxBlockNo socketPaths tracer = do (Map.fromList $ map (\socketPath -> (socketPath, AF.Empty AF.AnchorGenesis)) socketPaths) void $ flip mapConcurrently socketPaths $ \sockPath -> - let ProtocolInfo{pInfoConfig} = protocolInfo ptcl + let ProtocolInfo { pInfoConfig = cfg } = protocolInfo ptcl in createConnection chainsVar securityParam maxBlockNo tracer - pInfoConfig + cfg iocp sockPath @@ -125,7 +126,7 @@ createConnection -> SecurityParam -> Maybe BlockNo -> Tracer IO String - -> NodeConfig (BlockProtocol blk) + -> TopLevelConfig blk -> AssociateWithIOCP -> SocketPath -> IO () @@ -134,7 +135,7 @@ createConnection securityParam maxBlockNo tracer - pInfoConfig + cfg iocp socketPath = do path <- localSocketPath socketPath @@ -152,7 +153,7 @@ createConnection (showTracing tracer) nullTracer nullTracer - pInfoConfig) + cfg) path `catch` handleMuxError tracer chainsVar socketPath @@ -376,14 +377,14 @@ localInitiatorNetworkApplication -- ^ tracer which logs all local tx submission protocol messages send and -- received by the client (see 'Ouroboros.Network.Protocol.LocalTxSubmission.Type' -- in 'ouroboros-network' package). - -> NodeConfig (BlockProtocol blk) + -> TopLevelConfig blk -> Versions NodeToClientVersion DictVersion (OuroborosApplication 'InitiatorApp peer NodeToClientProtocols m ByteString () Void) -localInitiatorNetworkApplication sockPath chainsVar securityParam maxBlockNo chairmanTracer chainSyncTracer localTxSubmissionTracer pInfoConfig = +localInitiatorNetworkApplication sockPath chainsVar securityParam maxBlockNo chairmanTracer chainSyncTracer localTxSubmissionTracer cfg = simpleSingletonVersions NodeToClientV_1 - (NodeToClientVersionData (nodeNetworkMagic (Proxy @blk) pInfoConfig)) + (NodeToClientVersionData (nodeNetworkMagic (Proxy @blk) cfg)) (DictVersion nodeToClientCodecCBORTerm) $ OuroborosInitiatorApplication $ \_peer ptcl -> case ptcl of @@ -397,7 +398,7 @@ localInitiatorNetworkApplication sockPath chainsVar securityParam maxBlockNo cha ChainSyncWithBlocksPtcl -> \channel -> runPeer chainSyncTracer - (localChainSyncCodec pInfoConfig) + (localChainSyncCodec cfg) channel (chainSyncClientPeer $ chainSyncClient chairmanTracer sockPath chainsVar securityParam maxBlockNo) @@ -422,13 +423,13 @@ localChainSyncCodec ( RunNode blk , MonadST m ) - => NodeConfig (BlockProtocol blk) + => TopLevelConfig blk -> Codec (ChainSync blk (Tip blk)) DeserialiseFailure m ByteString -localChainSyncCodec pInfoConfig = +localChainSyncCodec cfg = codecChainSync - (Block.wrapCBORinCBOR (nodeEncodeBlock pInfoConfig)) - (Block.unwrapCBORinCBOR (nodeDecodeBlock pInfoConfig)) + (Block.wrapCBORinCBOR (nodeEncodeBlock cfg)) + (Block.unwrapCBORinCBOR (nodeDecodeBlock cfg)) (Block.encodePoint (nodeEncodeHeaderHash (Proxy @blk))) (Block.decodePoint (nodeDecodeHeaderHash (Proxy @blk))) (Block.encodeTip (nodeEncodeHeaderHash (Proxy @blk))) diff --git a/cardano-node/src/Cardano/Node/Run.hs b/cardano-node/src/Cardano/Node/Run.hs index 9d09a1fbfb7..0a6d5698407 100644 --- a/cardano-node/src/Cardano/Node/Run.hs +++ b/cardano-node/src/Cardano/Node/Run.hs @@ -66,6 +66,7 @@ import Ouroboros.Consensus.Node (NodeKernel (getChainDB), import qualified Ouroboros.Consensus.Node as Node (run) import Ouroboros.Consensus.Node.ProtocolInfo import Ouroboros.Consensus.NodeId +import qualified Ouroboros.Consensus.Config as Consensus import qualified Ouroboros.Consensus.Cardano as Consensus import Ouroboros.Consensus.Util.Orphans () import Ouroboros.Consensus.Util.STM (onEachChange) @@ -116,7 +117,7 @@ runNode loggingLayer npm = do (ncUpdate nc) (ncProtocol nc) - SomeProtocol (p :: Consensus.Protocol blk) <- + SomeProtocol (p :: Consensus.Protocol blk (BlockProtocol blk)) <- case eitherSomeProtocol of Left err -> (putTextLn . pack $ show err) >> exitFailure Right (SomeProtocol p) -> pure $ SomeProtocol p @@ -158,7 +159,7 @@ runNode loggingLayer npm = do handleSimpleNode :: forall blk. RunNode blk - => Consensus.Protocol blk + => Consensus.Protocol blk (BlockProtocol blk) -> Trace IO Text -> Tracers RemoteConnectionId LocalConnectionId blk -> NodeProtocolMode @@ -261,7 +262,7 @@ handleSimpleNode p trace nodeTracers npm onKernel = do createTracers :: NodeProtocolMode -> Tracer IO GHC.Base.String - -> Consensus.NodeConfig (BlockProtocol blk) + -> Consensus.TopLevelConfig blk -> IO () createTracers npm' tracer cfg = do case npm' of diff --git a/cardano-node/src/Cardano/Node/Submission.hs b/cardano-node/src/Cardano/Node/Submission.hs index 39dbcbe1a89..2689d9a6c41 100644 --- a/cardano-node/src/Cardano/Node/Submission.hs +++ b/cardano-node/src/Cardano/Node/Submission.hs @@ -26,11 +26,10 @@ import Control.Monad.Class.MonadThrow (MonadThrow) import Control.Monad.Class.MonadTimer (MonadTimer) import Control.Tracer (Tracer, nullTracer, traceWith) -import Ouroboros.Consensus.Block (BlockProtocol) import Ouroboros.Consensus.Mempool (ApplyTxErr, GenTx) import Ouroboros.Consensus.Node.Run (RunNode) import qualified Ouroboros.Consensus.Node.Run as Node -import Ouroboros.Consensus.Protocol.Abstract (NodeConfig) +import Ouroboros.Consensus.Config (TopLevelConfig) import Network.TypedProtocol.Driver (runPeer) import Ouroboros.Network.Codec (Codec, DeserialiseFailure) @@ -105,11 +104,11 @@ submitTx :: ( RunNode blk ) => AssociateWithIOCP -> SocketPath - -> NodeConfig (BlockProtocol blk) + -> TopLevelConfig blk -> GenTx blk -> Tracer IO TraceLowLevelSubmit -> IO () -submitTx iocp targetSocketFp protoInfoConfig tx tracer = do +submitTx iocp targetSocketFp cfg tx tracer = do targetSocketFp' <- localSocketPath targetSocketFp NodeToClient.connectTo (socketSnocket iocp) @@ -117,7 +116,7 @@ submitTx iocp targetSocketFp protoInfoConfig tx tracer = do nctMuxTracer = nullTracer, nctHandshakeTracer = nullTracer } - (localInitiatorNetworkApplication tracer protoInfoConfig tx) + (localInitiatorNetworkApplication tracer cfg tx) targetSocketFp' localInitiatorNetworkApplication @@ -129,16 +128,16 @@ localInitiatorNetworkApplication , Show (ApplyTxErr blk) ) => Tracer m TraceLowLevelSubmit - -> NodeConfig (BlockProtocol blk) + -> TopLevelConfig blk -> GenTx blk -> Versions NodeToClient.NodeToClientVersion NodeToClient.DictVersion (OuroborosApplication 'InitiatorApp peer NodeToClient.NodeToClientProtocols m ByteString () Void) -localInitiatorNetworkApplication tracer protoInfoConfig tx = +localInitiatorNetworkApplication tracer cfg tx = simpleSingletonVersions NodeToClient.NodeToClientV_1 (NodeToClient.NodeToClientVersionData - { NodeToClient.networkMagic = Node.nodeNetworkMagic (Proxy @blk) protoInfoConfig }) + { NodeToClient.networkMagic = Node.nodeNetworkMagic (Proxy @blk) cfg }) (NodeToClient.DictVersion NodeToClient.nodeToClientCodecCBORTerm) $ OuroborosInitiatorApplication $ \_peer ptcl -> case ptcl of @@ -157,7 +156,7 @@ localInitiatorNetworkApplication tracer protoInfoConfig tx = NodeToClient.ChainSyncWithBlocksPtcl -> \channel -> runPeer nullTracer - (localChainSyncCodec @blk protoInfoConfig) + (localChainSyncCodec @blk cfg) channel (chainSyncClientPeer NodeToClient.chainSyncClientNull) @@ -186,13 +185,13 @@ localTxSubmissionCodec = localChainSyncCodec :: forall blk m. (RunNode blk, MonadST m) - => NodeConfig (BlockProtocol blk) + => TopLevelConfig blk -> Codec (ChainSync blk (Point blk)) DeserialiseFailure m ByteString -localChainSyncCodec protoInfoConfig = +localChainSyncCodec cfg = codecChainSync - (Block.wrapCBORinCBOR (Node.nodeEncodeBlock protoInfoConfig)) - (Block.unwrapCBORinCBOR (Node.nodeDecodeBlock protoInfoConfig)) + (Block.wrapCBORinCBOR (Node.nodeEncodeBlock cfg)) + (Block.unwrapCBORinCBOR (Node.nodeDecodeBlock cfg)) (Block.encodePoint (Node.nodeEncodeHeaderHash (Proxy @blk))) (Block.decodePoint (Node.nodeDecodeHeaderHash (Proxy @blk))) (Block.encodePoint (Node.nodeEncodeHeaderHash (Proxy @blk))) diff --git a/cardano-node/src/Cardano/Node/TUI/LiveView.hs b/cardano-node/src/Cardano/Node/TUI/LiveView.hs index 382de7643d3..53a335a97b4 100644 --- a/cardano-node/src/Cardano/Node/TUI/LiveView.hs +++ b/cardano-node/src/Cardano/Node/TUI/LiveView.hs @@ -745,7 +745,7 @@ ppPeer (LVPeer cid _af status inflight) = ppStatus Net.PeerFetchStatusShutdown = "shutdown" ppStatus Net.PeerFetchStatusAberrant = "aberrant" ppStatus Net.PeerFetchStatusBusy = "fetching" - ppStatus (Net.PeerFetchStatusReady _blks) = "ready" + ppStatus (Net.PeerFetchStatusReady {}) = "ready" drawUI :: LiveViewState blk a -> [Widget ()] drawUI p = case lvsScreen p of diff --git a/cardano-node/src/Cardano/Tracing/MicroBenchmarking.hs b/cardano-node/src/Cardano/Tracing/MicroBenchmarking.hs index d4190200490..c90c267b4c8 100644 --- a/cardano-node/src/Cardano/Tracing/MicroBenchmarking.hs +++ b/cardano-node/src/Cardano/Tracing/MicroBenchmarking.hs @@ -38,7 +38,6 @@ import Control.Tracer.Transformers.ObserveOutcome import Ouroboros.Network.Block (SlotNo (..)) -import Ouroboros.Consensus.Ledger.Abstract (ProtocolLedgerView) import Ouroboros.Consensus.Mempool.API (ApplyTx (..), GenTx, GenTxId, HasTxId (..), MempoolSize (..), TraceEventMempool (..), txId) @@ -53,8 +52,8 @@ data MeasureTxs blk = MeasureTxsTimeStart (GenTx blk) !Word !Word !Time -- num txs, total size in bytes | MeasureTxsTimeStop !SlotNo blk [GenTx blk] !Time -deriving instance (ProtocolLedgerView blk, Eq blk, Eq (GenTx blk)) => Eq (MeasureTxs blk) -deriving instance (ProtocolLedgerView blk, Show blk, Show (GenTx blk)) => Show (MeasureTxs blk) +deriving instance (Eq blk, Eq (GenTx blk)) => Eq (MeasureTxs blk) +deriving instance (Show blk, Show (GenTx blk)) => Show (MeasureTxs blk) instance Transformable Text IO (MeasureTxs blk) where trTransformer _ verb tr = trStructured verb tr @@ -177,8 +176,8 @@ data MeasureBlockForging blk = MeasureBlockTimeStart !SlotNo !Time | MeasureBlockTimeStop !SlotNo blk !MempoolSize !Time -deriving instance (ProtocolLedgerView blk, Eq blk, Eq (GenTx blk)) => Eq (MeasureBlockForging blk) -deriving instance (ProtocolLedgerView blk, Show blk, Show (GenTx blk)) => Show (MeasureBlockForging blk) +deriving instance (Eq blk, Eq (GenTx blk)) => Eq (MeasureBlockForging blk) +deriving instance (Show blk, Show (GenTx blk)) => Show (MeasureBlockForging blk) instance Transformable Text IO (MeasureBlockForging blk) where trTransformer _ verb tr = trStructured verb tr diff --git a/cardano-node/src/Cardano/Tracing/ToObjectOrphans.hs b/cardano-node/src/Cardano/Tracing/ToObjectOrphans.hs index 82fec7be42d..8cdbb1a8c10 100644 --- a/cardano-node/src/Cardano/Tracing/ToObjectOrphans.hs +++ b/cardano-node/src/Cardano/Tracing/ToObjectOrphans.hs @@ -31,14 +31,15 @@ import Cardano.BM.Data.LogItem (LOContent (..), LogObject (..), import Cardano.BM.Tracing import Cardano.BM.Data.Tracer (trStructured, emptyObject, mkObject) -import Ouroboros.Consensus.Block (Header, SupportedBlock, headerPoint) +import Ouroboros.Consensus.Block (Header, headerPoint) import Ouroboros.Consensus.BlockFetchServer (TraceBlockFetchServerEvent) import Ouroboros.Consensus.ChainSyncClient (TraceChainSyncClientEvent (..)) import Ouroboros.Consensus.ChainSyncServer (TraceChainSyncServerEvent(..)) -import Ouroboros.Consensus.Ledger.Abstract +import Ouroboros.Consensus.Ledger.SupportsProtocol + (LedgerSupportsProtocol) import Ouroboros.Consensus.Mempool.API (GenTx, GenTxId, HasTxId, TraceEventMempool (..), TxId, txId) import Ouroboros.Consensus.Node.Tracers (TraceForgeEvent (..)) @@ -237,7 +238,7 @@ defaultTextTransformer _ verb tr = instance ( DefinePrivacyAnnotation (ChainDB.TraceAddBlockEvent blk) , DefineSeverity (ChainDB.TraceAddBlockEvent blk) - , ProtocolLedgerView blk + , LedgerSupportsProtocol blk , Show (Ouroboros.Consensus.Block.Header blk) , ToObject (ChainDB.TraceAddBlockEvent blk)) => Transformable Text IO (ChainDB.TraceAddBlockEvent blk) where @@ -374,7 +375,7 @@ instance DefineSeverity (TraceForgeEvent blk tx) where -- | instances of @Transformable@ -- transform @ChainSyncClient@ -instance (Condense (HeaderHash blk), ProtocolLedgerView blk, SupportedBlock blk) +instance (Condense (HeaderHash blk), LedgerSupportsProtocol blk) => Transformable Text IO (TraceChainSyncClientEvent blk) where trTransformer _ verb tr = trStructured verb tr @@ -405,14 +406,15 @@ instance Transformable Text IO (TraceTxSubmissionInbound (GenTxId blk) (GenTx blk)) where trTransformer = defaultTextTransformer -instance Transformable Text IO (TraceTxSubmissionOutbound +instance (Show (GenTxId blk), Show (GenTx blk)) + => Transformable Text IO (TraceTxSubmissionOutbound (GenTxId blk) (GenTx blk)) where trTransformer = defaultTextTransformer instance Transformable Text IO (TraceLocalTxSubmissionServerEvent blk) where trTransformer _ verb tr = trStructured verb tr -instance (Condense (HeaderHash blk), Show (TxId tx), HasTxId tx, Show blk, Show tx, ProtocolLedgerView blk) +instance (Condense (HeaderHash blk), Show (TxId tx), HasTxId tx, Show blk, Show tx, LedgerSupportsProtocol blk) => Transformable Text IO (TraceForgeEvent blk tx) where trTransformer = defaultTextTransformer @@ -442,7 +444,7 @@ instance (Show peer) trTransformer = defaultTextTransformer -- transform @TraceEvent@ -instance (Condense (HeaderHash blk), ProtocolLedgerView blk) +instance (Condense (HeaderHash blk), LedgerSupportsProtocol blk) => Transformable Text IO (WithTip blk (ChainDB.TraceEvent blk)) where -- structure required, will call 'toObject' trTransformer StructuredLogging verb tr = trStructured verb tr @@ -459,7 +461,7 @@ instance (Condense (HeaderHash blk), ProtocolLedgerView blk) -- human-readable trace messages. readableChainDBTracer :: forall m blk. - (Monad m, Condense (HeaderHash blk), ProtocolLedgerView blk) + (Monad m, Condense (HeaderHash blk), LedgerSupportsProtocol blk) => Tracer m String -> Tracer m (WithTip blk (ChainDB.TraceEvent blk)) readableChainDBTracer tracer = Tracer $ \case @@ -593,7 +595,7 @@ instance (Show peer) , "bearer" .= show b , "event" .= show ev ] -instance (Condense (HeaderHash blk), ProtocolLedgerView blk) +instance (Condense (HeaderHash blk), LedgerSupportsProtocol blk) => ToObject (WithTip blk (ChainDB.TraceEvent blk)) where -- example: turn off any tracing of @TraceEvent@s when minimal verbosity level is set -- toObject MinimalVerbosity _ = emptyObject -- no output @@ -612,14 +614,14 @@ instance ToObject SlotNo where mkObject [ "kind" .= String "SlotNo" , "slot" .= toJSON (unSlotNo slot) ] -instance (Condense (HeaderHash blk), ProtocolLedgerView blk) +instance Condense (HeaderHash blk) => ToObject (Point blk) where toObject MinimalVerbosity p = toObject NormalVerbosity p toObject verb p = mkObject [ "kind" .= String "Tip" , "tip" .= showPoint verb p ] -instance (Condense (HeaderHash blk), ProtocolLedgerView blk) +instance (Condense (HeaderHash blk), LedgerSupportsProtocol blk) => ToObject (ChainDB.TraceEvent blk) where toObject verb (ChainDB.TraceAddBlockEvent ev) = case ev of ChainDB.IgnoreBlockOlderThanK pt -> @@ -779,7 +781,7 @@ instance ToObject LedgerDB.DiskSnapshot where mkObject [ "kind" .= String "snapshot" , "snapshot" .= String (pack $ show snap) ] -instance (Condense (HeaderHash blk), ProtocolLedgerView blk, SupportedBlock blk) +instance (Condense (HeaderHash blk), LedgerSupportsProtocol blk) => ToObject (TraceChainSyncClientEvent blk) where toObject verb ev = case ev of TraceDownloadedHeader pt -> @@ -916,7 +918,7 @@ instance ToObject (TraceLocalTxSubmissionServerEvent blk) where toObject _verb _ = mkObject [ "kind" .= String "TraceLocalTxSubmissionServerEvent" ] -instance (HasTxId tx, ProtocolLedgerView blk, Condense (HeaderHash blk), Show (TxId tx)) +instance (HasTxId tx, LedgerSupportsProtocol blk, Condense (HeaderHash blk), Show (TxId tx)) => ToObject (TraceForgeEvent blk tx) where toObject MaximalVerbosity (TraceAdoptedBlock slotNo blk txs) = mkObject diff --git a/cardano-node/src/Cardano/Tracing/Tracers.hs b/cardano-node/src/Cardano/Tracing/Tracers.hs index 034ca061c87..f21e7e3a28b 100644 --- a/cardano-node/src/Cardano/Tracing/Tracers.hs +++ b/cardano-node/src/Cardano/Tracing/Tracers.hs @@ -46,6 +46,7 @@ import Cardano.BM.Data.Transformers import Ouroboros.Consensus.Block (Header) import Ouroboros.Consensus.BlockchainTime (SystemStart (..), TraceBlockchainTimeEvent (..)) import Ouroboros.Consensus.Ledger.Abstract +import Ouroboros.Consensus.Ledger.SupportsProtocol (LedgerSupportsProtocol) import Ouroboros.Consensus.Mempool.API (GenTx, MempoolSize (..), TraceEventMempool (..)) import qualified Ouroboros.Consensus.Node.Tracers as Consensus @@ -155,7 +156,7 @@ instance ElidingTracer -- mkTracers :: forall peer localPeer blk. - ( ProtocolLedgerView blk + ( LedgerSupportsProtocol blk , TraceConstraints blk , ShowQuery (Query blk) , Show peer diff --git a/cardano-node/src/Cardano/Wallet/Client.hs b/cardano-node/src/Cardano/Wallet/Client.hs index 1300d244f03..7838edd26b9 100644 --- a/cardano-node/src/Cardano/Wallet/Client.hs +++ b/cardano-node/src/Cardano/Wallet/Client.hs @@ -26,6 +26,7 @@ import Control.Monad.Class.MonadThrow import Control.Monad.Class.MonadTimer import Control.Tracer +import Ouroboros.Consensus.Config (TopLevelConfig) import Ouroboros.Consensus.Block (BlockProtocol) import Ouroboros.Consensus.Mempool import Ouroboros.Consensus.Node.ProtocolInfo @@ -55,7 +56,7 @@ runWalletClient :: forall blk. ( RunNode blk , TraceConstraints blk ) - => Protocol blk + => Protocol blk (BlockProtocol blk) -> SocketPath -> Tracer IO String -> IO () @@ -63,7 +64,7 @@ runWalletClient ptcl sockFp tracer = withIOManager $ \iocp -> do path <- localSocketPath sockFp - let ProtocolInfo{pInfoConfig} = protocolInfo ptcl + let ProtocolInfo { pInfoConfig = cfg } = protocolInfo ptcl chainSyncTracer = contramap show tracer localTxSubmissionTracer = contramap show tracer @@ -78,7 +79,7 @@ runWalletClient ptcl sockFp tracer = withIOManager $ \iocp -> do (Proxy :: Proxy blk) chainSyncTracer localTxSubmissionTracer - pInfoConfig) + cfg) path localInitiatorNetworkApplication @@ -101,14 +102,14 @@ localInitiatorNetworkApplication -- ^ tracer which logs all local tx submission protocol messages send and -- received by the client (see 'Ouroboros.Network.Protocol.LocalTxSubmission.Type' -- in 'ouroboros-network' package). - -> NodeConfig (BlockProtocol blk) + -> TopLevelConfig blk -> Versions NodeToClientVersion DictVersion (OuroborosApplication 'InitiatorApp peer NodeToClientProtocols m ByteString Void Void) -localInitiatorNetworkApplication Proxy chainSyncTracer localTxSubmissionTracer pInfoConfig = +localInitiatorNetworkApplication Proxy chainSyncTracer localTxSubmissionTracer cfg = simpleSingletonVersions NodeToClientV_1 - (NodeToClientVersionData { networkMagic = nodeNetworkMagic (Proxy @blk) pInfoConfig }) + (NodeToClientVersionData { networkMagic = nodeNetworkMagic (Proxy @blk) cfg }) (DictVersion nodeToClientCodecCBORTerm) $ OuroborosInitiatorApplication $ \_peer ptcl -> case ptcl of @@ -124,7 +125,7 @@ localInitiatorNetworkApplication Proxy chainSyncTracer localTxSubmissionTracer p ChainSyncWithBlocksPtcl -> \channel -> runPeer chainSyncTracer - (localChainSyncCodec @blk pInfoConfig) + (localChainSyncCodec @blk cfg) channel (chainSyncClientPeer chainSyncClient) @@ -198,13 +199,13 @@ localTxSubmissionCodec = localChainSyncCodec :: forall blk m. (RunNode blk, MonadST m) - => NodeConfig (BlockProtocol blk) + => TopLevelConfig blk -> Codec (ChainSync blk (Tip blk)) DeserialiseFailure m ByteString -localChainSyncCodec pInfoConfig = +localChainSyncCodec cfg = codecChainSync - (Block.wrapCBORinCBOR (nodeEncodeBlock pInfoConfig)) - (Block.unwrapCBORinCBOR (nodeDecodeBlock pInfoConfig)) + (Block.wrapCBORinCBOR (nodeEncodeBlock cfg)) + (Block.unwrapCBORinCBOR (nodeDecodeBlock cfg)) (Block.encodePoint (nodeEncodeHeaderHash (Proxy @blk))) (Block.decodePoint (nodeDecodeHeaderHash (Proxy @blk))) (Block.encodeTip (nodeEncodeHeaderHash (Proxy @blk))) diff --git a/stack.yaml b/stack.yaml index ea798d074e1..b82e54fce24 100644 --- a/stack.yaml +++ b/stack.yaml @@ -121,7 +121,7 @@ extra-deps: #Ouroboros-network dependencies - git: https://github.com/input-output-hk/ouroboros-network - commit: 68ebc7b8c53078629dd57fd579eece12c66576c8 + commit: 36861a97272de1e4de448925dd9bb9c0fddd80f6 subdirs: - io-sim - io-sim-classes