aboutsummaryrefslogtreecommitdiffstats
path: root/cmd/geth
diff options
context:
space:
mode:
authorJeffrey Wilcke <jeffrey@ethereum.org>2015-04-13 23:34:34 +0800
committerJeffrey Wilcke <jeffrey@ethereum.org>2015-04-13 23:34:34 +0800
commit5f9346bc7afd64706b3815aec6be2b2650929a6b (patch)
treeff02f1f4f36246e2431b43207f2400b49417e051 /cmd/geth
parentad4891a09a4f7c7fa3e77c5370c01f16a0a3070e (diff)
parent49a513bdebd7c4402b3a7f2f169a31c34f2ca9df (diff)
downloaddexon-5f9346bc7afd64706b3815aec6be2b2650929a6b.tar
dexon-5f9346bc7afd64706b3815aec6be2b2650929a6b.tar.gz
dexon-5f9346bc7afd64706b3815aec6be2b2650929a6b.tar.bz2
dexon-5f9346bc7afd64706b3815aec6be2b2650929a6b.tar.lz
dexon-5f9346bc7afd64706b3815aec6be2b2650929a6b.tar.xz
dexon-5f9346bc7afd64706b3815aec6be2b2650929a6b.tar.zst
dexon-5f9346bc7afd64706b3815aec6be2b2650929a6b.zip
Merge pull request #700 from bas-vk/issue_650
Added blockchain DB versioning support, closes #650
Diffstat (limited to 'cmd/geth')
-rw-r--r--cmd/geth/main.go95
1 files changed, 91 insertions, 4 deletions
diff --git a/cmd/geth/main.go b/cmd/geth/main.go
index 9e5ae5857..e18b92a2e 100644
--- a/cmd/geth/main.go
+++ b/cmd/geth/main.go
@@ -36,11 +36,13 @@ 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/state"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/logger"
"github.com/peterh/liner"
+ "path"
)
import _ "net/http/pprof"
@@ -208,12 +210,18 @@ JavaScript API. See https://github.com/ethereum/go-ethereum/wiki/Javascipt-Conso
Name: "export",
Usage: `export blockchain into file`,
},
+ {
+ Action: upgradeDb,
+ Name: "upgradedb",
+ Usage: "upgrade chainblock database",
+ },
}
app.Flags = []cli.Flag{
utils.UnlockedAccountFlag,
utils.PasswordFileFlag,
utils.BootnodesFlag,
utils.DataDirFlag,
+ utils.BlockchainVersionFlag,
utils.JSpathFlag,
utils.ListenPortFlag,
utils.MaxPeersFlag,
@@ -437,13 +445,29 @@ func importchain(ctx *cli.Context) {
if len(ctx.Args()) != 1 {
utils.Fatalf("This command requires an argument.")
}
- chainmgr, _, _ := utils.GetChain(ctx)
+
+ cfg := utils.MakeEthConfig(ClientIdentifier, Version, ctx)
+ cfg.SkipBcVersionCheck = true
+
+ ethereum, err := eth.New(cfg)
+ if err != nil {
+ utils.Fatalf("%v\n", err)
+ }
+
+ chainmgr := ethereum.ChainManager()
start := time.Now()
- err := utils.ImportChain(chainmgr, ctx.Args().First())
+ err = utils.ImportChain(chainmgr, ctx.Args().First())
if err != nil {
utils.Fatalf("Import error: %v\n", err)
}
+
+ // force database flush
+ ethereum.BlockDb().Close()
+ ethereum.StateDb().Close()
+ ethereum.ExtraDb().Close()
+
fmt.Printf("Import done in %v", time.Since(start))
+
return
}
@@ -451,9 +475,18 @@ func exportchain(ctx *cli.Context) {
if len(ctx.Args()) != 1 {
utils.Fatalf("This command requires an argument.")
}
- chainmgr, _, _ := utils.GetChain(ctx)
+
+ cfg := utils.MakeEthConfig(ClientIdentifier, Version, ctx)
+ cfg.SkipBcVersionCheck = true
+
+ ethereum, err := eth.New(cfg)
+ if err != nil {
+ utils.Fatalf("%v\n", err)
+ }
+
+ chainmgr := ethereum.ChainManager()
start := time.Now()
- err := utils.ExportChain(chainmgr, ctx.Args().First())
+ err = utils.ExportChain(chainmgr, ctx.Args().First())
if err != nil {
utils.Fatalf("Export error: %v\n", err)
}
@@ -461,6 +494,60 @@ func exportchain(ctx *cli.Context) {
return
}
+func upgradeDb(ctx *cli.Context) {
+ fmt.Println("Upgrade blockchain DB")
+
+ cfg := utils.MakeEthConfig(ClientIdentifier, Version, ctx)
+ cfg.SkipBcVersionCheck = true
+
+ ethereum, err := eth.New(cfg)
+ if err != nil {
+ utils.Fatalf("%v\n", err)
+ }
+
+ v, _ := ethereum.BlockDb().Get([]byte("BlockchainVersion"))
+ bcVersion := int(common.NewValue(v).Uint())
+
+ if bcVersion == 0 {
+ bcVersion = core.BlockChainVersion
+ }
+
+ filename := fmt.Sprintf("blockchain_%d_%s.chain", bcVersion, time.Now().Format("2006-01-02_15:04:05"))
+ exportFile := path.Join(ctx.GlobalString(utils.DataDirFlag.Name), filename)
+
+ err = utils.ExportChain(ethereum.ChainManager(), exportFile)
+ if err != nil {
+ utils.Fatalf("Unable to export chain for reimport %s\n", err)
+ }
+
+ ethereum.BlockDb().Close()
+ ethereum.StateDb().Close()
+ ethereum.ExtraDb().Close()
+
+ os.RemoveAll(path.Join(ctx.GlobalString(utils.DataDirFlag.Name), "blockchain"))
+
+ ethereum, err = eth.New(cfg)
+ if err != nil {
+ utils.Fatalf("%v\n", err)
+ }
+
+ ethereum.BlockDb().Put([]byte("BlockchainVersion"), common.NewValue(core.BlockChainVersion).Bytes())
+
+ err = utils.ImportChain(ethereum.ChainManager(), exportFile)
+ if err != nil {
+ utils.Fatalf("Import error %v (a backup is made in %s, use the import command to import it)\n", err, exportFile)
+ }
+
+ // force database flush
+ ethereum.BlockDb().Close()
+ ethereum.StateDb().Close()
+ ethereum.ExtraDb().Close()
+
+ os.Remove(exportFile)
+
+ fmt.Println("Import finished")
+}
+
func dump(ctx *cli.Context) {
chainmgr, _, stateDb := utils.GetChain(ctx)
for _, arg := range ctx.Args() {