aboutsummaryrefslogtreecommitdiffstats
path: root/simulation/app.go
diff options
context:
space:
mode:
authorWei-Ning Huang <w@dexon.org>2018-08-13 16:06:29 +0800
committermissionliao <38416648+missionliao@users.noreply.github.com>2018-08-13 16:06:29 +0800
commite22580beadb70991d95f13677f22701fe273791a (patch)
treec22a62d4c82c4b2bc66bdea7ab1a0e4cb790865f /simulation/app.go
parenta8ebf501e54406c7449f71dba0c9af696bbc4e21 (diff)
downloadtangerine-consensus-e22580beadb70991d95f13677f22701fe273791a.tar
tangerine-consensus-e22580beadb70991d95f13677f22701fe273791a.tar.gz
tangerine-consensus-e22580beadb70991d95f13677f22701fe273791a.tar.bz2
tangerine-consensus-e22580beadb70991d95f13677f22701fe273791a.tar.lz
tangerine-consensus-e22580beadb70991d95f13677f22701fe273791a.tar.xz
tangerine-consensus-e22580beadb70991d95f13677f22701fe273791a.tar.zst
tangerine-consensus-e22580beadb70991d95f13677f22701fe273791a.zip
simulation: fix concurrent map write (#52)
Fix concurrent map write and also change k8s settings.
Diffstat (limited to 'simulation/app.go')
-rw-r--r--simulation/app.go9
1 files changed, 9 insertions, 0 deletions
diff --git a/simulation/app.go b/simulation/app.go
index 89b41a1..0330f07 100644
--- a/simulation/app.go
+++ b/simulation/app.go
@@ -20,6 +20,7 @@ package simulation
import (
"encoding/json"
"fmt"
+ "sync"
"time"
"github.com/dexon-foundation/dexon-consensus-core/common"
@@ -38,6 +39,7 @@ type simApp struct {
// uncofirmBlocks stores the blocks whose timestamps are not ready.
unconfirmedBlocks map[types.ValidatorID]common.Hashes
blockByHash map[common.Hash]*types.Block
+ blockByHashMutex sync.RWMutex
}
// newSimApp returns point to a new instance of simApp.
@@ -53,6 +55,9 @@ func newSimApp(id types.ValidatorID, Network PeerServerNetwork) *simApp {
}
func (a *simApp) addBlock(block *types.Block) {
+ a.blockByHashMutex.Lock()
+ defer a.blockByHashMutex.Unlock()
+
a.blockByHash[block.Hash] = block
}
@@ -74,6 +79,7 @@ func (a *simApp) getAckedBlocks(ackHash common.Hash) (output common.Hashes) {
break
}
}
+
// All of the Height of unconfirmed blocks are lower than the acked block.
if len(output) == 0 {
output, a.unconfirmedBlocks[ackBlock.ProposerID] = hashes, common.Hashes{}
@@ -89,6 +95,9 @@ 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))
for idx := range blockHashes {