diff options
author | Wei-Ning Huang <w@dexon.org> | 2018-10-24 16:14:51 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@byzantine-lab.io> | 2019-06-12 17:27:16 +0800 |
commit | 5dde0c2ceb01183871b1aa1c7906cae7794a1293 (patch) | |
tree | 2e06c5fbd9b7054a47c28cc89f63b8efe547c4da /vendor/github.com | |
parent | bc2cfaa5cec22740b0f61a09fc129235eadc2134 (diff) | |
download | go-tangerine-5dde0c2ceb01183871b1aa1c7906cae7794a1293.tar.gz go-tangerine-5dde0c2ceb01183871b1aa1c7906cae7794a1293.tar.zst go-tangerine-5dde0c2ceb01183871b1aa1c7906cae7794a1293.zip |
vendor: sync consensus core
Diffstat (limited to 'vendor/github.com')
3 files changed, 28 insertions, 32 deletions
diff --git a/vendor/github.com/dexon-foundation/dexon-consensus-core/core/consensus.go b/vendor/github.com/dexon-foundation/dexon-consensus-core/core/consensus.go index c7bef4bb1..03855587c 100644 --- a/vendor/github.com/dexon-foundation/dexon-consensus-core/core/consensus.go +++ b/vendor/github.com/dexon-foundation/dexon-consensus-core/core/consensus.go @@ -81,6 +81,10 @@ func (recv *consensusBAReceiver) ProposeVote(vote *types.Vote) { func (recv *consensusBAReceiver) ProposeBlock() common.Hash { block := recv.consensus.proposeBlock(recv.chainID, recv.round) + if block == nil { + recv.consensus.logger.Error("unable to propose block") + return nullBlockHash + } recv.consensus.baModules[recv.chainID].addCandidateBlock(block) if err := recv.consensus.preProcessBlock(block); err != nil { recv.consensus.logger.Error("Failed to pre-process block", "error", err) @@ -230,9 +234,6 @@ type Consensus struct { authModule *Authenticator currentConfig *types.Config - // Modules. - nbModule *nonBlocking - // BA. baModules []*agreement receivers []*consensusBAReceiver @@ -248,6 +249,7 @@ type Consensus struct { // Interfaces. db blockdb.BlockDatabase + app Application gov Governance network Network tickerObj Ticker @@ -294,11 +296,9 @@ func NewConsensus( authModule := NewAuthenticator(prv) // Check if the application implement Debug interface. debugApp, _ := app.(Debug) - // Setup nonblocking module. - nbModule := newNonBlocking(app, debugApp) // Init lattice. lattice := NewLattice( - dMoment, config, authModule, nbModule, nbModule, db, logger) + dMoment, config, authModule, app, debugApp, db, logger) // Init configuration chain. ID := types.NewNodeID(prv.PublicKey()) recv := &consensusDKGReceiver{ @@ -321,7 +321,7 @@ func NewConsensus( currentConfig: config, ccModule: newCompactionChain(gov), lattice: lattice, - nbModule: nbModule, + app: app, gov: gov, db: db, network: network, @@ -814,7 +814,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, true); err != nil { + if err = con.lattice.SanityCheck(b); err != nil { return } if err = con.baModules[b.Position.ChainID].processBlock(b); err != nil { @@ -849,7 +849,7 @@ func (con *Consensus) processBlock(block *types.Block) (err error) { return } // TODO(mission): clone types.FinalizationResult - con.nbModule.BlockDelivered(b.Hash, b.Finalization) + con.app.BlockDelivered(b.Hash, b.Finalization) } if err = con.lattice.PurgeBlocks(deliveredBlocks); err != nil { return @@ -859,7 +859,7 @@ 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, false); err != nil { + if err = con.lattice.SanityCheck(block); err != nil { return } con.ccModule.processFinalizedBlock(block) @@ -878,7 +878,7 @@ func (con *Consensus) processFinalizedBlock(block *types.Block) (err error) { } err = nil } - con.nbModule.BlockDelivered(b.Hash, b.Finalization) + con.app.BlockDelivered(b.Hash, b.Finalization) if b.Position.Round+2 == con.roundToNotify { // Only the first block delivered of that round would // trigger this noitification. diff --git a/vendor/github.com/dexon-foundation/dexon-consensus-core/core/lattice-data.go b/vendor/github.com/dexon-foundation/dexon-consensus-core/core/lattice-data.go index 31604a6d7..b0fe9cfdd 100644 --- a/vendor/github.com/dexon-foundation/dexon-consensus-core/core/lattice-data.go +++ b/vendor/github.com/dexon-foundation/dexon-consensus-core/core/lattice-data.go @@ -268,11 +268,6 @@ func (data *latticeData) addBlock( bAck *types.Block updated bool ) - // TODO(mission): sanity check twice, might hurt performance. - // If a block does not pass sanity check, report error. - if err = data.sanityCheck(block); err != nil { - return - } if err = data.chains[block.Position.ChainID].addBlock(block); err != nil { return } diff --git a/vendor/github.com/dexon-foundation/dexon-consensus-core/core/lattice.go b/vendor/github.com/dexon-foundation/dexon-consensus-core/core/lattice.go index 0357a8d99..3259f3540 100644 --- a/vendor/github.com/dexon-foundation/dexon-consensus-core/core/lattice.go +++ b/vendor/github.com/dexon-foundation/dexon-consensus-core/core/lattice.go @@ -104,11 +104,10 @@ func (s *Lattice) PrepareEmptyBlock(b *types.Block) (err error) { } // SanityCheck check if a block is valid. -// If checkRelation is true, it also checks with current lattice status. // // If some acking blocks don't exists, Lattice would help to cache this block // and retry when lattice updated in Lattice.ProcessBlock. -func (s *Lattice) SanityCheck(b *types.Block, checkRelation bool) (err error) { +func (s *Lattice) SanityCheck(b *types.Block) (err error) { if b.IsEmpty() { // Only need to verify block's hash. var hash common.Hash @@ -134,6 +133,22 @@ func (s *Lattice) SanityCheck(b *types.Block, checkRelation bool) (err error) { return } } + if err = func() (err error) { + s.lock.RLock() + defer s.lock.RUnlock() + if err = s.data.sanityCheck(b); err != nil { + // Add to block pool, once the lattice updated, + // would be checked again. + if err == ErrAckingBlockNotExists { + s.pool.addBlock(b) + } + s.logger.Error("Sanity Check failed", "error", err) + return + } + return + }(); err != nil { + return + } // Verify data in application layer. s.logger.Debug("Calling Application.VerifyBlock", "block", b) // TODO(jimmy-dexon): handle types.VerifyRetryLater. @@ -141,20 +156,6 @@ func (s *Lattice) SanityCheck(b *types.Block, checkRelation bool) (err error) { err = ErrInvalidBlock return err } - if !checkRelation { - return - } - s.lock.RLock() - defer s.lock.RUnlock() - if err = s.data.sanityCheck(b); err != nil { - // Add to block pool, once the lattice updated, - // would be checked again. - if err == ErrAckingBlockNotExists { - s.pool.addBlock(b) - } - s.logger.Error("Sanity Check failed", "error", err) - return - } return } |