added latestBlockHash and latestTxHash.

pull/69/head
Richard Liu 6 years ago
parent 91f53904cb
commit 32d7047512
  1. 17
      consensus/consensus_leader.go

@ -4,6 +4,7 @@ import (
"bytes" "bytes"
"encoding/binary" "encoding/binary"
"encoding/gob" "encoding/gob"
"encoding/hex"
"errors" "errors"
"net/http" "net/http"
"net/url" "net/url"
@ -371,7 +372,7 @@ func (consensus *Consensus) processResponseMessage(payload []byte, targetState C
copy(blockHeaderObj.Bitmap[:], bitmap) copy(blockHeaderObj.Bitmap[:], bitmap)
consensus.OnConsensusDone(&blockHeaderObj) consensus.OnConsensusDone(&blockHeaderObj)
consensus.reportTPS(blockHeaderObj.NumTransactions) consensus.reportMetrics(blockHeaderObj)
// Send signal to Node so the new block can be added and new round of consensus can be triggered // Send signal to Node so the new block can be added and new round of consensus can be triggered
consensus.ReadySignal <- 1 consensus.ReadySignal <- 1
} }
@ -403,9 +404,10 @@ func (consensus *Consensus) verifyResponse(commitments *map[uint16]kyber.Point,
return nil return nil
} }
func (consensus *Consensus) reportTPS(numOfTxs int32) { func (consensus *Consensus) reportMetrics(block blockchain.Block) {
endTime := time.Now() endTime := time.Now()
timeElapsed := endTime.Sub(startTime) timeElapsed := endTime.Sub(startTime)
numOfTxs := block.NumTransactions
tps := float64(numOfTxs) / timeElapsed.Seconds() tps := float64(numOfTxs) / timeElapsed.Seconds()
consensus.Log.Info("TPS Report", consensus.Log.Info("TPS Report",
"numOfTXs", numOfTxs, "numOfTXs", numOfTxs,
@ -414,21 +416,20 @@ func (consensus *Consensus) reportTPS(numOfTxs int32) {
"timeElapsed", timeElapsed, "timeElapsed", timeElapsed,
"TPS", tps, "TPS", tps,
"consensus", consensus) "consensus", consensus)
consensus.reportMetrics(numOfTxs, tps)
}
func (consensus *Consensus) reportMetrics(numOfTxs int32, tps float64) { // Post metrics
URL := "http://localhost:3000/report" URL := "http://localhost:3000/report"
form := url.Values{ form := url.Values{
"tps": {strconv.FormatFloat(tps, 'f', 2, 64)}, "tps": {strconv.FormatFloat(tps, 'f', 2, 64)},
"txCount": {strconv.Itoa(int(numOfTxs))}, "txCount": {strconv.Itoa(int(numOfTxs))},
"nodeCount": {strconv.Itoa(len(consensus.validators) + 1)}, "nodeCount": {strconv.Itoa(len(consensus.validators) + 1)},
"latestBlockHash": {hex.EncodeToString(consensus.blockHash[:])},
"latestTxHash": {hex.EncodeToString(block.TransactionIds[len(block.TransactionIds)-1][:])},
} }
body := bytes.NewBufferString(form.Encode()) body := bytes.NewBufferString(form.Encode())
rsp, err := http.Post(URL, "application/x-www-form-urlencoded", body) rsp, err := http.Post(URL, "application/x-www-form-urlencoded", body)
if err != nil { if err == nil {
return
}
defer rsp.Body.Close() defer rsp.Body.Close()
} }
}

Loading…
Cancel
Save