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 | 34 |
1 files changed, 28 insertions, 6 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 f76813d82..e578e3f4f 100644 --- a/vendor/github.com/dexon-foundation/dexon-consensus/core/lattice.go +++ b/vendor/github.com/dexon-foundation/dexon-consensus/core/lattice.go @@ -39,7 +39,6 @@ type Lattice struct { app Application debug Debug pool blockPool - retryAdd bool data *latticeData toModule *totalOrdering ctModule *consensusTimestamp @@ -64,7 +63,7 @@ func NewLattice( debug: debug, pool: newBlockPool(cfg.NumChains), data: newLatticeData(db, dMoment, round, cfg), - toModule: newTotalOrdering(dMoment, cfg), + toModule: newTotalOrdering(dMoment, round, cfg), ctModule: newConsensusTimestamp(dMoment, round, cfg.NumChains), logger: logger, } @@ -211,10 +210,6 @@ func (l *Lattice) addBlockToLattice( } for _, b := range outputBlocks { - // TODO(jimmy-dexon): change this name of classic DEXON algorithm. - if l.debug != nil { - l.debug.StronglyAcked(b.Hash) - } l.logger.Debug("Calling Application.BlockConfirmed", "block", b) l.app.BlockConfirmed(*b.Clone()) // Purge blocks in pool with the same chainID and lower height. @@ -310,4 +305,31 @@ func (l *Lattice) AppendConfig(round uint64, config *types.Config) (err error) { // ProcessFinalizedBlock is used for syncing lattice data. func (l *Lattice) ProcessFinalizedBlock(b *types.Block) { + l.lock.Lock() + defer l.lock.Unlock() + // Syncing state for core.latticeData module. + if err := l.data.addFinalizedBlock(b); err != nil { + panic(err) + } + l.pool.purgeBlocks(b.Position.ChainID, b.Position.Height) + // Syncing state for core.totalOrdering module. + toDelivered, deliveredMode, err := l.toModule.processBlock(b) + if err != nil { + panic(err) + } + if len(toDelivered) == 0 { + return + } + hashes := make(common.Hashes, len(toDelivered)) + for idx := range toDelivered { + hashes[idx] = toDelivered[idx].Hash + } + if l.debug != nil { + l.debug.TotalOrderingDelivered(hashes, deliveredMode) + } + // Sync core.consensusTimestamp module. + if err = l.ctModule.processBlocks(toDelivered); err != nil { + panic(err) + } + return } |