aboutsummaryrefslogtreecommitdiffstats
path: root/dex/blockproposer.go
diff options
context:
space:
mode:
authorWei-Ning Huang <w@dexon.org>2019-03-21 16:27:57 +0800
committerWei-Ning Huang <w@dexon.org>2019-04-09 21:32:58 +0800
commit53e91f6c8d2a1b00727b2670ee1f658269b6fb7a (patch)
tree8b174686087d2de6578491088e4664012d025ea4 /dex/blockproposer.go
parenta18f103408de2552bb5f47b1d76f4c6f18f0677e (diff)
downloaddexon-53e91f6c8d2a1b00727b2670ee1f658269b6fb7a.tar
dexon-53e91f6c8d2a1b00727b2670ee1f658269b6fb7a.tar.gz
dexon-53e91f6c8d2a1b00727b2670ee1f658269b6fb7a.tar.bz2
dexon-53e91f6c8d2a1b00727b2670ee1f658269b6fb7a.tar.lz
dexon-53e91f6c8d2a1b00727b2670ee1f658269b6fb7a.tar.xz
dexon-53e91f6c8d2a1b00727b2670ee1f658269b6fb7a.tar.zst
dexon-53e91f6c8d2a1b00727b2670ee1f658269b6fb7a.zip
dex: fix fast sync in BP mode (#291)
Start blockproposer only after fast sync is completed (received ChainHead event), so watchcat is not falsely triggered.
Diffstat (limited to 'dex/blockproposer.go')
-rw-r--r--dex/blockproposer.go17
1 files changed, 8 insertions, 9 deletions
diff --git a/dex/blockproposer.go b/dex/blockproposer.go
index 24a277335..dc2b22e16 100644
--- a/dex/blockproposer.go
+++ b/dex/blockproposer.go
@@ -50,7 +50,7 @@ func (b *blockProposer) Start() error {
if !atomic.CompareAndSwapInt32(&b.running, 0, 1) {
return fmt.Errorf("block proposer is already running")
}
- log.Info("Block proposer started")
+ log.Info("Started block proposer")
b.stopCh = make(chan struct{})
b.wg.Add(1)
@@ -61,6 +61,9 @@ func (b *blockProposer) Start() error {
var err error
var c *dexCore.Consensus
if b.dMoment.After(time.Now()) {
+ // Start receiving core messages.
+ b.dex.protocolManager.SetReceiveCoreMessage(true)
+
c = b.initConsensus()
} else {
c, err = b.syncConsensus()
@@ -91,7 +94,7 @@ func (b *blockProposer) Stop() {
defer b.mu.Unlock()
if atomic.LoadInt32(&b.running) == 1 {
- atomic.StoreInt32(&b.dex.protocolManager.receiveEnabled, 0)
+ b.dex.protocolManager.SetReceiveCoreMessage(false)
close(b.stopCh)
b.wg.Wait()
atomic.StoreInt32(&b.proposing, 0)
@@ -124,10 +127,9 @@ func (b *blockProposer) syncConsensus() (*dexCore.Consensus, error) {
db, b.dex.network, privkey, log.Root())
// Start the watchCat.
- log.Info("Starting sync watchCat ...")
-
b.watchCat.Start()
defer b.watchCat.Stop()
+ log.Info("Started sync watchCat")
// Feed the current block we have in local blockchain.
cb := b.dex.blockchain.CurrentBlock()
@@ -156,9 +158,6 @@ func (b *blockProposer) syncConsensus() (*dexCore.Consensus, error) {
// Sync all blocks in compaction chain to core.
_, coreHeight := db.GetCompactionChainTipInfo()
- // Stop receiving block proposer message when syncing.
- atomic.StoreInt32(&b.dex.protocolManager.receiveEnabled, 0)
-
Loop:
for {
currentBlock := b.dex.blockchain.CurrentBlock()
@@ -211,7 +210,7 @@ ListenLoop:
log.Error("SyncBlocks fail", "err", err)
return nil, err
}
- atomic.CompareAndSwapInt32(&b.dex.protocolManager.receiveEnabled, 0, 1)
+ b.dex.protocolManager.SetReceiveCoreMessage(true)
if synced {
log.Debug("Consensus core synced")
break ListenLoop
@@ -249,7 +248,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)
+ b.dex.protocolManager.SetReceiveCoreMessage(true)
consensusSync.ForceSync(true)
break ListenLoop
}