aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-05-26 21:35:51 +0800
committerobscuren <geffobscura@gmail.com>2015-05-26 21:35:51 +0800
commiteae092759760341912dcc52d8287642b62abf889 (patch)
tree12e8662b2bf3a4a5aae7509f79a54e8b9325738a /core
parentd74ee40c86fed3a48d88de1094efc0a2f464b659 (diff)
downloaddexon-eae092759760341912dcc52d8287642b62abf889.tar
dexon-eae092759760341912dcc52d8287642b62abf889.tar.gz
dexon-eae092759760341912dcc52d8287642b62abf889.tar.bz2
dexon-eae092759760341912dcc52d8287642b62abf889.tar.lz
dexon-eae092759760341912dcc52d8287642b62abf889.tar.xz
dexon-eae092759760341912dcc52d8287642b62abf889.tar.zst
dexon-eae092759760341912dcc52d8287642b62abf889.zip
core: prevent crash when last block fails
Diffstat (limited to 'core')
-rw-r--r--core/chain_manager.go22
1 files changed, 16 insertions, 6 deletions
diff --git a/core/chain_manager.go b/core/chain_manager.go
index 4fb7506e5..2b86bb794 100644
--- a/core/chain_manager.go
+++ b/core/chain_manager.go
@@ -5,6 +5,7 @@ import (
"fmt"
"io"
"math/big"
+ "os"
"runtime"
"sync"
"time"
@@ -233,14 +234,23 @@ func (bc *ChainManager) setLastState() {
data, _ := bc.blockDb.Get([]byte("LastBlock"))
if len(data) != 0 {
block := bc.GetBlock(common.BytesToHash(data))
- bc.currentBlock = block
- bc.lastBlockHash = block.Hash()
-
- // Set the last know difficulty (might be 0x0 as initial value, Genesis)
- bc.td = common.BigD(bc.blockDb.LastKnownTD())
+ if block != nil {
+ bc.currentBlock = block
+ bc.lastBlockHash = block.Hash()
+ } else { // TODO CLEAN THIS UP TMP CODE
+ block = bc.GetBlockByNumber(400000)
+ if block == nil {
+ fmt.Println("Fatal. LastBlock not found. Report this issue")
+ os.Exit(1)
+ }
+ bc.currentBlock = block
+ bc.lastBlockHash = block.Hash()
+ bc.insert(block)
+ }
} else {
bc.Reset()
}
+ bc.td = bc.currentBlock.Td
bc.currentGasLimit = CalcGasLimit(bc.currentBlock)
if glog.V(logger.Info) {
@@ -471,7 +481,7 @@ func (self *ChainManager) GetAncestors(block *types.Block, length int) (blocks [
}
func (bc *ChainManager) setTotalDifficulty(td *big.Int) {
- bc.blockDb.Put([]byte("LTD"), td.Bytes())
+ //bc.blockDb.Put([]byte("LTD"), td.Bytes())
bc.td = td
}