aboutsummaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'cmd')
-rw-r--r--cmd/evm/main.go6
-rw-r--r--cmd/geth/main.go46
2 files changed, 49 insertions, 3 deletions
diff --git a/cmd/evm/main.go b/cmd/evm/main.go
index 7c9d27fac..f6ec8c21e 100644
--- a/cmd/evm/main.go
+++ b/cmd/evm/main.go
@@ -106,7 +106,7 @@ type VMEnv struct {
depth int
Gas *big.Int
- time int64
+ time uint64
logs []vm.StructLog
}
@@ -115,7 +115,7 @@ func NewEnv(state *state.StateDB, transactor common.Address, value *big.Int) *VM
state: state,
transactor: &transactor,
value: value,
- time: time.Now().Unix(),
+ time: uint64(time.Now().Unix()),
}
}
@@ -123,7 +123,7 @@ func (self *VMEnv) State() *state.StateDB { return self.state }
func (self *VMEnv) Origin() common.Address { return *self.transactor }
func (self *VMEnv) BlockNumber() *big.Int { return common.Big0 }
func (self *VMEnv) Coinbase() common.Address { return *self.transactor }
-func (self *VMEnv) Time() int64 { return self.time }
+func (self *VMEnv) Time() uint64 { return self.time }
func (self *VMEnv) Difficulty() *big.Int { return common.Big1 }
func (self *VMEnv) BlockHash() []byte { return make([]byte, 32) }
func (self *VMEnv) Value() *big.Int { return self.value }
diff --git a/cmd/geth/main.go b/cmd/geth/main.go
index a7b769270..be40d5137 100644
--- a/cmd/geth/main.go
+++ b/cmd/geth/main.go
@@ -37,8 +37,12 @@ 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"
"github.com/ethereum/go-ethereum/rpc/codec"
"github.com/ethereum/go-ethereum/rpc/comms"
@@ -68,6 +72,18 @@ 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 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,
importCommand,
exportCommand,
@@ -438,6 +454,36 @@ func unlockAccount(ctx *cli.Context, am *accounts.Manager, account string) (pass
return
}
+func blockRecovery(ctx *cli.Context) {
+ 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)
+ blockDb, err := ethdb.NewLDBDatabase(filepath.Join(cfg.DataDir, "blockchain"))
+ if err != nil {
+ 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)
+ }
+ glog.Infof("Recovery succesful. New HEAD %x\n", block.Hash())
+}
+
func startEth(ctx *cli.Context, eth *eth.Ethereum) {
// Start Ethereum itself