@@ -29,6 +29,8 @@ import (
2929 "sync"
3030 "time"
3131
32+ "github.com/hyperledger/fabric-lib-go/common/flogging"
33+
3234 "github.com/hyperledger/fabric-x-orderer/config/protos"
3335
3436 "github.com/hyperledger/fabric-x-orderer/testutil/fabric"
@@ -86,6 +88,8 @@ func init() {
8688 grpclog .SetLoggerV2 (grpclog .NewLoggerV2 (io .Discard , io .Discard , io .Discard ))
8789}
8890
91+ var logger = flogging .MustGetLogger ("armageddon" )
92+
8993type NetworkCryptoConfig struct {
9094 // map from party to its crypto config
9195 PartyToCryptoConfig map [types.PartyID ]CryptoConfigPerParty
@@ -257,6 +261,8 @@ func (cli *CLI) Run(args []string) {
257261 generate (cli .genConfigFile , cli .outputDir , cli .useTLS )
258262 } else if * cli .version == 2 {
259263 generateConfigAndCrypto (cli .genConfigFile , cli .outputDir , cli .sampleConfigPath )
264+ logger .Infof ("Configuration material was created successfully in %s" , * cli .outputDir )
265+
260266 } else {
261267 fmt .Fprintf (os .Stderr , "Invalid version: %d" , * cli .version )
262268 os .Exit (- 1 )
@@ -910,6 +916,8 @@ func submit(userConfigFile **os.File, transactions *int, rate *int, txSize *int)
910916 keyValMap : make (map [string ]bool ),
911917 mutex : sync.Mutex {},
912918 }
919+
920+ logger .Infof ("Submit starts....." )
913921 var waitForTxToBeSentAndReceived sync.WaitGroup
914922 waitForTxToBeSentAndReceived .Add (2 )
915923 go func () {
@@ -927,7 +935,7 @@ func submit(userConfigFile **os.File, transactions *int, rate *int, txSize *int)
927935
928936 waitForTxToBeSentAndReceived .Wait ()
929937 elapsed := time .Since (start )
930-
938+ logger . Infof ( "Submit Finished....." )
931939 // report results
932940 reportResults (* transactions , elapsed , txDelayTimes , numOfBlocks , * txSize )
933941}
@@ -977,7 +985,7 @@ func receive(userConfigFile **os.File, pullFromPartyId *int, receiveOutputDir *s
977985
978986 // pull blocks from the assembler and report statistics to statistics.csv file
979987 pullBlocksFromAssemblerAndCollectStatistics (userConfig , * pullFromPartyId , * receiveOutputDir , * expectedNumOfTxs )
980- fmt . Printf ("Receive command finished, statistics can be found in: %v\n " , path .Join (* receiveOutputDir , "statistics.csv" ))
988+ logger . Infof ("Receive command finished, statistics can be found in: %v\n " , path .Join (* receiveOutputDir , "statistics.csv" ))
981989}
982990
983991func trimPortFromEndpoint (endpoint string ) string {
@@ -1221,6 +1229,7 @@ func pullBlocksFromAssemblerAndCollectStatistics(userConfig *UserConfig, pullFro
12211229 // pull blocks from the assembler
12221230 // if a flag is given, stop when finish receiving all txs
12231231 go func () {
1232+ logger .Infof ("starting pulling blocks from the assembler" )
12241233 var txsTotal int
12251234 for {
12261235 block , err := pullBlock (stream , endpointToPullFrom , gRPCAssemblerClientConn )
@@ -1240,7 +1249,10 @@ func pullBlocksFromAssemblerAndCollectStatistics(userConfig *UserConfig, pullFro
12401249 blockChan <- blockWithTime
12411250 txsTotal += len (blockWithTime .block .Data .Data )
12421251
1243- if expectedNumOfTxs > 0 && expectedNumOfTxs == txsTotal {
1252+ logger .Debugf ("block with %d txs was pulled from the assembler, overall %d txs were received at this moment" , len (blockWithTime .block .Data .Data ), txsTotal )
1253+
1254+ if expectedNumOfTxs > 0 && expectedNumOfTxs <= txsTotal {
1255+ logger .Debugf ("overall %d txs were received, finished pulling" , txsTotal )
12441256 waitToFinish .Done ()
12451257 return
12461258 }
@@ -1262,6 +1274,7 @@ func pullBlocksFromAssemblerAndCollectStatistics(userConfig *UserConfig, pullFro
12621274 // iterate over txs in block
12631275 for j := 0 ; j < txs ; j ++ {
12641276 env , err := protoutil .GetEnvelopeFromBlock (blockWithTime .block .Data .Data [j ])
1277+ logger .Debugf ("tx %x was received from the assembler" , env .Payload )
12651278 if err != nil {
12661279 fmt .Fprintf (os .Stderr , "failed to get envelope from block: %v" , err )
12671280 os .Exit (3 )
@@ -1274,7 +1287,8 @@ func pullBlocksFromAssemblerAndCollectStatistics(userConfig *UserConfig, pullFro
12741287 }
12751288 statisticsAggregator .Add (txs , 1 , sumOfDelayTimes , sumOfTxsSize )
12761289
1277- if expectedNumOfTxs > 0 && expectedNumOfTxs == txsTotal {
1290+ if expectedNumOfTxs > 0 && expectedNumOfTxs <= txsTotal {
1291+ logger .Infof ("%d txs were expected and overall %d were successfully received" , expectedNumOfTxs , txsTotal )
12781292 close (stopChan )
12791293 waitToFinish .Done ()
12801294 return
@@ -1283,6 +1297,7 @@ func pullBlocksFromAssemblerAndCollectStatistics(userConfig *UserConfig, pullFro
12831297 }()
12841298
12851299 waitToFinish .Wait ()
1300+ logger .Debugf ("exit pulling blocks from the assembler" )
12861301}
12871302
12881303func calculateDelayOfTx (env * common.Envelope , acceptedTime time.Time ) time.Duration {
@@ -1322,7 +1337,8 @@ func pullBlock(stream ab.AtomicBroadcast_DeliverClient, endpointToPullFrom strin
13221337func sendTx (txsMap * protectedMap , streams []ab.AtomicBroadcast_BroadcastClient , i int , txSize int , sessionNumber []byte ) {
13231338 payload := prepareTx (i , txSize , sessionNumber )
13241339 if txsMap != nil {
1325- txsMap .Add (string (payload [:32 ]))
1340+ logger .Debugf ("Add tx %x to the map" , payload )
1341+ txsMap .Add (string (payload ))
13261342 }
13271343 for j := 0 ; j < len (streams ); j ++ {
13281344 err := streams [j ].Send (& common.Envelope {Payload : payload })
@@ -1356,17 +1372,18 @@ func reportResults(transactions int, elapsed time.Duration, txDelayTimesResult f
13561372 avgTxDelay := txDelayTimesResult / float64 (transactions )
13571373 avgBlockRate := float64 (numOfBlocksResult ) / elapsed .Seconds ()
13581374 avgBlockSize := transactions / numOfBlocksResult
1359- fmt . Printf ("SUCCESS: number of txs: %d, tx size: %d bytes, elapsed time: %v, avg. tx rate: %.2f, avg. tx delay: %vs, num of blocks: %d, avg. block rate: %v, avg. block size: %v txs\n " , transactions , txSize , elapsed , avgTxRate , avgTxDelay , numOfBlocksResult , avgBlockRate , avgBlockSize )
1375+ logger . Infof ("SUCCESS: number of txs: %d, tx size: %d bytes, elapsed time: %v, avg. tx rate: %.2f, avg. tx delay: %vs, num of blocks: %d, avg. block rate: %v, avg. block size: %v txs\n " , transactions , txSize , elapsed , avgTxRate , avgTxDelay , numOfBlocksResult , avgBlockRate , avgBlockSize )
13601376}
13611377
13621378func reportLoadResults (transactions int , elapsed time.Duration , txSize int ) {
13631379 avgTxSendingRate := float64 (transactions ) / elapsed .Seconds ()
1364- fmt . Printf ("Load command finished, sent %d TXs in %v seconds, TX size %d, avg. tx sending rate: %.2f\n " , transactions , elapsed , txSize , avgTxSendingRate )
1380+ logger . Infof ("Load command finished, sent %d TXs in %v seconds, TX size %d, avg. tx sending rate: %.2f\n " , transactions , elapsed , txSize , avgTxSendingRate )
13651381}
13661382
13671383// manageStatistics manages a statistics queue and every hour writes the queue to a CSV file
13681384func manageStatistics (receiveOutputDir string , statisticChan <- chan Statistics , stopChan <- chan bool , startTime float64 , expectedTxs int , pullFrom int , timeIntervalToSampleStat time.Duration ) {
13691385 filePath := path .Join (receiveOutputDir , "statistics.csv" )
1386+ logger .Infof ("Statistics are written to: %v\n " , filePath )
13701387 fmt .Printf ("Statistics are written to: %v\n " , filePath )
13711388 file , err := os .OpenFile (filePath , os .O_CREATE | os .O_WRONLY | os .O_TRUNC , 0o644 )
13721389 if err != nil {
@@ -1443,7 +1460,7 @@ func writeStatisticsToCSV(file *os.File, statistic Statistics, timeIntervalToSam
14431460 fmt .Sprintf ("%d" , avgNumOfTxsInBlock ),
14441461 })
14451462 if err != nil {
1446- fmt . Printf ("failed to write to CSV: %v" , err )
1463+ logger . Errorf ("failed to write to CSV: %v" , err )
14471464 }
14481465}
14491466
@@ -1548,6 +1565,7 @@ func receiveResponseFromAssembler(userConfig *UserConfig, txsMap *protectedMap,
15481565
15491566 // 2. delete the tx from the map
15501567 if txsMap != nil {
1568+ logger .Debugf ("remove tx %x from the map" , env .Payload )
15511569 txsMap .Remove (string (env .Payload ))
15521570 }
15531571 }
@@ -1558,7 +1576,7 @@ func receiveResponseFromAssembler(userConfig *UserConfig, txsMap *protectedMap,
15581576 continue
15591577 }
15601578
1561- if (txsMap != nil && txsMap .IsEmpty ()) || numOfTxsCalculated = = expectedNumOfTxs {
1579+ if (txsMap != nil && txsMap .IsEmpty ()) && numOfTxsCalculated > = expectedNumOfTxs {
15621580 break
15631581 }
15641582 }
0 commit comments