diff options
author | Jeffrey Wilcke <jeffrey@ethereum.org> | 2015-07-01 23:09:33 +0800 |
---|---|---|
committer | Jeffrey Wilcke <jeffrey@ethereum.org> | 2015-07-01 23:09:33 +0800 |
commit | 507869bff10adab3d4f183aeaf3ef31715041046 (patch) | |
tree | 3b21c721577d80e93d78a437c2dda908790ea977 /cmd | |
parent | bb418a43c1b9ebf9a32006652b405f8e1cb3acd2 (diff) | |
parent | 70d5d791cc695cff3b3448a1b4b47816a8bbd83f (diff) | |
download | go-tangerine-507869bff10adab3d4f183aeaf3ef31715041046.tar go-tangerine-507869bff10adab3d4f183aeaf3ef31715041046.tar.gz go-tangerine-507869bff10adab3d4f183aeaf3ef31715041046.tar.bz2 go-tangerine-507869bff10adab3d4f183aeaf3ef31715041046.tar.lz go-tangerine-507869bff10adab3d4f183aeaf3ef31715041046.tar.xz go-tangerine-507869bff10adab3d4f183aeaf3ef31715041046.tar.zst go-tangerine-507869bff10adab3d4f183aeaf3ef31715041046.zip |
Merge pull request #1373 from obscuren/recovery-tools
core, cmd/geth: improved recover functionality
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/geth/main.go | 36 |
1 files changed, 29 insertions, 7 deletions
diff --git a/cmd/geth/main.go b/cmd/geth/main.go index a7d3a73ef..645f51b9a 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -37,7 +37,10 @@ import ( "github.com/ethereum/go-ethereum/accounts" "github.com/ethereum/go-ethereum/cmd/utils" "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core" + "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/eth" + "github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/logger" "github.com/ethereum/go-ethereum/logger/glog" "github.com/ethereum/go-ethereum/metrics" @@ -72,10 +75,13 @@ func init() { { Action: blockRecovery, Name: "recover", - Usage: "attempts to recover a corrupted database by setting a new block head by number", + Usage: "attempts to recover a corrupted database by setting a new block by number or hash. See help recover.", Description: ` The recover commands will attempt to read out the last block based on that. + +recover #number recovers by number +recover <hex> recovers by hash `, }, blocktestCommand, @@ -450,17 +456,33 @@ func unlockAccount(ctx *cli.Context, am *accounts.Manager, account string) (pass } func blockRecovery(ctx *cli.Context) { - num := ctx.Args().First() - if len(ctx.Args()) < 1 { - glog.Fatal("recover requires block number") + arg := ctx.Args().First() + if len(ctx.Args()) < 1 && len(arg) > 0 { + glog.Fatal("recover requires block number or hash") } cfg := utils.MakeEthConfig(ClientIdentifier, nodeNameVersion, ctx) - ethereum, err := eth.New(cfg) + blockDb, err := ethdb.NewLDBDatabase(filepath.Join(cfg.DataDir, "blockchain")) if err != nil { - utils.Fatalf("%v", err) + glog.Fatalln("could not open db:", err) + } + + var block *types.Block + if arg[0] == '#' { + block = core.GetBlockByNumber(blockDb, common.String2Big(arg[1:]).Uint64()) + } else { + block = core.GetBlockByHash(blockDb, common.HexToHash(arg)) + } + + if block == nil { + glog.Fatalln("block not found. Recovery failed") + } + + err = core.WriteHead(blockDb, block) + if err != nil { + glog.Fatalln("block write err", err) } - ethereum.ChainManager().Recover(common.String2Big(num).Uint64()) + glog.Infof("Recovery succesful. New HEAD %x\n", block.Hash()) } func startEth(ctx *cli.Context, eth *eth.Ethereum) { |