diff options
author | Jimmy Hu <jimmy.hu@dexon.org> | 2019-03-04 18:30:03 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-04 18:30:03 +0800 |
commit | d4b4c8a05e94f66c85e7b4238ae5947b26f13c40 (patch) | |
tree | c2a10260820ac3a152506000aa03c41cd244d84f /core/consensus.go | |
parent | 603f8d6d999c1bb5b16c2f5dfc88f8bc9da7fc33 (diff) | |
download | dexon-consensus-d4b4c8a05e94f66c85e7b4238ae5947b26f13c40.tar.gz dexon-consensus-d4b4c8a05e94f66c85e7b4238ae5947b26f13c40.tar.zst dexon-consensus-d4b4c8a05e94f66c85e7b4238ae5947b26f13c40.zip |
core: first few round will not have DKG (#455)
* core: Add DKGDelayRound constant
* core: use constant value
* core, utils: set DKGDelayRound for utils.
* test: add dkgDelayRound to state
* core: do not run dkg and crs for round < DKGDelayRound
* fix test
Diffstat (limited to 'core/consensus.go')
-rw-r--r-- | core/consensus.go | 55 |
1 files changed, 22 insertions, 33 deletions
diff --git a/core/consensus.go b/core/consensus.go index 25fc16d..370df72 100644 --- a/core/consensus.go +++ b/core/consensus.go @@ -599,25 +599,8 @@ func (con *Consensus) prepare( return } if initRound == 0 { - dkgSet, err := con.nodeSetCache.GetDKGSet(initRound) - if err != nil { - return err - } - if _, exist := dkgSet[con.ID]; exist { - con.logger.Info("Selected as DKG set", "round", initRound) - go func() { - // Sleep until dMoment come. - time.Sleep(con.dMoment.Sub(time.Now().UTC())) - // Network is not stable upon starting. Wait some time to ensure first - // DKG would success. Three is a magic number. - time.Sleep(initConfig.MinBlockInterval * 3) - con.cfgModule.registerDKG(initRound, getDKGThreshold(initConfig)) - con.event.RegisterHeight( - initConfig.RoundLength/4, - func(uint64) { - con.runDKG(initRound, initConfig) - }) - }() + if DKGDelayRound == 0 { + panic("not implemented yet") } } // Register events. @@ -747,20 +730,22 @@ func (con *Consensus) initialRound( return default: } - curDkgSet, err := con.nodeSetCache.GetDKGSet(round) - if err != nil { - con.logger.Error("Error getting DKG set", "round", round, "error", err) - curDkgSet = make(map[types.NodeID]struct{}) - } - // Initiate CRS routine. - if _, exist := curDkgSet[con.ID]; exist { - con.event.RegisterHeight( - startHeight+config.RoundLength/2, - func(uint64) { - go func() { - con.runCRS(round) - }() - }) + if round >= DKGDelayRound { + curDkgSet, err := con.nodeSetCache.GetDKGSet(round) + if err != nil { + con.logger.Error("Error getting DKG set", "round", round, "error", err) + curDkgSet = make(map[types.NodeID]struct{}) + } + // Initiate CRS routine. + if _, exist := curDkgSet[con.ID]; exist { + con.event.RegisterHeight( + startHeight+config.RoundLength/2, + func(uint64) { + go func() { + con.runCRS(round) + }() + }) + } } // checkCRS is a generator of checker to check if CRS for that round is // ready or not. @@ -800,6 +785,10 @@ func (con *Consensus) initialRound( // Initiate DKG for this round. con.event.RegisterHeight(startHeight+config.RoundLength/2, func(uint64) { go func(nextRound uint64) { + if nextRound < DKGDelayRound { + con.logger.Info("Skip runDKG for round", "round", nextRound) + return + } // Normally, gov.CRS would return non-nil. Use this for in case of // unexpected network fluctuation and ensure the robustness. if !checkWithCancel( |