aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorJeffrey Wilcke <jeffrey@ethereum.org>2016-11-28 17:37:42 +0800
committerGitHub <noreply@github.com>2016-11-28 17:37:42 +0800
commit801a13f7915840c3a74e3bcfd51cc83f00f4899c (patch)
treecb8ec6799440ef0597e97d4d08d6de71100ec745 /core
parenteea8d6aa96a2fe2e6f06354e6bfdfcf20b1c5b3b (diff)
downloaddexon-801a13f7915840c3a74e3bcfd51cc83f00f4899c.tar
dexon-801a13f7915840c3a74e3bcfd51cc83f00f4899c.tar.gz
dexon-801a13f7915840c3a74e3bcfd51cc83f00f4899c.tar.bz2
dexon-801a13f7915840c3a74e3bcfd51cc83f00f4899c.tar.lz
dexon-801a13f7915840c3a74e3bcfd51cc83f00f4899c.tar.xz
dexon-801a13f7915840c3a74e3bcfd51cc83f00f4899c.tar.zst
dexon-801a13f7915840c3a74e3bcfd51cc83f00f4899c.zip
core: fixed unwinding bad hash (#3347)
Fixed unwinding of bad hashes when already on the canon chain
Diffstat (limited to 'core')
-rw-r--r--core/blockchain.go11
1 files changed, 8 insertions, 3 deletions
diff --git a/core/blockchain.go b/core/blockchain.go
index 9ace6d79a..2eb207d39 100644
--- a/core/blockchain.go
+++ b/core/blockchain.go
@@ -152,9 +152,14 @@ func NewBlockChain(chainDb ethdb.Database, config *params.ChainConfig, pow pow.P
// Check the current state of the block hashes and make sure that we do not have any of the bad blocks in our chain
for hash, _ := range BadHashes {
if header := bc.GetHeaderByHash(hash); header != nil {
- glog.V(logger.Error).Infof("Found bad hash, rewinding chain to block #%d [%x…]", header.Number, header.ParentHash[:4])
- bc.SetHead(header.Number.Uint64() - 1)
- glog.V(logger.Error).Infoln("Chain rewind was successful, resuming normal operation")
+ // get the canonical block corresponding to the offending header's number
+ headerByNumber := bc.GetHeaderByNumber(header.Number.Uint64())
+ // make sure the headerByNumber (if present) is in our current canonical chain
+ if headerByNumber != nil && headerByNumber.Hash() == header.Hash() {
+ glog.V(logger.Error).Infof("Found bad hash, rewinding chain to block #%d [%x…]", header.Number, header.ParentHash[:4])
+ bc.SetHead(header.Number.Uint64() - 1)
+ glog.V(logger.Error).Infoln("Chain rewind was successful, resuming normal operation")
+ }
}
}
// Take ownership of this particular state