diff options
author | bojie <a1346494@gmail.com> | 2018-11-12 09:15:21 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@dexon.org> | 2019-03-12 12:19:09 +0800 |
commit | 665b5c0c80b48e31a6da1f0afc36fc95c4580295 (patch) | |
tree | c81eb1321b5e63457f24974da53182620c9017fa /dex | |
parent | c0bd41b4341f5d305067526f4783c54ae572f122 (diff) | |
download | dexon-665b5c0c80b48e31a6da1f0afc36fc95c4580295.tar.gz dexon-665b5c0c80b48e31a6da1f0afc36fc95c4580295.tar.zst dexon-665b5c0c80b48e31a6da1f0afc36fc95c4580295.zip |
app: bug fix (#7)
Add notify mutex to prevent missing chain issue while concurrent
appending with same slice.
Diffstat (limited to 'dex')
-rw-r--r-- | dex/app.go | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/dex/app.go b/dex/app.go index 7d2165118..d0d911e86 100644 --- a/dex/app.go +++ b/dex/app.go @@ -51,6 +51,7 @@ type DexconApp struct { chainLocksInitMu sync.Mutex chainLocks map[uint32]*sync.RWMutex + notifyMu sync.Mutex notifyChan sync.Map chainLatestRoot sync.Map } @@ -79,6 +80,9 @@ func NewDexconApp(txPool *core.TxPool, blockchain *core.BlockChain, gov *DexconG } func (d *DexconApp) addNotify(height uint64) <-chan uint64 { + d.notifyMu.Lock() + defer d.notifyMu.Unlock() + result := make(chan uint64) v, ok := d.notifyChan.Load(height) if ok { @@ -92,6 +96,9 @@ func (d *DexconApp) addNotify(height uint64) <-chan uint64 { } func (d *DexconApp) notify(height uint64) { + d.notifyMu.Lock() + defer d.notifyMu.Unlock() + d.notifyChan.Range(func(key, value interface{}) bool { h := key.(uint64) n := value.(*notify) |