aboutsummaryrefslogtreecommitdiffstats
path: root/dex
diff options
context:
space:
mode:
authorWei-Ning Huang <w@dexon.org>2019-03-18 16:48:15 +0800
committerWei-Ning Huang <w@byzantine-lab.io>2019-06-12 17:27:23 +0800
commit00c39b0266a86061b06fe53114aa61b8d946301f (patch)
tree6d196eda10e26f0b5c50c7a4fa1eca8103a52009 /dex
parent637118e018c9f93490c68aa042ec2a977f28d1bc (diff)
downloadgo-tangerine-00c39b0266a86061b06fe53114aa61b8d946301f.tar
go-tangerine-00c39b0266a86061b06fe53114aa61b8d946301f.tar.gz
go-tangerine-00c39b0266a86061b06fe53114aa61b8d946301f.tar.bz2
go-tangerine-00c39b0266a86061b06fe53114aa61b8d946301f.tar.lz
go-tangerine-00c39b0266a86061b06fe53114aa61b8d946301f.tar.xz
go-tangerine-00c39b0266a86061b06fe53114aa61b8d946301f.tar.zst
go-tangerine-00c39b0266a86061b06fe53114aa61b8d946301f.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.
Diffstat (limited to 'dex')
-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()
}