aboutsummaryrefslogtreecommitdiffstats
path: root/simulation/verification.go
diff options
context:
space:
mode:
authorJimmy Hu <jimmy.hu@dexon.org>2018-07-31 16:22:58 +0800
committerGitHub <noreply@github.com>2018-07-31 16:22:58 +0800
commitc9cf5953512e4503f4781d6a441404ff9dfe5660 (patch)
tree3a5419aa11cbbaafeeaed229c32c325e33ce232d /simulation/verification.go
parent36d069fbecaf270974c920e6e27f0def22936fb9 (diff)
downloaddexon-consensus-c9cf5953512e4503f4781d6a441404ff9dfe5660.tar.gz
dexon-consensus-c9cf5953512e4503f4781d6a441404ff9dfe5660.tar.zst
dexon-consensus-c9cf5953512e4503f4781d6a441404ff9dfe5660.zip
Print block confirm latency when Peer Server stopped. (#23)
Diffstat (limited to 'simulation/verification.go')
-rw-r--r--simulation/verification.go37
1 files changed, 30 insertions, 7 deletions
diff --git a/simulation/verification.go b/simulation/verification.go
index bc1afc4..1f8947c 100644
--- a/simulation/verification.go
+++ b/simulation/verification.go
@@ -33,12 +33,14 @@ type timeStamp struct {
}
type totalOrderStatus struct {
- blockReceive []timeStamp
+ blockReceive []timeStamp
+ confirmLatency []time.Duration
}
// TotalOrderResult is the object maintaining peer's result of
// Total Ordering Algorithm.
type TotalOrderResult struct {
+ validatorID types.ValidatorID
hashList common.Hashes
curID int
pendingBlockList PendingBlockList
@@ -49,20 +51,28 @@ type TotalOrderResult struct {
type PeerTotalOrder = map[types.ValidatorID]*TotalOrderResult
// NewTotalOrderResult returns pointer to a a new TotalOrderResult instance.
-func NewTotalOrderResult() *TotalOrderResult {
- totalOrder := &TotalOrderResult{}
+func NewTotalOrderResult(vID types.ValidatorID) *TotalOrderResult {
+ totalOrder := &TotalOrderResult{
+ validatorID: vID,
+ }
heap.Init(&totalOrder.pendingBlockList)
return totalOrder
}
-// PushBlocks push a BlockList into the TotalOrderResult and return true if
-// there is new blocks ready for verifiy
-func (totalOrder *TotalOrderResult) PushBlocks(blocks BlockList) (ready bool) {
+func (totalOrder *TotalOrderResult) processStatus(blocks BlockList) {
totalOrder.status.blockReceive = append(totalOrder.status.blockReceive,
timeStamp{
time: time.Now(),
length: len(blocks.BlockHash),
})
+ totalOrder.status.confirmLatency = append(totalOrder.status.confirmLatency,
+ blocks.ConfirmLatency...)
+}
+
+// PushBlocks push a BlockList into the TotalOrderResult and return true if
+// there is new blocks ready for verifiy
+func (totalOrder *TotalOrderResult) PushBlocks(blocks BlockList) (ready bool) {
+ totalOrder.processStatus(blocks)
if blocks.ID != totalOrder.curID {
heap.Push(&totalOrder.pendingBlockList, &blocks)
return false
@@ -103,6 +113,16 @@ func (totalOrder *TotalOrderResult) CalculateBlocksPerSecond() float64 {
return float64(totalBlocks) / diffTime
}
+// CalculateAverageConfirmLatency calculates the result using
+// status.confirmLatency
+func (totalOrder *TotalOrderResult) CalculateAverageConfirmLatency() float64 {
+ sum := 0.0
+ for _, latency := range totalOrder.status.confirmLatency {
+ sum += latency.Seconds()
+ }
+ return sum / float64(len(totalOrder.status.confirmLatency))
+}
+
// VerifyTotalOrder verifies if the result of Total Ordering Algorithm
// returned by all validators are the same. However, the length of result
// of each validators may not be the same, so only the common part is verified.
@@ -151,6 +171,9 @@ func VerifyTotalOrder(id types.ValidatorID,
// LogStatus prints all the status to log.
func LogStatus(peerTotalOrder PeerTotalOrder) {
for vID, totalOrder := range peerTotalOrder {
- log.Printf("[Validator %s] BPS: %.6f\n", vID, totalOrder.CalculateBlocksPerSecond())
+ log.Printf("[Validator %s] BPS: %.6f\n",
+ vID, totalOrder.CalculateBlocksPerSecond())
+ log.Printf("[Validator %s] Confirm Latency: %.3fs\n",
+ vID, totalOrder.CalculateAverageConfirmLatency())
}
}