aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeffrey Wilcke <jeffrey@ethereum.org>2015-07-01 18:57:13 +0800
committerJeffrey Wilcke <jeffrey@ethereum.org>2015-07-01 18:57:13 +0800
commitbb418a43c1b9ebf9a32006652b405f8e1cb3acd2 (patch)
tree379d6ecbefce1d317ca2646a072cfa6879890dbe
parent2e5242f9bbbf8412fa5b6e94da942e69570d860d (diff)
parent29ab1fa8a50db8aa16c5d707f1cab7dc201a4053 (diff)
downloaddexon-bb418a43c1b9ebf9a32006652b405f8e1cb3acd2.tar
dexon-bb418a43c1b9ebf9a32006652b405f8e1cb3acd2.tar.gz
dexon-bb418a43c1b9ebf9a32006652b405f8e1cb3acd2.tar.bz2
dexon-bb418a43c1b9ebf9a32006652b405f8e1cb3acd2.tar.lz
dexon-bb418a43c1b9ebf9a32006652b405f8e1cb3acd2.tar.xz
dexon-bb418a43c1b9ebf9a32006652b405f8e1cb3acd2.tar.zst
dexon-bb418a43c1b9ebf9a32006652b405f8e1cb3acd2.zip
Merge pull request #1370 from obscuren/force-checkpoint
core, cmd/geth: recover by number
-rw-r--r--cmd/geth/main.go24
-rw-r--r--core/chain_manager.go12
2 files changed, 34 insertions, 2 deletions
diff --git a/cmd/geth/main.go b/cmd/geth/main.go
index c46343a60..a7d3a73ef 100644
--- a/cmd/geth/main.go
+++ b/cmd/geth/main.go
@@ -39,6 +39,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/logger"
+ "github.com/ethereum/go-ethereum/logger/glog"
"github.com/ethereum/go-ethereum/metrics"
"github.com/ethereum/go-ethereum/rpc/codec"
"github.com/ethereum/go-ethereum/rpc/comms"
@@ -68,6 +69,15 @@ func init() {
app.Action = run
app.HideVersion = true // we have a command to print the version
app.Commands = []cli.Command{
+ {
+ Action: blockRecovery,
+ Name: "recover",
+ Usage: "attempts to recover a corrupted database by setting a new block head by number",
+ Description: `
+The recover commands will attempt to read out the last
+block based on that.
+`,
+ },
blocktestCommand,
importCommand,
exportCommand,
@@ -439,6 +449,20 @@ func unlockAccount(ctx *cli.Context, am *accounts.Manager, account string) (pass
return
}
+func blockRecovery(ctx *cli.Context) {
+ num := ctx.Args().First()
+ if len(ctx.Args()) < 1 {
+ glog.Fatal("recover requires block number")
+ }
+
+ cfg := utils.MakeEthConfig(ClientIdentifier, nodeNameVersion, ctx)
+ ethereum, err := eth.New(cfg)
+ if err != nil {
+ utils.Fatalf("%v", err)
+ }
+ ethereum.ChainManager().Recover(common.String2Big(num).Uint64())
+}
+
func startEth(ctx *cli.Context, eth *eth.Ethereum) {
// Start Ethereum itself
diff --git a/core/chain_manager.go b/core/chain_manager.go
index cdbdeb5ae..a7b57b26b 100644
--- a/core/chain_manager.go
+++ b/core/chain_manager.go
@@ -238,6 +238,16 @@ func (self *ChainManager) setTransState(statedb *state.StateDB) {
self.transState = statedb
}
+func (bc *ChainManager) Recover(num uint64) {
+ block := bc.GetBlockByNumber(num)
+ if block != nil {
+ bc.insert(block)
+ glog.Infof("Recovery succesful. New HEAD %x\n", block.Hash())
+ } else {
+ glog.Fatalln("Recovery failed")
+ }
+}
+
func (bc *ChainManager) recover() bool {
data, _ := bc.blockDb.Get([]byte("checkpoint"))
if len(data) != 0 {
@@ -261,8 +271,6 @@ func (bc *ChainManager) setLastState() {
if len(data) != 0 {
block := bc.GetBlock(common.BytesToHash(data))
if block != nil {
- bc.blockDb.Put([]byte("checkpoint"), block.Hash().Bytes())
-
bc.currentBlock = block
bc.lastBlockHash = block.Hash()
} else {