diff options
author | Jimmy Hu <jimmy.hu@dexon.org> | 2018-11-16 10:45:06 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-11-16 10:45:06 +0800 |
commit | 591c80dbe9dbdea4cec202b07f4da081020f964a (patch) | |
tree | 451cfd667943a11ddbfcd09245161a614481fb5b | |
parent | 02669f255e0d131c9e5fce49660103a636dddd51 (diff) | |
download | dexon-consensus-591c80dbe9dbdea4cec202b07f4da081020f964a.tar dexon-consensus-591c80dbe9dbdea4cec202b07f4da081020f964a.tar.gz dexon-consensus-591c80dbe9dbdea4cec202b07f4da081020f964a.tar.bz2 dexon-consensus-591c80dbe9dbdea4cec202b07f4da081020f964a.tar.lz dexon-consensus-591c80dbe9dbdea4cec202b07f4da081020f964a.tar.xz dexon-consensus-591c80dbe9dbdea4cec202b07f4da081020f964a.tar.zst dexon-consensus-591c80dbe9dbdea4cec202b07f4da081020f964a.zip |
core: Fix various syncing issue. (#331)
-rw-r--r-- | core/blockdb/memory.go | 4 | ||||
-rw-r--r-- | core/consensus.go | 43 | ||||
-rw-r--r-- | core/lattice.go | 1 | ||||
-rw-r--r-- | core/total-ordering-syncer.go | 3 |
4 files changed, 32 insertions, 19 deletions
diff --git a/core/blockdb/memory.go b/core/blockdb/memory.go index 760646e..b45af22 100644 --- a/core/blockdb/memory.go +++ b/core/blockdb/memory.go @@ -124,6 +124,10 @@ func (m *MemBackedBlockDB) Put(block types.Block) error { // Update updates a block in the database. func (m *MemBackedBlockDB) Update(block types.Block) error { + if !m.Has(block.Hash) { + return ErrBlockDoesNotExist + } + m.blocksMutex.Lock() defer m.blocksMutex.Unlock() diff --git a/core/consensus.go b/core/consensus.go index a8fd3c8..251f475 100644 --- a/core/consensus.go +++ b/core/consensus.go @@ -701,23 +701,6 @@ func (con *Consensus) initialRound( con.logger.Debug("Calling Governance.Configuration", "round", nextRound) nextConfig := con.gov.Configuration(nextRound) - // Get configuration for the round next to next round. Configuration - // for that round should be ready at this moment and is required for - // lattice module. This logic is related to: - // - roundShift - // - notifyGenesisRound - futureRound := nextRound + 1 - con.logger.Debug("Calling Governance.Configuration", - "round", futureRound) - futureConfig := con.gov.Configuration(futureRound) - con.logger.Debug("Append Config", "round", futureRound) - if err := con.lattice.AppendConfig( - futureRound, futureConfig); err != nil { - con.logger.Debug("Unable to append config", - "round", futureRound, - "error", err) - panic(err) - } con.initialRound( startTime.Add(config.RoundInterval), nextRound, nextConfig) }) @@ -1015,6 +998,23 @@ func (con *Consensus) deliverBlock(b *types.Block) { con.logger.Debug("Calling Application.BlockDelivered", "block", b) con.app.BlockDelivered(b.Hash, b.Position, b.Finalization.Clone()) if b.Position.Round == con.roundToNotify { + // Get configuration for the round next to next round. Configuration + // for that round should be ready at this moment and is required for + // lattice module. This logic is related to: + // - roundShift + // - notifyGenesisRound + futureRound := con.roundToNotify + 1 + con.logger.Debug("Calling Governance.Configuration", + "round", con.roundToNotify) + futureConfig := con.gov.Configuration(futureRound) + con.logger.Debug("Append Config", "round", futureRound) + if err := con.lattice.AppendConfig( + futureRound, futureConfig); err != nil { + con.logger.Debug("Unable to append config", + "round", futureRound, + "error", err) + panic(err) + } // Only the first block delivered of that round would // trigger this noitification. con.logger.Debug("Calling Governance.NotifyRoundHeight", @@ -1063,7 +1063,10 @@ func (con *Consensus) processBlock(block *types.Block) (err error) { // processFinalizedBlock is the entry point for syncing blocks. func (con *Consensus) processFinalizedBlock(block *types.Block) (err error) { if err = con.lattice.SanityCheck(block); err != nil { - return + if err != ErrRetrySanityCheckLater { + return + } + err = nil } con.ccModule.processFinalizedBlock(block) for { @@ -1082,6 +1085,10 @@ func (con *Consensus) processFinalizedBlock(block *types.Block) (err error) { err = nil } con.lattice.ProcessFinalizedBlock(b) + // TODO(jimmy): BlockConfirmed and DeliverBlock may not be removed if + // application implements state snapshot. + con.logger.Debug("Calling Application.BlockConfirmed", "block", b) + con.app.BlockConfirmed(*b.Clone()) con.deliverBlock(b) } } diff --git a/core/lattice.go b/core/lattice.go index 634ed8b..7b66bd5 100644 --- a/core/lattice.go +++ b/core/lattice.go @@ -146,7 +146,6 @@ func (l *Lattice) SanityCheck(b *types.Block) (err error) { if _, ok := err.(*ErrAckingBlockNotExists); ok { err = ErrRetrySanityCheckLater } - l.logger.Error("Sanity Check failed", "error", err) return } return diff --git a/core/total-ordering-syncer.go b/core/total-ordering-syncer.go index aa90a1d..1360611 100644 --- a/core/total-ordering-syncer.go +++ b/core/total-ordering-syncer.go @@ -156,6 +156,9 @@ func (tos *totalOrderingSyncer) processBlock( // The finalized block should be passed by the order of consensus height. func (tos *totalOrderingSyncer) processFinalizedBlock(block *types.Block) { + if tos.synced() { + return + } tos.lock.Lock() defer tos.lock.Unlock() if len(tos.pendingDeliveryBlocks) > 0 { |