From 272a4e9067f048e14ca97d68d4c5bfd14fc2a43d Mon Sep 17 00:00:00 2001 From: Rongjian Lan Date: Thu, 12 Jul 2018 15:53:09 +0800 Subject: [PATCH] Add report on avg tx size in bytes --- node/node_handler.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/node/node_handler.go b/node/node_handler.go index cffd466dc..6fa5749d7 100644 --- a/node/node_handler.go +++ b/node/node_handler.go @@ -87,14 +87,26 @@ func (node *Node) NodeHandler(conn net.Conn) { node.log.Debug("UtxoPool Report", "numEntries", len(node.UtxoPool.UtxoMap), "sizeInBytes", sizeInBytes) avgBlockSizeInBytes := 0 + txCount := 0 + avgTxSize := 0 + for _, block := range node.blockchain.Blocks { byteBuffer := bytes.NewBuffer([]byte{}) encoder := gob.NewEncoder(byteBuffer) encoder.Encode(block) avgBlockSizeInBytes += len(byteBuffer.Bytes()) + + txCount += len(block.Transactions) + + byteBuffer = bytes.NewBuffer([]byte{}) + encoder = gob.NewEncoder(byteBuffer) + encoder.Encode(block.Transactions) + avgTxSize += len(byteBuffer.Bytes()) } avgBlockSizeInBytes = avgBlockSizeInBytes / len(node.blockchain.Blocks) - node.log.Debug("Blockchain Report", "numBlocks", len(node.blockchain.Blocks), "avgSizeInBytes", avgBlockSizeInBytes) + avgTxSize = avgTxSize / txCount + + node.log.Debug("Blockchain Report", "numBlocks", len(node.blockchain.Blocks), "avgBlockSize", avgBlockSizeInBytes, "numTxs", txCount, "avgTxSzie", avgTxSize) os.Exit(0) }