From 158d603528d2ba36b633a8f22a2bff8329f69717 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Thu, 6 Apr 2017 14:58:03 +0300 Subject: consensus, core: drop all the legacy custom core error types --- core/blockchain.go | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'core/blockchain.go') diff --git a/core/blockchain.go b/core/blockchain.go index 4793431d8..b601c462c 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -831,7 +831,7 @@ func (self *BlockChain) WriteBlock(block *types.Block) (status WriteStatus, err // Calculate the total difficulty of the block ptd := self.GetTd(block.ParentHash(), block.NumberU64()-1) if ptd == nil { - return NonStatTy, ParentError(block.ParentHash()) + return NonStatTy, consensus.ErrUnknownAncestor } // Make sure no inconsistent state is leaked during insertion self.mu.Lock() @@ -918,9 +918,8 @@ func (self *BlockChain) InsertChain(chain types.Blocks) (int, error) { } // If the header is a banned one, straight out abort if BadHashes[block.Hash()] { - err := BadHashError(block.Hash()) - self.reportBlock(block, nil, err) - return i, err + self.reportBlock(block, nil, ErrBlacklistedHash) + return i, ErrBlacklistedHash } // Wait for the block's verification to complete bstart := time.Now() @@ -930,25 +929,25 @@ func (self *BlockChain) InsertChain(chain types.Blocks) (int, error) { err = self.Validator().ValidateBody(block) } if err != nil { - if IsKnownBlockErr(err) { + if err == ErrKnownBlock { stats.ignored++ continue } - if err == BlockFutureErr { + if err == consensus.ErrFutureBlock { // Allow up to MaxFuture second in the future blocks. If this limit // is exceeded the chain is discarded and processed at a later time // if given. max := big.NewInt(time.Now().Unix() + maxTimeFutureBlocks) - if block.Time().Cmp(max) == 1 { - return i, fmt.Errorf("%v: BlockFutureErr, %v > %v", BlockFutureErr, block.Time(), max) + if block.Time().Cmp(max) > 0 { + return i, fmt.Errorf("future block: %v > %v", block.Time(), max) } self.futureBlocks.Add(block.Hash(), block) stats.queued++ continue } - if IsParentErr(err) && self.futureBlocks.Contains(block.ParentHash()) { + if err == consensus.ErrUnknownAncestor && self.futureBlocks.Contains(block.ParentHash()) { self.futureBlocks.Add(block.Hash(), block) stats.queued++ continue -- cgit v1.2.3