core, light: add unlock before Reset to avoid double lock

This commit is contained in:
BurtonQin 2020-02-12 17:16:49 +08:00
parent 34bb132b10
commit 1d7ee903e5
2 changed files with 6 additions and 0 deletions

View file

@ -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

View file

@ -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)