diff options
Diffstat (limited to 'vendor/github.com/dexon-foundation/dexon-consensus/core/lattice.go')
-rw-r--r-- | vendor/github.com/dexon-foundation/dexon-consensus/core/lattice.go | 49 |
1 files changed, 27 insertions, 22 deletions
diff --git a/vendor/github.com/dexon-foundation/dexon-consensus/core/lattice.go b/vendor/github.com/dexon-foundation/dexon-consensus/core/lattice.go index 108f2887b..7b66bd557 100644 --- a/vendor/github.com/dexon-foundation/dexon-consensus/core/lattice.go +++ b/vendor/github.com/dexon-foundation/dexon-consensus/core/lattice.go @@ -41,6 +41,7 @@ type Lattice struct { pool blockPool retryAdd bool data *latticeData + toSyncer *totalOrderingSyncer toModule *totalOrdering ctModule *consensusTimestamp logger common.Logger @@ -64,6 +65,7 @@ func NewLattice( debug: debug, pool: newBlockPool(cfg.NumChains), data: newLatticeData(db, dMoment, round, cfg), + toSyncer: newTotalOrderingSyncer(cfg.NumChains), toModule: newTotalOrdering(dMoment, cfg), ctModule: newConsensusTimestamp(dMoment, round, cfg.NumChains), logger: logger, @@ -144,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 @@ -236,28 +237,31 @@ func (l *Lattice) ProcessBlock( return } - // Perform total ordering for each block added to lattice. - for _, b = range inLattice { - toDelivered, deliveredMode, err = l.toModule.processBlock(b) - if err != nil { - // All errors from total ordering is serious, should panic. - panic(err) - } - if len(toDelivered) == 0 { - continue - } - hashes := make(common.Hashes, len(toDelivered)) - for idx := range toDelivered { - hashes[idx] = toDelivered[idx].Hash - } - if l.debug != nil { - l.debug.TotalOrderingDelivered(hashes, deliveredMode) - } - // Perform consensus timestamp module. - if err = l.ctModule.processBlocks(toDelivered); err != nil { - return + for _, blockToSyncer := range inLattice { + toTotalOrdering := l.toSyncer.processBlock(blockToSyncer) + // Perform total ordering for each block added to lattice. + for _, b = range toTotalOrdering { + toDelivered, deliveredMode, err = l.toModule.processBlock(b) + if err != nil { + // All errors from total ordering is serious, should panic. + panic(err) + } + if len(toDelivered) == 0 { + continue + } + hashes := make(common.Hashes, len(toDelivered)) + for idx := range toDelivered { + hashes[idx] = toDelivered[idx].Hash + } + if l.debug != nil { + l.debug.TotalOrderingDelivered(hashes, deliveredMode) + } + // Perform consensus timestamp module. + if err = l.ctModule.processBlocks(toDelivered); err != nil { + return + } + delivered = append(delivered, toDelivered...) } - delivered = append(delivered, toDelivered...) } return } @@ -304,4 +308,5 @@ func (l *Lattice) ProcessFinalizedBlock(b *types.Block) { panic(err) } l.pool.purgeBlocks(b.Position.ChainID, b.Position.Height) + l.toSyncer.processFinalizedBlock(b) } |