aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJimmy Hu <jimmy.hu@dexon.org>2018-10-23 12:02:28 +0800
committerWei-Ning Huang <aitjcize@gmail.com>2018-10-23 12:02:28 +0800
commit3e8b61ad3df8cb203dfb2c9c8b388bde10637b0a (patch)
tree9aee7620fb59ae70ef7cd3d9077d3f9f2b513436
parent3dc8d1e0c79e7706b373471e1ce7cdb0403aebe9 (diff)
downloaddexon-consensus-3e8b61ad3df8cb203dfb2c9c8b388bde10637b0a.tar
dexon-consensus-3e8b61ad3df8cb203dfb2c9c8b388bde10637b0a.tar.gz
dexon-consensus-3e8b61ad3df8cb203dfb2c9c8b388bde10637b0a.tar.bz2
dexon-consensus-3e8b61ad3df8cb203dfb2c9c8b388bde10637b0a.tar.lz
dexon-consensus-3e8b61ad3df8cb203dfb2c9c8b388bde10637b0a.tar.xz
dexon-consensus-3e8b61ad3df8cb203dfb2c9c8b388bde10637b0a.tar.zst
dexon-consensus-3e8b61ad3df8cb203dfb2c9c8b388bde10637b0a.zip
core: Change dkg timing (#241)
* Register DKG after CRS is proposed * Change round at only one place
-rw-r--r--core/consensus.go29
1 files changed, 17 insertions, 12 deletions
diff --git a/core/consensus.go b/core/consensus.go
index 9950787..bf3650f 100644
--- a/core/consensus.go
+++ b/core/consensus.go
@@ -558,12 +558,20 @@ func (con *Consensus) initialRound(startTime time.Time) {
con.event.RegisterTime(startTime.Add(con.currentConfig.RoundInterval/2),
func(time.Time) {
- go con.runCRS()
- })
- con.event.RegisterTime(startTime.Add(con.currentConfig.RoundInterval/2),
- func(time.Time) {
- con.cfgModule.registerDKG(
- con.round+1, int(con.currentConfig.DKGSetSize/3)+1)
+ go func() {
+ con.runCRS()
+ ticker := newTicker(con.gov, con.round, TickerDKG)
+ <-ticker.Tick()
+ // Normally, gov.CRS would return non-nil. Use this for in case of
+ // unexpected network fluctuation and ensure the robustness.
+ for (con.gov.CRS(con.round+1) == common.Hash{}) {
+ con.logger.Info("CRS is not ready yet. Try again later...",
+ "nodeID", con.ID)
+ time.Sleep(500 * time.Millisecond)
+ }
+ con.cfgModule.registerDKG(
+ con.round+1, int(con.currentConfig.DKGSetSize/3)+1)
+ }()
})
con.event.RegisterTime(startTime.Add(con.currentConfig.RoundInterval*2/3),
func(time.Time) {
@@ -578,6 +586,9 @@ func (con *Consensus) initialRound(startTime time.Time) {
func(time.Time) {
// Change round.
con.round++
+ con.logger.Debug("Calling Governance.Configuration",
+ "round", con.round+1)
+ con.lattice.AppendConfig(con.round+1, con.gov.Configuration(con.round+1))
con.initialRound(startTime.Add(con.currentConfig.RoundInterval))
})
}
@@ -838,12 +849,6 @@ func (con *Consensus) processBlock(block *types.Block) (err error) {
if err = con.db.Put(*b); err != nil {
return
}
- if b.Position.Round > con.round {
- con.round++
- con.logger.Debug("Calling Governance.Configuration",
- "round", con.round+1)
- con.lattice.AppendConfig(con.round+1, con.gov.Configuration(con.round+1))
- }
// TODO(mission): clone types.FinalizationResult
con.nbModule.BlockDelivered(b.Hash, b.Finalization)
}