diff options
author | Jeffrey Wilcke <jeffrey@ethereum.org> | 2016-11-23 20:32:25 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-11-23 20:32:25 +0800 |
commit | c04c8f10f04a41e762589358418c65fd99891bb4 (patch) | |
tree | e1894ef4d0cad67e45739d1db0ad05307cba9711 /core/blockchain.go | |
parent | e05d35e6e04f1378c18861016f96b39b35cef4f2 (diff) | |
download | dexon-c04c8f10f04a41e762589358418c65fd99891bb4.tar.gz dexon-c04c8f10f04a41e762589358418c65fd99891bb4.tar.zst dexon-c04c8f10f04a41e762589358418c65fd99891bb4.zip |
core: improved bad block error reporting (#3320)
Diffstat (limited to 'core/blockchain.go')
-rw-r--r-- | core/blockchain.go | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/core/blockchain.go b/core/blockchain.go index bbcff3b92..9ace6d79a 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -878,7 +878,7 @@ func (self *BlockChain) InsertChain(chain types.Blocks) (int, error) { if BadHashes[block.Hash()] { err := BadHashError(block.Hash()) - reportBlock(block, err) + self.reportBlock(block, nil, err) return i, err } // Stage 1 validation of the block using the chain's validator @@ -910,7 +910,7 @@ func (self *BlockChain) InsertChain(chain types.Blocks) (int, error) { continue } - reportBlock(block, err) + self.reportBlock(block, nil, err) return i, err } @@ -924,19 +924,19 @@ func (self *BlockChain) InsertChain(chain types.Blocks) (int, error) { err = self.stateCache.Reset(chain[i-1].Root()) } if err != nil { - reportBlock(block, err) + self.reportBlock(block, nil, err) return i, err } // Process block using the parent state as reference point. receipts, logs, usedGas, err := self.processor.Process(block, self.stateCache, vm.Config{}) if err != nil { - reportBlock(block, err) + self.reportBlock(block, receipts, err) return i, err } // Validate the state using the default validator err = self.Validator().ValidateState(block, self.GetBlock(block.ParentHash(), block.NumberU64()-1), self.stateCache, receipts, usedGas) if err != nil { - reportBlock(block, err) + self.reportBlock(block, receipts, err) return i, err } // Write state changes to database @@ -1207,10 +1207,23 @@ func (self *BlockChain) update() { } // reportBlock logs a bad block error. -func reportBlock(block *types.Block, err error) { +func (bc *BlockChain) reportBlock(block *types.Block, receipts types.Receipts, err error) { if glog.V(logger.Error) { - glog.Errorf("Bad block #%v (%s)\n", block.Number(), block.Hash().Hex()) - glog.Errorf(" %v", err) + var receiptString string + for _, receipt := range receipts { + receiptString += fmt.Sprintf("\t%v\n", receipt) + } + glog.Errorf(` +########## BAD BLOCK ######### +Chain config: %v + +Number: %v +Hash: 0x%x +%v + +Error: %v +############################## +`, bc.config, block.Number(), block.Hash(), receiptString, err) } } |