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/syncer | |
parent | c1ed57c4abaf1f4758e52f082bb7114ad00c8b39 (diff) | |
download | dexon-consensus-dce509a13ef5873b9cae3c1cabdb97e219b6fb7d.tar dexon-consensus-dce509a13ef5873b9cae3c1cabdb97e219b6fb7d.tar.gz dexon-consensus-dce509a13ef5873b9cae3c1cabdb97e219b6fb7d.tar.bz2 dexon-consensus-dce509a13ef5873b9cae3c1cabdb97e219b6fb7d.tar.lz dexon-consensus-dce509a13ef5873b9cae3c1cabdb97e219b6fb7d.tar.xz dexon-consensus-dce509a13ef5873b9cae3c1cabdb97e219b6fb7d.tar.zst dexon-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/syncer')
-rw-r--r-- | core/syncer/consensus.go | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/core/syncer/consensus.go b/core/syncer/consensus.go index 43a9e21..32bbab3 100644 --- a/core/syncer/consensus.go +++ b/core/syncer/consensus.go @@ -446,9 +446,10 @@ func (con *Consensus) SyncBlocks( return false, err } if syncBlock != nil { - con.logger.Info("deliver set found", syncBlock) + con.logger.Info("deliver set found", "block", syncBlock) // New lattice with the round of syncBlock. con.initConsensusObj(syncBlock) + con.setupConfigs(blocks) // Process blocks from syncBlock to blocks' last block. b := blocks[len(blocks)-1] blocksCount := b.Finalization.Height - syncBlock.Finalization.Height + 1 @@ -586,7 +587,7 @@ func (con *Consensus) setupConfigs(blocks []*types.Block) { con.resizeByNumChains(curMaxNumChains) // Notify core.Lattice for new configs. if con.lattice != nil { - for con.latticeLastRound+1 <= maxRound { + for con.latticeLastRound+1 <= untilRound { con.latticeLastRound++ if err := con.lattice.AppendConfig( con.latticeLastRound, @@ -714,14 +715,12 @@ func (con *Consensus) startCRSMonitor() { select { case <-con.ctx.Done(): return - case <-time.After(1 * time.Second): - // Notify agreement modules for the latest round that CRS is - // available if the round is not notified yet. - var crsRound = lastNotifiedRound - for (con.gov.CRS(crsRound+1) != common.Hash{}) { - crsRound++ - } - notifyNewCRS(crsRound) + case <-time.After(500 * time.Millisecond): + } + // Notify agreement modules for the latest round that CRS is + // available if the round is not notified yet. + if (con.gov.CRS(lastNotifiedRound+1) != common.Hash{}) { + notifyNewCRS(lastNotifiedRound + 1) } } }() @@ -732,7 +731,10 @@ func (con *Consensus) stopAgreement() { con.lock.Lock() defer con.lock.Unlock() for _, a := range con.agreements { - close(a.inputChan) + if a.inputChan != nil { + close(a.inputChan) + a.inputChan = nil + } } }() con.agreementWaitGroup.Wait() |