Make transaction Ids report flexible on empty blocks

pull/69/head
Rongjian Lan 6 years ago
parent d91ca0c27b
commit 1e23a94207
  1. 12
      consensus/consensus_leader.go

@ -419,16 +419,18 @@ func (consensus *Consensus) reportMetrics(block blockchain.Block) {
// Post metrics
URL := "http://localhost:3000/report"
txHashes := []string{}
for i := 1; i <= 3; i++ {
if len(block.TransactionIds)-i >= 0 {
txHashes = append(txHashes, hex.EncodeToString(block.TransactionIds[len(block.TransactionIds)-i][:]))
}
}
form := url.Values{
"tps": {strconv.FormatFloat(tps, 'f', 2, 64)},
"txCount": {strconv.Itoa(int(numOfTxs))},
"nodeCount": {strconv.Itoa(len(consensus.validators) + 1)},
"latestBlockHash": {hex.EncodeToString(consensus.blockHash[:])},
"latestTxHashes": {
hex.EncodeToString(block.TransactionIds[len(block.TransactionIds)-1][:]),
hex.EncodeToString(block.TransactionIds[len(block.TransactionIds)-2][:]),
hex.EncodeToString(block.TransactionIds[len(block.TransactionIds)-3][:]),
},
"latestTxHashes": txHashes,
"blockLatency": {strconv.Itoa(int(timeElapsed / time.Millisecond))},
}

Loading…
Cancel
Save