aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJimmy Hu <jimmy.hu@dexon.org>2019-01-07 12:04:43 +0800
committerGitHub <noreply@github.com>2019-01-07 12:04:43 +0800
commit492417dd55f6aaf0436c316634b66bf4882420f8 (patch)
treefa8a0849c43c42adfe63321a7d94664f9030e8b0
parent36d4d760f1d5a108af86094eefbb5303f0334e60 (diff)
downloadtangerine-consensus-492417dd55f6aaf0436c316634b66bf4882420f8.tar.gz
tangerine-consensus-492417dd55f6aaf0436c316634b66bf4882420f8.tar.zst
tangerine-consensus-492417dd55f6aaf0436c316634b66bf4882420f8.zip
simulation: Fix simulation stuffs (#405)
* test: fix marshal randomness pullrequest * Add result for witness latency
-rw-r--r--core/test/network.go8
-rw-r--r--simulation/app.go16
2 files changed, 22 insertions, 2 deletions
diff --git a/core/test/network.go b/core/test/network.go
index 066d36c..49342f0 100644
--- a/core/test/network.go
+++ b/core/test/network.go
@@ -75,6 +75,8 @@ func (req *PullRequest) MarshalJSON() (b []byte, err error) {
idAsBytes, err = json.Marshal(req.Identity.(common.Hashes))
case "vote":
idAsBytes, err = json.Marshal(req.Identity.(types.Position))
+ case "randomness":
+ idAsBytes, err = json.Marshal(req.Identity.(common.Hashes))
default:
err = fmt.Errorf("unknown ID type for pull request: %v", req.Type)
}
@@ -113,6 +115,12 @@ func (req *PullRequest) UnmarshalJSON(data []byte) (err error) {
break
}
ID = pos
+ case "randomness":
+ hashes := common.Hashes{}
+ if err = json.Unmarshal(rawReq.Identity, &hashes); err != nil {
+ break
+ }
+ ID = hashes
default:
err = fmt.Errorf("unknown pull request type: %v", rawReq.Type)
}
diff --git a/simulation/app.go b/simulation/app.go
index 2bf0e48..c72a0a5 100644
--- a/simulation/app.go
+++ b/simulation/app.go
@@ -51,8 +51,10 @@ const (
blockEventConfirmed
// Block delivered by lattice.
blockEventDelivered
- // block is ready (Randomness calculated)
+ // Block is ready (Randomness calculated)
blockEventReady
+ // Block is witness
+ blockEventWitnessed
blockEventCount
)
@@ -158,7 +160,7 @@ func (a *simApp) TotalOrderingDelivered(
a.lock.RLock()
defer a.lock.RUnlock()
for _, h := range blockHashes {
- latencies = append(latencies, time.Since(a.blockTimestamps[h][blockEventConfirmed]))
+ latencies = append(latencies, time.Since(a.blockTimestamps[h][blockEventReceived]))
}
}()
blockList := &BlockList{
@@ -186,6 +188,11 @@ func (a *simApp) BlockDelivered(
panic(err)
}
}
+ var witnessBlockHash common.Hash
+ if err := witnessBlockHash.UnmarshalText(block.Witness.Data); err != nil {
+ panic(err)
+ }
+ a.updateBlockEvent(witnessBlockHash)
} else {
panic(fmt.Errorf("Block is not confirmed yet: %s", blockHash))
}
@@ -193,8 +200,13 @@ func (a *simApp) BlockDelivered(
func() {
a.latestWitnessReady.L.Lock()
defer a.latestWitnessReady.L.Unlock()
+ data, err := blockHash.MarshalText()
+ if err != nil {
+ panic(err)
+ }
a.latestWitness = types.Witness{
Height: result.Height,
+ Data: data,
}
a.latestWitnessReady.Broadcast()
}()