aboutsummaryrefslogtreecommitdiffstats
path: root/simulation
diff options
context:
space:
mode:
authorJimmy Hu <jimmy.hu@dexon.org>2018-08-13 16:28:16 +0800
committermissionliao <38416648+missionliao@users.noreply.github.com>2018-08-13 16:28:16 +0800
commit3733e4c72dd1b16626bf257f4acb9a74f795d924 (patch)
treefb43a72f6460944a0f6a10d5d2da9317679fc930 /simulation
parent2d3725842cb995cc748aeb6c05adb725f6ae18f8 (diff)
downloadtangerine-consensus-3733e4c72dd1b16626bf257f4acb9a74f795d924.tar.gz
tangerine-consensus-3733e4c72dd1b16626bf257f4acb9a74f795d924.tar.zst
tangerine-consensus-3733e4c72dd1b16626bf257f4acb9a74f795d924.zip
Use RLock for simulation.simApp.blockByHash (#53)
Diffstat (limited to 'simulation')
-rw-r--r--simulation/app.go7
1 files changed, 3 insertions, 4 deletions
diff --git a/simulation/app.go b/simulation/app.go
index 0330f07..a6f9a57 100644
--- a/simulation/app.go
+++ b/simulation/app.go
@@ -58,6 +58,7 @@ func (a *simApp) addBlock(block *types.Block) {
a.blockByHashMutex.Lock()
defer a.blockByHashMutex.Unlock()
+ // TODO(jimmy-dexon) : Remove block in this hash if it's no longer needed.
a.blockByHash[block.Hash] = block
}
@@ -95,11 +96,11 @@ func (a *simApp) StronglyAcked(blockHash common.Hash) {
// TotalOrderingDeliver is called when blocks are delivered by the total
// ordering algorithm.
func (a *simApp) TotalOrderingDeliver(blockHashes common.Hashes, early bool) {
- a.blockByHashMutex.Lock()
- defer a.blockByHashMutex.Unlock()
now := time.Now()
blocks := make([]*types.Block, len(blockHashes))
+ a.blockByHashMutex.RLock()
+ defer a.blockByHashMutex.RUnlock()
for idx := range blockHashes {
blocks[idx] = a.blockByHash[blockHashes[idx]]
}
@@ -115,8 +116,6 @@ func (a *simApp) TotalOrderingDeliver(blockHashes common.Hashes, early bool) {
confirmLatency = append(confirmLatency,
now.Sub(block.Timestamps[a.ValidatorID]))
}
- // TODO(jimmy-dexon) : Remove block in this hash if it's no longer needed.
- a.blockByHash[block.Hash] = block
for hash := range block.Acks {
for _, blockHash := range a.getAckedBlocks(hash) {
payload = append(payload, TimestampMessage{