diff options
author | Mission Liao <mission.liao@dexon.org> | 2018-12-24 10:29:31 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-12-24 10:29:31 +0800 |
commit | dce509a13ef5873b9cae3c1cabdb97e219b6fb7d (patch) | |
tree | a17a2af9578d8b0d197a2897cc1fcf53770f7c48 /core/consensus.go | |
parent | c1ed57c4abaf1f4758e52f082bb7114ad00c8b39 (diff) | |
download | tangerine-consensus-dce509a13ef5873b9cae3c1cabdb97e219b6fb7d.tar tangerine-consensus-dce509a13ef5873b9cae3c1cabdb97e219b6fb7d.tar.gz tangerine-consensus-dce509a13ef5873b9cae3c1cabdb97e219b6fb7d.tar.bz2 tangerine-consensus-dce509a13ef5873b9cae3c1cabdb97e219b6fb7d.tar.lz tangerine-consensus-dce509a13ef5873b9cae3c1cabdb97e219b6fb7d.tar.xz tangerine-consensus-dce509a13ef5873b9cae3c1cabdb97e219b6fb7d.tar.zst tangerine-consensus-dce509a13ef5873b9cae3c1cabdb97e219b6fb7d.zip |
core: fix issues found when testing syncing. (#379)
* Avoid panic when stopping multiple times.
* Fix syncer panic when round switching
* Add getCurrentConfig to total-ordering,
and panic with more info
* Avoid infinite loop.
Diffstat (limited to 'core/consensus.go')
-rw-r--r-- | core/consensus.go | 42 |
1 files changed, 30 insertions, 12 deletions
diff --git a/core/consensus.go b/core/consensus.go index 44ce43f..0d4a38a 100644 --- a/core/consensus.go +++ b/core/consensus.go @@ -601,7 +601,11 @@ func (con *Consensus) prepare(initBlock *types.Block) error { // Setup lattice module. initPlusOneCfg := utils.GetConfigWithPanic(con.gov, initRound+1, con.logger) if err := con.lattice.AppendConfig(initRound+1, initPlusOneCfg); err != nil { - return err + if err == ErrRoundNotIncreasing { + err = nil + } else { + return err + } } // Register events. dkgSet, err := con.nodeSetCache.GetDKGSet(initRound) @@ -732,23 +736,37 @@ func (con *Consensus) initialRound( }() }) } + // checkCRS is a generator of checker to check if CRS for that round is + // ready or not. + checkCRS := func(round uint64) func() bool { + return func() bool { + nextCRS := con.gov.CRS(round) + if (nextCRS != common.Hash{}) { + return true + } + con.logger.Info("CRS is not ready yet. Try again later...", + "nodeID", con.ID, + "round", round) + return false + } + } // Initiate BA modules. con.event.RegisterTime( startTime.Add(config.RoundInterval/2+config.LambdaDKG), func(time.Time) { go func(nextRound uint64) { - for (con.gov.CRS(nextRound) == common.Hash{}) { - con.logger.Info("CRS is not ready yet. Try again later...", - "nodeID", con.ID, + if !checkWithCancel( + con.ctx, 500*time.Millisecond, checkCRS(nextRound)) { + con.logger.Info("unable to prepare CRS for baMgr", "round", nextRound) - time.Sleep(500 * time.Millisecond) + return } // Notify BA for new round. nextConfig := utils.GetConfigWithPanic( con.gov, nextRound, con.logger) - con.logger.Debug("Calling Governance.CRS", - "round", nextRound) - nextCRS := utils.GetCRSWithPanic(con.gov, nextRound, con.logger) + nextCRS := utils.GetCRSWithPanic( + con.gov, nextRound, con.logger) + con.logger.Info("appendConfig for baMgr", "round", nextRound) if err := con.baMgr.appendConfig( nextRound, nextConfig, nextCRS); err != nil { panic(err) @@ -761,11 +779,11 @@ func (con *Consensus) initialRound( go func(nextRound uint64) { // Normally, gov.CRS would return non-nil. Use this for in case of // unexpected network fluctuation and ensure the robustness. - for (con.gov.CRS(nextRound) == common.Hash{}) { - con.logger.Info("CRS is not ready yet. Try again later...", - "nodeID", con.ID, + if !checkWithCancel( + con.ctx, 500*time.Millisecond, checkCRS(nextRound)) { + con.logger.Info("unable to prepare CRS for DKG set", "round", nextRound) - time.Sleep(500 * time.Millisecond) + return } nextDkgSet, err := con.nodeSetCache.GetDKGSet(nextRound) if err != nil { |