Skip to content

Commit 801a13f

Browse files
authored
core: fixed unwinding bad hash (#3347)
Fixed unwinding of bad hashes when already on the canon chain
1 parent eea8d6a commit 801a13f

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

core/blockchain.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,14 @@ func NewBlockChain(chainDb ethdb.Database, config *params.ChainConfig, pow pow.P
152152
// Check the current state of the block hashes and make sure that we do not have any of the bad blocks in our chain
153153
for hash, _ := range BadHashes {
154154
if header := bc.GetHeaderByHash(hash); header != nil {
155-
glog.V(logger.Error).Infof("Found bad hash, rewinding chain to block #%d [%x…]", header.Number, header.ParentHash[:4])
156-
bc.SetHead(header.Number.Uint64() - 1)
157-
glog.V(logger.Error).Infoln("Chain rewind was successful, resuming normal operation")
155+
// get the canonical block corresponding to the offending header's number
156+
headerByNumber := bc.GetHeaderByNumber(header.Number.Uint64())
157+
// make sure the headerByNumber (if present) is in our current canonical chain
158+
if headerByNumber != nil && headerByNumber.Hash() == header.Hash() {
159+
glog.V(logger.Error).Infof("Found bad hash, rewinding chain to block #%d [%x…]", header.Number, header.ParentHash[:4])
160+
bc.SetHead(header.Number.Uint64() - 1)
161+
glog.V(logger.Error).Infoln("Chain rewind was successful, resuming normal operation")
162+
}
158163
}
159164
}
160165
// Take ownership of this particular state

0 commit comments

Comments
 (0)