From 1d7ee903e5d5330b6fc1384e715a393b7c6ae5db Mon Sep 17 00:00:00 2001 From: BurtonQin Date: Wed, 12 Feb 2020 17:16:49 +0800 Subject: [PATCH] core, light: add unlock before Reset to avoid double lock --- core/blockchain.go | 4 ++++ light/lightchain.go | 2 ++ 2 files changed, 6 insertions(+) diff --git a/core/blockchain.go b/core/blockchain.go index f083f53e04..590e05e0a8 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -329,6 +329,8 @@ func (bc *BlockChain) loadLastState() error { if head == (common.Hash{}) { // Corrupt or empty database, init from scratch log.Warn("Empty database, resetting chain") + bc.chainmu.Unlock() + defer bc.chainmu.Lock() return bc.Reset() } // Make sure the entire head block is available @@ -336,6 +338,8 @@ func (bc *BlockChain) loadLastState() error { if currentBlock == nil { // Corrupt or empty database, init from scratch log.Warn("Head block missing, resetting chain", "hash", head) + bc.chainmu.Unlock() + defer bc.chainmu.Lock() return bc.Reset() } // Make sure the state associated with the block is available diff --git a/light/lightchain.go b/light/lightchain.go index 636e06f518..88bea4fead 100644 --- a/light/lightchain.go +++ b/light/lightchain.go @@ -153,7 +153,9 @@ func (lc *LightChain) HeaderChain() *core.HeaderChain { func (lc *LightChain) loadLastState() error { if head := rawdb.ReadHeadHeaderHash(lc.chainDb); head == (common.Hash{}) { // Corrupt or empty database, init from scratch + lc.chainmu.Unlock() lc.Reset() + lc.chainmu.Lock() } else { if header := lc.GetHeaderByHash(head); header != nil { lc.hc.SetCurrentHeader(header)