Skip to content

Commit

Permalink
core: fix initialization from freezer
Browse files Browse the repository at this point in the history
Blockchain initialization from a kv-destroyed
but freezer-ok databases failed.

The two problems were:
- bc.empty was returning a false-negative
when the database had no KV full/fast/head block
data
- bc.loadLastState -> Reset -> SetHead were
endlessly looping, or panicing (because SetHead)
does not tolerate CurrentBlock() returning nil.

Signed-off-by: meows <[email protected]>
  • Loading branch information
meowsbits committed Aug 27, 2020
1 parent df0126c commit 7269a17
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, chainConfig ctyp
if frozen > 0 {
txIndexBlock = frozen
}
bc.writeHeadBlock(bc.genesisBlock)
}
if err := bc.loadLastState(); err != nil {
return nil, err
Expand Down Expand Up @@ -374,8 +375,11 @@ func (bc *BlockChain) GetVMConfig() *vm.Config {
// into node seamlessly.
func (bc *BlockChain) empty() bool {
genesis := bc.genesisBlock.Hash()
for _, hash := range []common.Hash{rawdb.ReadHeadBlockHash(bc.db), rawdb.ReadHeadHeaderHash(bc.db), rawdb.ReadHeadFastBlockHash(bc.db)} {
if hash != genesis {
for _, hash := range []common.Hash{
rawdb.ReadHeadBlockHash(bc.db),
rawdb.ReadHeadHeaderHash(bc.db),
rawdb.ReadHeadFastBlockHash(bc.db)} {
if hash != (common.Hash{}) && hash != genesis {
return false
}
}
Expand Down

0 comments on commit 7269a17

Please sign in to comment.