aboutsummaryrefslogtreecommitdiffstats
path: root/cmd/geth/main.go
diff options
context:
space:
mode:
authorBas van Kervel <basvankervel@ziggo.nl>2015-04-13 16:13:52 +0800
committerBas van Kervel <basvankervel@ziggo.nl>2015-04-13 16:13:52 +0800
commit49a513bdebd7c4402b3a7f2f169a31c34f2ca9df (patch)
tree2cb976e970a8aa757ce31ee867970cf3d53ad15c /cmd/geth/main.go
parent4de1e1609abb2e5be7e5cc5b8f206d305af8ce27 (diff)
downloaddexon-49a513bdebd7c4402b3a7f2f169a31c34f2ca9df.tar.gz
dexon-49a513bdebd7c4402b3a7f2f169a31c34f2ca9df.tar.zst
dexon-49a513bdebd7c4402b3a7f2f169a31c34f2ca9df.zip
Added blockchain DB versioning support, closes #650
Diffstat (limited to 'cmd/geth/main.go')
-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 4853a16fc..ba8bb6450 100644
--- a/cmd/geth/main.go
+++ b/cmd/geth/main.go
@@ -34,11 +34,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"
)
const (
@@ -205,12 +207,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,
@@ -429,13 +437,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
}
@@ -443,9 +467,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)
}
@@ -453,6 +486,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() {