diff options
author | Sonic <sonic@dexon.org> | 2019-03-20 16:34:56 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@dexon.org> | 2019-04-09 21:32:58 +0800 |
commit | 2a6418678807137dfe6e5fba2969863bd468b840 (patch) | |
tree | bea1a37f28080c1fcdf58a6f9eb9e1dbd01df16e /dex/blockproposer.go | |
parent | 4364f00e2204debb48edf2940e1f89f46d7a9a18 (diff) | |
download | dexon-2a6418678807137dfe6e5fba2969863bd468b840.tar dexon-2a6418678807137dfe6e5fba2969863bd468b840.tar.gz dexon-2a6418678807137dfe6e5fba2969863bd468b840.tar.bz2 dexon-2a6418678807137dfe6e5fba2969863bd468b840.tar.lz dexon-2a6418678807137dfe6e5fba2969863bd468b840.tar.xz dexon-2a6418678807137dfe6e5fba2969863bd468b840.tar.zst dexon-2a6418678807137dfe6e5fba2969863bd468b840.zip |
dex: recieve bp msg when recovery, use atomic to protect the flag (#286)
Diffstat (limited to 'dex/blockproposer.go')
-rw-r--r-- | dex/blockproposer.go | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/dex/blockproposer.go b/dex/blockproposer.go index 63aaa5b51..24a277335 100644 --- a/dex/blockproposer.go +++ b/dex/blockproposer.go @@ -91,7 +91,7 @@ func (b *blockProposer) Stop() { defer b.mu.Unlock() if atomic.LoadInt32(&b.running) == 1 { - b.dex.protocolManager.receiveEnabled = false + atomic.StoreInt32(&b.dex.protocolManager.receiveEnabled, 0) close(b.stopCh) b.wg.Wait() atomic.StoreInt32(&b.proposing, 0) @@ -157,7 +157,7 @@ func (b *blockProposer) syncConsensus() (*dexCore.Consensus, error) { _, coreHeight := db.GetCompactionChainTipInfo() // Stop receiving block proposer message when syncing. - b.dex.protocolManager.receiveEnabled = false + atomic.StoreInt32(&b.dex.protocolManager.receiveEnabled, 0) Loop: for { @@ -211,10 +211,7 @@ ListenLoop: log.Error("SyncBlocks fail", "err", err) return nil, err } - if !b.dex.protocolManager.receiveEnabled { - // Start receiving block proposer message. - b.dex.protocolManager.receiveEnabled = true - } + atomic.CompareAndSwapInt32(&b.dex.protocolManager.receiveEnabled, 0, 1) if synced { log.Debug("Consensus core synced") break ListenLoop @@ -252,6 +249,7 @@ ListenLoop: log.Info("Sleeping until next starting time", "time", nextDMoment) time.Sleep(time.Duration(nextDMoment-time.Now().Unix()) * time.Second) + atomic.StoreInt32(&b.dex.protocolManager.receiveEnabled, 1) consensusSync.ForceSync(true) break ListenLoop } |