diff options
author | Sonic <sonic@dexon.org> | 2019-03-20 16:34:56 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@byzantine-lab.io> | 2019-06-13 18:11:44 +0800 |
commit | 434e74e4b975c0f7fb3763cd6fd67eb7e020a768 (patch) | |
tree | 0128146e429faa1feb7aba0f235ef7fc6ccc6e0f /dex/blockproposer.go | |
parent | 1eacbcbe3c890238da49fcfdddc151a5b7748265 (diff) | |
download | go-tangerine-434e74e4b975c0f7fb3763cd6fd67eb7e020a768.tar go-tangerine-434e74e4b975c0f7fb3763cd6fd67eb7e020a768.tar.gz go-tangerine-434e74e4b975c0f7fb3763cd6fd67eb7e020a768.tar.bz2 go-tangerine-434e74e4b975c0f7fb3763cd6fd67eb7e020a768.tar.lz go-tangerine-434e74e4b975c0f7fb3763cd6fd67eb7e020a768.tar.xz go-tangerine-434e74e4b975c0f7fb3763cd6fd67eb7e020a768.tar.zst go-tangerine-434e74e4b975c0f7fb3763cd6fd67eb7e020a768.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 } |