diff options
author | Wei-Ning Huang <w@dexon.org> | 2019-03-18 16:48:15 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@dexon.org> | 2019-04-09 21:32:58 +0800 |
commit | 3b2a10e72d5e7113b803b2099eb27c2acbe5a6b9 (patch) | |
tree | c081f7f33dbab6283a2a2fc3f4f2ec2d2f07fda3 | |
parent | 8d4b89d61bc36b77b3676071e9fd50bc1bf1aaa9 (diff) | |
download | dexon-3b2a10e72d5e7113b803b2099eb27c2acbe5a6b9.tar dexon-3b2a10e72d5e7113b803b2099eb27c2acbe5a6b9.tar.gz dexon-3b2a10e72d5e7113b803b2099eb27c2acbe5a6b9.tar.bz2 dexon-3b2a10e72d5e7113b803b2099eb27c2acbe5a6b9.tar.lz dexon-3b2a10e72d5e7113b803b2099eb27c2acbe5a6b9.tar.xz dexon-3b2a10e72d5e7113b803b2099eb27c2acbe5a6b9.tar.zst dexon-3b2a10e72d5e7113b803b2099eb27c2acbe5a6b9.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.go | 17 |
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() } |