diff options
Diffstat (limited to 'core/consensus.go')
-rw-r--r-- | core/consensus.go | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/core/consensus.go b/core/consensus.go index 186d769..f4e3295 100644 --- a/core/consensus.go +++ b/core/consensus.go @@ -269,7 +269,7 @@ func NewConsensus( con := &Consensus{ ID: ID, currentConfig: config, - ccModule: newCompactionChain(), + ccModule: newCompactionChain(gov), lattice: lattice, nbModule: nbModule, gov: gov, @@ -521,8 +521,15 @@ func (con *Consensus) processMsg(msgChan <-chan interface{}) { switch val := msg.(type) { case *types.Block: - if err := con.preProcessBlock(val); err != nil { - log.Println(err) + // For sync mode. + if val.IsFinalized() { + if err := con.processFinalizedBlock(val); err != nil { + log.Println(err) + } + } else { + if err := con.preProcessBlock(val); err != nil { + log.Println(err) + } } case *types.Vote: if err := con.ProcessVote(val); err != nil { @@ -683,7 +690,7 @@ func (con *Consensus) ProcessBlockRandomnessResult( // preProcessBlock performs Byzantine Agreement on the block. func (con *Consensus) preProcessBlock(b *types.Block) (err error) { - if err = con.lattice.SanityCheck(b); err != nil { + if err = con.lattice.SanityCheck(b, true); err != nil { return } if err = con.baModules[b.Position.ChainID].processBlock(b); err != nil { @@ -730,6 +737,15 @@ func (con *Consensus) processBlock(block *types.Block) (err error) { return } +// processFinalizedBlock is the entry point for syncing blocks. +func (con *Consensus) processFinalizedBlock(block *types.Block) (err error) { + // TODO(jimmy-dexon): drop block that is already in compaction chain. + if err = con.lattice.SanityCheck(block, false); err != nil { + return + } + return +} + // PrepareBlock would setup header fields of block based on its ProposerID. func (con *Consensus) prepareBlock(b *types.Block, proposeTime time.Time) (err error) { |