10
10
{-# OPTIONS_GHC -Wno-missed-specialisations #-}
11
11
12
12
module Cardano.CLI.Tx.Generation
13
- ( TargetNodeId (.. )
14
- , NumberOfTxs (.. )
13
+ ( NumberOfTxs (.. )
15
14
, NumberOfInputsPerTx (.. )
16
15
, NumberOfOutputsPerTx (.. )
17
16
, FeePerTx (.. )
@@ -31,10 +30,7 @@ import qualified Control.Exception as Exception
31
30
import Control.Monad (forM , forM_ , mapM , when )
32
31
import qualified Control.Monad.Class.MonadSTM as MSTM
33
32
import Control.Monad.Trans.Except (ExceptT )
34
- import Control.Monad.Trans.Except.Extra (firstExceptT ,
35
- hoistEither ,
36
- left , newExceptT ,
37
- right )
33
+ import Control.Monad.Trans.Except.Extra (left , right )
38
34
import Data.Bifunctor (bimap )
39
35
import qualified Data.ByteString.Lazy as LB
40
36
import Data.Either (isLeft )
@@ -69,11 +65,7 @@ import Cardano.Config.Logging (LoggingLayer (..), Trace)
69
65
import Cardano.Config.Types (NodeCLI (.. ))
70
66
import qualified Cardano.Crypto as Crypto
71
67
import Cardano.Config.Topology (NodeAddress (.. ),
72
- NodeHostAddress (.. ),
73
- TopologyError (.. ),
74
- TopologyInfo (.. ),
75
- createNodeAddress ,
76
- readTopologyFile )
68
+ NodeHostAddress (.. ))
77
69
import Cardano.CLI.Tx (txSpendGenesisUTxOByronPBFT )
78
70
import Cardano.CLI.Tx.BenchmarkingTxSubmission (ROEnv (.. ),
79
71
TraceBenchTxSubmit (.. ),
@@ -91,19 +83,15 @@ import Ouroboros.Consensus.Block(BlockProtocol)
91
83
import Ouroboros.Consensus.Ledger.Byron.Config (pbftProtocolMagic )
92
84
import Ouroboros.Consensus.Node.ProtocolInfo (ProtocolInfo (.. ),
93
85
protocolInfo )
94
- import Ouroboros.Consensus.NodeId (NodeId (.. ))
95
86
import qualified Ouroboros.Consensus.Protocol as Consensus
96
87
import Ouroboros.Consensus.Ledger.Byron (ByronBlock (.. ),
97
88
GenTx (.. ),
98
89
ByronConsensusProtocol )
99
90
import qualified Ouroboros.Consensus.Ledger.Byron as Byron
91
+ import Ouroboros.Consensus.NodeId (NodeId (.. ))
100
92
import Ouroboros.Consensus.Protocol.Abstract (NodeConfig )
101
93
import Ouroboros.Consensus.Protocol.PBFT (pbftExtConfig )
102
94
103
- newtype TargetNodeId =
104
- TargetNodeId Int
105
- deriving (Eq , Ord , Show )
106
-
107
95
newtype NumberOfTxs =
108
96
NumberOfTxs Word64
109
97
deriving (Eq , Ord , Show )
@@ -140,11 +128,7 @@ newtype TxAdditionalSize =
140
128
data TxGenError = CurrentlyCannotSendTxToRelayNode FilePath
141
129
-- ^ Relay nodes cannot currently be transaction recipients.
142
130
| InsufficientFundsForRecipientTx
143
- | TargetNodeAddressError TopologyError
144
131
-- ^ Error occurred while creating the target node address.
145
- | TopologyFileReadError String
146
- | NeedMinimumOneTargetNodeId [TargetNodeId ]
147
- -- ^ Need at least 1 target node id.
148
132
| NeedMinimumThreeSigningKeyFiles [FilePath ]
149
133
-- ^ Need at least 3 signing key files.
150
134
| SecretKeyDeserialiseError String
@@ -160,8 +144,7 @@ genesisBenchmarkRunner
160
144
:: LoggingLayer
161
145
-> NodeCLI
162
146
-> Consensus. Protocol ByronBlock
163
- -> TopologyInfo
164
- -> [TargetNodeId ]
147
+ -> NonEmpty NodeAddress
165
148
-> NumberOfTxs
166
149
-> NumberOfInputsPerTx
167
150
-> NumberOfOutputsPerTx
@@ -173,8 +156,7 @@ genesisBenchmarkRunner
173
156
genesisBenchmarkRunner loggingLayer
174
157
nCli
175
158
protocol@ (Consensus. ProtocolRealPBFT genesisConfig _ _ _ _)
176
- topologyInfo
177
- targetNodeIds
159
+ targetNodeAddresses
178
160
numOfTxs@ (NumberOfTxs rawNumOfTxs)
179
161
numOfInsPerTx
180
162
numOfOutsPerTx
@@ -185,29 +167,11 @@ genesisBenchmarkRunner loggingLayer
185
167
when (length signingKeyFiles < 3 ) $
186
168
left $ NeedMinimumThreeSigningKeyFiles signingKeyFiles
187
169
188
- when (null targetNodeIds) $
189
- left $ NeedMinimumOneTargetNodeId targetNodeIds
190
-
191
170
let (benchTracer, connectTracer, submitTracer, lowLevelSubmitTracer) = createTracers loggingLayer
192
171
193
172
liftIO . traceWith benchTracer . TraceBenchTxSubDebug
194
173
$ " ******* Tx generator, tracers are ready *******"
195
174
196
- liftIO . traceWith benchTracer . TraceBenchTxSubDebug
197
- $ " ******* Tx generator, protocol info and topology are ready *******"
198
-
199
- -- We have to extract host and port of the nodes we want to talk with
200
- -- (based on values of `--target-node-id` CLI argument) from the topology file.
201
- topology <- firstExceptT TopologyFileReadError . newExceptT $
202
- readTopologyFile (topologyFile topologyInfo)
203
- targetNodeAddresses <- forM targetNodeIds $ \ (TargetNodeId targetNodeId) -> do
204
- let eitherNodeAddress = createNodeAddress (CoreId targetNodeId) topology (topologyFile topologyInfo)
205
- targetNodeAddress <- firstExceptT TargetNodeAddressError . hoistEither $ eitherNodeAddress
206
- return targetNodeAddress
207
-
208
- liftIO . traceWith benchTracer . TraceBenchTxSubDebug
209
- $ " ******* Tx generator, target node's address is ready *******"
210
-
211
175
-- 'genesisKey' is for genesis address with initial amount of money (1.4 billion ADA for now).
212
176
-- 'sourceKey' is for source address that we'll use as a source of money for next transactions.
213
177
-- 'recepientKey' is for recipient address that we'll use as an output for next transactions.
@@ -236,7 +200,6 @@ genesisBenchmarkRunner loggingLayer
236
200
nCli
237
201
genesisConfig
238
202
pInfoConfig
239
- topologyInfo
240
203
genesisUtxo
241
204
genesisAddress
242
205
sourceAddress
@@ -255,7 +218,6 @@ genesisBenchmarkRunner loggingLayer
255
218
pInfoConfig
256
219
sourceKey
257
220
recipientAddress
258
- topologyInfo
259
221
targetNodeAddresses
260
222
numOfTxs
261
223
numOfInsPerTx
@@ -430,7 +392,6 @@ prepareInitialFunds
430
392
-> NodeCLI
431
393
-> CC.Genesis. Config
432
394
-> NodeConfig ByronConsensusProtocol
433
- -> TopologyInfo
434
395
-> Map Int ((CC.UTxO. TxIn , CC.UTxO. TxOut ), Crypto. SigningKey )
435
396
-> CC.Common. Address
436
397
-> CC.Common. Address
@@ -440,7 +401,6 @@ prepareInitialFunds llTracer
440
401
nCli
441
402
genesisConfig
442
403
pInfoConfig
443
- topologyInfo
444
404
genesisUtxo
445
405
genesisAddress
446
406
targetAddress
@@ -459,7 +419,7 @@ prepareInitialFunds llTracer
459
419
genesisAddress
460
420
(NE. fromList [outForBig])
461
421
462
- submitTx nCli pInfoConfig (node topologyInfo ) genesisTx llTracer
422
+ submitTx nCli pInfoConfig (CoreId 0 ) genesisTx llTracer
463
423
-- Done, the first transaction 'initGenTx' is submitted, now 'sourceAddress' has a lot of money.
464
424
465
425
let txIn = CC.UTxO. TxInUtxo (getTxIdFromGenTx genesisTx) 0
@@ -686,8 +646,7 @@ runBenchmark
686
646
-> NodeConfig ByronConsensusProtocol
687
647
-> Crypto. SigningKey
688
648
-> CC.Common. Address
689
- -> TopologyInfo
690
- -> [NodeAddress ]
649
+ -> NonEmpty NodeAddress
691
650
-> NumberOfTxs
692
651
-> NumberOfInputsPerTx
693
652
-> NumberOfOutputsPerTx
@@ -703,7 +662,6 @@ runBenchmark benchTracer
703
662
pInfoConfig
704
663
sourceKey
705
664
recipientAddress
706
- topologyInfo
707
665
targetNodeAddresses
708
666
numOfTxs
709
667
numOfInsPerTx
@@ -719,7 +677,6 @@ runBenchmark benchTracer
719
677
pInfoConfig
720
678
sourceKey
721
679
txFee
722
- topologyInfo
723
680
numOfTxs
724
681
numOfInsPerTx
725
682
@@ -769,7 +726,7 @@ runBenchmark benchTracer
769
726
recipientAddress
770
727
sourceKey
771
728
txFee
772
- (length targetNodeAddresses)
729
+ (NE. length targetNodeAddresses)
773
730
numOfTxs
774
731
numOfInsPerTx
775
732
numOfOutsPerTx
@@ -780,7 +737,7 @@ runBenchmark benchTracer
780
737
781
738
liftIO $ do
782
739
txsLists <- STM. atomically $ STM. takeTMVar txsListsForTargetNodes
783
- let targetNodesAddrsAndTxsLists = zip remoteAddresses txsLists
740
+ let targetNodesAddrsAndTxsLists = zip ( NE. toList remoteAddresses) txsLists
784
741
allAsyncs <- forM targetNodesAddrsAndTxsLists $ \ (remoteAddr, txsList) -> do
785
742
-- Launch connection and submission threads for a peer
786
743
-- (corresponding to one target node).
@@ -807,7 +764,6 @@ createMoreFundCoins
807
764
-> NodeConfig ByronConsensusProtocol
808
765
-> Crypto. SigningKey
809
766
-> FeePerTx
810
- -> TopologyInfo
811
767
-> NumberOfTxs
812
768
-> NumberOfInputsPerTx
813
769
-> ExceptT TxGenError IO ()
@@ -816,7 +772,6 @@ createMoreFundCoins llTracer
816
772
pInfoConfig
817
773
sourceKey
818
774
(FeePerTx txFee)
819
- topologyInfo
820
775
(NumberOfTxs numOfTxs)
821
776
(NumberOfInputsPerTx numOfInsPerTx) = do
822
777
let feePerTx = assumeBound . CC.Common. mkLovelace $ txFee
@@ -854,7 +809,7 @@ createMoreFundCoins llTracer
854
809
txOut
855
810
[]
856
811
liftIO $ forM_ splittingTxs $ \ (tx, txDetailsList) -> do
857
- submitTx nCli pInfoConfig (node topologyInfo ) tx llTracer
812
+ submitTx nCli pInfoConfig (CoreId 0 ) tx llTracer
858
813
-- Update available fundValueStatus to reuse the numSplittingTxOuts TxOuts.
859
814
forM_ txDetailsList addToAvailableFunds
860
815
where
0 commit comments