From bdde6109ffa6fa4d295708a2a75271186a12c761 Mon Sep 17 00:00:00 2001 From: Wei-Ning Huang Date: Tue, 15 Jan 2019 16:59:52 +0800 Subject: core: do not panic on fork (#146) It is possible for someone on the network to send a block with correct tx and tSig but wrong state root. When this happens, a fork block will be inserted as side chain. Do not panic on this case or all nodes will be down. --- core/blockchain.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/core/blockchain.go b/core/blockchain.go index b69b6c681..2e5265782 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -1778,7 +1778,7 @@ func (bc *BlockChain) insertDexonChain(chain types.Blocks) (int, []interface{}, blockInsertTimer.UpdateSince(bstart) events = append(events, ChainSideEvent{block}) - panic("fork found") + return 0, nil, nil, errors.New("fork round") } stats.processed++ stats.usedGas += usedGas @@ -1917,7 +1917,10 @@ func (bc *BlockChain) processBlock( bc.gcproc += proctime case SideStatTy: - return nil, nil, nil, fmt.Errorf("insert pending block and fork found") + log.Debug("Inserted forked block", "number", block.Number(), "hash", block.Hash(), "diff", block.Difficulty(), "elapsed", + common.PrettyDuration(time.Since(bstart)), "txs", len(block.Transactions()), "gas", block.GasUsed(), "uncles", len(block.Uncles())) + + return nil, nil, nil, errors.New("fork round") } stats.processed++ @@ -1996,7 +1999,9 @@ func (bc *BlockChain) ProcessEmptyBlock(block *types.Block) (*common.Hash, error bc.gcproc += proctime case SideStatTy: - return nil, fmt.Errorf("insert pending block and fork found") + log.Debug("Inserted forked block", "number", block.Number(), "hash", block.Hash(), "diff", block.Difficulty(), "elapsed", + common.PrettyDuration(time.Since(bstart)), "txs", len(block.Transactions()), "gas", block.GasUsed(), "uncles", len(block.Uncles())) + return nil, fmt.Errorf("fork found") } stats.processed++ @@ -2284,7 +2289,6 @@ func (bc *BlockChain) InsertDexonHeaderChain(chain []*types.HeaderWithGovState, if status == SideStatTy { log.Debug("Inserted forked block header", "number", header.Number, "hash", header.Hash, "diff", header.Difficulty, "gas", header.GasUsed) - panic("fork found") } return err } -- cgit v1.2.3