aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWei-Ning Huang <w@dexon.org>2019-01-15 16:59:52 +0800
committerGitHub <noreply@github.com>2019-01-15 16:59:52 +0800
commitbdde6109ffa6fa4d295708a2a75271186a12c761 (patch)
treead4c08bce7e7d359bde69f979e47c76f1fb10dc4
parent297a8b8d4900336af14dc1e829f70ade79529b71 (diff)
downloaddexon-bdde6109ffa6fa4d295708a2a75271186a12c761.tar
dexon-bdde6109ffa6fa4d295708a2a75271186a12c761.tar.gz
dexon-bdde6109ffa6fa4d295708a2a75271186a12c761.tar.bz2
dexon-bdde6109ffa6fa4d295708a2a75271186a12c761.tar.lz
dexon-bdde6109ffa6fa4d295708a2a75271186a12c761.tar.xz
dexon-bdde6109ffa6fa4d295708a2a75271186a12c761.tar.zst
dexon-bdde6109ffa6fa4d295708a2a75271186a12c761.zip
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.
-rw-r--r--core/blockchain.go12
1 files 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
}