Skip to content

Commit

Permalink
CAD-2897 update tx-generator to latest cardano-node
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcFontaine committed May 4, 2021
1 parent 3e25c54 commit 1961584
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 30 deletions.
Expand Up @@ -20,11 +20,6 @@ import Data.Text (pack)
import Cardano.Prelude hiding (TypeError, show)
import Control.Monad.Trans.Except.Extra (firstExceptT)

import Ouroboros.Consensus.Block.Abstract (BlockProtocol)

import qualified Ouroboros.Consensus.Cardano as Consensus
import Ouroboros.Consensus.Cardano (Protocol, ProtocolCardano)

import Ouroboros.Consensus.Config
( configBlock, configCodec)
import Ouroboros.Consensus.Config.SupportsNode
Expand All @@ -39,19 +34,20 @@ import qualified Cardano.Chain.Genesis as Genesis
import Cardano.Node.Configuration.Logging
import Cardano.Node.Configuration.POM
import Cardano.Node.Protocol.Cardano
import Cardano.Node.Protocol.Types (SomeConsensusProtocol)
import Cardano.Node.Types

import Cardano.Benchmarking.DSL
import Cardano.Benchmarking.Tracer

import Cardano.Benchmarking.GeneratorTx.NodeToNode
import Cardano.Benchmarking.OuroborosImports (CardanoBlock, getGenesis, protocolToTopLevelConfig, protocolToNetworkId)
import Cardano.Benchmarking.OuroborosImports (getGenesis, protocolToTopLevelConfig, protocolToNetworkId)

import qualified Cardano.Benchmarking.GeneratorTx as GeneratorTx
import qualified Cardano.Benchmarking.GeneratorTx.Tx as GeneratorTx

mangleLocalProtocolDefinition ::
Consensus.Protocol IO CardanoBlock ptcl
SomeConsensusProtocol
-> IOManager
-> SocketPath
-> BenchTracers
Expand Down Expand Up @@ -122,22 +118,23 @@ runBenchmarkScriptWith iocp logConfigFile socketFile script = do

startProtocol
:: FilePath
-> ExceptT CliError IO (LoggingLayer, Protocol IO CardanoBlock ProtocolCardano)
-> ExceptT CliError IO (LoggingLayer, SomeConsensusProtocol)
startProtocol logConfigFile = do
nc <- liftIO $ mkNodeConfig logConfigFile
case ncProtocolConfig nc of
NodeProtocolConfigurationByron _ -> error "NodeProtocolConfigurationByron not supported"
NodeProtocolConfigurationShelley _ -> error "NodeProtocolConfigurationShelley not supported"
NodeProtocolConfigurationCardano byC shC hfC -> do
ptcl :: Protocol IO CardanoBlock ProtocolCardano <- firstExceptT (ProtocolInstantiationError . pack . show) $
mkConsensusProtocolCardano byC shC hfC Nothing
ptcl :: SomeConsensusProtocol <- firstExceptT (ProtocolInstantiationError . pack . show) $
mkSomeConsensusProtocolCardano byC shC hfC Nothing

loggingLayer <- mkLoggingLayer nc ptcl
return (loggingLayer, ptcl)
where
mkLoggingLayer :: NodeConfiguration -> Protocol IO blk (BlockProtocol blk) -> ExceptT CliError IO LoggingLayer
mkLoggingLayer :: NodeConfiguration -> SomeConsensusProtocol -> ExceptT CliError IO LoggingLayer
mkLoggingLayer nc ptcl =
firstExceptT (\(ConfigErrorFileNotFound fp) -> ConfigNotFoundError fp) $
createLoggingLayer (pack $ showVersion version) nc ptcl
createLoggingLayer (pack $ showVersion version) nc ptcl

mkNodeConfig :: FilePath -> IO NodeConfiguration
mkNodeConfig logConfig = do
Expand Down
Expand Up @@ -89,9 +89,10 @@ dummyTxSizeInEra metadata = case makeTransactionBody dummyTx of
Right b -> BS.length $ serialiseToCBOR b
Left err -> error $ "metaDataSize " ++ show err
where
dummyTx :: TxBodyContent era
dummyTx :: TxBodyContent BuildTx era
dummyTx = TxBodyContent {
txIns = [ TxIn "dbaff4e270cfb55612d9e2ac4658a27c79da4a5271c6f90853042d1403733810" (TxIx 0) ]
txIns = [( TxIn "dbaff4e270cfb55612d9e2ac4658a27c79da4a5271c6f90853042d1403733810" (TxIx 0)
, BuildTxWith $ KeyWitness KeyWitnessForSpending )]
, txOuts = []
, txFee = mkFee 0
, txValidityRange = (TxValidityNoLowerBound, mkValidityUpperBound 0)
Expand Down
Expand Up @@ -66,7 +66,7 @@ mkGenesisTransaction key _payloadSize ttl fee txins txouts
Left err -> error $ show err
where
txBodyContent = TxBodyContent {
txIns = txins
txIns = zip txins $ repeat $ BuildTxWith $ KeyWitness $ KeyWitnessForSpending
, txOuts = txouts
, txFee = fees
, txValidityRange = (TxValidityNoLowerBound, validityUpperBound)
Expand Down Expand Up @@ -101,7 +101,7 @@ mkTransaction key metadata ttl fee txins txouts
Left err -> error $ show err
where
txBodyContent = TxBodyContent {
txIns = txins
txIns = zip txins $ repeat $ BuildTxWith $ KeyWitness $ KeyWitnessForSpending
, txOuts = txouts
, txFee = mkFee fee
, txValidityRange = (TxValidityNoLowerBound, mkValidityUpperBound ttl)
Expand Down
32 changes: 20 additions & 12 deletions cardano-tx-generator/src/Cardano/Benchmarking/OuroborosImports.hs
Expand Up @@ -5,8 +5,6 @@
module Cardano.Benchmarking.OuroborosImports
(
CardanoBlock
, Consensus.Protocol
, Consensus.ProtocolCardano
, LocalSubmitTx
, LoggingLayer
, PaymentKey
Expand Down Expand Up @@ -36,6 +34,7 @@ import Ouroboros.Consensus.Shelley.Eras (StandardShelley)
import Ouroboros.Network.Protocol.LocalTxSubmission.Type (SubmitResult (..))

import Cardano.Node.Configuration.Logging (LoggingLayer)
import Cardano.Node.Protocol.Types ( SomeConsensusProtocol(..))

import Cardano.Api.Shelley (CardanoMode)
import Cardano.CLI.Types (SigningKeyFile)
Expand All @@ -44,25 +43,34 @@ import Cardano.Api (NetworkId(..), LocalNodeConnectInfo(..), Consensus
, TxInMode, TxValidationErrorInMode
, SigningKey, PaymentKey
, submitTxToNodeLocal)
import Cardano.Api.Protocol.Types (BlockType(..), ProtocolInfoArgs(..), protocolInfo)

import Shelley.Spec.Ledger.Genesis (ShelleyGenesis)

type CardanoBlock = Consensus.CardanoBlock StandardCrypto

getGenesis :: Consensus.Protocol IO CardanoBlock ptcl -> ShelleyGenesis StandardShelley
getGenesis
(Consensus.ProtocolCardano
_
Consensus.ProtocolParamsShelleyBased{Consensus.shelleyBasedGenesis}
_ _ _ _ _ _ ) = shelleyBasedGenesis
toProtocolInfo :: SomeConsensusProtocol -> ProtocolInfo IO CardanoBlock
toProtocolInfo (SomeConsensusProtocol CardanoBlockType info) = protocolInfo info
toProtocolInfo _ = error "toProtocolInfo unkown protocol"

getGenesis :: SomeConsensusProtocol -> ShelleyGenesis StandardShelley
getGenesis (SomeConsensusProtocol CardanoBlockType info) = shelleyBasedGenesis
where
(ProtocolInfoArgsCardano
_
Consensus.ProtocolParamsShelleyBased{Consensus.shelleyBasedGenesis}
_ _ _ _ _ _ ) = info
getGenesis (SomeConsensusProtocol _ _ ) = error "getGenesis (SomeConsensusProtocol _ _ ) unknown protocol"

protocolToTopLevelConfig :: Consensus.Protocol IO CardanoBlock ptcl -> TopLevelConfig CardanoBlock
protocolToTopLevelConfig :: SomeConsensusProtocol -> TopLevelConfig CardanoBlock
protocolToTopLevelConfig ptcl = pInfoConfig
where ProtocolInfo{pInfoConfig} = Consensus.protocolInfo ptcl
where
ProtocolInfo {pInfoConfig} = toProtocolInfo ptcl

protocolToCodecConfig :: Consensus.Protocol IO CardanoBlock ptcl -> CodecConfig CardanoBlock
protocolToCodecConfig :: SomeConsensusProtocol -> CodecConfig CardanoBlock
protocolToCodecConfig = configCodec . protocolToTopLevelConfig

protocolToNetworkId :: Consensus.Protocol IO CardanoBlock ptcl -> NetworkId
protocolToNetworkId :: SomeConsensusProtocol -> NetworkId
protocolToNetworkId ptcl
= Testnet $ getNetworkMagic $ configBlock $ protocolToTopLevelConfig ptcl

Expand Down
6 changes: 4 additions & 2 deletions cardano-tx-generator/src/Cardano/Benchmarking/Script/Store.hs
Expand Up @@ -19,9 +19,11 @@ import Data.GADT.Compare.TH (deriveGCompare, deriveGEq)
import Data.GADT.Show.TH (deriveGShow)

import Cardano.Api as Cardano (InAnyCardanoEra(..), Tx)
import Cardano.Node.Protocol.Types (SomeConsensusProtocol)

import Cardano.Benchmarking.Script.Setters as Setters
import Cardano.Benchmarking.OuroborosImports as Cardano
( Protocol, CardanoBlock, ProtocolCardano, LoggingLayer, ShelleyGenesis, StandardShelley
( LoggingLayer, ShelleyGenesis, StandardShelley
, NetworkId, SigningKey, PaymentKey)

import Cardano.Benchmarking.Tracer as Core (BenchTracers)
Expand All @@ -33,7 +35,7 @@ type Fund = (Core.Fund, SigningKey PaymentKey)
data Store v where
User :: Setters.Tag x -> Store x
LoggingLayer :: Store LoggingLayer
Protocol :: Store (Cardano.Protocol IO CardanoBlock ProtocolCardano)
Protocol :: Store SomeConsensusProtocol
BenchTracers :: Store Core.BenchTracers
NetworkId :: Store Cardano.NetworkId -- could be in Setters (just need JSON instance)
Genesis :: Store (ShelleyGenesis StandardShelley)
Expand Down

0 comments on commit 1961584

Please sign in to comment.