diff options
author | Jimmy Hu <jimmy.hu@dexon.org> | 2018-11-30 19:07:36 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@byzantine-lab.io> | 2019-06-12 17:27:19 +0800 |
commit | 8cb40bd72ed4b8d3016c22a5edfb8d5779cba4da (patch) | |
tree | f4d86e8e631c78cbf498764a427b2fbdf88c9f86 /vendor/github.com/dexon-foundation/dexon-consensus/core/consensus.go | |
parent | 2777a457ba570455ef9641faf33f59852ea93d9e (diff) | |
download | go-tangerine-8cb40bd72ed4b8d3016c22a5edfb8d5779cba4da.tar go-tangerine-8cb40bd72ed4b8d3016c22a5edfb8d5779cba4da.tar.gz go-tangerine-8cb40bd72ed4b8d3016c22a5edfb8d5779cba4da.tar.bz2 go-tangerine-8cb40bd72ed4b8d3016c22a5edfb8d5779cba4da.tar.lz go-tangerine-8cb40bd72ed4b8d3016c22a5edfb8d5779cba4da.tar.xz go-tangerine-8cb40bd72ed4b8d3016c22a5edfb8d5779cba4da.tar.zst go-tangerine-8cb40bd72ed4b8d3016c22a5edfb8d5779cba4da.zip |
vendor: update to latest core (#71)
Diffstat (limited to 'vendor/github.com/dexon-foundation/dexon-consensus/core/consensus.go')
-rw-r--r-- | vendor/github.com/dexon-foundation/dexon-consensus/core/consensus.go | 77 |
1 files changed, 6 insertions, 71 deletions
diff --git a/vendor/github.com/dexon-foundation/dexon-consensus/core/consensus.go b/vendor/github.com/dexon-foundation/dexon-consensus/core/consensus.go index af4041766..253c9a59f 100644 --- a/vendor/github.com/dexon-foundation/dexon-consensus/core/consensus.go +++ b/vendor/github.com/dexon-foundation/dexon-consensus/core/consensus.go @@ -401,7 +401,7 @@ func NewConsensus( ID: ID, ccModule: newCompactionChain(gov), lattice: lattice, - app: app, + app: newNonBlocking(app, debugApp), gov: gov, db: db, network: network, @@ -639,9 +639,9 @@ func (con *Consensus) initialRound( // Stop the Consensus core. func (con *Consensus) Stop() { + con.ctxCancel() con.baMgr.stop() con.event.Reset() - con.ctxCancel() } func (con *Consensus) processMsg(msgChan <-chan interface{}) { @@ -761,44 +761,9 @@ func (con *Consensus) ProcessVote(vote *types.Vote) (err error) { func (con *Consensus) ProcessAgreementResult( rand *types.AgreementResult) error { // Sanity Check. - notarySet, err := con.nodeSetCache.GetNotarySet( - rand.Position.Round, rand.Position.ChainID) - if err != nil { + if err := VerifyAgreementResult(rand, con.nodeSetCache); err != nil { return err } - if len(rand.Votes) < len(notarySet)/3*2+1 { - return ErrNotEnoughVotes - } - if len(rand.Votes) > len(notarySet) { - return ErrIncorrectVoteProposer - } - for _, vote := range rand.Votes { - if rand.IsEmptyBlock { - if (vote.BlockHash != common.Hash{}) { - return ErrIncorrectVoteBlockHash - } - } else { - if vote.BlockHash != rand.BlockHash { - return ErrIncorrectVoteBlockHash - } - } - if vote.Type != types.VoteCom { - return ErrIncorrectVoteType - } - if vote.Position != rand.Position { - return ErrIncorrectVotePosition - } - if _, exist := notarySet[vote.ProposerID]; !exist { - return ErrIncorrectVoteProposer - } - ok, err := verifyVoteSignature(&vote) - if err != nil { - return err - } - if !ok { - return ErrIncorrectVoteSignature - } - } // Syncing BA Module. if err := con.baMgr.processAgreementResult(rand); err != nil { return err @@ -956,39 +921,9 @@ 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) { - if err = con.lattice.SanityCheck(block); err != nil { - if err != ErrRetrySanityCheckLater { - return - } - err = nil - } - con.ccModule.processFinalizedBlock(block) - for { - confirmed := con.ccModule.extractFinalizedBlocks() - if len(confirmed) == 0 { - break - } - if err = con.lattice.ctModule.processBlocks(confirmed); err != nil { - return - } - for _, b := range confirmed { - if err = con.db.Put(*b); err != nil { - if err != blockdb.ErrBlockExists { - return - } - 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) - } - } - return +// processFinalizedBlock is the entry point for handling finalized blocks. +func (con *Consensus) processFinalizedBlock(block *types.Block) error { + return con.ccModule.processFinalizedBlock(block) } // PrepareBlock would setup header fields of block based on its ProposerID. |