aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWei-Ning Huang <w@dexon.org>2019-03-18 16:48:15 +0800
committerWei-Ning Huang <w@dexon.org>2019-04-09 13:50:04 +0800
commit53c757786e033cc40d08e9e3d779981bbb93a7bb (patch)
tree058defeefee21b1b73cd7bed6343a87242a66618
parent41f11316cf0f764b4dc7f0047e68ea04d228f8c9 (diff)
downloaddexon-53c757786e033cc40d08e9e3d779981bbb93a7bb.tar
dexon-53c757786e033cc40d08e9e3d779981bbb93a7bb.tar.gz
dexon-53c757786e033cc40d08e9e3d779981bbb93a7bb.tar.bz2
dexon-53c757786e033cc40d08e9e3d779981bbb93a7bb.tar.lz
dexon-53c757786e033cc40d08e9e3d779981bbb93a7bb.tar.xz
dexon-53c757786e033cc40d08e9e3d779981bbb93a7bb.tar.zst
dexon-53c757786e033cc40d08e9e3d779981bbb93a7bb.zip
dex: align recovery dMoment when resuming consensus (#271)
In theory BA should tolerant inconsistant start time between every node. Since the vote cache is limited, we can not keep all the votes and pass them around all nodes. To fix this, we align the next recovery dmoment so nodes start at the same time.
-rw-r--r--dex/blockproposer.go17
1 files changed, 16 insertions, 1 deletions
diff --git a/dex/blockproposer.go b/dex/blockproposer.go
index b51c9d10b..63d424ab6 100644
--- a/dex/blockproposer.go
+++ b/dex/blockproposer.go
@@ -122,6 +122,7 @@ func (b *blockProposer) syncConsensus() (*dexCore.Consensus, error) {
// Start the watchCat.
log.Info("Starting sync watchCat ...")
b.watchCat.Start()
+ defer b.watchCat.Stop()
// Feed the current block we have in local blockchain.
cb := b.dex.blockchain.CurrentBlock()
@@ -217,11 +218,25 @@ ListenLoop:
return nil, errors.New("early stop")
case <-b.watchCat.Meow():
log.Info("WatchCat signaled to stop syncing")
+
+ // Sleep until the next consensus start time slot.
+ // The interval T_i need to meet the following requirement:
+ //
+ // T_i > T_timeout + T_panic + T_restart
+ //
+ // Currently, T_timeout = 120, T_panic = 60, T_restart ~ 60
+ //
+ // We set T_i = 600 to be safe.
+
+ interval := int64(600)
+ nextDMoment := (time.Now().Unix()/interval + 1) * interval
+ log.Info("Sleeping until next starting time", "time", nextDMoment)
+ time.Sleep(time.Duration(nextDMoment-time.Now().Unix()) * time.Second)
+
consensusSync.ForceSync(true)
break ListenLoop
}
}
- b.watchCat.Stop()
return consensusSync.GetSyncedConsensus()
}